Repository navigation
DDP: upload to the Hub from rank 0 only - #17868
Conversation
Under plain DDP every rank ran model.push_to_hub, and save_pretrained / zoo save_lora with push_to_hub = True, so each rank made its own commits to the repo. Every rank holds the same weights, so rank 0 alone uploads (no rendezvous, as tokenizer pushes under tensor parallel); local saves still run on every rank and FSDP2's collective save is unchanged.
Codex Review Summary: ✅ CompletedThis 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4be016e9de
ℹ️ 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".
| if fsdp2_units(model): | ||
| return False | ||
| return method == "push_to_hub" or bool( |
There was a problem hiding this comment.
Exclude FSDP1 models from the rank-zero-only upload path
When a model contains FSDP1 FullyShardedDataParallel children, this predicate still identifies it as plain DDP because fsdp2_units() only recognizes FSDP2. Calling save_pretrained(push_to_hub=True) without a supplied state dict then skips saving on nonzero ranks, while rank 0 enters the FSDP1 state-dict hooks and waits for their all-gather collectives. An all-rank save that previously completed can therefore hang or time out. Exclude FSDP1-managed models as well before applying the rank-zero-only shortcut.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in the latest commit: a model containing an FSDP1 FullyShardedDataParallel module now keeps the all-rank save, since its state dict hooks all-gather. New test test_fsdp1_models_keep_the_all_rank_save checks that plain DDP still takes the rank-0 path and FSDP1 does not.
…ct hooks all-gather [skip ci]
|
@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]
…oding in test_bind_local_cuda_device (#17892) ## Summary Two repo-wide reds on `main`, both from test files added in the last few merges: 1. `tests/test_ci_repo_cpu_shards.py::TestEveryTestFileLandsInExactlyOneShard::test_no_file_is_dropped_or_run_twice` (`Repo tests (CPU, rest)`): - #17862 added `tests/test_tokenizer_save_ddp_gloo.py`. No shard collects it: `gloo` takes `test_[!fpt]*gloo*`, and `rest` ignores `test_[!f]*gloo*`. It never runs in CI. - #17868 added `tests/test_ddp_push_rank0_gloo.py`. Both `gloo` (`test_[!fpt]*gloo*`) and `rest-2` (`test_[dimsu]*.py`) collect it, so it runs twice, and in `rest-2` without the gloo shard's setup. 2. `tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding` (`Repo tests (CPU, rest-2)`): #17867's `tests/test_bind_local_cuda_device.py:47` reads `unsloth/__init__.py` with `read_text()` and no encoding. Both new files are correct tests. They only needed a shard home and an explicit encoding. ## Changes - `.github/workflows/studio-backend-ci.yml`: - `gloo` gains `tests/test_t[!p]*gloo*.py`, which covers `test_tokenizer_*`. `test_tp_*` keeps its existing split between `gloo` and `gloo-tp`. - `rest-2` gains `--ignore-glob=tests/test_[dimsu]*gloo*.py`, so a gloo file starting with d/i/m/s/u runs only in `gloo`. - The comment that listed `test_t[!p]*` as an unclaimed name is updated. - `tests/test_bind_local_cuda_device.py`: `read_text(encoding = "utf-8")`. ## Verification `tests/test_ci_repo_cpu_shards.py tests/test_source_read_encoding.py tests/test_bind_local_cuda_device.py`: 38 passed. Removing either workflow line brings back the matching failure: ``` these files are collected by more than one shard: [('tests/test_ddp_push_rank0_gloo.py', ['gloo', 'rest-2'])] these files are collected by no shard, so Repo tests (CPU) no longer runs them: ['tests/test_tokenizer_save_ddp_gloo.py'] ```
…on without Triton, kernel and test gates (unslothai#17882) Backend CI on main has been red since today's merges. Every failure traces to one commit; this fixes the unsloth side (the gloo-cp shard also needs unslothai/unsloth-zoo#2542, since CI installs zoo from main). | CI shard / test | Cause | Fix | |---|---|---| | gloo: `test_qwen4exp_parallel_matches_one_process[pp*]`, `test_pp_splits_streams_and_runs_the_mixer_last`, all of `test_frozen_table_pp_gloo.py` | unslothai#17785: transformers 5.17 (the CI pin) names the Qwen4Exp layer type `qwen_sparse_attention`, 5.22 renamed it `indexed_attention`; pipeline parallel only accepted the new name, so every rank raised "hybrid layer stacks" | accept both names in `_PP_HYBRID_FAMILIES` | | diffusion (Python 3.13): 13 tests in `test_diffusion_int8_attention_triton_device.py` | unslothai#17855: `_launch` read `triton.runtime` while `triton` is `None` on that shard | check `triton is not None` first | | rest: `test_every_constexpr_line_has_a_comment` | unslothai#17860: 23 uncommented `tl.constexpr` parameters in `large_head_attention.py` | comments added; `_tma_tile`'s signature split one parameter per line | | rest: `test_every_launch_requests_fp_fusion` | unslothai#17860: the `_launch` helper forwards `enable_fp_fusion` from every caller, but the gate did not know it is a helper | registered like `layernorm.py`'s | | rest: `test_no_file_is_dropped_or_run_twice` | unslothai#17868: `tests/test_ddp_push_rank0_gloo.py` matched both the gloo shard and rest-2's `test_[dimsu]*.py` | renamed `tests/test_hub_push_rank0_ddp_gloo.py` | | rest-2: `test_checked_in_file_reads_name_an_encoding` | unslothai#17867: `read_text()` without an encoding in `tests/test_bind_local_cuda_device.py` | `encoding = "utf-8"` | | rest-2: `test_sentence_transformer_trainer_checks_the_placement_before_the_deferred_compile[*]` | unslothai#17859: `patch_train_dataloader` assumed every trainer class has `get_train_dataloader` | skip the patch when the method is missing | | rest-2: `test_router_aux_loss_gradient_survives_unsloth_checkpointing[*]` | unslothai#17873: the gpu-marked test still runs under CI's `-m 'not server and not e2e'` | `has_real_accelerator()` skip next to the gpu mark | | studio: `test_no_skip_guard_reads_a_spoofable_accelerator_probe` | unslothai#17850: `test_block_cudagraphs_side_grad.py` skipped on `torch.cuda.is_available()`, which the CUDA spoof fakes | skip on `has_real_cuda()` | ## Tests In a venv matching CI (Python 3.12, torch 2.10.0+cpu, transformers 5.17.0, TRL 1.15, PEFT 0.21.3, `UNSLOTH_COMPILE_DISABLE=1`, `-m 'not server and not e2e'`): - gloo: `test_qwen4exp_parallel_gloo.py` failed on main, 9 / 9 pass here; `test_frozen_table_pp_gloo.py` 13 / 13. - rest / rest-2 / studio: the nine affected files had exactly CI's 9 failures on main; 153 passed / 6 skipped here. - diffusion: with Triton blocked (as on the Python 3.13 shard), the 13 failures pass here; with Triton present everything passes. The only non-test code changes are the PP layer-type name, the Triton `None` check and the Sentence Transformers method check; `large_head_attention.py` changes are comments only.
Under plain DDP,
model.push_to_hubandsave_pretrained(push_to_hub = True)uploaded from every rank, creating duplicate Hub commits. zoo'ssave_lora(push_to_hub = True)goes through the same path.These calls now go through the existing
tp_world_push: rank 0 uploads, and the other ranks do not wait on a rendezvous. TP tokenizers already use this path.tests/test_ddp_push_rank0_gloo.py(2-rank gloo CPU): on main, rank 1 also runs both uploads; with this PR only rank 0 does.test_tp_world_save_dirs_gloo.pyandsaving/test_peft_base_export_guard.pypass.push_to_hub_mergedandpush_to_hub_ggufunder DDP still upload from every rank, because they sit behind different decorators.