Skip to content

delete --disable_loss_parallel flag - #3694

Merged
pianpwk merged 18 commits into
mainfrom
gh/pianpwk/44/head
Jun 18, 2026
Merged

pianpwk merged 18 commits into
mainfrom
gh/pianpwk/44/head

Conversation

@pianpwk

@pianpwk pianpwk commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

loss migration: loss-parallel custom autograd handling, DTensor local_map / unwrapping, now lives under cross_entropy_loss fn

loss-parallel flag deletion:

  • for trainers, TP on = LP on, uses custom autograd impl instead of pytorch's implicit loss_parallel() context. Sets model sharding configs to return vocab-sharded logits: tp_gather_logits=False
  • RL usecases require full logits from lm_head, tp_gather_logits=True
  • GraphTrainer TP on = LP on

Stack from ghstack (oldest at bottom):

pianpwk added 2 commits June 16, 2026 16:22
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@pianpwk pianpwk changed the title [spmd_types] require loss parallel for TP require loss parallel for TP Jun 16, 2026
Comment thread torchtitan/trainer.py Outdated
)
self.train_context = dist_utils.get_train_context(
enable_loss_parallel=loss_parallel_enabled,
enable_loss_parallel=parallel_dims.tp_enabled,

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.

remove this flag enable_loss_parallel globally -- it is always enabled

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.

uhhh reshuffling things a bit while I figure this out but...

  • ended up keeping the top-level disable_loss_parallel flag
  • require LP for TP trainer (torchft too)
  • delete flag from dist_utils.train_context
  • renamed sharding config flag to gather_tp_logits - appears both RL policy trainer & generator expect full logits from lm_head, so is_inference is misleading
  • main blocker is graph trainer - unclear what they want, though no reliance on train_context

[ghstack-poisoned]
pianpwk added a commit that referenced this pull request Jun 17, 2026
pianpwk added a commit that referenced this pull request Jun 17, 2026
No immediate effect, just prepping for next commit.

decided not to use `spmd.local_map` to avoid larger refactor

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.12.0)
(oldest at bottom):
* #3690
* #3673
* #3655
* #3664
* #3654
* #3278
* #3694
* #3472
* __->__ #3632
* #3653
pianpwk added 2 commits June 16, 2026 23:37
[ghstack-poisoned]
[ghstack-poisoned]
@pianpwk pianpwk changed the title require loss parallel for TP require loss parallel for TP training Jun 17, 2026
pianpwk added 2 commits June 17, 2026 14:29
[ghstack-poisoned]
[ghstack-poisoned]
@pianpwk pianpwk changed the title require loss parallel for TP training delete --disable_loss_parallel flag Jun 17, 2026
@pianpwk
pianpwk requested a review from tianyu-l June 17, 2026 21:43
pianpwk added 2 commits June 17, 2026 15:48
[ghstack-poisoned]
[ghstack-poisoned]
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Jun 17, 2026
Comment thread torchtitan/components/loss.py Outdated
pred.device_mesh.get_group("tp"),
pred.shape[-1],
)
else:

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.

when would we hit this? We should delete loss_parallel flag.

[ghstack-poisoned]
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Jun 18, 2026

@tianyu-l tianyu-l left a comment

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.

Please remove tp_gather_logits and always do S(-1).

Please let me know if you disagree.

loss_parallel_enabled = (
parallel_dims.tp_enabled and not config.parallelism.disable_loss_parallel
)
loss_parallel_ctx = (

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.

This ctx should be removed since we migrate to megatron-style loss parallel? Can leave a TODO. cc @bobrenjc93

# model-agnostic `update_from_config` hook (RL's trainer bypasses
# `torchtitan.Trainer's` call, so we invoke it directly).
model_spec.model.update_from_config(config=config)
model_spec.model.update_from_config(config=config, tp_gather_logits=True)

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.

instead of doing this, let's change this code to TP dim all-gather

logits = logits.to_local()

self.config.update_from_config(config=_InferenceConfig(parallelism=parallelism))
self.config.update_from_config(
config=_InferenceConfig(parallelism=parallelism),
tp_gather_logits=True,

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.

Instead of doing this, let's update the logits = logits.to_local() below to TP dim all-gather.

else dense_activation_placement(tp=spmd.I)
)
loss_tp = spmd.S(-1) if loss_parallel else spmd.I
loss_tp = spmd.I if tp_gather_logits else spmd.S(-1)

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.

Let's not introduce tp_gather_logits. Instead, let's always do S(-1) and give the all-gather responsibility to RL trainer / generator.

I feel the scope of such all-gather is pretty limited (right after RL trainer / generator exits), so it's not worth spreading this config everywhere. Hope that makes sense.

pianpwk added 2 commits June 18, 2026 01:51
[ghstack-poisoned]
[ghstack-poisoned]
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Jun 18, 2026
@pianpwk
pianpwk changed the base branch from gh/pianpwk/44/base to main June 18, 2026 17:01
@pianpwk
pianpwk changed the base branch from main to gh/pianpwk/44/base June 18, 2026 17:03
pianpwk added 2 commits June 18, 2026 10:09
[ghstack-poisoned]
[ghstack-poisoned]
@pianpwk
pianpwk changed the base branch from gh/pianpwk/44/base to main June 18, 2026 17:11
@pianpwk
pianpwk changed the base branch from main to gh/pianpwk/44/base June 18, 2026 17:30
@pianpwk
pianpwk changed the base branch from gh/pianpwk/44/base to main June 18, 2026 17:33
@pianpwk
pianpwk merged commit b3b60da into main Jun 18, 2026
13 of 19 checks passed
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Jun 18, 2026
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Jun 24, 2026
…7th sync)

Upstream b3b60da removed the --disable_loss_parallel flag: TP-on now
always implies loss-parallel-on, with the LP autograd handling moved
into cross_entropy_loss (vocab-sharded logits via tp_gather_logits=
False). The ParallelismConfig.disable_loss_parallel field is gone, so
every ezpz reference to it would TypeError at config construction.

Replayed:
- agpt/sharding.py + moe/sharding.py: drop loss_parallel kwarg from
  set_{agpt,moe}_sharding_config and the set_decoder_sharding_config
  call (matches upstream set_{llama3,deepseek_v3}_sharding_config).
- agpt/model.py + moe/model.py: drop loss_parallel=not parallelism.
  disable_loss_parallel from the sharding-config call sites.
- trainer.py: drop loss_parallel_enabled + enable_loss_parallel from
  get_train_context (upstream get_train_context no longer accepts it).

Smoke (job 12469466, rl-monarch-torch213 venv, sunspot 1N, seed=42
--debug.deterministic): agpt_debugmodel loss 10.83863 -> 10.67256,
moe_debugmodel loss 12.90956 -> 12.36751, both rc=0. agpt step-1 loss
bitwise identical across two runs (12469465, 12469466).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl 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