Skip to content

Refactor post dataloading process - #4116

Merged
jinsooihm merged 2 commits into
pytorch:mainfrom
jinsooihm:refactor-post-dataloading-process
Aug 27, 2026
Merged

jinsooihm merged 2 commits into
pytorch:mainfrom
jinsooihm:refactor-post-dataloading-process

Conversation

@jinsooihm

@jinsooihm jinsooihm commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Update Aug 18

BaseModel defines preprocess_inputs and _build_forward_inputs.
preprocess_inputs does the following:

  1. prepares additional inputs using _build_forward_inputs which also returns input_sharding, an information on how to shard the tensor inputs.
  2. CP shard the inputs based on input_sharding
  3. annotate spmd_types or full_dtensor-ize the inputs based on input_sharding on the tensors
  4. Also return local_ntokens counted after CP sharding and before dtensorizing labels.

Trainer's post_dataloading_process is replaced with _prepare_batch for now to count ntokens_seen. This can be removed after dtensor support is removed, so the local_ntokens can be counted outside of preprocess_inputs.

When a model has additional inputs to CP shard/annotate, one can override _build_forward_inputs as in Kimi.

The above recipe can handle most of the type annotation except Qwen3.5, which annotates cu_seq_q inside VarlenMetadata. In such cases one can override preprocess_inputs.

Remark

This could allow CP in multimodal models (assuming the decoder part allows CP like Muse Glimmer)
by building a index tensor in _build_forward_inputs that indicates for each token position, which vision encoder output it should get. Then we CP shard this tensor in the same way as tokens, and scatter it inside forward.

Remove decoder specific logic in `Trainer.post_dataloading_process` to be configurable.
  1. Each model defines preprocess_inputs as a function in BaseModel.preprocess_inputs. This reads the input batch given from the dataloader and produces additional input that the model needs, such as attention masks.
  2. Each model defines input_sharding: dict[str, SpmdLayout] in BaseModel.Config that is used to give correct DTensor or spmd_types for each argument in the model.forward.
  3. prepare_context_parallel_input is also generalized to infer from input_sharding on which inputs and which dimension to CP shard.

This would allow multimodal models to annotate spmd_types for additional inputs such as pixel_values with a simple configuration.
<\del>

Test Plan

python -m tests.integration_tests.run_tests <output_dir> --test_suit models --ngpu 8 runs without error.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 11, 2026
@jinsooihm
jinsooihm marked this pull request as ready for review August 11, 2026 22:14
@jinsooihm
jinsooihm requested a review from pianpwk August 11, 2026 22:14
Comment thread torchtitan/models/common/decoder.py Outdated
def preprocess_inputs(
self,
input_dict: dict[str, torch.Tensor],
labels: torch.Tensor,

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.

why don't we put labels into input_dict?
(Yes we can change dataloader behavior)

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.

Maybe this can be done in a separate PR?

Comment thread torchtitan/protocols/model.py Outdated
Comment on lines +60 to +61
input_dict: "dict[str, torch.Tensor]",
labels: "torch.Tensor",

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.

why putting types as str?

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.

Hmm yes, weird.

Comment thread torchtitan/protocols/model.py Outdated
"""

# Per-input SPMD layouts; single source of truth for input parallelization.
input_sharding: "dict[str, SpmdLayout] | None" = 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.

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.

Yes, then should we just use one of in_src_sharding or in_dst_sharding? It feels a little hacky since ShardingConfig is defining redistribution contract.

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.

Actually, we'll remove src / dst so it becomes a static contract. Even if we don't, it's clear that we should use src?

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.

My concern is that if we use ShardingConfig, then it would be used to set up redistribution by Module.parallelize() and this could behave weirdly when PP is applied? Wouldn't this make the second PP stage to impose ShardingConfig on the activation passed from the previous stage?

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.

I didn't complete get it.

  • we will REMOVE one of src / dst, so that module boundary does NOT have redistribute
  • since you are still doing CP sharding from outside, different PP stages should have the SAME input sharding?

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.

Suppose model.forward(x, ...) and we set ShardingConfig on the model on x to be R on TP. If we do sequence parallel, then it would become sharded on TP after token embedding and fed to layers.

If we apply PP, then wouldn't PP stage 2 expect the first positional argument to be R on TP from the above ShardingConfig, but the layer that gets called right away, without token embedding, inside forward expect shard on TP?

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.

Now I get it. Thanks

Comment thread torchtitan/trainer.py Outdated
).preprocess_inputs(input_dict, labels)

if self.parallel_dims.cp_enabled:
dims = cp_shard_dims(input_sharding) if input_sharding else 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.

is this used anywhere else? If not let's not create another API; instead you could pass input_sharding into the prepare_context_parallel_input (which eventually should be put into dataloder?)

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.

I don't think we should create this file / function. We will deprecate all backends other than spmd_types.

Comment thread torchtitan/trainer.py Outdated
@@ -646,59 +648,32 @@ def batch_generator(
def post_dataloading_process(

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.

What's the plan with this function? My original thought is that we should kill it entirely. Is this your goal?

This would allow multimodal models to annotate spmd_types for additional inputs such as pixel_values with a simple configuration.

Right now you are still annotating spmd_types outside preprocess_inputs, so I don't see how it makes things different for multimodal models.

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.

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.

I'm not sure I'm convinced, would love to see an integration for multimodal (maybe after that Kimi PR is landed)

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.

Hmm, yes. I do not see a nice way to take out annotation out of forward for multimodal. The reason is the below inside Kimi forward:

with self.multimodal_context():
if get_spmd_backend() == "spmd_types":
annotate_multimodal_input_spmd_types(
pixel_values=pixel_values,
grid_thw=grid_thw,
pixel_values_videos=pixel_values_videos,
grid_thw_videos=grid_thw_videos,
)

I think we can still call annotate_multimodal_input_spmd_types outside forward and the context, but it seems like a semantically wrong thing to do.

One way for now would be to just let those special case annotations to be handled in the model forward, while move the post_dataloading_process logic to be owned by model's preprocess_inputs.
Perhaps it can be cleaned up a little more if we write a multimodal trainer that calls vision encoder part separately from decoder.

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.

Thanks. For now it feels to me that

  • model should own preprocess_inputs because each model can do different things
  • so we should refactor post_dataloading_process to model.preprocess_inputs

WDYT?

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.

Yes, I agree. I am making the changes and will let you know when I think it is ready to review.

I also think that it is fine to call the annotate_multimodal_input_spmd_types outside of multimodal_context, since spmd.set_current_mesh(local_axes=("dp",)) is used to just not enforce the global spmd typechecking on DP. So it is fine to annotate DP to be V outside as long as we do not operate on those inputs.

This would be more of an aesthetics choice on whether annotating all the inputs should be done in preprocess_inputs or some there and some in forward.
I personally think it would be better to collect them at one place before forward, although it functionally would not really matter if type checking is off when PP is on.

@jinsooihm
jinsooihm marked this pull request as draft August 14, 2026 04:50
@jinsooihm
jinsooihm force-pushed the refactor-post-dataloading-process branch 3 times, most recently from 6b9b4c3 to 08a86f2 Compare August 17, 2026 20:50
@jinsooihm

Copy link
Copy Markdown
Contributor Author

@tianyu-l I made some changes, please take a look. cc @fegin

Comment on lines +130 to +137
@@ -119,56 +134,86 @@ def prepare_context_parallel_input(
device: torch.device,
load_balancer_type: str | None = "headtail",
ptrr_mask_key: str | None = None,
input_sharding: dict[str, SpmdLayout] | None = 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.

Should we change the arguments to:

inputs: dict[str, Any], input_shardings: dict[str, SpmdLayout | None], cp_mesh: DeviceMesh, device: ...

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.

inputs.keys() == input_shardings.keys()

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.

I made it so that preprocess_inputs take in a single input_dict with labels and extra_kwargs folded in so internally, everything information is passed around as a single dict. We can change the dataloader behavior later.

Comment thread torchtitan/trainer.py Outdated
once per microbatch on the PP path, so token accounting matches the
batch stream.

The 4th element (``local_ntokens``) is a transitional workaround; see

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 statement is confusing. Can we say The 4th returned value of model.preprocess_inputs ...

Comment thread torchtitan/protocols/model.py Outdated
CP-shard, then SPMD-wrap. Returns ``(inputs, labels, extra_kwargs,
local_ntokens)``.

TODO(return-type): the 4th element (local token count) is a transitional

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.

Same here, 4th element is confusing. 4th return value is more clear.

@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.

Comment thread torchtitan/distributed/full_dtensor.py Outdated

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 is removed I think

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.

Soon it will be #4217

Comment thread torchtitan/distributed/spmd_types.py Outdated
Analogous to ``full_dtensor.parallelize_inputs()`` but for the
``spmd_types`` path.
"""
def spmd_layout_to_dtensor_placements(

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.

I'm not sure you need this. Does spmd_types not having any util for it? @pianpwk

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.

could you take a look at

def resolve_placements(

unfold_dp_axis + spmd.spmd_type_to_dtensor_placement should work

"""
dims: dict[str, int] = {}
for name, layout in input_sharding.items():
cp_dim = layout.shard_dim(MeshAxisName.CP)

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.

Is the .shard_dim API only used here? If so, maybe not worth introducing.

logger.info("Applied Context Parallel (forward wrapping) to the model")


def cp_shard_dims(input_sharding: dict[str, SpmdLayout]) -> dict[str, int]:

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.

Suggested change
def cp_shard_dims(input_sharding: dict[str, SpmdLayout]) -> dict[str, int]:
def _cp_shard_dims(input_sharding: dict[str, SpmdLayout]) -> dict[str, int]:

if only used in this file

Comment thread torchtitan/protocols/model.py Outdated
labels = input_dict.pop("labels")
return inputs, labels, input_dict, local_ntokens

def _build_forward_inputs(

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.

kill this

buffer_device = kwargs.get("buffer_device")
self.init_states(buffer_device=buffer_device)

def preprocess_inputs(

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.

move this to decoder; we may still define the interface here -- but need justification

@jinsooihm jinsooihm Aug 20, 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.

I only left the interface and moved the logic to decoder.

"Could not find rotary_emb in the model. Please check the model structure."
)

def _build_forward_inputs(

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.

try inherit decoder -- if not possible, just duplicate code

Comment thread torchtitan/distributed/spmd_types.py Outdated
if layout is None:
untyped.append(name)
continue
spmd.assert_type(value, layout.per_axis_spmd_types())

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.

nit: could also assert with per-axis-types + partition spec I think

@jinsooihm
jinsooihm force-pushed the refactor-post-dataloading-process branch 2 times, most recently from 8200edb to 00370da Compare August 20, 2026 21:20
Comment thread torchtitan/trainer.py Outdated
@sl.log_trace_span("post_dataloading_process")
def post_dataloading_process(
@sl.log_trace_span("preprocess_inputs")
def _prepare_batch(

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.

can we not define this function?

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.

I think the code would look cleaner with this helper because the body is pretty long, and it is called at two places.

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.

I didn't get it. The function is extremely short, what is pretty long? Could you please show the change with this indirection removed?

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.

I removed it. I think it will become a lot cleaner after the TODO on typing model_parts to be BaseModel and making dataloader emits labels in the input dictionary.

Comment thread torchtitan/models/common/decoder.py Outdated
input_dict: dict[str, torch.Tensor],
*,
parallel_dims: ParallelDims,
device: torch.device,

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.

not used

untyped.append(name)
continue
spmd.assert_type(value, layout.per_axis_spmd_types())
if untyped:

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.

can you just raise in the for loop?

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.

Well, doing this would tell the user every missing annotation.

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.

don't put test under torchtitan/

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.

similar

Comment thread torchtitan/protocols/tests/__init__.py Outdated

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.

similar

Comment thread torchtitan/models/kimi_k2_7/sharding.py Outdated
multimodal_type = {
MeshAxisName.DP: spmd.V,
MeshAxisName.TP: spmd.I,
def multimodal_input_sharding() -> dict[str, SpmdLayout]:

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.

is this not shareable by all multimodal models?

@jinsooihm jinsooihm Aug 20, 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.

Almost. Qwen35 has mrope_positions. But in forward, positions and mrope_positions are never used together. I think we can

  1. remove the separate mrope_positions from the forward input signature
  2. preprocess_inputs build the mask using positions
  3. preprocess_inputs puts the result of rope_positions = mrope_positions if mrope_positions is not None else positions into input_dict which goes into forward?

Then, every multimodal models would have the same input signature.

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.

we can give it a try and let @shuhuayu and I take a look

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.

@shuhuayu @tianyu-l I made a change in qwen35 to remove mrope_positions form forward arguments. Please take a look.

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.

i am ok with unifying with other vlms in terms of forward apis. looks clean to me.

config.vision_adapter.build() if config.vision_adapter is not None else None
)

def preprocess_inputs(

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.

can we define a multimodel base to share this function?

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.

Currently, Muse Glimmer and Kimi does the same thing but I am planning to enable CP by doing something different in preprocess_inputs for Muse Glimmer. Also Qwen does something different already.

@jinsooihm
jinsooihm force-pushed the refactor-post-dataloading-process branch 3 times, most recently from 58006e4 to 16fb1cc Compare August 24, 2026 17:31
@jinsooihm
jinsooihm marked this pull request as ready for review August 24, 2026 17:41

@fegin fegin 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.

Thanks for the nice refactor.

# (context_parallel.api -> models.common -> decoder).
from torchtitan.distributed.context_parallel.api import (
prepare_context_parallel_input,
)

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 is sad :/

Comment thread torchtitan/trainer.py
from torchtitan.distributed.spmd_types import annotate_input_spmd_types
from torchtitan.models.common.attention import FlexAttention, VarlenAttention
from torchtitan.models.common.decoder import Decoder
from torchtitan.models.common.attention import FlexAttention

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.

Do we still use this in Trainer?

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.

It is used in __post_init__

Comment on lines +373 to +380
if parallel_dims.cp_enabled:
batch = prepare_context_parallel_input(
batch,
input_sharding,
parallel_dims.get_mesh("cp"),
parallelism.context_parallel_load_balancer,
parallelism.context_parallel_ptrr_mask_key,
)

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 is a good place to do prepare_context_parallel_input as how do we shard the mask is also affected by the CP kernel.

…inputs

Rework how decoder models declare and apply the SPMD layout of their forward
inputs, and collapse the input pipeline into a single overridable method.

SpmdLayout / input sharding:
- SpmdLayout carries per-axis SPMD types plus an optional PartitionSpec, so a
  tensor dim sharded by multiple mesh axes (e.g. DP+CP token sharding) has an
  explicit, ordered layout. per_axis_spmd_types() stays a helper for
  redistribute; annotate_input_spmd_types asserts with the raw
  (axis_types, partition_spec) so multi-axis and higher-rank inputs validate
  correctly.
- Context-parallel shard dims are derived from the layout (_cp_shard_dims),
  removing per-model CP wiring. Drop the unused
  spmd_layout_to_dtensor_placements path.

preprocess_inputs:
- Remove the _build_forward_inputs and input_sharding() hooks.
  BaseModel.preprocess_inputs has no meaningful default (it raises
  NotImplementedError); models on the standard trainer/validator path
  -- Decoder, HFTransformerModel, Qwen35Model, KimiK25Model, MuseGlimmerModel
  -- each inline their own (mask building, CP-shard, SPMD-wrap, pop) with no
  super()-chaining, while bespoke-pipeline models (e.g. Flux) never call it.
- Qwen3.5 folds mrope_positions into the single positions input and asserts
  RoPE positions at the boundary; its GatedDeltaNet cu_seqlens annotation stays
  inline under the spmd_types branch (skipped when the batch has no varlen
  deltanet metadata). MRoPE positions fold to (tokens, 3), so they are given a
  rank-matching layout that replicates the trailing component axis instead of
  the 1D token layout.
- Consolidate identical multimodal input sharding into common/multimodal.py and
  vision_encoder_sharding.py.

Tests drive the real preprocess_inputs via a single-rank ParallelDims, and the
spmd_types error message no longer references the removed hooks.
@jinsooihm
jinsooihm force-pushed the refactor-post-dataloading-process branch from 16fb1cc to 0837eef Compare August 26, 2026 23:36
@jinsooihm
jinsooihm force-pushed the refactor-post-dataloading-process branch from 0837eef to 9648ccd Compare August 26, 2026 23:42
@jinsooihm
jinsooihm merged commit e8e39ab into pytorch:main Aug 27, 2026
27 of 28 checks passed
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Aug 28, 2026
…helper

21 commits behind upstream/main. Merged into a scratch clone (../tt-sync82)
rather than the production one, because three optcmp arms are mid-chain with
7 links queued on afterany: each released link re-reads the working tree at
launch, so landing this now would have later links training on different code
than earlier ones and silently break comparability of the +10B measurement
in progress.

The merge is clean -- zero conflicts across 127 files -- and agpt is fine:
all three optcmp configs build, and SpmdLayout (removed by pytorch#4265) turns out
to appear in ezpz only in comments and as a local variable name.

ezpz/moe does not build. pytorch#4300 rewrote models/utils.py and removed
get_moe_model_nparams_and_flops, which moe/model.py imports at :30 and calls
at :344. It is a port rather than a rename: the replacement
get_nparams_and_active_nparams takes (model, *, modules_excluded...) and
returns (nparams, active_nparams), dropping flops, which are now composed
separately via quadratic_attention_flops_per_token. deepseek_v3's
get_deepseek_v3_nparams_and_flops is the reference pattern.

Landing plan is unchanged: finish the +10B run, then merge, then 2N smoke,
with pytorch#4116 (post-dataloading refactor) checked against BlendCorpus
specifically since that is where the token-unit fold bugs have lived.
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Aug 29, 2026
…oved the hook

Upstream pytorch#4116 deleted Trainer.post_dataloading_process and moved the work
onto the model as BaseModel.preprocess_inputs. EzpzValidator called the
deleted method, so validation would have raised AttributeError on the first
validation step -- after startup, mid-run.

The new contract differs in shape, not just name: labels go INSIDE the input
dict rather than as a positional arg, and parallel_dims/parallelism are passed
explicitly. Both are already attributes of the base Validator, so no plumbing
was needed. Mirrors the non-PP branch of torchtitan/components/validate.py.

Worth noting how this was nearly missed: the sync-82 trial merge tested config
imports and pronounced only ezpz/moe broken. Config imports never touch the
validator. What found it was importing EVERY ezpz module -- 75 of 79 now
import, and the 4 failures are pre-existing RL deps (monarch, renderers, the
vLLM-only actors path), unrelated to this sync.
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Aug 29, 2026
sync79_smoke.pbs is stale and would abort in flag parsing: it passes
--training.seq-len and --training.local-batch-size, neither of which exists
after pytorch#4121 renamed them to max-context-length and
num-tokens-per-microbatch-per-dp-rank. Running it against a clean merge would
have produced three VOID arms and read as a merge failure.

Adds an explicit validator import gate alongside the two config gates. The
config gates cannot catch pytorch#4116: EzpzValidator called the deleted
Trainer.post_dataloading_process, and importing a config_registry never
touches the validator, so the trial merge pronounced only moe broken.

Result on the merged tree (job 12474288, 6m39s, Exit_status=0): all three
import gates OK, and agpt2b / agpt2b-tp2 / moe_10b_2b_sdpa each rc=0 with 20
real steps, losses 12.88->7.18, 12.89->6.93, 12.92->7.04.
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Aug 29, 2026
266 non-merge commits, 185 under experiments/ezpz/.

Leads with the optimizer comparison finishing: Mano 2.43889 vs AdamW 2.51357
at 23.59B tokens, both arms to the training.steps=6000 ceiling with rc=0 and
zero NaN/inf. Includes the full 250-step binned gap table and states plainly
that the last two windows reverse because they straddle a transient in the
Mano arm -- fitting a crossover through the tail fits a detour, so the
monotone stretch is 2750-5500.

The SophiaG section is the substantive change to what was believed. "3/3" was
three forks of one checkpoint; a fourth arm from random init with the seed
pinned diverged anyway, which also closes out data order since dataloader.seed
was already 42 everywhere. The new result is that pre-onset noise is not a
precursor: the original ran 17.9% above grad_norm 2.0 for 1,027 steps before
blowing up, the fresh one ran 1,529 steps at 0.0% and blew up regardless. It
then escaped completely and has held ~1,730 steps since.

Sync 82 is written up with the detail that matters for next time: the trial
merge in a scratch clone found the moe break and MISSED the validator break,
because config-import gates never touch the validator and pytorch#4116's removal
raises at validation time rather than at import. Importing all 79 ezpz modules
is what found it.

Closes with two method notes, both from errors made repeatedly this period:
bin before characterizing (the fresh SophiaG arm got three different
characterizations in three readings, every optimistic one wrong), and empty
output from a still-running job is not a no-op.
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.

5 participants