Repository navigation
Studio: read lookup tables lazily when needed to enable the MoE cache - #16444
Merged
danielhanchen merged 4 commits intoNov 2, 2026
Merged
Conversation
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. |
Member
Author
|
Reached Codex review convergence at oobabooga#443. |
danielhanchen
added a commit
that referenced
this pull request
Nov 2, 2026
## Summary `Repo tests (CPU, gloo-tp-pp)` failed on #16444 and #16451 in `tests/test_pp_env_gloo.py`, which #16407 added. Neither PR touches pipeline parallel. Both failures are the same case, with an identical value: ``` test_pp_env_gradient_accumulation_and_microbatches[gemma3_ga1_bs4] base_model.model.model.layers.0.mlp.gate_proj.lora_A.weight: Tensor-likes are not close! Mismatched elements: 1 / 64 (1.6%) Greatest absolute difference: 1.5791505575180054e-05 at index (2, 2) (up to 1e-05 allowed) ``` The identical value means the result depends on the runner's CPU, not on chance, so any run that lands on that runner type fails. The adapter comparison runs after several optimizer steps, so it carries the fp32 reduction-order noise of a 2-stage split against the single-process reference. The file already records that noise for the grad norms ("3e-5 absolute ... between two identical reference runs"). On this host, the largest adapter difference across all five cases of the test is 3.7e-6, which is why 1e-5 looked safe. ## Change `tests/test_pp_env_gloo.py`: in `test_pp_env_gradient_accumulation_and_microbatches` only, the trained-adapter comparison takes `atol = 5e-5`, about 3x the CI value. `rtol` is unchanged, and so is every other `_same_tensors` call: save_pretrained, Trainer.save_model and export. The `_close` call just before it is also unchanged. It pins the step count and every loss at rel 1e-5. It pins the first grad norm at rel 1e-5 and the rest at 1e-4. ## Testing - `tests/test_pp_env_gloo.py`: 14 passed, 1 skipped. - Sabotage: I temporarily scaled every `lora_A` by `1 + 1e-4` in the pipeline-parallel ranks only. `[ga1_bs4]` and `[gemma3_ga1_bs4]` both still fail, as they do at `1 + 1e-3`. So a real divergence much smaller than any pipeline bug would be still fails the test.
danielhanchen
added a commit
that referenced
this pull request
Nov 2, 2026
…ard (#16447) ## Summary Since #16407, `Repo tests (CPU, gloo)` sits right at its step cap. On main (`9341351954`) it ran 1922 s of the 2100 s cap. On #16444, against the same base, it hit the cap and was killed (`exit code 124`) after 145 of its 153 tests had passed. #16407 grew `tests/test_parallel_cp_compose_gloo.py` to 27 tests. I timed the shard per file locally (`-n 4 --dist loadgroup --durations=0`, the CI selection). That one file takes 1143 of the shard's 3605 test-seconds, about a third: | File | test-seconds | share | |---|---|---| | `test_parallel_cp_compose_gloo.py` | 1143 | 31.7% | | `test_tp_env_gloo.py` | 796 | 22.1% | | `test_tp_replica_gloo.py` | 533 | 14.8% | | `test_tp_full_finetune_gloo.py` | 429 | 11.9% | | the other 12 files | 704 | 19.5% | `gloo-tp-pp` cannot absorb it, because it already runs 1397 s on main. The file also cannot run four tests at a time on its own. Each test spawns 2 to 8 gloo ranks. In this PR's first two runs of a dedicated shard at `-n 4`, the runner was shut down mid-run both times (`The runner has received a shutdown signal`, exit 143). Measured locally as summed PSS over the pytest process tree, the peak is: | workers | peak memory | local wall time | |---|---|---| | 4 | about 20 GB | 291 s | | 2 | about 12 GB | 440 s | A hosted runner has 16 GB. In the mixed `gloo` shard, the file's tests were interleaved with lighter ones, so they rarely overlapped four at a time. ## Change `.github/workflows/studio-backend-ci.yml`: - New `gloo-cp` shard: `tests/test_parallel_c*gloo*.py`, with `workers: 2`. - The repo-cpu pytest command reads `-n ${{ matrix.workers || 4 }}`, so every other shard keeps `-n 4`. - The `gloo` shard's `tests/test_p[!p]*gloo*.py` becomes `tests/test_parallel_[!c]*gloo*.py`. Its other globs are unchanged. - Comments record why the split and the worker count exist. They also note that a future `*gloo*` file named `test_p[!ap]*` would match no shard; `tests/test_ci_repo_cpu_shards.py` reports that as a dropped file. `tests/studio/test_backend_ci_parallel_isolation.py`: - Its command scan substitutes each shard's `workers` (or the expression's default), the way it already substitutes `selection`. Before that, its existing "no unexpanded `${{`" assertion caught the new expression. - The pinned counts move from 11 to 12 parallel runs, and from 8 to 9 repo-root shards. ## Testing - With main (now including #16446) merged in, these pass (176 passed): - `tests/test_ci_repo_cpu_shards.py` - `tests/test_ci_backend_pytest_shards.py` - `tests/studio/test_backend_ci_parallel_isolation.py` - `tests/test_rendezvous_port_everywhere.py` - `tests/studio/test_cache_budget_discipline.py` - `tests/test_parallel_cp_compose_gloo.py` at `-n 2`: 23 passed, 3 skipped. - A first attempt, `test_p[!ap]*gloo*.py`, matched no file, and the guard's unexpanded-pattern check caught it. Hence the explicit `test_parallel_` globs.
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.
Problem
Qwen3.8-Flash-Next UD-IQ4_XS on a host with 94 GiB of RAM and a 48 GB card launches without llama.cpp's MoE cache, so decode runs the overflowing layers' experts on the CPU through the
--fitsplit:Root cause
The lookup-table decision runs first and keeps the 26.8 GB
per_layer_token_embdtable resident whenever RAM covers it beside the weights. The MoE cache gate then charges that table, the 55.4 GB of pinned experts and the prompt cache to host RAM, and the sum does not fit. Nothing reconsiders the table decision, although llama.cpp can read the table lazily under--load-mode nonetoo, which frees the RAM the experts need.Fix
When the cache gate fails only because Unsloth's own
--lazy-mode offkeeps the table resident, the gate prices the launch again with the table read lazily. If the pinned experts and the prompt cache fit,--lazy-mode offis dropped at the point where--moe-cache-mib autois actually added, after the effective loader and fitter checks, so a launch that ends up without the cache keeps its resident table. The load mode staysnone, so the experts stay pinned.New log line on that path (it follows the earlier table decision's line, which it reverses):
Behavior boundaries
--lazy-modeor--load-mode(per-model setting, extra argument or env) is untouched. A user's mmap keeps the cache off and the resident table.kcompactd) used about one core.Measurements
Qwen3.8-Flash-Next UD-IQ4_XS with the separate MTP drafter, RTX 6000 Ada 48 GB, i9-14900K, 94 GiB RAM. Studio Auto with the context set to 32768, greedy, thinking off, one request at a time. Before is
0455cae42c, after is this change on top of it; the two were launched alternately, and each figure is the median of 4 requests.--load-modenonenone--lazy-modeoff--moe-cache-mibauto--parallel 4 -c 32768 --ubatch-size 2048 --spec-type draft-mtpDecode, tokens/s:
Prompt reads, tokens/s:
Available RAM after the load: 26.2 to 32.7 GiB before, 25.0 to 26.1 GiB after.
Verification
test_a_resident_table_that_crowds_out_the_pinned_experts_is_read_lazily_for_the_cache: the cache path with a lazy table, plus the ample-RAM and short-RAM cases. Fails on the base commit.test_a_user_mmap_keeps_the_resident_table_when_the_cache_stays_off: mmap from the per-model setting, extra arguments andLLAMA_ARG_LOAD_MODEkeeps--lazy-mode offand no cache. Fails if the flag is dropped at the RAM gate instead of where the cache is added.tests/test_llama_weight_placement.py,tests/test_lookup_table_fit.pyandtests/test_llama_cpp_placement.py: 717 passed on681111a2e2.681111a2e2; the patches are identical and none of the commits in between touch the lookup-table, load-mode or MoE cache code.