Skip to content

Commit 59f337f

Browse files
committed
Allow sharding config to wrap declared plain inputs
1 parent 77444f3 commit 59f337f

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

torchtitan/protocols/module.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -590,20 +590,19 @@ def _redistribute_inputs(
590590
if mesh is None:
591591
continue
592592

593-
if (
594-
not isinstance(value, DTensor)
595-
and parallel_dims.spmd_backend == "full_dtensor"
596-
):
597-
raise ValueError("Got a plain Tensor under the full_dtensor mode.")
598-
599-
if not isinstance(value, DTensor) and src_spmd_layout is not None:
600-
layout = resolve_placements(src_spmd_layout, mesh)
601-
value = DTensor.from_local(
602-
value,
603-
mesh,
604-
layout,
605-
run_check=False,
606-
)
593+
if not isinstance(value, DTensor):
594+
if src_spmd_layout is not None:
595+
layout = resolve_placements(src_spmd_layout, mesh)
596+
value = DTensor.from_local(
597+
value,
598+
mesh,
599+
layout,
600+
run_check=False,
601+
)
602+
elif parallel_dims.spmd_backend == "full_dtensor":
603+
raise ValueError(
604+
"Got a plain Tensor under the full_dtensor mode."
605+
)
607606

608607
if isinstance(value, DTensor) and src_spmd_layout is not None:
609608
expected = resolve_placements(src_spmd_layout, mesh)

0 commit comments

Comments
 (0)