Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c5f9de8
feat: add generic pre-decoder hook mechanism to GPTModel
fzyzcjy Apr 1, 2026
77185e1
fix: use direct attribute access for _pre_decoder_hooks
fzyzcjy Apr 2, 2026
153fa7f
more
fzyzcjy Apr 2, 2026
593ab51
refactor: replace pre-decoder hooks with witness_ids forward parameter
fzyzcjy Apr 2, 2026
91bbff1
fix: use witness_ids param directly instead of miles_kwargs dict
fzyzcjy Apr 2, 2026
76b54ca
feat: propagate witness_ids through build_schedule_plan path
fzyzcjy Apr 2, 2026
f12f77b
more
fzyzcjy Apr 2, 2026
4a8e159
gitignore
fzyzcjy Apr 2, 2026
c83e553
feat: add tail_witness support, revert build_schedule_plan changes
fzyzcjy Apr 2, 2026
b7af836
more
fzyzcjy Apr 2, 2026
8225413
more
fzyzcjy Apr 2, 2026
8bc9ab7
fix: transpose witness output to match Megatron SBH layout
fzyzcjy Apr 5, 2026
9960ac2
fix: scatter witness output for sequence parallelism
fzyzcjy Apr 5, 2026
3c25800
fix: guard witness forward with hasattr for PP stage awareness
fzyzcjy Apr 5, 2026
2592086
fix: use pre_process/post_process assert instead of hasattr for witness
fzyzcjy Apr 5, 2026
bc8ed09
fix: exclude witness params from grad_norm computation
fzyzcjy Apr 5, 2026
aea2040
fix: propagate _is_witness_param flag to main params in distributed o…
fzyzcjy Apr 5, 2026
4028201
fix: assert witness params not used with precision-aware optimizer
fzyzcjy Apr 6, 2026
755c9f7
fix: use hasattr guard for witness forward instead of pre_process/pos…
fzyzcjy Apr 6, 2026
9cc8cb8
refactor: rename head_witness/tail_witness to local_head_witness/loca…
fzyzcjy Apr 6, 2026
43cb211
fix: use witness_broadcast_add for tail witness to prevent gradient c…
fzyzcjy Apr 6, 2026
9a5447d
refactor: simplify witness calls in gpt_model — one-line API
fzyzcjy Apr 6, 2026
496e76b
Merge origin/miles-main into trainer_ft/dev (true-on-policy dense + f…
fzyzcjy Jun 5, 2026
c30d54d
Add deterministic_collectives module (fixed-tree SUM fold)
fzyzcjy Jun 5, 2026
336dd33
Gate grad-bucket sync on deterministic collectives
fzyzcjy Jun 5, 2026
02b995b
Gate finalize/optimizer SUM all-reduces on deterministic collectives
fzyzcjy Jun 5, 2026
85c2ce9
Add unit test for deterministic_collectives
fzyzcjy Jun 5, 2026
bb8aa73
Simplify deterministic_collectives after review
fzyzcjy Jun 5, 2026
3998005
Fix deterministic_collectives audit findings (chunking test, non-cont…
fzyzcjy Jun 5, 2026
e73bec7
Revert in-tree deterministic collectives (superseded by miles det_ncc…
fzyzcjy Jun 5, 2026
07d03a1
Require CUDA_DEVICE_MAX_CONNECTIONS != 1 for the fault-tolerant trainer
fzyzcjy Jun 8, 2026
0ed59ff
Revert "Require CUDA_DEVICE_MAX_CONNECTIONS != 1 for the fault-tolera…
fzyzcjy Jun 9, 2026
9910ff5
Merge branch 'miles-main' into trainer_ft/dev
fzyzcjy Jun 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ onelogger.err
runs/
/test_cases/
**/dist/
.idea

# Sphinx documentation
docs/_build
Expand Down
10 changes: 10 additions & 0 deletions megatron/core/models/gpt/gpt_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ def forward(
loss_mask: Optional[Tensor] = None,
padding_mask: Optional[Tensor] = None,
mtp_kwargs: Optional[dict] = {},
witness_ids: Optional[Tensor] = None,
) -> Tensor:
"""Forward function of the GPT Model This function passes the input tensors
through the embedding layer, and then the decoder and finally into the post
Expand Down Expand Up @@ -592,6 +593,12 @@ def forward(

rotary_pos_cos_sin = preproc_output[6] if len(preproc_output) == 7 else None

if witness_ids is not None and hasattr(self, "local_head_witness"):
if decoder_input is not None:
decoder_input = self.local_head_witness(witness_ids, decoder_input)
else:
self.decoder.input_tensor = self.local_head_witness(witness_ids, self.decoder.input_tensor)

# Run decoder.
hidden_states = self.decoder(
hidden_states=decoder_input,
Expand All @@ -608,6 +615,9 @@ def forward(
**(extra_block_kwargs or {}),
)

if witness_ids is not None and hasattr(self, "local_tail_witness"):
hidden_states = self.local_tail_witness(witness_ids, hidden_states)

return self._postprocess(
hidden_states=hidden_states,
input_ids=input_ids,
Expand Down
8 changes: 8 additions & 0 deletions megatron/core/optimizer/distrib_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,14 @@ def _build_model_and_main_param_groups(
)
if hasattr(model_param, 'shared'):
shard_main_param.shared = model_param.shared
if getattr(model_param, '_is_witness_param', False):
shard_main_param._is_witness_param = True
else:
# When using precision-aware optimizer, main params are held by FusedAdam.
assert not getattr(model_param, '_is_witness_param', False), (
"Witness params are not supported with precision-aware optimizer. "
"_is_witness_param flag cannot be propagated to FusedAdam-held params."
)
shard_main_param = None

# Store handle to main_param.
Expand All @@ -431,6 +437,8 @@ def _build_model_and_main_param_groups(
)
if hasattr(model_param, 'shared'):
shard_model_param.shared = model_param.shared
if getattr(model_param, '_is_witness_param', False):
shard_model_param._is_witness_param = True

else:
raise TypeError(
Expand Down
3 changes: 2 additions & 1 deletion megatron/core/optimizer/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ def get_main_grads_for_grad_norm(self) -> List[torch.Tensor]:
is_not_tp_duplicate = tensor_parallel.param_is_not_tensor_parallel_duplicate(
param, getattr(self, 'tp_group', None)
)
if grad_not_none and is_not_shared and is_not_tp_duplicate:
is_not_witness = not getattr(param, "_is_witness_param", False)
if grad_not_none and is_not_shared and is_not_tp_duplicate and is_not_witness:
grads_for_norm.append(grad)

return grads_for_norm
Expand Down