cp: fix: apply offloading change from v2 to v1 (1726) into r0.5.0#1737
cp: fix: apply offloading change from v2 to v1 (1726) into r0.5.0#1737
fix: apply offloading change from v2 to v1 (1726) into r0.5.0#1737Conversation
Signed-off-by: Terry Kong <terryk@nvidia.com> Signed-off-by: Yuki Huang <yukih@nvidia.com> Co-authored-by: Yuki Huang <yukih@nvidia.com> Signed-off-by: NeMo Bot <nemo-bot@nvidia.com>
ℹ️ File Consistency CheckCheck based on commit: ed92b26 (PR #1737 from ✅ DTensor Policy Worker Synchronization CheckBoth DTensor policy worker files were modified in this PR:
Please ensure that the changes are consistent between both files where applicable. This check ensures that related file implementations remain synchronized across the codebase. If you believe this warning is incorrect or the files should intentionally differ, please add a comment explaining the reasoning. |
📝 WalkthroughWalkthroughModified DTensor policy workers to use Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/unit/models/generation/test_vllm_generation.py (1)
1667-1669: Backend parameterization for vLLM weight-update memory test is sound; consider deepcopy and cleanupThe new
train_backendparameter and config switch correctly exercise both DTensor backends:
dtensor_v1→ basebasic_dtensor_test_config(v1 worker).dtensor_v2→ deepcopy +dtensor_cfg["_v2"] = True(v2 worker), matching howPolicyselects DTensorPolicyWorkerV2.- The extra
"megatron"branch is currently unused but kept for possible future expansion, consistent with the comment about only testing DTensor for now.Two minor, non-blocking polish suggestions:
For symmetry and to avoid any accidental shared-state mutations in future changes, you could also
deepcopythe v1 config:if train_backend == "dtensor_v1": train_config = deepcopy(basic_dtensor_test_config)If you don’t expect to bring back the Megatron case here, you could drop the
"megatron"branch andValueErrorto reduce dead code; otherwise this is fine as is.Also applies to: 1690-1699
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
nemo_rl/models/policy/workers/dtensor_policy_worker.pynemo_rl/models/policy/workers/dtensor_policy_worker_v2.pytests/unit/models/generation/test_vllm_generation.py
🧰 Additional context used
📓 Path-based instructions (4)
**/*.py
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.py: Conform code to Python 3.12+
Indent code with 4 spaces. Do not use tabs
Use snake_case for file names
Use PascalCase for class names
Use snake_case for function and method names
Use snake_case for local variables
Prefix variable names that start with a number with 'k' (e.g., k_99th_percentile)
Use upper snake_case with 'G' prefix for global variables (e.g., G_MY_GLOBAL)
Use upper snake_case for constants
Avoid shadowing variables declared in an outer scope
Initialize all externally visible members of a class in the constructor
Prefer docstrings over comments for interfaces that may be used outside a file
Reserve comments for code within a function or interfaces that are local to a file
If a piece of code is commented out, include a comment describing its usage and why it's commented out. Remove debug comments before merging
Use Google style docstrings for classes and functions in Python, which can be parsed by Sphinx
Avoid using reflection when functionality can be easily achieved without reflection
When using try-except blocks, limit the except clause to the smallest set of specific errors possible
When using try-except blocks for duck-typing, keep the body of the try as small as possible and use the else block for logic
YAML is the single source of truth for configuration defaults. Do not set non-None defaults in code for configuration values
For required configuration attributes, access config directly and expect presence (e.g., policy_cfg['precision']) without hidden defaults
Use typing.NotRequired to mark optional attributes in TypedDict for configuration
When adding a new config key to a TypedDict subclass, document the key's purpose, valid values/types, and recommended default, and reflect the default in exemplar YAMLs under examples/configs/*.yaml
Follow the Google Python Style Guide for Python code
Files:
nemo_rl/models/policy/workers/dtensor_policy_worker.pynemo_rl/models/policy/workers/dtensor_policy_worker_v2.pytests/unit/models/generation/test_vllm_generation.py
nemo_rl/**/*.py
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
For any source file under nemo_rl/*.py that defines a class or function decorated with @ray.remote, add a coverage pragma (# pragma: no cover) because these run in separate Ray processes
Files:
nemo_rl/models/policy/workers/dtensor_policy_worker.pynemo_rl/models/policy/workers/dtensor_policy_worker_v2.py
!(**/tests/**|**/test_*.py|**/test_*.sh)
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Add the NVIDIA copyright header to all Python files and shell scripts (excluding tests). The header should include the current year
Files:
nemo_rl/models/policy/workers/dtensor_policy_worker.pynemo_rl/models/policy/workers/dtensor_policy_worker_v2.pytests/unit/models/generation/test_vllm_generation.py
**/*.{py,sh}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
The NVIDIA copyright header should appear at the top of all Python files and shell scripts (excluding tests)
Files:
nemo_rl/models/policy/workers/dtensor_policy_worker.pynemo_rl/models/policy/workers/dtensor_policy_worker_v2.pytests/unit/models/generation/test_vllm_generation.py
🧠 Learnings (1)
📚 Learning: 2025-09-18T14:20:36.297Z
Learnt from: zpqiu
Repo: NVIDIA-NeMo/RL PR: 1006
File: examples/configs/recipes/llm/distillation-qwen3-32b-to-8b-base-2n8g-fsdp2tp2.v1.yaml:113-120
Timestamp: 2025-09-18T14:20:36.297Z
Learning: In distillation workflows, the teacher policy does not perform generation - it only does inference/logprob computation on sequences generated by the student policy. Therefore, teacher generation configuration mismatches (like vLLM tensor parallelism settings) and colocation concerns are not relevant.
Applied to files:
tests/unit/models/generation/test_vllm_generation.py
🧬 Code graph analysis (1)
tests/unit/models/generation/test_vllm_generation.py (1)
nemo_rl/models/policy/lm_policy.py (1)
Policy(58-887)
🪛 Ruff (0.14.10)
tests/unit/models/generation/test_vllm_generation.py
1699-1699: Avoid specifying long messages outside the exception class
(TRY003)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Lint check
- GitHub Check: Lint check
- GitHub Check: Lint check
- GitHub Check: Post submodule check comment / Comment on PR
🔇 Additional comments (2)
nemo_rl/models/policy/workers/dtensor_policy_worker.py (1)
1837-1844: swap_tensors-based buffer move looks correct and matches v2 implementationUsing
torch.utils.swap_tensors(v, v.to(device))here preserves buffer object identity while moving storage to the target device, which is exactly what you want under FSDP2/DTensor and aligns this worker with the v2 implementation. Assumesmodel.buffers()only yieldstorch.Tensor(notDTensor), which is consistent with the rest of this module.Please double-check against the PyTorch 2.9
swap_tensorsdocs that its semantics are stable for non-parameter buffers and that no DTensor buffers are expected frommodel.buffers()in your FSDP2 setup.nemo_rl/models/policy/workers/dtensor_policy_worker_v2.py (1)
1890-1897: Consistent swap_tensors buffer migration for DTensor v2Mirroring v1, using
torch.utils.swap_tensors(v, v.to(device))for buffers is appropriate here: it moves buffer storage across devices without rebinding attributes, which plays nicely with FSDP2 and the Automodel stack.Please confirm against your current PyTorch version that
swap_tensorsis supported and officially recommended for device moves in this context.
…NVIDIA-NeMo#1737) Signed-off-by: Terry Kong <terryk@nvidia.com> Signed-off-by: Yuki Huang <yukih@nvidia.com> Signed-off-by: NeMo Bot <nemo-bot@nvidia.com> Co-authored-by: Terry Kong <terrycurtiskong@gmail.com> Co-authored-by: Yuki Huang <yukih@nvidia.com>
beep boop [🤖]: Hi @terrykong 👋,
Summary by CodeRabbit
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.