-
Notifications
You must be signed in to change notification settings - Fork 159
fix: Fix policy worker placement when using unified placement group #1341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughAdds GPU-aware bundle ordering to RayVirtualCluster via a new actor and internal sorting, updates master address/port selection to use the sorted bundles, and adjusts LM policy worker-group construction to map workers to bundle indices when a single placement group is used. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User
participant RayVirtualCluster
participant Ray as Ray API
participant PG as PlacementGroups
participant GPUActor as GetGPUIDActor
User->>RayVirtualCluster: initialize()
RayVirtualCluster->>Ray: create_placement_groups()
Ray-->>RayVirtualCluster: handles to PGs
RayVirtualCluster->>Ray: placement_group_table(PG)
Ray-->>RayVirtualCluster: bundle->node mapping
loop per bundle
RayVirtualCluster->>GPUActor: create remote (num_gpus=1)
RayVirtualCluster->>GPUActor: get_gpu_id()
GPUActor-->>RayVirtualCluster: gpu_id
end
RayVirtualCluster->>RayVirtualCluster: _get_sorted_bundle_indices()
RayVirtualCluster->>RayVirtualCluster: self._sorted_bundle_indices = result
note over RayVirtualCluster: Later:
User->>RayVirtualCluster: get_master_address_and_port()
alt sorted indices available
RayVirtualCluster->>PG: select first addr/port by sorted bundle order
else fallback
RayVirtualCluster->>PG: select first available addr/port (default)
end
RayVirtualCluster-->>User: (address, port)
sequenceDiagram
autonumber
participant Policy as LMPolicy
participant RWG as RayWorkerGroup
participant Cluster as RayVirtualCluster
Policy->>Cluster: query placement groups
alt Single placement group
Policy->>Policy: build bundle_indices_list (tie every 8 bundles per group index)
Policy->>RWG: construct(bundle_indices_list=..., sharding_annotations=...)
else Multiple placement groups
Policy->>RWG: construct(workers_per_node=..., sharding_annotations=...)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Pre-merge checks and finishing touches❌ Failed checks (4 warnings)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
nemo_rl/distributed/virtual_cluster.py
(4 hunks)nemo_rl/models/policy/lm_policy.py
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.py
: Follow the Google Python Style Guide for all Python code
Target Python 3.12+ for all Python code in NeMo-RL
Indent Python code with 4 spaces; do not use tabs
Python filenames should be snake_case (e.g., some_file.py)
Class names should be PascalCase
Function and method names should be snake_case
Local variable names should be snake_case; if starting with a number, prefix with k (e.g., k_99th_percentile)
Global variables should be UPPER_SNAKE_CASE and prefixed with G_ (e.g., G_MY_GLOBAL)
Constants should be UPPER_SNAKE_CASE
Avoid shadowing variables declared in an outer scope
Initialize all externally visible members of a class in the constructor
For public interfaces used outside a file, prefer docstrings over comments
Use comments mainly for code within a function or interfaces local to a file
Commented-out code must include a nearby comment explaining usage and why it is commented out; otherwise remove before merging
Use Google-style docstrings for classes and functions (Sphinx-parseable)
Avoid using reflection when functionality can be easily achieved without it
Limit except clauses to the smallest specific set of exceptions possible
For duck-typing via try/except, keep the try body minimal and use else for main logic
Add the NVIDIA copyright header (with current year) at the top of all Python files, excluding tests/ and test-only scripts
Files:
nemo_rl/distributed/virtual_cluster.py
nemo_rl/models/policy/lm_policy.py
nemo_rl/**/*.py
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
nemo_rl/**/*.py
: Do not set non-None configuration defaults in code; YAML is the single source of truth for defaults
Access required config attributes directly (e.g., policy_cfg["precision"]) and assume presence; do not introduce hidden defaults
Express configuration optionality via TypedDict using typing.NotRequired
When adding a new config key to a TypedDict subclass, document the key’s purpose, valid values/types, and recommended default in code
For any class or function decorated with @ray.remote, add '# pragma: no cover' on the class/def line (and on remote functions)
Files:
nemo_rl/distributed/virtual_cluster.py
nemo_rl/models/policy/lm_policy.py
🧬 Code graph analysis (1)
nemo_rl/models/policy/lm_policy.py (4)
tests/unit/models/generation/test_vllm_generation.py (1)
cluster
(221-232)tests/unit/utils/test_native_checkpoint.py (1)
cluster
(96-109)nemo_rl/distributed/virtual_cluster.py (1)
get_placement_groups
(354-362)nemo_rl/distributed/worker_groups.py (1)
RayWorkerGroup
(303-1004)
🪛 Ruff (0.13.3)
nemo_rl/distributed/virtual_cluster.py
419-419: 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). (2)
- GitHub Check: Post automodel integration comment / Comment on PR
- GitHub Check: Post submodule check comment / Comment on PR
Note that simply setting placement strategy to "PACK" does not apply, refer to this table showing node IP of workers in different setups:
|
Thank you @guyueh1! Might need some help to under the PR. |
yes, this PR will make sure that every contiguous 8 megatron workers (0-7, 8-15, ...) will be in the same node, so in EP/PP mapping, this will make sure EP group contains NVLink and maximize the EP all-gather bandwidth. Previously we were using "SPREAD" strategy for unified placement-group code path (link), according to Ray issue ray-project/ray#51117, there is no way (even if we use |
Correct; this PR just ensures that megatron worker IDs is node-wise packed, i.e. worker ID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome change with great improvement
Thank you @guyueh1 for the change and explanation. LGTM!
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Guyue Huang <140554423+guyueh1@users.noreply.github.com>
Signed-off-by: Guyue Huang <guyueh@nvidia.com>
Hi @richardliaw. Would love to hear your opinion here. What do you think about this approach from the lens of ray? Do you think PACK should do this? |
|
ℹ️ File Consistency CheckCheck based on commit: 79a4090 (PR #1341 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. |
…mock cluster test Signed-off-by: Guyue Huang <guyueh@nvidia.com>
ℹ️ File Consistency CheckCheck based on commit: 7ab2263 (PR #1341 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. |
ℹ️ File Consistency CheckCheck based on commit: bf8712d (PR #1341 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. |
What does this PR do ?
When using unified placement group, fix the worker placement so that every contiguous group of
num_gpus_per_node
workers are placed in the same node.Relevant issues: ray-project/ray#51117
Referred to implementation in NovaSky-AI/SkyRL#338
Issues
closes #945
closes #895
Usage
# Add a code snippet demonstrating how to use this
Before your PR is "Ready for review"
Pre checks:
Additional Information
Summary by CodeRabbit
New Features
Bug Fixes
Performance