Repository navigation
Refuse accelerate config cp_size under Unsloth SFT, not only TrainingArguments - #15212
Merged
Merged
Conversation
…Arguments accelerate launch with parallelism_config_cp_size builds the Accelerator's ParallelismConfig from the environment, so TrainingArguments.parallelism_config stays None and the existing cp_size check passed. accelerate's ring then ran over Unsloth's model. Check the accelerator's config as well and point to SFTConfig(context_parallel_size = N).
Member
Author
|
@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. You're on a roll. 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". |
danielhanchen
added a commit
that referenced
this pull request
Oct 25, 2026
…5239) ## Summary `Source lint` is red on main, and so on every PR (for example #15212 and #15217). The step that fails is `Duplicate definitions (whole tree)`: ``` tests/test_fp8_torchao_import_route.py:13: has_real_cuda is imported twice from the same module (first at line 11) ``` #15211 and c993bf3 (skip the QAT MX and FP8 block GEMM GPU cases on the recorded real CUDA) landed the same `from real_accelerator import has_real_cuda` fix 18 minutes apart. Their import lines sit at different spots, so git merged both without a conflict and left the name bound twice. `scripts/lint_duplicate_definitions.py` exists to catch exactly this merge damage. ## Change - Drop the second import. Nothing else in the file changes. ## Verification - `python scripts/lint_duplicate_definitions.py tests/test_fp8_torchao_import_route.py`: on main `duplicate definitions (1)` with exit 1. With this change: `clean: 1 file(s) checked` and exit 0. - `tests/test_fp8_torchao_import_route.py` and `tests/python/test_accelerator_skip_guards.py`: `52 passed, 1 skipped`.
danielhanchen
added a commit
that referenced
this pull request
Oct 25, 2026
…ranks (#15250) ## Summary `tests/test_float8_training_fsdp2_gloo.py::test_float8_linear_trains_under_native_fsdp2` fails in the `Repo tests (CPU, rest)` shard on unrelated PRs (#15212, #15217, #15218) and passes when run on its own: ``` Mismatched elements: 1 / 4: Max relative difference: 6.84e-05 Index | Obtained | Expected 3 | 5.603824138641357 | 5.603440761566162 ± 5.6e-05 ``` The sharded run is the correct one. Training the same unsharded fp8 model in a clean process gives `5.603824139` at step 4, and the result is identical with 1, 2, 4 and 8 threads. The value that moved is the reference. The test trained it inside the pytest worker, so it inherited whatever earlier tests in the shard had left in that process, while the two gloo ranks start fresh under `spawn`. The tolerance is fine. The two sides were simply not run under the same conditions. ## Change - The unsharded reference trains in its own spawned process (`_reference_worker`, `nprocs = 1`), so both sides of the comparison start from a clean interpreter. The tolerance is unchanged (`rel = 1e-5, abs = 1e-6`). - The JSON reads and both writes name `encoding = "utf-8"`. ## Verification - `tests/test_float8_training_fsdp2_gloo.py`: passes, and the clean reference matches the sharded losses exactly. - Sabotage 1 (the CI failure): a pytest plugin that changes only the parent process (scales `F.cross_entropy` by `1 + 1e-4`, which `spawn` children do not inherit). The old test fails with `Max relative difference: 2.0e-04`. The new test passes. - Sabotage 2 (the guard still bites): scaling the sharded ranks' losses by `1 + 1e-4` makes the new test fail. I did not pin down which earlier test leaves the state behind. With this change, the comparison no longer depends on it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TRL's long context recipe turns on context parallelism through the accelerate config:
accelerate launchexportsACCELERATE_USE_PARALLELISM_CONFIG=trueandPARALLELISM_CONFIG_CP_SIZE, and the Accelerator builds itsParallelismConfigfrom them.TrainingArguments.parallelism_configstaysNone, so the existing check in the SFTTrainer patch (which only readsargs.parallelism_config) let it through. transformers then wraps every step inaccelerator.maybe_context_paralleland shards the inputs over Unsloth's model, which Unsloth does not support.This change also checks
trainer.accelerator.parallelism_config.cp_sizeand raises the same error, pointing atSFTConfig(context_parallel_size = N).Behaviour
TrainingArguments(parallelism_config = ParallelismConfig(cp_size = 2))parallelism_config_cp_size: 2(env)SFTTrainer.__init__UNSLOTH_FSDP2=1(native) with either of the aboveSFTConfig(context_parallel_size = 2)Tests
test_accelerate_config_cp_size_is_refused[1, 2]intests/test_context_parallel.py: fails on main for cp_size 2, passes here; cp_size 1 still builds.SFTTrainerwith the accelerate env set: main reaches the training step and fails inside torch's CP dispatcher (aten._scaled_dot_product_flash_attention_for_cpuhas no sharding rule), which shows the ring was engaged; with this change it stops at__init__with the message above.tests/test_context_parallel*.py,tests/test_ulysses*.py: 142 passed on main, 144 passed here (the 2 new cases).