Skip to content

Conversation

zilongzheng
Copy link
Contributor

What does this PR do?

This PR extends the OffloadActivations context manager to enable activation offloading on Intel XPU and Huawei NPU devices, in addition to the existing CUDA support.

The key changes include:

  • Detecting the current accelerator type (xpu, npu, or cuda).
  • Using the correct device-specific PyTorch APIs for creating and managing streams (e.g., torch.npu.Stream, torch.xpu.current_stream).
  • Resolving a TypeError on non-CUDA devices by using the proper stream context managers (torch.npu.stream and torch.xpu.stream) instead of attempting to use the raw stream object.

This allows users on NPU and XPU hardware to leverage the memory savings provided by activation offloading, improving their ability to train larger models.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
          Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link
          to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
    • Reused test_activation_offloading.py on ascend npu devices.

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@qgallouedec
Copy link
Member

Thanks! I cannot test myself but LGTM!

@qgallouedec qgallouedec requested a review from kashif September 11, 2025 23:39
@qgallouedec
Copy link
Member

@kashif I let you merge if it looks good to you

@qgallouedec qgallouedec changed the title feat: Add NPU and XPU support for activation offloading ℹ️ feat: Add NPU and XPU support for activation offloading Sep 18, 2025
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@qgallouedec qgallouedec merged commit a6c0c57 into huggingface:main Sep 18, 2025
7 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants