Skip to content

[spmd_types] Enable Kimi K3 backend - #4446

Merged
pianpwk merged 4 commits into
mainfrom
gh/pianpwk/101/head
Sep 5, 2026
Merged

pianpwk merged 4 commits into
mainfrom
gh/pianpwk/101/head

Conversation

@pianpwk

@pianpwk pianpwk commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

[ghstack-poisoned]
[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 3, 2026
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Sep 3, 2026
[ghstack-poisoned]
[ghstack-poisoned]
@pianpwk
pianpwk marked this pull request as ready for review September 4, 2026 18:19
# Kimi K3 only declares layouts for its MoE modules. Seed replicated
# layouts for the remaining decoder and vision parameters before the
# MoE declarations replace the expert parameters with sparse shards.
annotate_replicated_parameters(model, parallel_dims)

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.

hmm, I would rather everything be declared explicitly, instead of having this fallback. Agents probably can automate this for you?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i guess that's ok, but it's just going to declare all params as R, it only gets interesting when TP is involved? And I thought that was an upcoming PR

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.

oh, I see your point. I think we anyway needs TP for RL, but sure we can worry about it later.

# Kimi K3 only declares layouts for its MoE modules. Seed replicated
# layouts for the remaining decoder and vision parameters before the
# MoE declarations replace the expert parameters with sparse shards.
annotate_replicated_parameters(model, parallel_dims)

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.

oh, I see your point. I think we anyway needs TP for RL, but sure we can worry about it later.

@pianpwk
pianpwk changed the base branch from gh/pianpwk/101/base to main September 4, 2026 23:43
@pianpwk
pianpwk merged commit 314c207 into main Sep 5, 2026
8 of 9 checks passed
@QIU023

QIU023 commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Hi @pianpwk and @tianyu-l , noticed this SPMD backend enabled change for K3 and it might have broken the K3 debug flavor since the ViT part some are not included in sharding declaration

Published a full SPMD PR: #4492 for K3 to both fix it and unblock further spmd sharding declaration changes, during implementing K3 CP and K3 TP/SP locally containing

The kimi_k3_debugmodel_mm_fsdp2 fails at step 1 on main as merged.

  • Error: ValueError: spmd_types backend requires an SPMD layout for every tensor input, but these have no entry in input_sharding: ['grid_thw', 'pixel_values'], raised by annotate_input_spmd_types under Decoder.preprocess_inputs (traceback below).
  • Cause: the flavor's partial_dtensor pin is gone, the default backend is spmd_types, and Kimi K3 declares no layout for its multimodal inputs. Every kimi_k3_debugmodel run without an explicit --parallelism.spmd_backend partial_dtensor hits it, dp1 included.
  • Reproduced on 390e298 with the cell's own recipe (dp2, type checking on).
  • Fix: two lines in KimiK3Model.preprocess_inputs, folding multimodal_input_sharding() into input_sharding as qwen3_5 and kimi_k2_7 do. I carry it in the declarations PR I am about to open; I can send it as a standalone fix first if you prefer.
  File "torchtitan/trainer.py", line 744, in forward_backward_step
  File "torchtitan/models/common/decoder.py", line 345, in preprocess_inputs
    batch = annotate_input_spmd_types(parallel_dims, batch, input_sharding)
  File "torchtitan/distributed/spmd_types.py", line 223, in annotate_input_spmd_types
    raise ValueError(
ValueError: spmd_types backend requires an SPMD layout for every tensor input, but these have no entry in input_sharding: ['grid_thw', 'pixel_values']. Add them to the input layout the model declares in ``preprocess_inputs``, or annotate nested/container tensors at their construction site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants