Repository navigation
[muse] Define the Muse vision processor kwargs and special tokens in the model flavors - #5981
Conversation
… 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.
|
@claude review this pr |
|
Claude finished @fegin's task in 1m 11s —— View job Approve: review posted. This is a mechanical move with identical values and every callsite updated. |
There was a problem hiding this comment.
Verdict: Approve -- a mechanical move that puts the Muse special tokens, the VisionProcessor kwargs and the resize rule where qwen3_5, kimi_k2_7 and kimi_k3 keep theirs. No values change.
What this PR does. MuseGlimmerPatchGridResize moves from torchtitan_recipes/models/muse_spark.py to the shared vision_processor.py, next to PixelBudgetResize and NaViTPatchGridResize. Two models use it (muse_spark and muse_glimmer), so it belongs in the shared module. The MUSE_SPARK_* and MUSE_GLIMMER_* token and kwargs dicts move into each model's flavors.py and are re-exported from the package __init__. The recipes, dapo_math.py and the tests now import them from the model packages.
Example.
# before
from torchtitan_recipes.models.muse_spark import MUSE_SPARK_SPECIAL_TOKENS, MuseGlimmerPatchGridResize
# after
from torchtitan.models.muse_spark import MUSE_SPARK_SPECIAL_TOKENS
from torchtitan.components.data.multimodal.vision_processor import MuseGlimmerPatchGridResizeDetails
- Moved code matches the old code. I diffed the moved class, the 4 kwargs dicts and the 4 token dicts against the removed code. They are byte-identical, except that
_MUSE_GLIMMER_MAX_IMAGE_TOKENSis inlined to4096, the valueMUSE_GLIMMER_30B_VISION_PROCESSOR_KWARGSalready used. The numerics claim holds. - Every callsite is updated. A grep for the moved names finds no import from
torchtitan_recipes.models.muse_sparkortorchtitan_recipes.tests.models.muse_glimmer. The one remaining recipe-to-recipe import,torchtitan_recipes/tests/models/muse_spark.py:50, only pulls helpers that stay in the recipe. - Dependency direction is fine. The model flavors now import
vision_processor, which qwen3_5, kimi_k2_7 and kimi_k3 flavors already do. The module stays free of torchvision: the moved class uses onlyitertoolsandmath. - The test is relocated, not added. Its 3 cases match the old parametrized test exactly.
- Duplication left alone.
MUSE_GLIMMER_30B_*overlapsMUSE_SPARK_*: the glimmer dicts are the spark ones minus the audio tokens andvideo_resize. That overlap existed before this PR, and deduplicating it would be a separate concern.
vision_processor.py is shared component code, so a maintainer still needs to review.
…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.
…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. stack-info: PR: #5981, branch: fegin/stack/28
Stacked PRs:
[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.
What changed
Mechanical move, no value change:
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