Skip to content

Support any accelerator in activation offloading - #7670

Merged
qgallouedec merged 3 commits into
mainfrom
activation-offloading-any-accelerator
Oct 14, 2026
Merged

qgallouedec merged 3 commits into
mainfrom
activation-offloading-any-accelerator

Conversation

@qgallouedec

@qgallouedec qgallouedec commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Resolves #7662

OffloadActivations used torch.cuda for every accelerator other than XPU/NPU, so it crashed on Trainium. It now uses torch.get_device_module (25 fewer lines). The offloading tests pass on H100. On Trainium the losses are identical, and Qwen3-0.6B SFT without gradient checkpointing trains instead of running out of memory.

cc @michaelbenayoun


Note

Medium Risk
Changes core stream/sync/offload paths for all accelerators; behavior should match prior CUDA/XPU/NPU logic but any get_device_module gap could affect training stability on less-tested hardware.

Overview
OffloadActivations now routes accelerator-specific work through torch.get_device_module instead of hard-coded CUDA/XPU/NPU branches, so devices like Trainium no longer incorrectly call CUDA APIs.

After resolving the current accelerator type, the manager caches device_module and uses it for comm streams, stream contexts, current_stream, empty_cache, and the “already on CPU / skip offload” device check (compare against accelerator_type instead of a fixed device list). NPU-only storage refcount paths are unchanged.

Reviewed by Cursor Bugbot for commit a31d468. Bugbot is set up for automated code reviews on this repo. Configure here.

Use the generic device module (`torch.get_device_module`) for the side stream, stream contexts, current stream and cache, instead of special-casing XPU and NPU and falling back to `torch.cuda` for everything else. Offload activations on the current accelerator, whatever its type.

Resolves #7662
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T03:51:00.782069Z e199ad9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@bot-ci-comment

Copy link
Copy Markdown

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e199ad92ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread trl/models/activation_offloading.py
@qgallouedec
qgallouedec requested a review from kashif October 13, 2026 05:12

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a31d468. Configure here.

Comment thread trl/models/activation_offloading.py
@qgallouedec
qgallouedec merged commit 7d4250c into main Oct 14, 2026
10 checks passed
@qgallouedec
qgallouedec deleted the activation-offloading-any-accelerator branch October 14, 2026 16:01
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.

activation_offloading=True crashes on Trainium: torch.cuda.Stream is used for every non-XPU/NPU accelerator

2 participants