Repository navigation
Run each FlashAdamW update on its parameter's CUDA device - #14773
Conversation
FlashOptim launches its Triton kernels on the current CUDA device. With a model split across GPUs by device_map, parameters on another GPU then fail with 'Pointer argument cannot be accessed from Triton' when peer access is unavailable. Enter torch.cuda.device(p.device) around each CUDA parameter update; CPU and other devices are unchanged.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
pre-commit.ci fails `ruff-format-with-kwargs` on every open PR (#14806, #14805, #14803, #14790, #14785, #14781, #14780, #14777, #14776, #14775, #14774, #14773, #14772, #14770, #14769, #14768, and others): "files were modified by this hook". pre-commit.ci runs the hooks on all files, and 20 files on main (26 by the time this lands) are not in the formatter's output, so every PR is reformatted outside its own diff. Where pre-commit.ci can push, its autofix commit drags those unrelated files into the PR (for example #14790's touches `tests/test_block_compile.py`, `tests/test_bnb_integration_compile.py` and `unsloth/models/_utils.py`). The drift came in with PRs merged today, among them #14702, #14751, #14759, #14784, #14786, #14787, #14788, #14791 and the FP8 block decode, GRPO routing replay, 4-bit decode, compiled blocks and MoE LoRA target changes. ### Change `python scripts/run_ruff_format.py` (the hook's own entry point, `ruff==0.6.9` as pinned in `.pre-commit-config.yaml`) applied to those 20 files, plus 6 more from #14739, #14779 and #14806, which merged while this was open. Formatting only. ### Verification - Every changed file parses to an identical AST before and after. - A second run of the hook over the same files changes nothing (fixed point), and over all tracked Python files on this branch it changes nothing. - `ruff check` passes on the changed files; `tests/test_formatter_fixed_point.py` passes (16). Open PRs pick this up on their next pre-commit.ci run after merging main.
# Conflicts: # tests/utils/test_flash_adamw_optim.py
compress_state_dict=False dequantizes the moments in state_dict() and requantizes them on load, both through Triton kernels that launch on the current device. Route step_param, _state_dict_for_param and _load_state_for_param through one device guard. [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
[skip ci]
optim = "adamw_flash" delegates every parameter update to FlashOptim, whose Triton
kernels launch on the current CUDA device. With a model split across GPUs through
device_map (for example the documented "balanced"), parameters on a GPU other than
the current one are then updated from the wrong device. Without peer access between
the GPUs this fails with "Pointer argument cannot be accessed from Triton".
Reach: multi GPU device_map training with optim = "adamw_flash". Single GPU training
and DDP / FSDP (one device per process) are unaffected.
Fix: UnslothFlashAdamW.step_param runs each update for a CUDA parameter inside
torch.cuda.device(p.device). FlashOptim's step() calls step_param for every parameter
and gradient release calls it directly, so both paths are covered. The context only
switches the current device and restores the caller's afterwards; CPU and other
devices go through the unchanged path.
Tests:
the current device at each update and checks that every CUDA parameter is updated
with its own device current, the CPU parameter enters no device context, and the
caller's device is restored. It fails on main and passes with this change.
updates of parameters on cuda:0 and cuda:1 from one optimizer must match, bit for
bit, the same updates run with each device made current explicitly (fp32 and bf16
unquantized, bf16 and fp16 quantized, through step() and step_param()). Skips
without two GPUs.
Not covered here: the two GPU test was not run on this host (one GPU per job); the device mismatch it reproduces was shown on two B200s (parameter on cuda:1 with cuda:0 current: "Pointer argument cannot be accessed from Triton" before, bit-identical updates after).