Skip to content

[muse] Define the Muse vision processor kwargs and special tokens in the model flavors - #5981

Merged
fegin merged 1 commit into
mainfrom
fegin/stack/28
Nov 10, 2026
Merged

fegin merged 1 commit into
mainfrom
fegin/stack/28

Conversation

@fegin

@fegin fegin commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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.

Model Special tokens Kwargs Resize rule
qwen3_5, qwen3_6, qwen3_8 torchtitan/models//flavors.py torchtitan/models//flavors.py PixelBudgetResize in vision_processor.py
kimi_k2_7, kimi_k3 torchtitan/models//flavors.py torchtitan/models//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.

@pytorch-bot pytorch-bot Bot added ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl labels Nov 9, 2026
@github-actions
github-actions Bot requested a review from pzhan9 November 9, 2026 20:46
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 9, 2026
fegin added a commit that referenced this pull request Nov 9, 2026
… 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.
@fegin
fegin marked this pull request as draft November 9, 2026 21:57
@fegin
fegin changed the base branch from fegin/stack/17 to main November 9, 2026 21:57
@pytorch-bot pytorch-bot Bot removed the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 9, 2026
@fegin
fegin changed the base branch from main to fegin/stack/17 November 9, 2026 21:58
@fegin
fegin marked this pull request as ready for review November 9, 2026 21:58
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 9, 2026
@fegin

fegin commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@claude review this pr

@claude

claude Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MuseGlimmerPatchGridResize
Details
  • 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_TOKENS is inlined to 4096, the value MUSE_GLIMMER_30B_VISION_PROCESSOR_KWARGS already used. The numerics claim holds.
  • Every callsite is updated. A grep for the moved names finds no import from torchtitan_recipes.models.muse_spark or torchtitan_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 only itertools and math.
  • The test is relocated, not added. Its 3 cases match the old parametrized test exactly.
  • Duplication left alone. MUSE_GLIMMER_30B_* overlaps MUSE_SPARK_*: the glimmer dicts are the spark ones minus the audio tokens and video_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.

fegin added a commit that referenced this pull request Nov 9, 2026
…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
@fegin
fegin marked this pull request as draft November 9, 2026 23:25
@fegin
fegin changed the base branch from fegin/stack/17 to main November 9, 2026 23:25
@pytorch-bot pytorch-bot Bot removed the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 9, 2026
@fegin
fegin marked this pull request as ready for review November 9, 2026 23:27
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 9, 2026
@fegin
fegin merged commit 11b1fda into main Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants