Skip to content

[spmd_types] llama3 enablement - #3278

Closed
pianpwk wants to merge 211 commits into
mainfrom
gh/pianpwk/9/head
Closed

pianpwk wants to merge 211 commits into
mainfrom
gh/pianpwk/9/head

Conversation

pianpwk added 2 commits May 7, 2026 17:57
[ghstack-poisoned]
[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 8, 2026
pianpwk added 6 commits May 7, 2026 23:04
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
pianpwk added 6 commits May 10, 2026 12:11
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@pianpwk pianpwk changed the title [draft][spmd_llama3] ChunkedCELoss local_map refactor [spmd_llama3] ChunkedCELoss local_map refactor May 12, 2026
pianpwk added 2 commits May 11, 2026 17:26
[ghstack-poisoned]
[ghstack-poisoned]
Comment thread torchtitan/components/loss.py Outdated
# Distributed log-sum-exp: 2 all-reduces for numerical stability
with torch.no_grad():
local_max = logits_2d.max(dim=-1).values
global_max = funcol.all_reduce(local_max, "MAX", tp_pg)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this needs {tp: R} annot

Comment thread torchtitan/components/loss.py Resolved
pianpwk added 3 commits May 12, 2026 17:54
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
pianpwk added 3 commits June 18, 2026 23:16
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
lora_a_sharding = ShardingConfig(
state_shardings={"weight": dense_param_placement(tp=spmd.S(1))},
)
return lora_a_sharding, replicated_weight

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@tianyu-l lora feature test has implicit weight redistribution (for rowwise vs. colwise), checking if this makes sense

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm, this makes sense to me. I must have missed the point when I was reviewing it. Curious what redistribution happens.

lse_NT, spmd.V, spmd.PartitionSpec("tp", ("dp", "cp"))
)

out_BLNH = out_TNH.view(B, L, -1, H).to(q_BLNH.dtype)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@tianyu-l for varlen

[ghstack-poisoned]
pianpwk added 2 commits June 20, 2026 15:52
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Comment thread torchtitan/models/common/attention.py Outdated
assert isinstance(result, torch.Tensor)
if get_spmd_backend() == "spmd_types" and spmd.is_type_checking():
spmd.assert_type(
result, spmd.V, spmd.PartitionSpec(("dp", "cp"), "tp", None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Whenever there's any tensor dim sharded as (dp, cp), that's likely incorrect, because it must be coming from folding [S(0), S(1)], which should've resulted in StridedShard.

Maybe no_typecheck() the entire region for now and leave a TODO.

@pianpwk pianpwk Jun 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the folding is needed for VarLen's signature (in the code above), but I just realized VarLen + CP is supported yet, so removing CP from assert_type for now, adding a comment.

pianpwk added 3 commits June 21, 2026 21:07
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
pianpwk added 6 commits June 22, 2026 18:01
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
src_spmd_layout.axis_types,
src_spmd_layout.partition_spec,
)
if spmd.is_type_checking():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe mention why it doesn't work with compile during erasure, if not having this if/else

pianpwk added 4 commits June 23, 2026 17:20
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
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.

3 participants