Skip to content

cp: docs: Update callback code snippets to include all imports needed for example (2283) into r0.3.0#2291

Merged
ko3n1g merged 1 commit intor0.3.0from
cherry-pick-2283-r0.3.0
Feb 10, 2026
Merged

cp: docs: Update callback code snippets to include all imports needed for example (2283) into r0.3.0#2291
ko3n1g merged 1 commit intor0.3.0from
cherry-pick-2283-r0.3.0

Conversation

@ko3n1g
Copy link
Copy Markdown
Contributor

@ko3n1g ko3n1g commented Feb 9, 2026

beep boop [🤖]: Hi @ananthsub 👋,

we've cherry picked #2283 into  for you! 🚀

Please review and approve this cherry pick by your convenience!

Summary by CodeRabbit

  • Documentation
    • Updated training callbacks documentation with improved examples demonstrating class-based callbacks, functional callbacks, and combined pattern approaches for model training workflows.

… example (#2283)

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
Signed-off-by: NeMo Bot <nemo-bot@nvidia.com>
@ko3n1g
Copy link
Copy Markdown
Contributor Author

ko3n1g commented Feb 9, 2026

/ok to test 11c6a55

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

Updates documentation examples in the callbacks guide to use new imports (time, forward_step, qwen25_500m_pretrain_config) and replace forward_step_func with forward_step, adding config instantiation across multiple example sections.

Changes

Cohort / File(s) Summary
Documentation Updates
docs/training/callbacks.md
Updated callback examples across three sections (Quick Start, Functional Callbacks, Mixing Both Patterns) to include new imports (time, forward_step, qwen25_500m_pretrain_config), replace forward_step_func with forward_step, and add config instantiation (config = qwen25_500m_pretrain_config()).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested labels

documentation, docs-only, r0.3.0

Suggested reviewers

  • yaoyu-33
🚥 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 clearly describes the main change: updating callback code snippets in documentation to include all necessary imports, with a reference to the original PR #2283.
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 PR contains only minor documentation updates to code examples in docs/training/callbacks.md, with no impact on runtime behavior or functionality.

✏️ 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
  • Commit unit tests in branch cherry-pick-2283-r0.3.0

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

🤖 Fix all issues with AI agents
In `@docs/training/callbacks.md`:
- Around line 67-82: The example uses undefined callback classes (MyCallback,
TimingCallback, MetricsCallback) when creating CallbackManager and calling
manager.add/register; update the snippet to be self-contained by either
importing/defining the referenced callbacks or adding a short inline comment
above the manager.add calls stating these are placeholder/example callback names
that must be defined or imported by the user (e.g., "Assuming
MyCallback/TimingCallback/MetricsCallback are defined elsewhere"), and ensure
references to CallbackManager, manager.add, and manager.register remain correct.

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

Documentation clarity: code example is not self-contained.

This code block references MyCallback(), TimingCallback(), and MetricsCallback() (line 74-75) but none of these are defined or imported in this example. While MyCallback is defined in the first example, TimingCallback and MetricsCallback are not defined anywhere in this document.

For better documentation, consider either:

  1. Adding a comment noting these are example callback names and users should define them
  2. Importing or defining these callbacks in the example
  3. Using simpler inline examples that don't reference undefined classes
📝 Suggested improvement for clarity
 ```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

+# Assuming MyCallback is defined as shown in the Quick Start example above
+# and you have defined TimingCallback and MetricsCallback for your use case
+
 manager = CallbackManager()
 manager.add(MyCallback())
-manager.add([TimingCallback(), MetricsCallback()])
+manager.add([MyOtherCallback()])  # Add any other callback instances
 manager.register("on_eval_end", lambda ctx: print("Evaluation complete!"))
🤖 Prompt for AI Agents
In `@docs/training/callbacks.md` around lines 67 - 82, The example uses undefined
callback classes (MyCallback, TimingCallback, MetricsCallback) when creating
CallbackManager and calling manager.add/register; update the snippet to be
self-contained by either importing/defining the referenced callbacks or adding a
short inline comment above the manager.add calls stating these are
placeholder/example callback names that must be defined or imported by the user
(e.g., "Assuming MyCallback/TimingCallback/MetricsCallback are defined
elsewhere"), and ensure references to CallbackManager, manager.add, and
manager.register remain correct.

@ko3n1g ko3n1g merged commit b10d7e3 into r0.3.0 Feb 10, 2026
22 of 23 checks passed
@ko3n1g ko3n1g deleted the cherry-pick-2283-r0.3.0 branch February 10, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants