Skip to content

[models] Split multimodal families into text Decoder and MultimodalModel classes - #6084

Merged
tianyu-l merged 3 commits into
mainfrom
multimodal-class-split
Nov 13, 2026
Merged

tianyu-l merged 3 commits into
mainfrom
multimodal-class-split

Conversation

@tianyu-l

@tianyu-l tianyu-l commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

Why

Whether a model has a vision encoder is decided in three places: the flavor
(vision_encoder=None), the RL generator (keep_vision_encoder in
build_inference_model, which raises if a text-only engine gets a config with
an encoder), and runtime vision_encoder is None branches inside every
multimodal model. MultimodalModel doesn't mean "has encoders": on main, the
Qwen3.5, Kimi K3/K2.x and Muse Glimmer text flavors are MultimodalModels with
their encoders set to None, and the Muse Spark text flavors build both encoders
and skip them with dataset_modalities=(). So callers fall back to
getattr(config, "vision_encoder", None).

Example.

# Before (main)
build_model_config("9B")     # Qwen35Model.Config(vision_encoder=None) -- a MultimodalModel
build_model_config("9B_mm")  # Qwen35Model.Config(vision_encoder=...)
build_inference_model(cfg, ..., keep_vision_encoder=supports_multimodal(wrapper))

# After
build_model_config("9B")     # Qwen35Model.Config            -- Decoder, no encoder field
build_model_config("9B_mm")  # Qwen35MultimodalModel.Config  -- vision_encoder required
build_inference_model(cfg, ...)  # builds exactly what the config says
replace(build_model_config("9B_mm"), vision_encoder=None)  # ValueError

What changed

  • Two classes per family with encoders: a text-only Decoder subclass and
    a multimodal subclass of it and MultimodalModel whose config requires its
    encoders. Text flavors build the text class, multimodal flavors the
    multimodal one. The text class is listed first in both the model and Config
    bases, because dataclass fields resolve over the reversed MRO (documented in
    torchtitan/models/README.md). Kimi K2.5 is the exception, see follow-ups.

    Family Text class Multimodal class
    Qwen3.5 (+ qwen3_6 / qwen3_8 flavors) Qwen35Model Qwen35MultimodalModel
    Kimi K3 KimiK3Model KimiK3MultimodalModel
    Kimi K2.x KimiK2Model (new; Moonlight) KimiK25Model
    Muse Glimmer MuseGlimmerModel MuseGlimmerMultimodalModel
    Muse Spark MuseSparkModel MuseSparkMultimodalModel

    Flavor names are unchanged. For Qwen3.5, Kimi K3, Muse Glimmer and Muse
    Spark, the plain flavors are text-only and _mm adds the encoders. The
    qwen3_6 / qwen3_8 flavors already carried a vision encoder by default and
    stay multimodal.

  • MultimodalModel.Config.__post_init__ raises when no encoder is set.
    Config-driven vision_encoder is None branches are removed, including the
    ones guarding main's explicit TP collectives around the vision scatter
    (maybe_gather_tp_input, replicate_to_residual). Runtime None handling
    stays where pipeline stages after the first drop the encoders.

  • Text classes reuse Decoder.forward / Decoder.preprocess_inputs where
    numerically identical. Where the tail after the embedding differs, the model
    overrides Decoder.forward_embeddings: Kimi K3 (attention-residual blocks,
    keyword-only block_residual_TND) and Muse Glimmer (blocks without padding
    mask or aux-loss denominator) are new, and Muse Spark's override (from [rl] Muse Spark image prompts and a SLAKE LoRA GRPO recipe for Muse Spark 816B #6025)
    moves to the text class. Multimodal forwards end with
    self.forward_embeddings(...).

  • annotate_input_spmd_types (shared, so it applies to every model) now calls
    annotate_spmd_types() on non-tensor inputs, or the values of a mapping input
    such as attention_metadata, that implement the new runtime-checkable
    SpmdAnnotatedInput protocol. This replaces the per-model
    GDN/KDA metadata annotation (annotate_linear_attention_metadata, deleted),
    and also types full-attention varlen offsets. Checked with spmd typechecking
    (see Testing).

  • Kimi K3 drops its parallelize override. MultimodalModel.parallelize
    already applies activation remat to the encoder, and the override's
    annotate_replicated_parameters call had nothing left to annotate: every
    Kimi K3 parameter's module has a ShardingConfig. Typechecked runs pass
    without it.

  • State dict adapters choose the vision mapping by config type. A text flavor
    still loads the decoder from the multimodal HF checkpoint.

  • RL: keep_vision_encoder is deleted from build_inference_model. The
    Controller check is two-way: vision_processor set requires a multimodal
    generator model with a vision encoder, and a multimodal generator model
    requires vision_processor.

  • Kimi K2.x: Moonlight builds the new KimiK2Model(DeepSeekV3Model) instead of
    KimiK25Model(vision_encoder=None). It keeps Kimi's QK-clip optimizer hook
    and HF adapter (plain DeepSeekV3Model would silently drop both), and pins
    local_compile to empty to keep Moonlight's current regions (see
    follow-ups). Moonlight's code path changes: it now runs
    MTPDecoder.preprocess_inputs / forward (with no MTP layers, the plain
    Decoder path) instead of KimiK25Model's, and it no longer rejects CP,
    since KimiK25Model's CP rejection is for the vision scatter. Loss and
    grad_norm are unchanged (the Kimi K2 text row below); CP on Moonlight is not
    tested. KimiK25Model now inherits DeepSeekV3Model through
    KimiK2Model (main: MTPDecoder). Its config already derived from
    DeepSeekV3Model.Config, and KimiK2Model overrides both class attributes
    DeepSeekV3Model adds (state_dict_adapter_cls,
    _register_optimizer_hooks), so behavior is unchanged.

  • Muse Spark behavior change: plain flavors (debugmodel, 816B-A42B) no
    longer build the vision/audio encoders, so checkpoints saved from text runs
    have no encoder weights, the same trade-off Qwen3.5/Kimi text flavors make.
    dataset_modalities moves to MuseSparkMultimodalModel, where it is
    required and must list at least one modality, so text-only training always
    means MuseSparkModel.

  • graph_trainer Muse Glimmer: the text-only check moves from its
    Config.__post_init__ to its build_model_config, which raises for
    multimodal flavors.

  • scripts/checkpoint_conversion/numerical_tests_{qwen3_5,kimi_k3}.py compare
    vision parity and now raise a ValueError for text-only flavors.

  • Mechanical (skim): flavor files, __init__ exports, READMEs, the
    numerical_tests_qwen3_5_shard.py script, recipes, and test updates that
    follow the class names.

Alternatives considered

  • isinstance(config, MultimodalModel.Config) without the split: text flavors
    are MultimodalModels today, so it can't tell them apart.
  • Keep vision_encoder: X | None and check it everywhere: that's the status quo
    this removes.
  • Keep Muse Spark text flavors carrying unused encoders: two ways to be
    text-only, and the generator would build and sync a 1.85B-parameter vision
    encoder it never runs.

User-facing changes

Before After
Text flavor config is the family's multimodal class with encoders None Text flavor config is the text class (no encoder fields)
replace(mm_config, vision_encoder=None) allowed Raises ValueError; use the text flavor
build_inference_model(..., keep_vision_encoder=...) Argument removed
Multimodal generator model without vision_processor raises in build_inference_model Controller.Config raises at config time
Muse Spark 816B-A42B / debugmodel build encoders, skipped via dataset_modalities=() No encoders; dataset_modalities only on _mm flavors, and empty raises

Numerics

Bitwise-identical loss and grad_norm on all 10 steps vs. main a1f6dcd25
(seed 42, deterministic, flex attention, scripts/loss_compare.py --export-result
/ --import-result --assert-equal, grad_norm compared from TensorBoard at full
precision). GB300, attn-gym 0.0.18; the four Qwen3.5 configs were rerun on
the pinned attn-gym 0.0.20 and are also bitwise equal.

Config Layout GPUs Result
Qwen3.5 debugmodel single GPU 1 bitwise equal
Qwen3.5 debugmodel FSDP2 + TP2 + SP 4 bitwise equal
Qwen3.5 debugmodel_mm single GPU 1 bitwise equal
Qwen3.5 debugmodel_mm FSDP2 + TP2 + SP 4 bitwise equal
Kimi K3 debugmodel single GPU 1 bitwise equal
Kimi K3 debugmodel_mm single GPU 1 bitwise equal
Kimi K2.5 debugmodel (multimodal) FSDP 4 4 bitwise equal
Kimi K2 text: K2.5 debugmodel without its encoder (main: KimiK25Model(vision_encoder=None), as Moonlight; here: KimiK2Model) FSDP 4 4 bitwise equal
Muse Glimmer debugmodel single GPU 1 bitwise equal
Muse Glimmer debugmodel_mm single GPU 1 bitwise equal
Muse Spark debugmodel FSDP2 + TP2 + EP2 + SP 4 bitwise equal
Muse Spark debugmodel_mm TP2 + EP2 + CP2 + SP 4 bitwise equal

Muse Spark debugmodel matches even though it no longer builds encoders: they
were skipped in forward before, received no gradients, and the decoder's init
is unchanged on the meta-device build path.

Not run: Moonlight 16B itself (adapter mapping verified on synthetic state
dicts), CP on Kimi K2 (main rejects it), GPU unit tests.

Testing

  • spmd typechecking (debug.spmd_typechecking, 3 steps) passes on Llama 3
    varlen Ulysses CP2 and TP2 + Ulysses CP2; Qwen3.5 and Kimi K3 multimodal with
    all-gather-KV CP2 and Ulysses CP2; Qwen3.5 and Kimi K3 text varlen; Kimi K3
    text TP2 + EP2 + SP; Kimi K3 multimodal FSDP2 + TP2 + EP2 + SP.
  • CPU unit + RL suites (tests/unit_tests/cpu, tests/rl/unit_tests/cpu): no
    new failures vs. main.
  • Every flavor of the five families builds as config + meta model with the
    expected class; dataclasses.fields defaults of each multimodal Config
    match the pre-split class.
  • New tests/unit_tests/cpu/models/common/test_multimodal.py: catches a
    multimodal config with no encoder being accepted. It sets Kimi K3
    debugmodel_mm's vision_encoder=None, where MultimodalModel.Config is the
    only check (with the check removed, the config is accepted).
  • test_vllm_multimodal_wrapper.py: the Controller test now covers both
    directions.
  • Deleted test_shared_model_builds_without_vision_encoder (qwen3_8): it built
    a multimodal flavor with vision_encoder=None, which now raises
    (test_multimodal.py covers that). No CPU unit test builds the text-only
    Qwen3.5 model; the Qwen3.5 text numerics runs above and the RL debug recipes
    (rl_grpo_qwen3_5_debug_varlen) build it.

Known issues / follow-ups

  • KimiK25Model.Config(MultimodalModel.Config, DeepSeekV3Model.Config) (on
    main) loses DeepSeekV3Model.Config's local_compile default, so Kimi K2.x
    flavors run with no compiled regions. Left as is (fixing it changes compiled
    regions); KimiK2Model.Config carries a TODO.
  • tests/unit_tests/cpu/models/qwen3_5/test_qwen3_5.py is always skipped by
    pytest.importorskip("fla") (fla is in no requirements file). With the
    guard stubbed out, the same 5 tests fail on main and on this branch
    (test_qwen35_always_calls_vision_encoder_twice x4,
    test_qwen35_vision_projections_are_not_dense_tp_boundaries); the rest pass.
  • These CPU tests fail on aarch64 on both main and this branch (inductor CPU
    flex_attention): test_qwen3_5_mrope_positions.py (3), test_lora_forward,
    test_lora_head_only_matches_cross_entropy.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 12, 2026
@tianyu-l tianyu-l mentioned this pull request Nov 12, 2026
@anijain2305
anijain2305 force-pushed the text-only-rl-flavors branch 2 times, most recently from 73c9d2e to 94185ff Compare November 13, 2026 03:03
…del classes

Each family with modality encoders now has a text-only Decoder subclass and
an XMultimodalModel(XModel, MultimodalModel) whose Config requires its
encoders: Qwen3.5 (+ qwen3_6/qwen3_8), Kimi K3, Kimi K2.x (new KimiK2Model for
Moonlight), Muse Glimmer and Muse Spark. Plain flavors build the text class,
_mm flavors the multimodal one. MultimodalModel.Config raises when no encoder
is set, so config-driven `vision_encoder is None` branches are removed.

RL: build_inference_model's keep_vision_encoder is gone (the generator builds
what the config says); the Controller checks vision_processor <-> multimodal
generator model in both directions.

annotate_input_spmd_types calls annotate_spmd_types() on non-tensor inputs
(or the values of a mapping input such as attention_metadata), replacing the
per-model linear-attention metadata annotation. Kimi K3, Muse Spark and Muse
Glimmer override Decoder.forward_embeddings where their tail differs, and
multimodal forwards end in self.forward_embeddings. Kimi K3 drops its
replicated-parameter annotation override.
@tianyu-l
tianyu-l force-pushed the multimodal-class-split branch from 98d1ebc to 8c7f8b7 Compare November 13, 2026 08:01
@tianyu-l
tianyu-l changed the base branch from text-only-rl-flavors to main November 13, 2026 08:01
@tianyu-l
tianyu-l marked this pull request as ready for review November 13, 2026 08:23
@tianyu-l

Copy link
Copy Markdown
Contributor Author

@claude review

@claude

claude Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @tianyu-l's task in 6m 18s —— View job


Approve -- please address the items before merging (empty human-written summary; the Moonlight description is inaccurate): review --

@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 -- please address the items below before merging -- Splitting each family into text and multimodal classes removes the vision_encoder is None branches and keep_vision_encoder, which were driven by config. Numerics are bitwise equal for every family except Moonlight, and the description misstates how Moonlight changes. A maintainer still needs to review, because this touches shared code (spmd_types.py, multimodal.py, the RL controller and generator).

What this PR does. Each family that has encoders (Qwen3.5, Kimi K3, Kimi K2.x, Muse Glimmer, Muse Spark) now has a text Decoder subclass and a multimodal subclass whose config requires at least one encoder. Text flavors build the text class. The RL generator builds exactly what the config says, and Controller.Config checks vision_processor against the model type in both directions. annotate_input_spmd_types now also annotates any non-tensor input that defines annotate_spmd_types(), including values inside mappings such as attention_metadata.

Example.

# main
build_model_config("9B")   # Qwen35Model.Config(vision_encoder=None), a MultimodalModel
replace(build_model_config("9B_mm"), vision_encoder=None)  # accepted
# this PR
build_model_config("9B")   # Qwen35Model.Config (Decoder, no encoder field)
replace(build_model_config("9B_mm"), vision_encoder=None)  # ValueError in __post_init__
# Moonlight: KimiK25Model(vision_encoder=None) -> KimiK2Model(DeepSeekV3Model)

Must fix

  1. The "Summary (human-written)" section is empty: only the template comment is there. The author needs to write it.
  2. torchtitan/models/kimi_k2_7/model.py:48 -- Moonlight's code path changes, contrary to the description ("text path unchanged apart from the class"). It now runs MTPDecoder.preprocess_inputs/forward and no longer rejects CP. Correct the description; ideally add one Moonlight-shaped run.

Should consider

  • torchtitan/models/muse_glimmer/flavors.py:386 -- _model_config has a single caller and repeats that caller's branch with asserts. Inline it.
  • torchtitan/models/muse_spark/flavors.py:961 -- builds a throwaway MuseSparkModel.Config and copies its fields into a second config. Build one fields dict instead.
  • torchtitan/distributed/spmd_types.py:216 -- getattr(item, "annotate_spmd_types", None) is duck typing in a helper every model uses. A small Protocol (or an isinstance check against the metadata base classes) would make the contract explicit. Minor.

Questions

  • torchtitan/models/muse_spark/model.py:612 -- should dataset_modalities=() still be allowed on the multimodal config? It keeps the second text-only path that "Alternatives considered" rejects.
Details
  • Gate. The problem is real on main. Text flavors are MultimodalModels whose encoders are None, so callers use getattr(config, "vision_encoder", None). The split is the minimal explicit fix and moves validation to config time.
  • Kimi K2.x FSDP. On main, the MRO is (MultimodalModel, MTPDecoder), so MultimodalModel._apply_fsdp already called super() into MTPDecoder._apply_fsdp. Moonlight's FSDP grouping is therefore unchanged. The changes are preprocess/forward and the CP rejection.
  • The local_compile TODO on KimiK2Model.Config documents a bug that already exists on main (Kimi K2.5 compiles no regions because of the reversed-MRO field resolution). Keeping it out of scope is fine.
  • spmd_types. VarlenAttentionMetadata offsets are now typed for every model ({DP: V, CP: R, TP: R}). That matches the global offsets AllGatherKV uses. AllGatherKVVarlenAttentionMetadata.inverse_permutation stays untyped.
  • RL. The Controller check is engine-agnostic, so SGLang (which rejects vision_processor) keeps the guard that keep_vision_encoder=False used to give it.
  • Kimi K3. Dropping the parallelize override is safe for local_compile: both BaseModel.parallelize and MultimodalModel.parallelize call local_compile.apply().

Not verified: Moonlight and Kimi K2 text numerics, and CP on Moonlight. I also did not check the claim that every Kimi K3 parameter's module has a ShardingConfig; the description says typechecked runs cover it.



class KimiK25Model(MultimodalModel, MTPDecoder):
class KimiK2Model(DeepSeekV3Model):

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.

The description says Moonlight's "text path [is] unchanged apart from the class", but the code path does change. On main, Moonlight was a KimiK25Model with vision_encoder=None. It ran KimiK25Model.parallelize, which raised NotImplementedError under CP ("vision scatter needs the full sequence"), and also used KimiK25's own preprocess_inputs and forward (embedding under spmd_local_context("dp")).

As a KimiK2Model, Moonlight now gets MTPDecoder.preprocess_inputs/forward, which fall through to Decoder.forward when there are no MTP layers. CP is also no longer rejected. FSDP wrapping is unchanged, since main's MultimodalModel._apply_fsdp already called through to MTPDecoder._apply_fsdp.

Dropping the CP rejection is probably right, because its reason was the vision scatter. But nothing here exercises it: there is no text-only Kimi K2 debug flavor, and the Numerics table has no Moonlight row. Please fix the description to say Moonlight now uses the DeepSeek-V3/MTPDecoder text path and accepts CP. Ideally, also add one small Moonlight-shaped run (e.g. debugmodel built as KimiK2Model) to the numerics table.

return encoder, adapter


def _model_config(

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.

_model_config has a single caller, _muse_glimmer_config at line 444. That caller already branches on vision_adapter_dim to build vision_projection and perception_emb_norm. The helper then re-derives that branch from vision_encoder is None and asserts the four arguments agree.

Inlining it removes the four asserts and one function. Build the shared fields dict once, then return MuseGlimmerModel.Config(**fields) or MuseGlimmerMultimodalModel.Config(..., **fields) inside the existing if vision_adapter_dim is not None branch. Kimi's _moonlight_16b_a3b_config in this PR already uses this pattern.

Comment thread torchtitan/models/muse_spark/model.py Outdated

@dataclass(kw_only=True, slots=True)
class Config(MuseSparkModel.Config, MultimodalModel.Config):
dataset_modalities: tuple[Literal["vision", "audio"], ...] = ()

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.

dataset_modalities=() is still allowed on MuseSparkMultimodalModel.Config, and the README documents it as "no media; the encoders are skipped". That keeps a second way to be text-only: a multimodal config whose encoders are built and synced but never run. The "Alternatives considered" section rejects exactly that ("two ways to be text-only").

Should __post_init__ require at least one modality, so that text-only always means MuseSparkModel? Or is there a recipe that trains encoder-carrying checkpoints on text-only data? If such a recipe exists, it is worth naming in the README.

vision_invariant_linear_sharding_config()
),
)
return MuseSparkMultimodalModel.Config(

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.

For multimodal flavors, this builds a throwaway MuseSparkModel.Config and copies its fields via dataclasses.fields into a second config. That runs validation twice, and the copy silently depends on the two configs sharing every field.

Building a fields dict once and constructing exactly one config is shorter and states the intent directly. It is the same pattern Kimi's _moonlight_16b_a3b_config uses:

fields = dict(max_context_length=..., tok_embeddings=..., layers=layers, ...)
if audio_encoder is None and vision_encoder is None:
    return MuseSparkModel.Config(**fields)
...
return MuseSparkMultimodalModel.Config(**fields, dataset_modalities=..., ...)

…ntract

- Muse Glimmer: inline the single-caller _model_config; the builder takes
  vision=(encoder, adapter) and derives vision_projection's input size from
  the adapter.
- Muse Spark: build one fields dict and construct exactly one config, instead
  of copying a throwaway MuseSparkModel.Config into the multimodal one.
- MuseSparkMultimodalModel.Config requires a non-empty dataset_modalities, so
  text-only training always means MuseSparkModel.
- annotate_input_spmd_types checks a runtime-checkable SpmdAnnotatedInput
  Protocol instead of getattr duck typing.

Flavor configs are unchanged (every Glimmer/Spark flavor dumped before and
after, TP1 and TP2+EP2+SP).
@tianyu-l

Copy link
Copy Markdown
Contributor Author

@claude review

@claude

claude Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @tianyu-l's task in 2m 4s —— View job


Approve -- please address the items before merging (the human-written summary is still empty, and test_multimodal.py needs to target a family that only the generic encoder check guards): review

@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 -- please address the items below before merging -- 000bf44 resolves every code item from the previous review. Two small items are left: the human-written summary is still empty, and the new Muse Spark check leaves test_multimodal.py testing a guard that Spark no longer relies on. A maintainer still needs to review, because this touches shared code (spmd_types.py, multimodal.py, the RL controller and generator).

What this PR does. Each family that has encoders (Qwen3.5, Kimi K3, Kimi K2.x, Muse Glimmer, Muse Spark) now has two classes: a text Decoder and a multimodal subclass whose config requires at least one encoder. Text flavors build the text class, and the RL generator builds exactly what the config says. The latest commit inlines the Glimmer and Spark config builders so each builds exactly one config. It also makes MuseSparkMultimodalModel.Config require a non-empty dataset_modalities, and replaces getattr duck typing in annotate_input_spmd_types with a runtime-checkable SpmdAnnotatedInput Protocol.

Example.

build_model_config("9B")     # Qwen35Model.Config (Decoder, no encoder field)
replace(build_model_config("9B_mm"), vision_encoder=None)  # ValueError, MultimodalModel.Config
# Muse Spark after 000bf44:
replace(spark_mm, dataset_modalities=())  # ValueError, MuseSparkMultimodalModel.Config
replace(spark_mm, vision_encoder=None, audio_encoder=None)  # ValueError from either check

Must fix

  1. The "Summary (human-written)" section is still empty, with only the template placeholder. The author needs to write it.
  2. tests/unit_tests/cpu/models/common/test_multimodal.py:15 -- Spark now rejects a config with no encoders by itself, so this test only pins which ValueError fires first. Point it at Kimi K3 or Qwen3.5 vision_encoder=None instead, where MultimodalModel.Config is the only guard, and update the Testing bullet in the description (inline suggestion).
Details
  • Previous review items at HEAD. Moonlight description: fixed. It now says Moonlight runs MTPDecoder.preprocess_inputs/forward, accepts CP (untested), and the numerics table has a Kimi K2 text row. Glimmer _model_config: inlined, and vision_projection.in_features now comes from vision_adapter.c_proj.out_features, the same way Spark does it. Spark throwaway config: replaced by a single fields dict. Duck typing: replaced by SpmdAnnotatedInput. dataset_modalities=(): now raises, and the README and docstring are updated.
  • Check order in Spark. MuseSparkMultimodalModel.Config resolves its MRO as MuseSparkModel.Config -> MultimodalModel.Config -> Decoder.Config. Because super().__post_init__() runs first, the generic "needs at least one of" error is raised before Spark's dataset_modalities checks. That ordering is the only reason the current test passes.
  • SpmdAnnotatedInput. A runtime_checkable isinstance only checks that the attribute exists, so behavior is the same as the old getattr. The four implementers (attention.py:354, linear_attention.py:51, cp_linear_attention.py:47,90) match the Protocol structurally and need no changes.
  • RL. The two-way Controller check is engine-agnostic, so engines without a vision processor keep the guard that keep_vision_encoder=False used to give them.

Not verified: the Glimmer and Spark flavor-config equivalence after 000bf44 (the author reports dumping every flavor before and after), and CP on Moonlight.

Comment on lines +15 to +23
def test_multimodal_config_requires_an_encoder() -> None:
"""Muse Spark's encoders are each optional, so MultimodalModel.Config is
what rejects a multimodal config with none."""
config = build_model_config("debugmodel_mm", parallelism=ParallelismConfig())
dataclasses.replace(config, audio_encoder=None, dataset_modalities=("vision",))
with pytest.raises(ValueError, match="needs at least one of"):
dataclasses.replace(
config, audio_encoder=None, vision_encoder=None, dataset_modalities=()
)

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.

After 000bf44, Muse Spark no longer depends on MultimodalModel.Config to reject a config with no encoders. MuseSparkMultimodalModel.Config.__post_init__ (muse_spark/model.py:621-634) now requires a non-empty dataset_modalities, and it requires an encoder for each listed modality, so Spark already rejects that config by itself. The docstring and the description's Testing bullet ("Muse Spark is the only family where each encoder is optional, so this check is its only guard") are no longer true.

The test now passes only because the MRO runs MultimodalModel.Config.__post_init__ before Spark's own check. Delete the generic check and this still raises ValueError, just with the wrong message: the test pins which error fires first, not that the config is rejected.

The generic check is now the only guard for the families whose encoder field is required but can still be set to None explicitly. That is the replace(build_model_config("9B_mm"), vision_encoder=None) example in the description. Point the test at one of those families instead, e.g. Kimi K3, whose CPU tests already import cleanly:

Suggested change
def test_multimodal_config_requires_an_encoder() -> None:
"""Muse Spark's encoders are each optional, so MultimodalModel.Config is
what rejects a multimodal config with none."""
config = build_model_config("debugmodel_mm", parallelism=ParallelismConfig())
dataclasses.replace(config, audio_encoder=None, dataset_modalities=("vision",))
with pytest.raises(ValueError, match="needs at least one of"):
dataclasses.replace(
config, audio_encoder=None, vision_encoder=None, dataset_modalities=()
)
def test_multimodal_config_requires_an_encoder() -> None:
"""Kimi K3's vision_encoder is its only encoder, so MultimodalModel.Config
is the only check that rejects setting it to None."""
config = build_model_config("debugmodel_mm", parallelism=ParallelismConfig())
with pytest.raises(ValueError, match="needs at least one of"):
dataclasses.replace(config, vision_encoder=None)

This needs from torchtitan.models.kimi_k3 import build_model_config at line 12. Then update the Testing bullet in the description.

Muse Spark now rejects a config with no encoders by itself (dataset_modalities
must be non-empty and each listed modality needs its encoder), so the test only
pinned which ValueError fires first. For Kimi K3, MultimodalModel.Config is the
only check rejecting vision_encoder=None; with it removed, the config is
accepted.
@tianyu-l

Copy link
Copy Markdown
Contributor Author

@claude review

@claude

claude Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @tianyu-l's task in 49s —— View job


Approve -- please address the item before merging (the human-written summary is still empty; 73137f0 fixed the test_multimodal.py item): review

@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 -- please address the item below before merging -- 73137f0 fixes the test item from the last review. The only item left is the empty human-written summary. A maintainer still needs to review, because this touches shared code (spmd_types.py, multimodal.py, the RL controller and generator).

What changed since the last review. One commit, 73137f0. It points test_multimodal.py at Kimi K3 debugmodel_mm with vision_encoder=None instead of Muse Spark.

Example.

config = kimi_k3.build_model_config("debugmodel_mm", parallelism=ParallelismConfig())
dataclasses.replace(config, vision_encoder=None)
# ValueError: KimiK3MultimodalModel needs at least one of ('vision_encoder',); ...

Must fix

  1. The "Summary (human-written)" section is still empty: it has only the template placeholder. The author needs to write it.
Details
  • Previous item, test_multimodal.py: resolved. KimiK3MultimodalModel.Config (kimi_k3/model.py:316) defines no __post_init__, and neither does KimiK3Model.Config. So MultimodalModel.Config.__post_init__ (multimodal.py:46-57) is the only check that rejects vision_encoder=None, and the test fails if that check is removed. multimodal_encoder_fqns = ("vision_encoder",) at line 312 matches the field the test clears. The Testing bullet in the description already names Kimi K3.
  • All other items from the earlier reviews were resolved at 000bf44 and are unchanged at HEAD.

Not verified: I did not run the test (running tests needs approval in this job), and CP on Moonlight is still untested.

@tianyu-l
tianyu-l merged commit 1e797a8 into main Nov 13, 2026
@tianyu-l
tianyu-l deleted the multimodal-class-split branch November 13, 2026 15:18
JavaZeroo added a commit to JavaZeroo/torchtitan that referenced this pull request Nov 13, 2026
Follow the Kimi K3 split from pytorch#6084: debugmodel and Kimi-K3.1-Pro build the text KimiK31Model, and the _mm flavors build KimiK31MultimodalModel with the vision encoder. kimi_k3_config takes the multimodal config class next to the text one.
JavaZeroo added a commit to JavaZeroo/torchtitan that referenced this pull request Nov 13, 2026
Follow the Kimi K3 split from pytorch#6084: debugmodel and Kimi-K3.1-Pro build the text KimiK31Model, and the _mm flavors build KimiK31MultimodalModel with the vision encoder. kimi_k3_config takes the multimodal config class next to the text one.
JavaZeroo added a commit to JavaZeroo/torchtitan that referenced this pull request Nov 19, 2026
Follow the Kimi K3 split from pytorch#6084: debugmodel and Kimi-K3.1-Pro build the text KimiK31Model, and the _mm flavors build KimiK31MultimodalModel with the vision encoder. kimi_k3_config takes the multimodal config class next to the text one.
JavaZeroo added a commit to JavaZeroo/torchtitan that referenced this pull request Nov 19, 2026
Follow the Kimi K3 split from pytorch#6084: debugmodel and Kimi-K3.1-Pro build the text KimiK31Model, and the _mm flavors build KimiK31MultimodalModel with the vision encoder. kimi_k3_config takes the multimodal config class next to the text one.
JavaZeroo added a commit to JavaZeroo/torchtitan that referenced this pull request Nov 19, 2026
Follow the Kimi K3 split from pytorch#6084: debugmodel and Kimi-K3.1-Pro build the text KimiK31Model, and the _mm flavors build KimiK31MultimodalModel with the vision encoder. kimi_k3_config takes the multimodal config class next to the text one.
JavaZeroo added a commit to JavaZeroo/torchtitan that referenced this pull request Nov 23, 2026
Follow the Kimi K3 split from pytorch#6084: debugmodel and Kimi-K3.1-Pro build the text KimiK31Model, and the _mm flavors build KimiK31MultimodalModel with the vision encoder. kimi_k3_config takes the multimodal config class next to the text one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/b200 Trigger B200 CI 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