Skip to content

docs: Update callback code snippets to include all imports needed for example#2283

Merged
ananthsub merged 1 commit intoNVIDIA-NeMo:mainfrom
ananthsub:callback-docs-update
Feb 9, 2026
Merged

docs: Update callback code snippets to include all imports needed for example#2283
ananthsub merged 1 commit intoNVIDIA-NeMo:mainfrom
ananthsub:callback-docs-update

Conversation

@ananthsub
Copy link
Copy Markdown
Contributor

@ananthsub ananthsub commented Feb 9, 2026

What does this PR do ?

Update callback docs to be directly runnable if copy/pasting the code snippet

Changelog

  • Add specific line by line info of high level changes in this PR.

GitHub Actions CI

See the CI sectionin the Contributing doc for how to trigger the CI. A Nvidia developer will need to approve and trigger the CI for external contributors.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

If you haven't finished some of the above items you can still open "Draft" PR.

Additional Information

  • Related to # (issue)

Summary by CodeRabbit

  • Documentation
    • Updated training callback docs with refreshed examples that follow the current API, including how to create and pass configurations and callbacks.
    • Added on-trace usage examples and updated example import lines for clarity.
    • Clarified examples only—no runtime or public API behavior changed.

@ananthsub ananthsub requested a review from yaoyu-33 February 9, 2026 18:54
@ananthsub ananthsub added documentation docs-only With great power comes great responsibility. r0.3.0 Cherry-pick label for r0.3.0 release branch labels Feb 9, 2026
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Feb 9, 2026

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.

@ananthsub
Copy link
Copy Markdown
Contributor Author

/ok to test 7777851

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

Documentation examples in docs/training/callbacks.md updated to import and use forward_step from megatron.bridge.training.gpt_step, replace forward_step_func occurrences, and switch example config usage to qwen25_500m_pretrain_config with adjusted pretrain call signatures.

Changes

Cohort / File(s) Summary
Training Documentation
docs/training/callbacks.md
Updated example snippets to import forward_step from megatron.bridge.training.gpt_step, replace forward_step_func references with forward_step, add imports for qwen25_500m_pretrain_config, and adjust pretrain example call signatures to pass the new config and callbacks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: updating callback documentation code snippets to include necessary imports for runnable examples.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Test Results For Major Changes ✅ Passed This pull request contains only minor documentation changes that update callback code snippets with necessary imports. No code logic or functionality is affected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/training/callbacks.md (1)

3-3: ⚠️ Potential issue | 🟡 Minor

Fix typo in intro sentence.

“propietary” → “proprietary”.

🤖 Fix all issues with AI agents
In `@docs/training/callbacks.md`:
- Around line 67-82: The example uses undefined callbacks (MyCallback,
TimingCallback, MetricsCallback) which breaks copy‑paste; update the code block
to include minimal in‑block callback definitions or replace their usages with
simple inline callbacks that implement the expected interface used by
CallbackManager (e.g., define a small class MyCallback with the relevant hook
methods or add lambdas/anonymous functions) so the snippet from CallbackManager,
manager.register(...), and pretrain(config, forward_step, callbacks=manager) is
fully runnable without external imports.

Comment on lines 67 to 82
```python
from megatron.bridge.training.callbacks import CallbackManager
from megatron.bridge.training.gpt_step import forward_step
from megatron.bridge.training.pretrain import pretrain
from megatron.bridge.recipes.qwen import qwen25_500m_pretrain_config

manager = CallbackManager()
manager.add(MyCallback())
manager.add([TimingCallback(), MetricsCallback()])
manager.register("on_eval_end", lambda ctx: print("Evaluation complete!"))

pretrain(config, forward_step_func, callbacks=manager)
# Create a config that fits on a single GPU
config = qwen25_500m_pretrain_config()

pretrain(config, forward_step, callbacks=manager)
```
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.

⚠️ Potential issue | 🟡 Minor

Mixing example still isn’t copy‑paste runnable.

This snippet references MyCallback, TimingCallback, and MetricsCallback without definitions/imports in the block. Given the PR objective (“directly runnable when copy/pasted”), please either add minimal class definitions in this block or replace with fully in‑block example callbacks.

🤖 Prompt for AI Agents
In `@docs/training/callbacks.md` around lines 67 - 82, The example uses undefined
callbacks (MyCallback, TimingCallback, MetricsCallback) which breaks copy‑paste;
update the code block to include minimal in‑block callback definitions or
replace their usages with simple inline callbacks that implement the expected
interface used by CallbackManager (e.g., define a small class MyCallback with
the relevant hook methods or add lambdas/anonymous functions) so the snippet
from CallbackManager, manager.register(...), and pretrain(config, forward_step,
callbacks=manager) is fully runnable without external imports.

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
@ananthsub ananthsub force-pushed the callback-docs-update branch from 7777851 to 91d28d7 Compare February 9, 2026 22:58
@ananthsub
Copy link
Copy Markdown
Contributor Author

/ok to test 91d28d7

@ananthsub ananthsub enabled auto-merge (squash) February 9, 2026 22:59
@ananthsub ananthsub merged commit a51b265 into NVIDIA-NeMo:main Feb 9, 2026
23 of 24 checks passed
ko3n1g pushed a commit that referenced this pull request Feb 9, 2026
… example (#2283)

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
Signed-off-by: NeMo Bot <nemo-bot@nvidia.com>
sowmen pushed a commit to sowmen/Megatron-Bridge that referenced this pull request Feb 11, 2026
… example (NVIDIA-NeMo#2283)

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
Signed-off-by: sowmen <sowmendipta@gmail.com>
@yaoyu-33 yaoyu-33 added docs Documentation-only updates or documentation debt and removed documentation labels Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation-only updates or documentation debt docs-only With great power comes great responsibility. r0.3.0 Cherry-pick label for r0.3.0 release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants