Skip to content

Add optimizer-provider and pg_collection hooks to setup_model_and_optimizer - #5332

Closed
yashaswikarnati wants to merge 1 commit into
NVIDIA:mainfrom
yashaswikarnati:ykarnati/upstream-trainloop-tl-opt
Closed

Add optimizer-provider and pg_collection hooks to setup_model_and_optimizer#5332
yashaswikarnati wants to merge 1 commit into
NVIDIA:mainfrom
yashaswikarnati:ykarnati/upstream-trainloop-tl-opt

Conversation

@yashaswikarnati

Copy link
Copy Markdown
Contributor

Adds two optional hooks to setup_model_and_optimizer:

  • optimizer_provider_func (defaults to get_megatron_optimizer) so a caller can inject a custom optimizer factory (e.g. MIMO per-module MimoOptimizer).
  • pg_collection forwarded to get_model.

Both default to the current behavior => byte-for-byte unchanged for existing callers. Enables reusing stock pretrain()/setup_model_and_optimizer for heterogeneous MIMO.

Part of the NMFW-516 MIMO-on-stock-trainloop series.

cog: per-rank verified green on cw-dfw 8-GPU.

@copy-pr-bot

copy-pr-bot Bot commented Jun 13, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Comment thread megatron/training/training.py Outdated
model_provider_func,
model_type,
checkpointing_context=None,
optimizer_provider_func=None,

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.

instead of having a provider function, can we instead change get_megatron_optimizer to handle mimo training ?

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.

Done — dropped the provider hook. get_megatron_optimizer now dispatches a single MimoModel chunk to get_mimo_optimizer directly (lazy import to avoid the circular dep, since get_mimo_optimizer already calls get_megatron_optimizer per module). setup_model_and_optimizer keeps only the pg_collectionget_model forwarding. (b3913cc)

Add optional optimizer_provider_func and pg_collection parameters to
setup_model_and_optimizer so a MIMO entry can build a per-module
MimoOptimizer and pass per-module process groups while reusing the stock
pretrain()/setup path end-to-end. Both parameters default to None and
preserve byte-identical behavior for existing callers: when
optimizer_provider_func is None it falls back to get_megatron_optimizer,
and pg_collection=None is forwarded to get_model as before.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: ykarnati <ykarnati@nvidia.com>
@yashaswikarnati

Copy link
Copy Markdown
Contributor Author

Folded into #5333 (combined the optimizer dispatch + setup pg_collection into the schedule-plumbing PR, and slimmed the test). Closing in favor of #5333.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant