Repository navigation
Studio: batch MoE fine-tuning jobs with per-job expert LoRA - #15809
Conversation
…skips only that job's step
[skip ci]
…brid # Conflicts: # studio/backend/tests/test_multi_lora_trainer.py
…rt multi-LoRA kernels
…the single job does [skip ci]
…adapters in the graph [skip ci]
# Conflicts: # studio/backend/tests/test_multi_lora_trainer.py
… folded experts rank-major [skip ci]
…r; pack with the single job's worker count [skip ci]
# Conflicts: # studio/backend/tests/test_multi_lora_trainer.py
…ps documents apart [skip ci]
…udio-ft-batch-moe-hybrid
…ybrid # Conflicts: # studio/backend/core/training/multi_lora_trainer.py # studio/backend/tests/test_multi_lora_trainer.py
…dio-ft-batch-moe-hybrid
…dio-ft-batch-moe-hybrid
…eights itself [skip ci]
…dio-ft-batch-moe-hybrid
…dio-ft-batch-moe-hybrid
…ybrid # Conflicts: # studio/backend/core/training/multi_lora_trainer.py # studio/backend/tests/test_multi_lora_trainer.py
…ybrid # Conflicts: # unsloth/kernels/multi_lora.py
|
@codex review |
1 similar comment
|
@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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8921aaa296
ℹ️ 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".
| expert_targets = _expert_targets(model, _lone_target_modules(config.get("target_modules"))) | ||
| if expert_targets: | ||
| from unsloth.kernels.multi_lora import inject_multi_lora_experts | ||
| inject_multi_lora_experts( |
There was a problem hiding this comment.
Allow expert-only targets before requiring dense LoRA layers
For a Qwen3 MoE job targeting only gate_up_proj (or only gate_proj/up_proj on its fused-expert layout), there are no matching dense Linear modules. The unconditional inject_multi_lora() call above therefore raises ValueError: No linear layers named ... found before this expert injection is reached. These requests previously trained individually through get_moe_target_parameters(), but _moe_batches() now admits them to batching, so otherwise valid queued jobs fail simply because another matching job is present. Resolve expert targets first and permit an expert-only adapter without requiring a dense injection, or keep these requests on the single-job path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 1089103: expert targets are resolved first, and when the requested names match no dense layer but do match fused experts (e.g. only gate_up_proj), the batch trains the expert LoRA alone, as the single job does; the saved adapter config keeps the requested target_modules. New test: an expert-only target trains batched and saves only expert tensors, all trained.
|
|
||
| def _routed_modules(model): | ||
| """The modules a forward calls: dense LoRA layers and expert containers (their stacks are not modules).""" | ||
| from unsloth.kernels.multi_lora import MultiLoraExperts, MultiLoraLinear |
There was a problem hiding this comment.
Preserve dense batching without the expert kernel installed
When Studio uses an installed Unsloth that has dense multi-LoRA kernels but predates expert support, _multi_lora_available() still enables dense batching and _multi_lora_experts_available() only excludes MoE jobs. However, _check_routed() now unconditionally calls this helper, whose import of MultiLoraExperts fails on that installation, causing every dense batch to error after loading and tokenizing. Keep the expert class optional for dense jobs, or update the batching capability check so such installations fall back to individual training.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 1089103: the routing check now takes MultiLoraExperts only when the installed kernel has it, so an Unsloth that predates expert support keeps batching dense jobs (MoE jobs are already routed alone there by _multi_lora_experts_available). New test runs the check against a kernel module with only MultiLoraLinear; it failed with the ImportError before.
…out expert support [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]
Queued LoRA / QLoRA fine-tuning jobs on fused-expert MoE models (Qwen3 MoE, Qwen3.5 / Qwen3.6 MoE such as Qwen3.6-35B-A3B) now batch together like dense models, with each job's expert LoRA on its own adapter through the expert multi-LoRA kernel from #15742. Until now every MoE job trained alone.
What batches:
qwen3_moe,qwen3_5_moeandqwen3_5_moe_texton transformers 5.x (expert-only targets such as justgate_up_projincluded), where their experts are fused stacks that Unsloth Zoo's MoE forward reads LoRA for. Each job gets the expert LoRA its single run gets: the same PEFTtarget_parameters(fromget_moe_target_parameters), the same per-expert init (fan-in over the input dimension, as PEFT inits its(E*r, in)matrix) and the same rank and alpha. Its saved adapter is the PEFTtarget_parametersadapter the single run saves.Tests (CPU,
studio/backend/tests/test_multi_lora_trainer.py,test_openai_fine_tuning.py): a batched MoE member's losses, gradients and saved adapter (dense and expert LoRA) match its single run and do not move with its neighbour; every expertlora_Btrains; MoE layouts and configs outside the list, router aux loss and SSM mixers are routed to train alone. 128 pass.GPU, through the OpenAI-compatible API on a fresh
install.sh --localStudio (tiny Qwen3.6 MoE,trl-internal-testing/tiny-Qwen3_5MoeForConditionalGeneration-3.6; a job trained alone, then the same job batched beside another while a third holds the GPU; 16 documents, 20 steps):On a T4 (fp16, each job with its own loss scale): 4-bit step 1 12.3861 / 12.3861, step 20 12.1697 / 12.1669; 16-bit step 1 12.3844 / 12.3844, step 20 12.1696 / 12.1679; learning rate identical every step, no skipped steps.
Every run trained all 20 steps on the same 8240 tokens, and the same with packing off. Step 1 gradient norms differ (0.64 alone, 0.55 batched) while the step 1 losses match: a batched member draws its LoRA A from its own seed (the same Kaiming distribution PEFT uses, independent of batch order, as dense members already do since #15344), so the random A differs from the single run's draw and with it the first gradient; the saved adapters hold the same tensors with norms within 5%.
Expert kernel tests (
tests/test_multi_lora_experts.py, from #15742) pass on an L4 inside each of Studio's transformers environments.