Skip to content

[spmd_types] global_valid_tokens: float | None - #3586

Merged
pianpwk merged 4 commits into
mainfrom
gh/pianpwk/29/head
Jun 9, 2026
Merged

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

Conversation

@pianpwk

@pianpwk pianpwk commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

pianpwk added 2 commits June 8, 2026 23:19
[ghstack-poisoned]
[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 9, 2026
@pianpwk pianpwk changed the title Make global_valid_tokens a float [spmd_types] Make global_valid_tokens a float Jun 9, 2026
@pianpwk pianpwk changed the title [spmd_types] Make global_valid_tokens a float [spmd_types] global_valid_tokens: float | None Jun 9, 2026
pianpwk added a commit that referenced this pull request Jun 9, 2026
Adding this to allow both spmd types specs, and DTensor-style
placements. We're adding something like D107576760 in spmd_types, but in
the meantime, because non-llama3 models are still in DTensor placement
form, I think we have 2 options:

1) keep this as a hybrid spmd/DTensor container (e.g. moe_sharding.py
calls `dense_activation_placement(tp=Replicate())`, and migrate to
SpmdLayout once all models are off full_dtensor.
2) since we're adding a spmd->DTensor translation shim anyways, migrate
all models from `Replicate/Shard/Partial` to `spmd.R/S/P` immediately,
use SpmdLayout, and go deal with I/R distinctions later. This should be
ok because non-llama3 models won't support spmd backend yet.

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.12.0)
(oldest at bottom):
* #3278
* #3472
* #3468
* #3471
* #3253
* #3587
* #3586
* __->__ #3501
pianpwk added 2 commits June 9, 2026 00:59
[ghstack-poisoned]
[ghstack-poisoned]
@pianpwk
pianpwk marked this pull request as ready for review June 9, 2026 08:02
@pianpwk
pianpwk changed the base branch from gh/pianpwk/29/base to main June 9, 2026 08:02
@pianpwk
pianpwk merged commit 842d354 into main Jun 9, 2026
22 checks passed
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Jun 9, 2026
…one)

Upstream `[spmd_types] global_valid_tokens: float | None (pytorch#3586,
2026-06-09)` retyped `global_valid_tokens` from `torch.Tensor` to
`float | None` and switched the no-DP branch from
`local_valid_tokens.float()` (returns a Tensor) to
`float(local_valid_tokens.item())` (returns a Python float).

Mirror that in:
  - `ezpz/trainer.py` `forward_backward_step` no-DP branch
  - `ezpz/validator.py` `validate` no-DP branch

DP branch is left as-is (still returns a Tensor from `dist_sum`) —
upstream itself does the same, the annotation is loose, and consumers
(BaseLoss.__call__, ChunkedCELoss) accept either at runtime.

The DP path is the only one any current production / smoke run takes,
so functional behavior is unchanged. This replay just keeps the no-DP
fallback honest about its return type.
wwwjn pushed a commit that referenced this pull request Jun 10, 2026
Adding this to allow both spmd types specs, and DTensor-style
placements. We're adding something like D107576760 in spmd_types, but in
the meantime, because non-llama3 models are still in DTensor placement
form, I think we have 2 options:

1) keep this as a hybrid spmd/DTensor container (e.g. moe_sharding.py
calls `dense_activation_placement(tp=Replicate())`, and migrate to
SpmdLayout once all models are off full_dtensor.
2) since we're adding a spmd->DTensor translation shim anyways, migrate
all models from `Replicate/Shard/Partial` to `spmd.R/S/P` immediately,
use SpmdLayout, and go deal with I/R distinctions later. This should be
ok because non-llama3 models won't support spmd backend yet.

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.12.0)
(oldest at bottom):
* #3278
* #3472
* #3468
* #3471
* #3253
* #3587
* #3586
* __->__ #3501
wwwjn pushed a commit that referenced this pull request Jun 10, 2026
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Sep 16, 2026
components/loss.py passes global_valid_tokens to spmd.assert_type(), which
does tensor.ndim. Our no-DP branch handed it a Python float, so every rank
died with "'float' object has no attribute 'ndim'" once the SPMD mesh was
live -- on torch 2.14.0+xpu and the 2.15 nightly alike (12477652, 12477644),
both immediately AFTER FSDP wrapping succeeded.

Core keeps a tensor on BOTH branches (trainer.py:902-908) and uses
dist_sum_tensor rather than dist_sum. Matched that.

The float came from mirroring PR pytorch#3586 (2026-06-09), which retyped this as
'float | None'. Upstream has since reverted to a tensor, so the comment
justifying the float described a contract that no longer holds.

This is OUR bug, not a spmd_types one -- downgrading spmd_types would not fix
it, since the caller is what violates the tensor contract.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants