Repository navigation
[recipes] Muse Glimmer SLAKE LoRA SFT recipes: LoRA decoder, LoRA vision + decoder - #5904
Conversation
…ion + decoder
## Summary (human-written)
Add Muse Glimmer SLAKE LoRA SFT recipes.
## Why
There is no recipe to fine-tune Muse Glimmer 30B on medical VQA. The Muse Spark SLAKE LoRA recipes exist in torchtitan_recipes/sft/slake.py, but their data path (messages, dataset, packing, validation) is written for the Spark renderer and dataloader.
**Example.**
```
from torchtitan_recipes.sft.slake import muse_glimmer_30b_slake_lora_vision_decoder_sft
config = muse_glimmer_30b_slake_lora_vision_decoder_sft()
# 4 GB300, FSDP 4, no remat, 4K packed sequences, 90 steps
# trainable: LoRA adapters on the decoder and on the vision encoder, adapter and projection
```
## What changed
- Add muse_glimmer_30b_slake_lora_decoder_sft and muse_glimmer_30b_slake_lora_vision_decoder_sft to torchtitan_recipes/sft/slake.py, next to the Spark SLAKE recipes. They mirror the Spark SLAKE recipes: English SLAKE, image in the user turn, the LLaVA 1.5 short-answer prompt, loss on the answer only, packed rows, validation at step 1 and every 10 steps, TensorBoard, LoRA rank 8 / alpha 16, AdamW lr 1e-4 with 10 warmup steps and cosine decay, 32 x 4096 tokens per step, CUDA graphs off.
- Glimmer specifics: flavor 30B_mm, the released Glimmer special tokens (MultiModalTokenizer), the in-tree MuseGlimmerRenderer with reasoning_strength="low", and the released image processor (MUSE_GLIMMER_30B_VISION_PROCESSOR_KWARGS: closest-aspect patch grid, LANCZOS). The Glimmer chat template always renders a "Current date" line, so the recipe pins current_date to keep the prompt the same every day. The Glimmer renderer trains only the answer and <|eot|>; the "to=user" header is a prompt token.
- Layout: dense 30B, FSDP 4 on one node of 4 GB300 GPUs, TP=CP=PP=1. dtype float32 with frozen weights stored in bf16 (the default precision config) and varlen attention from the muse_glimmer_30b base recipe. Activation remat is off: peak 116 GiB of 276.6 GiB per GPU, about 28% faster than full remat.
- LoRA targets: decoder wqkv, wo, o_gate, w13, w2 (Glimmer names); vision targets are the same NaViT list as Spark, conv1_linear stays frozen.
- Data numbers, measured on CPU with this recipe's data path and the released tokenizer: shortest English sample 142 tokens (so max_images_per_microbatch = 4096 // 142 = 28), longest 1476. At DP 4 each rank packs 46 to 53 English validation microbatches (196 in total), so validation runs 53 steps, the largest per-rank count; ranks with fewer microbatches wrap around. One pass over English train is 859 microbatches at DP 4, or 26.8 steps. Training runs 90 steps (about 3.4 passes), set from the validation-loss runs below.
- Env vars: MUSE_GLIMMER_HF_ASSETS_PATH (default ./assets/hf/Muse-Glimmer-30B) and MUSE_GLIMMER_SLAKE_PATH (default ./assets/datasets/slake).
- Mechanical, inside slake.py: the private SLAKE data helpers become model-agnostic and both models share them. _slake_dataset takes the renderer, and _use_slake_sft_data takes the dataloader and sets packing, max images per microbatch and the validator. The Spark-only part (vision-only modality, Spark image processor, renderer, dataloader) moves into _use_muse_spark_slake_sft_data. The per-model numbers (shortest sample, validation steps) depend on the chat format, so they are per-model constants. The decoder LoRA targets depend on module names: Glimmer's are a constant in slake.py and Spark's are MUSE_SPARK_LORA_DECODER_TARGETS; _slake_lora_transform takes the decoder targets. The Spark-only part of the answer-prompt comment stays next to the Spark renderer. The Glimmer recipes use the SLAKE LoRA optimizer that the Spark recipes use (same values as before).
- The Glimmer recipes reuse muse_glimmer_30b from torchtitan_recipes/models/muse_glimmer.py; that module is unchanged.
- MUSE_GLIMMER_30B_SPECIAL_TOKENS and MUSE_GLIMMER_30B_VISION_PROCESSOR_KWARGS come from torchtitan/models/muse_glimmer/flavors.py.
## User-facing changes
| Before | After |
| --- | --- |
| No Glimmer SLAKE recipes | torchtitan_recipes.sft.slake: muse_glimmer_30b_slake_{lora_decoder,lora_vision_decoder}_sft |
| - | MUSE_GLIMMER_HF_ASSETS_PATH and MUSE_GLIMMER_SLAKE_PATH env vars |
## Numerics
No change to existing recipes. Both Spark SLAKE recipes, the Spark UltraData LoRA recipe and the other Muse Spark and Muse Glimmer recipes build the same config before and after (--print-config compared, ignoring function object addresses). The Glimmer recipes are new and have no baseline.
## Testing
- test_slake_lora_trainable_split (tests/unit_tests/cpu/recipes/test_slake.py) covers the Glimmer variants on debugmodel_mm, with the Spark checks: the adapted decoder modules are exactly the Glimmer decoder targets. It catches a renamed module, since LoRA only warns on unmatched targets (for example o_gate on Glimmer vs output_gate on Spark).
- LoRA + HF state dict on CPU: the Glimmer adapter maps every base weight of the LoRA vision + decoder model to HF and back with equal values and skips the adapters.
- `python -m torchtitan.train --module torchtitan_recipes.sft.slake --config <recipe> --print-config` passes for both Glimmer SLAKE recipes and both Spark SLAKE recipes; --print-config also passes for muse_glimmer_30b and the muse_glimmer_30b_mm test recipe.
- CPU tests: components/data, components/test_renderer.py, models/muse_spark, models/muse_glimmer, config and recipes: 669 passed, 1 skipped, 3 xfailed; RL CPU tests 534 passed, 9 skipped (test_dapo_math and test_vllm_wrapper skipped: attn_gym.mla is not installed locally).
- GPU, LoRA vision + decoder from the released HF checkpoint on 4 GB300, through a recipe not in this PR that only changes the step count, remat and checkpoint saving:
- Job 2389895, 90 steps, full remat: validation loss 2.73 at step 1 -> 0.169 at step 90, still falling slowly. 13.9 s per step.
- Job 2390442, 150 steps, no remat: validation loss flattens after step 70 and moves between 0.16 and 0.20 (0.157 at step 100, 0.185 at step 150) while training loss keeps falling, so it overfits past about 3 passes. 10.0 s per step, peak 116 GiB of 276.6 GiB per GPU, no OOM.
- Job 2390757, this commit's recipe as is (90 steps, no remat; only checkpoint saving off; 49 validation steps): validation loss 2.739 at step 1, 0.322 at step 30, 0.200 at step 60 and 0.179 at step 90 (lowest); training loss 2.580 -> 0.107. grad_norm max 29.3 at step 1 and below 23 after warmup; the 150-step run's spikes (422 at step 76, 237 at step 144) did not recur. 10.1 s per step, 3,267 tokens/s per GPU, MFU 27.2%, peak 116.2 GiB of 276.6 GiB per GPU, no errors and no FSDP view warning.
- Job 2526742, the LoRA decoder recipe as is (90 steps; only checkpoint saving off; 53 validation steps): validation loss 2.732 at step 1, 0.319 at step 30, 0.202 at step 60 and 0.164 at step 90 (lowest); training loss 2.580 -> 0.080. grad_norm max 14.3. 6.3 s per step, 5,221 tokens/s per GPU, MFU 43.4%, peak 74.5 GiB of 276.6 GiB per GPU, no errors.
- The FSDP2 "returned a view tensor" warning in the full-remat run comes from the view_as boundary of torch_remat; it is absent without remat.
## Known issues / follow-ups
- The SLAKE train/test leak TODO from the Spark recipe applies here too (it lives in _slake_dataset).
stack-info: PR: #5904, branch: fegin/stack/25
…ion + decoder
## Summary (human-written)
Add Muse Glimmer SLAKE LoRA SFT recipes.
## Why
There is no recipe to fine-tune Muse Glimmer 30B on medical VQA. The Muse Spark SLAKE LoRA recipes exist, but their data path (messages, dataset, packing, validation) lives in the Spark recipe module as private helpers, so a Glimmer recipe cannot reuse it.
**Example.**
```
config = muse_glimmer_30b_slake_lora_vision_decoder_sft()
# 4 GB300, FSDP 4, no remat, 4K packed sequences, 90 steps
# trainable: LoRA adapters on the decoder and on the vision encoder, adapter and projection
```
## What changed
- Add muse_glimmer_30b_slake_lora_decoder_sft and muse_glimmer_30b_slake_lora_vision_decoder_sft. They mirror the Spark SLAKE recipes: English SLAKE, image in the user turn, the LLaVA 1.5 short-answer prompt, loss on the answer only, packed rows, validation at step 1 and every 10 steps, TensorBoard, LoRA rank 8 / alpha 16, AdamW lr 1e-4 with 10 warmup steps and cosine decay, 32 x 4096 tokens per step, CUDA graphs off.
- Glimmer specifics: flavor 30B_mm, the released Glimmer special tokens (MultiModalTokenizer), the in-tree MuseGlimmerRenderer with reasoning_strength="low", and the released image processor (closest-aspect patch grid, LANCZOS). The Glimmer chat template always renders a "Current date" line, so the recipe pins current_date to keep the prompt the same every day. The Glimmer renderer trains only the answer and <|eot|>; the "to=user" header is a prompt token.
- Layout: dense 30B, FSDP 4 on one node of 4 GB300 GPUs, TP=CP=PP=1. dtype float32 with frozen weights stored in bf16 (the default precision config) and varlen attention from the muse_glimmer_30b base recipe. Activation remat is off: peak 116 GiB of 276.6 GiB per GPU, about 28% faster than full remat.
- LoRA targets: decoder wqkv, wo, o_gate, w13, w2 (Glimmer names); vision targets are the same NaViT list as Spark, conv1_linear stays frozen.
- Data numbers, measured on CPU with this recipe's data path and the released tokenizer: shortest English sample 142 tokens (so max_images_per_microbatch = 4096 // 142 = 28), longest 1476. The English validation split packs into 196 microbatches at DP 4, so validation runs ceil(196 / 4) = 49 steps. One pass over English train is 859 microbatches at DP 4, or 26.8 steps. Training runs 90 steps (about 3.4 passes), set from the validation-loss runs below.
- Env vars: MUSE_GLIMMER_HF_ASSETS_PATH (default ./assets/hf/Muse-Glimmer-30B) and MUSE_GLIMMER_SLAKE_PATH (default ./assets/datasets/slake).
- Mechanical: the SLAKE data helpers move from the Spark recipe module to torchtitan_recipes/data.py as public names: SLAKE_DATASET_PATH, slake_messages, slake_dataset (takes the renderer) and use_slake_sft_data (packing, max images per microbatch, validator). The per-model numbers (shortest sample, validation microbatches) stay in each recipe because they depend on the chat format. The Spark-only part of the answer-prompt comment stays next to the Spark renderer.
- Mechanical: MUSE_GLIMMER_30B_SPECIAL_TOKENS moves from the Glimmer test recipes to the public Glimmer recipe module; the test module imports it.
## User-facing changes
| Before | After |
| --- | --- |
| No Glimmer SLAKE recipes | muse_glimmer_30b_slake_{lora_decoder,lora_vision_decoder}_sft |
| - | MUSE_GLIMMER_HF_ASSETS_PATH and MUSE_GLIMMER_SLAKE_PATH env vars |
## Numerics
No change to existing recipes. Both Spark SLAKE recipes and the Spark UltraData LoRA recipe build the same config before and after (repr compared, ignoring function object addresses; the only difference is the qualified name of the filter lambdas, which move with slake_dataset). The Glimmer recipes are new and have no baseline.
## Testing
- test_slake_lora_trainable_split covers the Glimmer variants on debugmodel_mm, and now checks that every decoder target matches a module. It catches a renamed module, since LoRA only warns on unmatched targets (for example o_gate on Glimmer vs output_gate on Spark).
- LoRA + HF state dict on CPU: the Glimmer adapter maps every base weight of the LoRA vision + decoder model to HF and back with equal values and skips the adapters.
- --print-config passes for both Glimmer SLAKE recipes, both Spark SLAKE recipes, muse_glimmer_30b and the muse_glimmer_30b_mm test recipe.
- CPU tests: recipes, models/muse_glimmer, models/muse_spark, components/data and config: 640 passed, 1 skipped, 3 xfailed. After the steps and remat change: recipe tests 53 passed.
- GPU, LoRA vision + decoder from the released HF checkpoint on 4 GB300, through a recipe not in this PR that only changes the step count, remat and checkpoint saving:
- Job 2389895, 90 steps, full remat: validation loss 2.73 at step 1 -> 0.169 at step 90, still falling slowly. 13.9 s per step.
- Job 2390442, 150 steps, no remat: validation loss flattens after step 70 and moves between 0.16 and 0.20 (0.157 at step 100, 0.185 at step 150) while training loss keeps falling, so it overfits past about 3 passes. 10.0 s per step, peak 116 GiB of 276.6 GiB per GPU, no OOM.
- Job 2390757, this commit's recipe as is (90 steps, no remat; only checkpoint saving off): validation loss 2.739 at step 1, 0.322 at step 30, 0.200 at step 60 and 0.179 at step 90 (lowest); training loss 2.580 -> 0.107. grad_norm max 29.3 at step 1 and below 23 after warmup; the 150-step run's spikes (422 at step 76, 237 at step 144) did not recur. 10.1 s per step, 3,267 tokens/s per GPU, MFU 27.2%, peak 116.2 GiB of 276.6 GiB per GPU, no errors and no FSDP view warning.
- The FSDP2 "returned a view tensor" warning in the full-remat run comes from the view_as boundary of torch_remat; it is absent without remat.
## Known issues / follow-ups
- The LoRA decoder variant uses the same settings without a separate GPU run.
- The SLAKE train/test leak TODO from the Spark recipe applies here too (it lives in slake_dataset).
stack-info: PR: #5904, branch: fegin/stack/25
|
@claude review this pr |
|
Claude finished @fegin's task in 3m 27s —— View job Approve, with four small cleanups suggested -- see the review on this PR. |
There was a problem hiding this comment.
Verdict: Approve -- recipes-only change with a real consumer and a GPU run of the exact recipe; the remaining items are small cleanups.
What this PR does. It adds two Muse Glimmer 30B SLAKE LoRA SFT recipes that mirror the Spark ones. To share code between them, the SLAKE data path (messages, dataset, packing, max images per microbatch, validator) moves from private helpers in muse_spark.py to public functions in torchtitan_recipes/data.py. Each recipe keeps its own renderer and its measured per-model constants. MUSE_GLIMMER_30B_SPECIAL_TOKENS moves out of the test recipe module so the public recipe can use it.
Example.
# Spark, before: renderer hardcoded inside the private _slake_dataset(root)
# Spark, after:
dataset = slake_dataset(root, renderer=MuseSparkRendererConfig(reasoning_effort="low", current_date=""))
use_slake_sft_data(config, _muse_spark_mm_dataloader(model_config, dataset),
root=root, min_sample_tokens=219, num_validation_microbatches=214)
# Glimmer, new: same helpers, MuseGlimmerRenderer with a pinned current_date
# (an empty date falls back to datetime.now() in the Glimmer renderer, so pinning is required)
# -> 4096 // 142 = 28 images per microbatch, ceil(196 / 4) = 49 validation stepsShould consider
torchtitan_recipes/models/muse_glimmer.py:328-- this is the third copy of the Muse-NaViT loader wiring. Move_muse_glimmer_mm_dataloaderinto the public recipe module (taking a dataset config) and use it from both places.torchtitan_recipes/models/muse_glimmer.py:212-- the vision target list and_slake_lora_transformare copied from Spark. Define them once; the test then stops importing two modules' private helpers.torchtitan_recipes/models/muse_glimmer.py:238-- the docstring says step counts are untuned, which contradicts the 90-step choice taken from the validation runs.torchtitan_recipes/data.py:77-- "loss on the answer only" depends on the renderer, not onslake_dataset. For Spark it is wrong, because that renderer also trains theto=userheader.
Questions
- The extended
test_slake_lora_trainable_splitexists becauseLoRATransformonly warns on unmatchedtarget_modules(torchtitan/config/transform/lora.py:303). Under the explicit-over-implicit rule, that check should raiseValueErrorinLoRATransform. That would catch a typo likeoutput_gatevso_gatein every LoRA recipe, and the new decoder-set assertion would no longer be needed. Is there a caller that depends on the warning? If not, it is worth a separate PR.
Not verified: I could not build the recipe configs locally (no Python execution here). The numbers above come from reading the code and the PR's measurements.
| processor = replace( | ||
| dataset.processor, | ||
| patch_size=patch_size, | ||
| temporal_patch_size=temporal_patch_size, | ||
| spatial_merge_size=spatial_merge_size, | ||
| resize_fn=resize_to_muse_glimmer_patch_grid, | ||
| image_interpolation_mode=TVF.InterpolationMode.LANCZOS, | ||
| ) | ||
| loader = GrainDataLoader.Config( | ||
| dataset=replace(dataset, processor=processor), | ||
| collator=MultiModalCollator.Config( | ||
| patch_size=patch_size, | ||
| temporal_patch_size=temporal_patch_size, | ||
| spatial_merge_size=spatial_merge_size, | ||
| patch_order="raster", | ||
| build_mrope_positions=False, | ||
| ), | ||
| ) |
There was a problem hiding this comment.
This processor + collator block is the third copy of the same Muse-NaViT loader wiring: _muse_glimmer_mm_dataloader in torchtitan_recipes/tests/models/muse_glimmer.py:58 and _muse_spark_mm_dataloader in muse_spark.py:235 do the same thing (patch geometry from the encoder, resize_to_muse_glimmer_patch_grid + LANCZOS, raster order, no MRoPE). This PR already moves MUSE_GLIMMER_30B_SPECIAL_TOKENS from the test module into this module so both can share it. The same move works for the loader. Move _muse_glimmer_mm_dataloader here, have it take a SingleDatasetConfig the way the Spark helper does (the test callers would pass MM_DATASETS[name]), and call it from both places. That removes about 20 lines and keeps the Spark and Glimmer SLAKE recipes symmetric. This is a should-consider, not a blocker.
| _SLAKE_LORA_VISION_TARGETS = [ | ||
| "vision_encoder.block.attn.wq", | ||
| "vision_encoder.block.attn.wk", | ||
| "vision_encoder.block.attn.wv", | ||
| "vision_encoder.block.attn.proj", | ||
| "vision_encoder.block.mlp.fc1", | ||
| "vision_encoder.block.mlp.fc2", | ||
| "vision_adapter.c_fc", | ||
| "vision_adapter.c_proj", | ||
| "vision_projection", | ||
| ] | ||
| _SlakeVariant = Literal["lora_decoder", "lora_vision_decoder"] |
There was a problem hiding this comment.
_SLAKE_LORA_VISION_TARGETS is a verbatim copy of the list in muse_spark.py, and the comment above says why: it is the same NaViT. _SlakeVariant and _slake_lora_transform are also copies; they differ only in the decoder target tuple. Because of the duplication, the test has to import the private _slake_lora_transform from both modules. Suggestion: define the NaViT vision targets once, either as a public constant in muse_spark.py that Glimmer imports or next to slake_dataset in data.py as slake_lora_transform(variant, *, decoder_targets). Each recipe then passes only its decoder names (o_gate vs output_gate), and the test uses the public function.
| root. See ``use_slake_sft_data`` for packing and validation. Learning rates and | ||
| step counts are untuned starting points. |
There was a problem hiding this comment.
This docstring says step counts are untuned, but the comment at config.training.steps = 90 and the PR description say 90 was picked from the 90- and 150-step validation-loss runs. Only the learning rate is untuned.
| root. See ``use_slake_sft_data`` for packing and validation. Learning rates and | |
| step counts are untuned starting points. | |
| root. See ``use_slake_sft_data`` for packing and validation. The learning rate | |
| is an untuned starting point. |
|
|
||
|
|
||
| def slake_dataset(root: str, *, renderer: RendererConfig) -> SingleDatasetConfig: | ||
| """Return English SLAKE train rows as chat samples with loss on the answer only. |
There was a problem hiding this comment.
"Loss on the answer only" is not something this function controls; the renderer argument decides it. The Spark caller's own comment says its renderer also trains the to=user header, so for Spark this docstring is wrong. Now that the helper is shared and takes the renderer as an argument, describe it in renderer terms.
| """Return English SLAKE train rows as chat samples with loss on the answer only. | |
| """Return English SLAKE train rows as chat samples; ``renderer`` decides which | |
| tokens get loss. |
…ion + decoder
## Summary (human-written)
Add Muse Glimmer SLAKE LoRA SFT recipes.
## Why
There is no recipe to fine-tune Muse Glimmer 30B on medical VQA. The Muse Spark SLAKE LoRA recipes exist, but their data path (messages, dataset, packing, validation) lives in the Spark recipe module as private helpers, so a Glimmer recipe cannot reuse it.
**Example.**
```
config = muse_glimmer_30b_slake_lora_vision_decoder_sft()
# 4 GB300, FSDP 4, no remat, 4K packed sequences, 90 steps
# trainable: LoRA adapters on the decoder and on the vision encoder, adapter and projection
```
## What changed
- Add muse_glimmer_30b_slake_lora_decoder_sft and muse_glimmer_30b_slake_lora_vision_decoder_sft. They mirror the Spark SLAKE recipes: English SLAKE, image in the user turn, the LLaVA 1.5 short-answer prompt, loss on the answer only, packed rows, validation at step 1 and every 10 steps, TensorBoard, LoRA rank 8 / alpha 16, AdamW lr 1e-4 with 10 warmup steps and cosine decay, 32 x 4096 tokens per step, CUDA graphs off.
- Glimmer specifics: flavor 30B_mm, the released Glimmer special tokens (MultiModalTokenizer), the in-tree MuseGlimmerRenderer with reasoning_strength="low", and the released image processor (closest-aspect patch grid, LANCZOS). The Glimmer chat template always renders a "Current date" line, so the recipe pins current_date to keep the prompt the same every day. The Glimmer renderer trains only the answer and <|eot|>; the "to=user" header is a prompt token.
- Layout: dense 30B, FSDP 4 on one node of 4 GB300 GPUs, TP=CP=PP=1. dtype float32 with frozen weights stored in bf16 (the default precision config) and varlen attention from the muse_glimmer_30b base recipe. Activation remat is off: peak 116 GiB of 276.6 GiB per GPU, about 28% faster than full remat.
- LoRA targets: decoder wqkv, wo, o_gate, w13, w2 (Glimmer names); vision targets are the same NaViT list as Spark, conv1_linear stays frozen.
- Data numbers, measured on CPU with this recipe's data path and the released tokenizer: shortest English sample 142 tokens (so max_images_per_microbatch = 4096 // 142 = 28), longest 1476. The English validation split packs into 196 microbatches at DP 4, so validation runs ceil(196 / 4) = 49 steps. One pass over English train is 859 microbatches at DP 4, or 26.8 steps. Training runs 90 steps (about 3.4 passes), set from the validation-loss runs below.
- Env vars: MUSE_GLIMMER_HF_ASSETS_PATH (default ./assets/hf/Muse-Glimmer-30B) and MUSE_GLIMMER_SLAKE_PATH (default ./assets/datasets/slake).
- Mechanical: the SLAKE data helpers move from the Spark recipe module to torchtitan_recipes/data.py as public names: SLAKE_DATASET_PATH, slake_messages, slake_dataset (takes the renderer) and use_slake_sft_data (packing, max images per microbatch, validator). The per-model numbers (shortest sample, validation microbatches) stay in each recipe because they depend on the chat format. The Spark-only part of the answer-prompt comment stays next to the Spark renderer.
- Mechanical: MUSE_GLIMMER_30B_SPECIAL_TOKENS moves from the Glimmer test recipes to the public Glimmer recipe module; the test module imports it.
## User-facing changes
| Before | After |
| --- | --- |
| No Glimmer SLAKE recipes | muse_glimmer_30b_slake_{lora_decoder,lora_vision_decoder}_sft |
| - | MUSE_GLIMMER_HF_ASSETS_PATH and MUSE_GLIMMER_SLAKE_PATH env vars |
## Numerics
No change to existing recipes. Both Spark SLAKE recipes and the Spark UltraData LoRA recipe build the same config before and after (repr compared, ignoring function object addresses; the only difference is the qualified name of the filter lambdas, which move with slake_dataset). The Glimmer recipes are new and have no baseline.
## Testing
- test_slake_lora_trainable_split covers the Glimmer variants on debugmodel_mm, and now checks that every decoder target matches a module. It catches a renamed module, since LoRA only warns on unmatched targets (for example o_gate on Glimmer vs output_gate on Spark).
- LoRA + HF state dict on CPU: the Glimmer adapter maps every base weight of the LoRA vision + decoder model to HF and back with equal values and skips the adapters.
- --print-config passes for both Glimmer SLAKE recipes, both Spark SLAKE recipes, muse_glimmer_30b and the muse_glimmer_30b_mm test recipe.
- CPU tests: recipes, models/muse_glimmer, models/muse_spark, components/data and config: 640 passed, 1 skipped, 3 xfailed. After the steps and remat change: recipe tests 53 passed.
- GPU, LoRA vision + decoder from the released HF checkpoint on 4 GB300, through a recipe not in this PR that only changes the step count, remat and checkpoint saving:
- Job 2389895, 90 steps, full remat: validation loss 2.73 at step 1 -> 0.169 at step 90, still falling slowly. 13.9 s per step.
- Job 2390442, 150 steps, no remat: validation loss flattens after step 70 and moves between 0.16 and 0.20 (0.157 at step 100, 0.185 at step 150) while training loss keeps falling, so it overfits past about 3 passes. 10.0 s per step, peak 116 GiB of 276.6 GiB per GPU, no OOM.
- Job 2390757, this commit's recipe as is (90 steps, no remat; only checkpoint saving off): validation loss 2.739 at step 1, 0.322 at step 30, 0.200 at step 60 and 0.179 at step 90 (lowest); training loss 2.580 -> 0.107. grad_norm max 29.3 at step 1 and below 23 after warmup; the 150-step run's spikes (422 at step 76, 237 at step 144) did not recur. 10.1 s per step, 3,267 tokens/s per GPU, MFU 27.2%, peak 116.2 GiB of 276.6 GiB per GPU, no errors and no FSDP view warning.
- The FSDP2 "returned a view tensor" warning in the full-remat run comes from the view_as boundary of torch_remat; it is absent without remat.
## Known issues / follow-ups
- The LoRA decoder variant uses the same settings without a separate GPU run.
- The SLAKE train/test leak TODO from the Spark recipe applies here too (it lives in slake_dataset).
stack-info: PR: #5904, branch: fegin/stack/25
… processor (#5887) Stacked PRs: * #5904 * #5895 * #5885 * #5894 * #5893 * #5892 * #5891 * #5890 * #5889 * #5981 * #5888 * __->__#5887 --- --- --- ### [muse_spark] Resample multimodal images with LANCZOS, as the released processor ## Summary (human-written) Use the correct resample for Muse Spark ## Why The Muse Spark multimodal dataloader resizes images with VisionProcessor's default interpolation, BICUBIC. The released Muse Spark processor_config.json resamples with LANCZOS (resample=1). So on main, training sees slightly different pixels than the released model's preprocessing. **Example.** ``` MUSE_SPARK_VISION_PROCESSOR_KWARGS before: image_interpolation_mode = "bicubic" (VisionProcessor default) after: image_interpolation_mode = "lanczos" (processor_config.json resample=1) ``` ## What changed - MUSE_SPARK_VISION_PROCESSOR_KWARGS sets image_interpolation_mode="lanczos". It applies to every Muse Spark multimodal recipe, for images and video frames. ## Numerics Image preprocessing changes for every Muse Spark multimodal recipe, including muse_spark_debugmodel_mm, so their multimodal losses change. Muse Spark has no golden loss files. Text-only recipes are unchanged. ## Testing - No new test: this is a single config value. tests/unit_tests/cpu/recipes/test_muse_spark.py builds muse_spark_debugmodel_mm; 6 passed at this commit.
…ion + decoder
## Summary (human-written)
Add Muse Glimmer SLAKE LoRA SFT recipes.
## Why
There is no recipe to fine-tune Muse Glimmer 30B on medical VQA. The Muse Spark SLAKE LoRA recipes exist, but their data path (messages, dataset, packing, validation) lives in the Spark recipe module as private helpers, so a Glimmer recipe cannot reuse it.
**Example.**
```
config = muse_glimmer_30b_slake_lora_vision_decoder_sft()
# 4 GB300, FSDP 4, no remat, 4K packed sequences, 90 steps
# trainable: LoRA adapters on the decoder and on the vision encoder, adapter and projection
```
## What changed
- Add muse_glimmer_30b_slake_lora_decoder_sft and muse_glimmer_30b_slake_lora_vision_decoder_sft. They mirror the Spark SLAKE recipes: English SLAKE, image in the user turn, the LLaVA 1.5 short-answer prompt, loss on the answer only, packed rows, validation at step 1 and every 10 steps, TensorBoard, LoRA rank 8 / alpha 16, AdamW lr 1e-4 with 10 warmup steps and cosine decay, 32 x 4096 tokens per step, CUDA graphs off.
- Glimmer specifics: flavor 30B_mm, the released Glimmer special tokens (MultiModalTokenizer), the in-tree MuseGlimmerRenderer with reasoning_strength="low", and the released image processor (MUSE_GLIMMER_30B_VISION_PROCESSOR_KWARGS: closest-aspect patch grid, LANCZOS). The Glimmer chat template always renders a "Current date" line, so the recipe pins current_date to keep the prompt the same every day. The Glimmer renderer trains only the answer and <|eot|>; the "to=user" header is a prompt token.
- Layout: dense 30B, FSDP 4 on one node of 4 GB300 GPUs, TP=CP=PP=1. dtype float32 with frozen weights stored in bf16 (the default precision config) and varlen attention from the muse_glimmer_30b base recipe. Activation remat is off: peak 116 GiB of 276.6 GiB per GPU, about 28% faster than full remat.
- LoRA targets: decoder wqkv, wo, o_gate, w13, w2 (Glimmer names); vision targets are the same NaViT list as Spark, conv1_linear stays frozen.
- Data numbers, measured on CPU with this recipe's data path and the released tokenizer: shortest English sample 142 tokens (so max_images_per_microbatch = 4096 // 142 = 28), longest 1476. The English validation split packs into 196 microbatches at DP 4, so validation runs ceil(196 / 4) = 49 steps. One pass over English train is 859 microbatches at DP 4, or 26.8 steps. Training runs 90 steps (about 3.4 passes), set from the validation-loss runs below.
- Env vars: MUSE_GLIMMER_HF_ASSETS_PATH (default ./assets/hf/Muse-Glimmer-30B) and MUSE_GLIMMER_SLAKE_PATH (default ./assets/datasets/slake).
- Mechanical: the SLAKE data helpers move from the Spark recipe module to torchtitan_recipes/data.py as public names: SLAKE_DATASET_PATH, slake_messages, slake_dataset (takes the renderer) and use_slake_sft_data (packing, max images per microbatch, validator). The per-model numbers (shortest sample, validation microbatches) stay in each recipe because they depend on the chat format. The Spark-only part of the answer-prompt comment stays next to the Spark renderer.
- MUSE_GLIMMER_30B_SPECIAL_TOKENS and MUSE_GLIMMER_30B_VISION_PROCESSOR_KWARGS come from torchtitan/models/muse_glimmer/flavors.py.
## User-facing changes
| Before | After |
| --- | --- |
| No Glimmer SLAKE recipes | muse_glimmer_30b_slake_{lora_decoder,lora_vision_decoder}_sft |
| - | MUSE_GLIMMER_HF_ASSETS_PATH and MUSE_GLIMMER_SLAKE_PATH env vars |
## Numerics
No change to existing recipes. Both Spark SLAKE recipes and the Spark UltraData LoRA recipe build the same config before and after (repr compared, ignoring function object addresses; the only difference is the qualified name of the filter lambdas, which move with slake_dataset). The Glimmer recipes are new and have no baseline.
## Testing
- test_slake_lora_trainable_split covers the Glimmer variants on debugmodel_mm, and now checks that every decoder target matches a module. It catches a renamed module, since LoRA only warns on unmatched targets (for example o_gate on Glimmer vs output_gate on Spark).
- LoRA + HF state dict on CPU: the Glimmer adapter maps every base weight of the LoRA vision + decoder model to HF and back with equal values and skips the adapters.
- --print-config passes for both Glimmer SLAKE recipes, both Spark SLAKE recipes, muse_glimmer_30b and the muse_glimmer_30b_mm test recipe.
- CPU tests: recipes, models/muse_glimmer, models/muse_spark, components/data and config: 657 passed, 1 skipped, 3 xfailed. Recipe tests: 53 passed.
- GPU, LoRA vision + decoder from the released HF checkpoint on 4 GB300, through a recipe not in this PR that only changes the step count, remat and checkpoint saving:
- Job 2389895, 90 steps, full remat: validation loss 2.73 at step 1 -> 0.169 at step 90, still falling slowly. 13.9 s per step.
- Job 2390442, 150 steps, no remat: validation loss flattens after step 70 and moves between 0.16 and 0.20 (0.157 at step 100, 0.185 at step 150) while training loss keeps falling, so it overfits past about 3 passes. 10.0 s per step, peak 116 GiB of 276.6 GiB per GPU, no OOM.
- Job 2390757, this commit's recipe as is (90 steps, no remat; only checkpoint saving off): validation loss 2.739 at step 1, 0.322 at step 30, 0.200 at step 60 and 0.179 at step 90 (lowest); training loss 2.580 -> 0.107. grad_norm max 29.3 at step 1 and below 23 after warmup; the 150-step run's spikes (422 at step 76, 237 at step 144) did not recur. 10.1 s per step, 3,267 tokens/s per GPU, MFU 27.2%, peak 116.2 GiB of 276.6 GiB per GPU, no errors and no FSDP view warning.
- The FSDP2 "returned a view tensor" warning in the full-remat run comes from the view_as boundary of torch_remat; it is absent without remat.
## Known issues / follow-ups
- The LoRA decoder variant uses the same settings without a separate GPU run.
- The SLAKE train/test leak TODO from the Spark recipe applies here too (it lives in slake_dataset).
stack-info: PR: #5904, branch: fegin/stack/25
…e_glimmer_30b_mm test recipe (#5888) Stacked PRs: * #5904 * #5895 * #5885 * #5894 * #5893 * #5892 * #5891 * #5890 * #5889 * #5981 * __->__#5888 --- --- --- ### [recipes] Use the released Muse tokens and image processor in the muse_glimmer_30b_mm test recipe ## Summary (human-written) The Muse Glimmer multimodal recipe uses incorrect tokens and image processor. This PR fixes the mismatch. ## Why On main, muse_glimmer_30b_mm does not build. It uses the Qwen-style debug tokens (<|image_pad|>, <|vision_start|>, ...), which the released Muse Glimmer 30B tokenizer does not have, so the tokenizer build raises. It also uses the debug pixel budget (max_pixels=3136, 4 merged tokens per image), not the released image processor. **Example.** ``` before: muse_glimmer_30b_mm -> tokenizer build raises (no <|image_pad|> in the released tokenizer) after: image tokens <|patch|> (200092), <|video|> (200091), <|image_start|> (200080), <|image_end|> (200081), pad <|finetune_right_pad|> (200018) images: closest-aspect grid up to 4096 merged tokens, LANCZOS ``` ## What changed - muse_glimmer_30b_mm uses the released special tokens and image processor. Its output matches the HF MuseGlimmerImageProcessor to 1.2e-7 with identical grids. - The released image processor is MUSE_GLIMMER_30B_VISION_PROCESSOR_KWARGS: the Muse Spark recipe's MuseGlimmerPatchGridResize with max_image_tokens=4096, and LANCZOS. Images only. - Mechanical: the debug token map and image processor settings are renamed MUSE_GLIMMER_DEBUG_SPECIAL_TOKENS and MUSE_GLIMMER_DEBUG_VISION_PROCESSOR_KWARGS. The debug recipe keeps them, because the debug tokenizer asset defines only those tokens. ## Numerics muse_glimmer_30b_mm did not build on main, so there is no baseline. The Muse Glimmer debug recipe and the Muse Spark recipes are unchanged (same tokens, same image processor). ## Testing - CPU test: three resize grids match the HF processor, one on the 4096-token cap path. It catches drift from the released processor. - CPU tests at this commit: recipes/test_muse_spark.py, components/data, models/muse_spark and models/muse_glimmer all pass (3 xfailed). Skips depend on the environment: one test needs a local tokenizer directory, one needs an accelerator.
…ion + decoder
## Summary (human-written)
Add Muse Glimmer SLAKE LoRA SFT recipes.
## Why
There is no recipe to fine-tune Muse Glimmer 30B on medical VQA. The Muse Spark SLAKE LoRA recipes exist, but their data path (messages, dataset, packing, validation) lives in the Spark recipe module as private helpers, so a Glimmer recipe cannot reuse it.
**Example.**
```
config = muse_glimmer_30b_slake_lora_vision_decoder_sft()
# 4 GB300, FSDP 4, no remat, 4K packed sequences, 90 steps
# trainable: LoRA adapters on the decoder and on the vision encoder, adapter and projection
```
## What changed
- Add muse_glimmer_30b_slake_lora_decoder_sft and muse_glimmer_30b_slake_lora_vision_decoder_sft. They mirror the Spark SLAKE recipes: English SLAKE, image in the user turn, the LLaVA 1.5 short-answer prompt, loss on the answer only, packed rows, validation at step 1 and every 10 steps, TensorBoard, LoRA rank 8 / alpha 16, AdamW lr 1e-4 with 10 warmup steps and cosine decay, 32 x 4096 tokens per step, CUDA graphs off.
- Glimmer specifics: flavor 30B_mm, the released Glimmer special tokens (MultiModalTokenizer), the in-tree MuseGlimmerRenderer with reasoning_strength="low", and the released image processor (MUSE_GLIMMER_30B_VISION_PROCESSOR_KWARGS: closest-aspect patch grid, LANCZOS). The Glimmer chat template always renders a "Current date" line, so the recipe pins current_date to keep the prompt the same every day. The Glimmer renderer trains only the answer and <|eot|>; the "to=user" header is a prompt token.
- Layout: dense 30B, FSDP 4 on one node of 4 GB300 GPUs, TP=CP=PP=1. dtype float32 with frozen weights stored in bf16 (the default precision config) and varlen attention from the muse_glimmer_30b base recipe. Activation remat is off: peak 116 GiB of 276.6 GiB per GPU, about 28% faster than full remat.
- LoRA targets: decoder wqkv, wo, o_gate, w13, w2 (Glimmer names); vision targets are the same NaViT list as Spark, conv1_linear stays frozen.
- Data numbers, measured on CPU with this recipe's data path and the released tokenizer: shortest English sample 142 tokens (so max_images_per_microbatch = 4096 // 142 = 28), longest 1476. The English validation split packs into 196 microbatches at DP 4, so validation runs ceil(196 / 4) = 49 steps. One pass over English train is 859 microbatches at DP 4, or 26.8 steps. Training runs 90 steps (about 3.4 passes), set from the validation-loss runs below.
- Env vars: MUSE_GLIMMER_HF_ASSETS_PATH (default ./assets/hf/Muse-Glimmer-30B) and MUSE_GLIMMER_SLAKE_PATH (default ./assets/datasets/slake).
- Mechanical: the SLAKE data helpers move from the Spark recipe module to torchtitan_recipes/data.py as public names: SLAKE_DATASET_PATH, slake_messages, slake_dataset (takes the renderer) and use_slake_sft_data (packing, max images per microbatch, validator). The per-model numbers (shortest sample, validation microbatches) stay in each recipe because they depend on the chat format. The Spark-only part of the answer-prompt comment stays next to the Spark renderer.
- MUSE_GLIMMER_30B_SPECIAL_TOKENS and MUSE_GLIMMER_30B_VISION_PROCESSOR_KWARGS come from torchtitan/models/muse_glimmer/flavors.py.
## User-facing changes
| Before | After |
| --- | --- |
| No Glimmer SLAKE recipes | muse_glimmer_30b_slake_{lora_decoder,lora_vision_decoder}_sft |
| - | MUSE_GLIMMER_HF_ASSETS_PATH and MUSE_GLIMMER_SLAKE_PATH env vars |
## Numerics
No change to existing recipes. Both Spark SLAKE recipes and the Spark UltraData LoRA recipe build the same config before and after (repr compared, ignoring function object addresses; the only difference is the qualified name of the filter lambdas, which move with slake_dataset). The Glimmer recipes are new and have no baseline.
## Testing
- test_slake_lora_trainable_split covers the Glimmer variants on debugmodel_mm, and now checks that every decoder target matches a module. It catches a renamed module, since LoRA only warns on unmatched targets (for example o_gate on Glimmer vs output_gate on Spark).
- LoRA + HF state dict on CPU: the Glimmer adapter maps every base weight of the LoRA vision + decoder model to HF and back with equal values and skips the adapters.
- --print-config passes for both Glimmer SLAKE recipes, both Spark SLAKE recipes, muse_glimmer_30b and the muse_glimmer_30b_mm test recipe.
- CPU tests: recipes, models/muse_glimmer, models/muse_spark, components/data and config: 657 passed, 1 skipped, 3 xfailed. Recipe tests: 53 passed.
- GPU, LoRA vision + decoder from the released HF checkpoint on 4 GB300, through a recipe not in this PR that only changes the step count, remat and checkpoint saving:
- Job 2389895, 90 steps, full remat: validation loss 2.73 at step 1 -> 0.169 at step 90, still falling slowly. 13.9 s per step.
- Job 2390442, 150 steps, no remat: validation loss flattens after step 70 and moves between 0.16 and 0.20 (0.157 at step 100, 0.185 at step 150) while training loss keeps falling, so it overfits past about 3 passes. 10.0 s per step, peak 116 GiB of 276.6 GiB per GPU, no OOM.
- Job 2390757, this commit's recipe as is (90 steps, no remat; only checkpoint saving off): validation loss 2.739 at step 1, 0.322 at step 30, 0.200 at step 60 and 0.179 at step 90 (lowest); training loss 2.580 -> 0.107. grad_norm max 29.3 at step 1 and below 23 after warmup; the 150-step run's spikes (422 at step 76, 237 at step 144) did not recur. 10.1 s per step, 3,267 tokens/s per GPU, MFU 27.2%, peak 116.2 GiB of 276.6 GiB per GPU, no errors and no FSDP view warning.
- The FSDP2 "returned a view tensor" warning in the full-remat run comes from the view_as boundary of torch_remat; it is absent without remat.
## Known issues / follow-ups
- The LoRA decoder variant uses the same settings without a separate GPU run.
- The SLAKE train/test leak TODO from the Spark recipe applies here too (it lives in slake_dataset).
stack-info: PR: #5904, branch: fegin/stack/25
…the model flavors (#5981) Stacked PRs: * #5904 * #5895 * #5885 * #5894 * #5893 * #5892 * #5891 * #5890 * #5889 * __->__#5981 --- --- --- ### [muse] Define the Muse vision processor kwargs and special tokens in the model flavors ## Summary (human-written) Fix the issue discussed in #5887 (comment). ## Why Every other multimodal model defines its special tokens and VisionProcessor kwargs in its model flavors, and their resize rules live in the shared vision_processor.py. The Muse models keep theirs in recipe modules, so a model package cannot use them and readers look in the wrong place. | Model | Special tokens | Kwargs | Resize rule | | --- | --- | --- | --- | | qwen3_5, qwen3_6, qwen3_8 | torchtitan/models/<model>/flavors.py | torchtitan/models/<model>/flavors.py | PixelBudgetResize in vision_processor.py | | kimi_k2_7, kimi_k3 | torchtitan/models/<model>/flavors.py | torchtitan/models/<model>/flavors.py | NaViTPatchGridResize in vision_processor.py | | muse_spark (before) | torchtitan_recipes/models/muse_spark.py (debug: torchtitan_recipes/tests/models/muse_spark.py) | torchtitan_recipes/models/muse_spark.py | MuseGlimmerPatchGridResize in torchtitan_recipes/models/muse_spark.py | | muse_glimmer (before) | torchtitan_recipes/tests/models/muse_glimmer.py | torchtitan_recipes/tests/models/muse_glimmer.py | same | ## What changed Mechanical move, no value change: - MuseGlimmerPatchGridResize moves to torchtitan/components/data/multimodal/vision_processor.py, next to PixelBudgetResize and NaViTPatchGridResize. - MUSE_SPARK_VISION_PROCESSOR_KWARGS moves to torchtitan/models/muse_spark/flavors.py. The private _MUSE_GLIMMER_MAX_IMAGE_TOKENS = 4096 is inlined, as in MUSE_GLIMMER_30B_VISION_PROCESSOR_KWARGS. - MUSE_GLIMMER_DEBUG_VISION_PROCESSOR_KWARGS and MUSE_GLIMMER_30B_VISION_PROCESSOR_KWARGS move to torchtitan/models/muse_glimmer/flavors.py. - MUSE_SPARK_SPECIAL_TOKENS and MUSE_SPARK_DEBUG_SPECIAL_TOKENS move to torchtitan/models/muse_spark/flavors.py. The dataset TODO that shared a comment with MUSE_SPARK_SPECIAL_TOKENS stays in the recipe, above _muse_spark_mm_dataloader. - MUSE_GLIMMER_DEBUG_SPECIAL_TOKENS and MUSE_GLIMMER_30B_SPECIAL_TOKENS move to torchtitan/models/muse_glimmer/flavors.py. - Both model packages export the special tokens and kwargs, like qwen3_5 and kimi_k3. The recipes, the dapo_math RL recipe and the tests import them from there. - test_muse_glimmer_patch_grid_resize moves from tests/unit_tests/cpu/recipes/test_muse_spark.py to TestMuseGlimmerPatchGridResize in tests/unit_tests/cpu/components/data/test_mm_dataset_preprocessing.py, with the same cases. ## Numerics None. The VisionProcessor.Config of muse_spark_debugmodel_mm, muse_glimmer_debugmodel_mm and muse_glimmer_30b_mm has the same repr before and after; only the module of the resize rule class changes. The tokenizer configs are unchanged. ## Testing - CPU tests at this commit: recipes, components/data, models/muse_spark and models/muse_glimmer: 436 passed, 1 skipped, 3 xfailed.
4fb4b6f to
fd9a670
Compare
Stacked PRs:
[recipes] Muse Glimmer SLAKE LoRA SFT recipes: LoRA decoder, LoRA vision + decoder
Summary (human-written)
Add Muse Glimmer SLAKE LoRA SFT recipes.
Why
There is no recipe to fine-tune Muse Glimmer 30B on medical VQA. The Muse Spark SLAKE LoRA recipes exist in torchtitan_recipes/sft/slake.py, but their data path (messages, dataset, packing, validation) is written for the Spark renderer and dataloader.
Example.
What changed
User-facing changes
Numerics
No change to existing recipes. Both Spark SLAKE recipes, the Spark UltraData LoRA recipe and the other Muse Spark and Muse Glimmer recipes build the same config before and after (--print-config compared, ignoring function object addresses). The Glimmer recipes are new and have no baseline.
Testing
python -m torchtitan.train --module torchtitan_recipes.sft.slake --config <recipe> --print-configpasses for both Glimmer SLAKE recipes and both Spark SLAKE recipes; --print-config also passes for muse_glimmer_30b and the muse_glimmer_30b_mm test recipe.Known issues / follow-ups