Repository navigation
[Qwen3VL] replace mask_scatter and boolean indexing by slice assignment - #3099
Merged
Merged
Conversation
shuhuayu
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
April 24, 2026 23:42
tianyu-l
approved these changes
Apr 25, 2026
fegin
added a commit
that referenced
this pull request
Apr 30, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
## Framework changes
### ``Module.from_nn_module`` auto-generates a ``Config``
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
### Centralize ``from_nn_module`` calls
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
### ``LocalMapConfig`` accepts ``None`` per-arg
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
## Vision encoder Configs
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
## ``set_qwen3_vl_sharding_config`` helper
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
## ``parallelize_qwen3_vl`` rewritten
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
## ``apply_moe_ep_tp`` deleted
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
## Verification
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
## Status of the three deferral blockers from sharding_known_fixes_and_pending
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: fa224e0
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
Apr 30, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
## Framework changes
### ``Module.from_nn_module`` auto-generates a ``Config``
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
### Centralize ``from_nn_module`` calls
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
### ``LocalMapConfig`` accepts ``None`` per-arg
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
## Vision encoder Configs
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
## ``set_qwen3_vl_sharding_config`` helper
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
## ``parallelize_qwen3_vl`` rewritten
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
## ``apply_moe_ep_tp`` deleted
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
## Verification
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
## Status of the three deferral blockers from sharding_known_fixes_and_pending
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 9b5afe9
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
Apr 30, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
## Framework changes
### ``Module.from_nn_module`` auto-generates a ``Config``
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
### Centralize ``from_nn_module`` calls
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
### ``LocalMapConfig`` accepts ``None`` per-arg
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
## Vision encoder Configs
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
## ``set_qwen3_vl_sharding_config`` helper
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
## ``parallelize_qwen3_vl`` rewritten
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
## ``apply_moe_ep_tp`` deleted
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
## Verification
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
## Status of the three deferral blockers from sharding_known_fixes_and_pending
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 7a88a5b
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
Apr 30, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 5e17765
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 1, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 25772c6
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 1, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: d156097
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 1, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 8327125
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 5, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: f995e3e
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 5, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 0f3e937
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 5, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 1f37242
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 5, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 94e7c67
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 6, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 04b2dde
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 7, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: ef6d09c
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 7, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: ef6d09c
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 12, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: c16441f
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 12, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 67d3a48
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 12, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 67d3a48
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 12, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 67d3a48
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 12, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 67d3a48
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 13, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 9f1403d
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 13, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 1c24118
Pull-Request: #3165
fegin
added a commit
that referenced
this pull request
May 13, 2026
Convert Qwen3-VL entirely to config-based sharding (decoder dense + MoE
+ vision encoder) and enable ``--training.full_dtensor`` for Qwen3-VL.
This closes the deferral that has tracked qwen3_vl across PR1-PR8. After
this PR, Qwen3-VL uses the same declarative ``model.parallelize
(parallel_dims)`` flow as qwen3 / llama4 / gpt_oss / deepseek_v3, and
``apply_moe_ep_tp`` is fully deleted (no remaining callers).
``Module.from_nn_module(nn.Foo)`` now also generates a ``Foo.Config``
subclass of ``Module.Config``. The Config inherits ``sharding_config``
and ``param_init`` slots; a custom ``build(*args, **kwargs)`` forwards
positional / keyword args to the underlying ``nn.Module`` constructor
and applies the slots to the resulting instance. Two usage patterns:
LayerNorm = Module.from_nn_module(nn.LayerNorm)
# Direct construction (no declarative sharding):
norm = LayerNorm(dim, eps)
# Config-based construction:
norm = LayerNorm.Config(
sharding_config=norm_config(enable_sp=False),
).build(dim, eps)
The cache key (``_created_classes``) stays keyed on ``nn_module_cls`` --
distinct sharding plans live on Config instances, not on the class.
New ``torchtitan/models/common/nn_modules.py`` is the single source of
truth for ``from_nn_module``-wrapped standard nn modules: ``Conv2d``,
``GELU``, ``GroupNorm``, ``Identity``, ``LayerNorm``, ``SiLU``. Top-of-
file docstring documents the two usage patterns. All five existing call
sites import from here.
``LocalMapConfig.in_placements`` / ``out_placements`` /
``in_grad_placements`` types loosen to ``tuple[NamedPlacement | None,
...]`` so non-tensor function args can pass through ``local_map``
unchanged. ``Module._needed_axes`` skips ``None`` entries; the framework
passes ``None`` to ``torch.distributed.tensor.experimental.local_map``.
Each of ``PatchEmbed``, ``VisionRotaryEmbedding``, ``PatchMerger``,
``VisionAttention``, ``VisionMLP``, ``VisionTransformerBlock`` now has
its own ``Config`` subclass of ``Module.Config``. ``Qwen3VLVisionEncoder``
constructs children via ``Sub.Config(...).build()`` instead of direct
positional construction, so the Config tree is walkable for
``set_qwen3_vl_sharding_config``. The flat fields on
``Qwen3VLVisionEncoder.Config`` (e.g. ``attn_qkv: Linear.Config``) are
preserved as the external contract; the parent ``__init__`` builds the
nested Configs from them.
New ``torchtitan/models/qwen3_vl/sharding.py`` covers:
- Decoder dense (mirrors ``set_qwen3_sharding_config`` with
``enable_sp=False`` -- VLM keeps Replicate hidden states for vision
scatter and DeepStack).
- MoE FFN (delegates to ``set_moe_sharding_config`` from PR7 with
``enable_sp=False``).
- Vision encoder: ``patch_embed.proj`` Replicate, ``pos_embed`` declared
via ``state_shardings`` on encoder root, vision blocks
(``norm1/norm2``, ``attn.qkv`` colwise, ``attn.proj`` rowwise with
Replicate output, ``mlp.linear_fc1`` colwise, ``mlp.linear_fc2``
rowwise with Replicate output), and mergers (main + DeepStack).
Vision activations flow as ``DTensor(Replicate)`` throughout (no SP);
linears shard on TP for memory but redistribute back to Replicate on
output, matching the legacy ``_apply_tp_to_vision_encoder`` pattern.
Drops ``_apply_tp_to_vision_encoder``, ``_apply_non_moe_tp_to_decoder``,
the ``apply_moe_ep_tp`` call, and the manual inner-attention
``local_map`` wraps. Uses the llama3-style branch: ``validate_config``
+ ``model.parallelize(parallel_dims)`` under full_dtensor; legacy CP
wrap + parallelize otherwise. ``apply_fsdp`` accepts the new
``dp_mesh_dims`` / ``edp_mesh_dims`` kwargs from PR8.
The ``NotImplementedError("Context Parallel is not yet supported for
Qwen3-VL")`` gate now triggers only under ``full_dtensor=False`` --
under full_dtensor, CP flows through inner attention's ``LocalMapConfig``.
After Qwen3-VL migrates, no callers remain. The function is removed
from ``torchtitan/models/llama4/parallelize.py`` along with all its
imports (``parallelize_module``, ``PrepareModuleInputOutput``,
``RowwiseParallel``, ``ExpertParallel``, ``ExpertTensorParallel``,
``TensorParallel``, ``ColwiseParallelWithGradPlacement``, ``NoParallel``,
``AllToAllTokenDispatcher``, ``TorchAOTokenDispatcher``, ``Partial``,
``Replicate``).
- 33/33 ``test_module.py`` unit tests pass (4 new tests for
``Module.from_nn_module(...).Config``).
- ``pre-commit run --all-files`` clean.
- qwen3 EP=2 non-full_dtensor regression bit-identical to PR8 (loss
8.15586 / grad_norm 3.0237).
- Full Qwen3-VL training-loop verification skipped (test environment
lacks torchvision); construction tests confirm the new Config tree
builds correctly. Real Qwen3-VL multimodal verification is owed to
a follow-up validation run on the user's primary dev environment.
(a) ``ShardingConfig.local_output_grad_placements`` -- landed in
Pre-PR7 (as part of the PR7 commit).
(b) ``Module.from_nn_module(...)`` auto-generates a Config so call sites
can attach a sharding plan -- this PR.
(c) ``_compute_learned_pos_embeds`` and vision-embed boolean indexing:
the boolean indexing was already replaced by slice assignment in
PR #3099 (no lift needed); the ``_compute_learned_pos_embeds``
``local_map`` wrap remains imperative because the
Module-owns-param-passed-through-local_map pattern doesn't compose
cleanly with ``LocalMapConfig`` (the framework's ``local_map``
converts function arguments, not module parameters accessed via
``self``).
ghstack-source-id: 43a4e41
Pull-Request: #3165
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace
masked_scatterand boolean indexing in vision scatter and deepstack with slice assignment. This avoids DTensor-incompatible opsmasked_scatter, andbooleanindexing in the first place, and thus hidden states can now flow asDTensor(Replicate)throughout the decoder withoutto_local()conversions. This saves DTensor side changes to support new ops.Since
masked_scatterinternally creates a new tensor, this new in-place mutation approach can save some memory operations. The canonical example in our config of8bmodel training has an improved mfu of37.7%compared to the previous36.9%.The new introduced
_compute_vision_positionsmethod shares some overlapped computation with_compute_mrope_freqs, but the current way it cleaner, and the additional cost is around0.2ms compared to the total forward pass cost around35ms.