Skip to content

[muse_glimmer] Enable CP for the multimodal model - #4387

Open
jinsooihm wants to merge 1 commit into
pytorch:mainfrom
jinsooihm:muse-glimmer-cp
Open

[muse_glimmer] Enable CP for the multimodal model#4387
jinsooihm wants to merge 1 commit into
pytorch:mainfrom
jinsooihm:muse-glimmer-cp

Conversation

@jinsooihm

Copy link
Copy Markdown
Contributor

Summary

This PR enables CP for the multimodal muse_glimmer.

MuseGlimmerModel.preprocess_inputs builds vision_bank_indices_T: [T] from unsharded text tokens, which maps each token position to the index of vision encoder output that should be placed there.
Then, vision_bank_indices_T gets permuted and sharded by prepare_context_parallel_input jointly with tokens, so it can be used in the model forward to gather the vision encoder output (which is replicated on CP) after token is embedded.

Test Plan

TP2+SP vs TP2+CP2+SP: max loss difference 1.38e-5; max grad_norm difference 5.04e-4 from running loss_compare.py

Build packed vision source indices before context-parallel token sharding and carry them through the same load-balancing permutation. Keep vision compute replicated across CP, then use a stateless sharding boundary to gather each local token shard while preserving TP and FSDP gradient semantics.

Generalize the shared vision attention layouts, keep multimodal embedding preparation on pipeline stage 0, and support the combined TP+CP+PP+SP topology without changing existing non-CP behavior or checkpoint keys.

Test Plan: 71 focused CPU tests; 2 distributed GPU tests; 10-step CP2xPP2 and TP2xCP2xPP2+SP real-process-group runs; exact 10-step deterministic loss and grad-norm parity; repository pre-commit hooks excluding the separately documented optional-dependency Pyrefly blocker.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 31, 2026
@jinsooihm
jinsooihm marked this pull request as ready for review September 1, 2026 00:59
return vision_bank_indices_T.masked_fill(~vision_mask_T, -1)


class VisionScatter(Module):

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.

Question 1: are you putting it here because other multimodal models could share? Is there a vlm model in torchtitan that cannot use this to implement CP?

Question 2: do you create this stateless module only because you want _vision_scatter_config to perform spmd collectives at the module boundary? Fwiw we are moving away from such pattern because they couldn't express fused comm + computation. Could you put collectives INSIDE model code instead? I think we at least we could have a function that does vision scattering, instead of a module.

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.

2 participants