Repository navigation
MoE grouped GEMM: share autotuners across identical cards; fix the TMA test on one-GPU hosts and macOS - #14490
Conversation
…ssigned configs; fix TMA test on one-GPU hosts and the macOS triton stub
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 |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
## Problem Five checks fail on main, so the `Repo tests (CPU, studio)`, `Repo tests (CPU, rest)` and `workflow-trigger lint` shards are red on every open PR (for example #14472, #14482, #14488, #14490 and #14494). All five reproduce on main `4d7ebf5cea`. | Test | Introduced by | Fault | |---|---|---| | `tests/security/test_lint_risky_loaders.py::test_the_tree_matches_the_baseline` | #14437 | Baseline. Two new dynamic-import sites: `import_module` in `studio/backend/core/rag/embeddings.py`, and a third `import_from_string` in `unsloth/models/sentence_transformer.py` (`_require_word_tokenizer`). Both are safe, see below. | | `tests/studio/test_tauri_branding_contract.py::test_desktop_surfaces_do_not_restore_studio_branding` | #14473 | Product. "Studio" became "Unsloth Studio" in the Markdown import errors and the Tauri webview reject message. The desktop contract allows "Unsloth" there, never "Unsloth Studio". "Unsloth" meets both #14473's rule (no bare "Studio") and this one. | | `tests/studio/test_usage_examples_model_source_contract.py::test_auto_switch_section_sits_above_the_usage_examples` | #14455 | Test. The redesign moved the usage examples above the monitor link on purpose, and its own `api-settings-tab.test.ts` pins that. | | `tests/studio/test_usage_examples_model_source_contract.py::test_monitor_can_unload_the_loaded_model` | #14455 | Test. Unloading moved from a standalone button on the page into the model picker's eject (`ApiModelLoadControls`). The `/unload` path itself is unchanged. | | `tests/studio/test_settings_compact_overflow_contract.py::test_api_monitor_entries_and_expanded_text_can_shrink` | #14455 | Test. Entry rows are now rounded cards (no `border-b`), and the prompt/reply box's `rounded-lg` became conditional, so the class literals the test matched are gone. The overflow guards themselves are still in the source. | ## Fix - **Risky loaders:** two baseline entries with reasons. - `embeddings.py` imports only the three `sentence_transformers.models` paths written out in a literal tuple, to wrap their `import_from_string` with the trust gate. - `_require_word_tokenizer` imports only after its caller has refused any `tokenizer_class` outside `sentence_transformers.*`, and only dotted identifiers. - **Branding:** "Unsloth Studio" to "Unsloth" in those seven Markdown import errors and the Rust reject message. `conversation-markdown-import.test.ts` now matches `/Unsloth Markdown/`. - **#14455 contracts:** rewritten to guard what the redesign keeps: - the auto-switch section still follows the monitor link, and the usage examples come before both; - the page passes `unloadActiveModel` to the load controls as `onUnloadActive`, and eject is withheld while `busy` (`modelLoading || unloading`, #11223's rule); - the `/unload` call still reads the internal id from status; - entry rows keep `w-full min-w-0`; - the prompt/reply box keeps `max-h-72 overflow-auto break-words`; - the model id keeps `min-w-0 break-all`. ## Verification - The four Python files: 78 passed (5 failed on main). - `studio/frontend/tests/conversation-markdown-import.test.ts`: 20 passed. - Sabotage, each run against the rewritten tests, each failing exactly one test: - removing `min-w-0` from the entry row, or `break-words` from the text box: the overflow test fails; - dropping `unloading` from `busy`, or passing `onEject` while busy: the unload test fails; - putting the auto-switch section above the monitor link: the order test fails.
…ds share the results cache [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a5d182d412
ℹ️ 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 tuner is None: | ||
| tuner = copy.copy(kernel) | ||
| tuner.cache = {} | ||
| tuner.cache = _MODEL_AUTOTUNE_CACHES.setdefault((id(kernel), _device_model(device)), {}) |
There was a problem hiding this comment.
Serialize cold misses in the shared autotune cache
When identical devices encounter an unseen shape concurrently—as can happen in the per-device autograd threads mentioned here—each tuner can observe the shared cache key as absent before either inserts it. Both tuners then benchmark the complete configuration set, defeating the intended tune-once behavior, and the concurrent load can skew the timings and make the last writer's potentially suboptimal result win. The shared cache needs per-model/key single-flight synchronization rather than only a shared dictionary.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e671c69: copies on one card model now run under a per-model lock, so a second card that misses the same shape waits and then reads the first card's result. With the real Triton 3.6 autotuner and two concurrent identical cards: one shape benchmarks once (2 runs, was 4 on main), distinct shapes still tune once each, no errors. test_identical_cards_tune_a_cold_shape_once.
…ingle flight) [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
# Conflicts: # unsloth/kernels/moe/grouped_gemm/interface.py [skip ci]
… again (#14544) `pre-commit.ci` is red on every PR opened or pushed since #14490 merged (#14510, #14515, #14543 so far), and it cannot push its autofix ("a conflict occurred when applying fixes to the pr"). #14490 landed `_run_single_flight(*args, _run = run, _lock = lock, **kwargs)` in `unsloth/kernels/moe/grouped_gemm/interface.py` on one line, which is not what `ruff-format-with-kwargs` produces, and pre-commit.ci runs the hook over all files. Running the hook over all 4525 tracked Python files on main changes only this one signature. This PR is that formatter output and nothing else. It is a fixed point: running the hook again leaves it unchanged. ## Testing - `tests/test_formatter_fixed_point.py` on main: fails, naming `unsloth/kernels/moe/grouped_gemm/interface.py`. - Same test on this branch: 16 passed.
…ount once per card (unslothai#14605) ## Summary Follow-up to unslothai#14490 from a post-merge review. unslothai#14490 wrapped every grouped GEMM autotuner launch on a multi-GPU host in a per-GPU-model lock, so identical cards would tune a new shape once. The lock was also held on cache hits: every launch paid it (about 0.5 us more per call), and a cold shape being tuned on one card blocked already-tuned launches on an identical card until the benchmark finished. ## What changes - **No lock.** Per-card tuner copies still share one results cache per GPU model, so a shape tuned on one card is reused by every identical card. A cached launch never waits on another card. Two identical cards hitting the same cold shape at the same instant may both tune it, which is what every multi-GPU host did before unslothai#14490. - **SM count read once per card.** The forward, dX and dW launchers called `torch.cuda.get_device_properties(...)` on every launch (three per MoE layer per step); it is now cached per device index, since it cannot change within a process. Single-GPU hosts are unchanged (they never used the per-card copies). ## Tests - `tests/test_grouped_gemm_mixed_tma_device.py`: `test_identical_cards_launch_concurrently` (two cached launches on identical cards must be inside `run` at once; main fails with `BrokenBarrierError` because the lock serializes them) and `test_sm_count_is_read_once_per_card` (fails on main). The shared-cache, separate-model and configs-follow tests still pass. - MoE CPU suites (11 files): main 225 passed / 48 skipped, this branch 226 / 48 (one new test), 0 failures on both. - B200, base and head interleaved: forward, dX and dW with autotune off and on give the identical output hash on every run. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Summary
Follow-up to #14358 from a post-merge regression review. Three problems, all fixed here.
What changes
device_map="auto"over identical cards) re-ran autotuning on every card. Each card still gets its own tuner object (Triton keeps per-run state such asnargson it, and backward runs one autograd thread per device, so a shared object races), but copies on the same card model (name, compute capability, SM count) now share one results cache. Different models or MIG sizes stay separate, a single GPU still uses the kernel itself, and each copy follows a reassignedkernel.configs. Checked with the real Triton 3.6 autotuner: two concurrent cold-key calls on identical cards raiseTypeErrorwith one shared tuner and pass here.test_launches_are_guarded_on_the_operands_devicefailed on any single-GPU CUDA host withCUDA error: invalid device ordinal:FakeTensorModeinitialised a realcuda:1context. The test now stubstorch._subclasses.fake_tensor.init_gpu_context, so no real context opens.make_tensor_descriptordid not hide it. The module now skips whentritonis that stub.Not changed
One older visible card still turns TMA off process-wide (the flag is precomputed to avoid graph breaks, and the default autotune configs already disable TMA).
Tests
tests/test_grouped_gemm_mixed_tma_device.py: 18 passed; 2 fail against main's source.invalid device ordinal, this branch passes all 18.