-
Notifications
You must be signed in to change notification settings - Fork 540
fix: Reconcile #2315 and #2612 #2902
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1f01c59
fix: Reconcile #2315 and #2612
tdene 5b96ce0
Add unit-test for init_cluster_placement_groups
tdene 48edb3d
Claude functional test for topology-aware MInf
tdene 90a202a
Address reviewer comments
tdene 3afd33a
Fix `megatron_generation-async-gym` nightly
tdene eb17aa8
lint
tdene File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #!/bin/bash | ||
|
|
||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) | ||
| PROJECT_ROOT=$(realpath $SCRIPT_DIR/../..) | ||
| # Mark the current repo as safe, since wandb fetches metadata about the repo | ||
| git config --global --add safe.directory $PROJECT_ROOT | ||
|
|
||
| set -eou pipefail | ||
|
|
||
| EXP_NAME=$(basename $0 .sh) | ||
| EXP_DIR=$SCRIPT_DIR/$EXP_NAME | ||
| LOG_DIR=$EXP_DIR/logs | ||
| JSON_METRICS=$EXP_DIR/metrics.json | ||
| RUN_LOG=$EXP_DIR/run.log | ||
| export PYTHONPATH=${PROJECT_ROOT}:${PYTHONPATH:-} | ||
|
|
||
| rm -rf $EXP_DIR $LOG_DIR | ||
| mkdir -p $EXP_DIR $LOG_DIR | ||
|
|
||
| cd $PROJECT_ROOT | ||
|
|
||
| # cluster.segment_size only engages when Ray nodes carry nvlink_domain_* labels, | ||
| # which ray.sub probes from `nvidia-smi -q` ClusterUUID on NVLink-fabric clusters | ||
| # (e.g. GB200 NVL72); CI runners have none. Pre-start a Ray head with a synthetic | ||
| # domain label so init_ray() attaches to it (externally managed cluster) and the | ||
| # topology-aware megatron placement path runs for real. | ||
| cleanup() { | ||
| uv run ray stop --force || true | ||
| } | ||
| trap cleanup EXIT | ||
| uv run ray stop --force || true # don't attach to a stale cluster | ||
| uv run ray start --head --disable-usage-stats \ | ||
| --resources='{"nvlink_domain_ci_synthetic": 1, "topo_rank": 1}' | ||
|
|
||
| uv run coverage run -a --data-file=$PROJECT_ROOT/tests/.coverage --source=$PROJECT_ROOT/nemo_rl \ | ||
| $PROJECT_ROOT/examples/run_grpo.py \ | ||
| --config $PROJECT_ROOT/examples/configs/grpo_math_1B_megatron.yaml \ | ||
| policy.model_name=Qwen/Qwen2.5-0.5B \ | ||
| grpo.num_prompts_per_step=2 \ | ||
| grpo.num_generations_per_prompt=4 \ | ||
| policy.train_global_batch_size=4 \ | ||
| policy.logprob_batch_size=4 \ | ||
| policy.train_micro_batch_size=1 \ | ||
| policy.generation.backend=megatron \ | ||
| cluster.gpus_per_node=2 \ | ||
| cluster.segment_size=1 \ | ||
|
terrykong marked this conversation as resolved.
|
||
| grpo.max_num_steps=2 \ | ||
| logger.tensorboard_enabled=true \ | ||
| logger.log_dir=$LOG_DIR \ | ||
| logger.wandb_enabled=false \ | ||
| logger.monitor_gpus=true \ | ||
| checkpointing.enabled=false \ | ||
| $@ \ | ||
| 2>&1 | tee $RUN_LOG | ||
|
|
||
| # Guard against the silent fallback: with no (or unreadable) domain labels the run | ||
| # would succeed without ever exercising the topology placement path under test. | ||
| grep -q "Topology-aware allocation" $RUN_LOG || { | ||
| echo "ERROR: topology-aware allocation did not engage (no segment selection logged)" >&2 | ||
| exit 1 | ||
| } | ||
| # NOTE: `! grep` is exempt from `set -e`, hence the explicit if. | ||
| if grep -q "no NVLink domain info" $RUN_LOG; then | ||
| echo "ERROR: segment_size fell back to unordered allocation" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| uv run tests/json_dump_tb_logs.py $LOG_DIR --output_path $JSON_METRICS | ||
|
|
||
| uv run tests/check_metrics.py $JSON_METRICS \ | ||
| 'max(data["train/token_mult_prob_error"]) < 1.05' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from nemo_rl.models.generation.megatron import MegatronGeneration | ||
|
|
||
|
|
||
| def _placement_policy_config( | ||
| *, | ||
| tp: int = 1, | ||
| pp: int = 1, | ||
| cp: int = 1, | ||
| ep: int = 1, | ||
| etp: int = 1, | ||
| colocated: bool = False, | ||
| mcore_overrides: dict | None = None, | ||
| ) -> dict: | ||
| """Minimal PolicyConfig slice consumed by init_cluster_placement_groups.""" | ||
| return { | ||
| "megatron_cfg": { | ||
| "tensor_model_parallel_size": tp, | ||
| "pipeline_model_parallel_size": pp, | ||
| "context_parallel_size": cp, | ||
| "expert_model_parallel_size": ep, | ||
| "expert_tensor_parallel_size": etp, | ||
| }, | ||
| "generation": { | ||
| "colocated": {"enabled": colocated}, | ||
| "mcore_generation_config": mcore_overrides or {}, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "config_kwargs,expected_strategy,expected_unified", | ||
| [ | ||
| # cross-node span via TP alone -> one unified PG | ||
| (dict(tp=8), "PACK", True), | ||
| # PP is excluded from the NVLink span: TP*CP=4 fits a node even | ||
| # though the full TP*PP*CP instance would not | ||
| (dict(tp=2, pp=2, cp=2), "PACK", False), | ||
| # node-local span at the == boundary -> per-node PGs | ||
| (dict(tp=4), "PACK", False), | ||
| # cross-node MoE expert group (ETP*EP > TP*CP) -> one unified PG: | ||
| # the NVLS dispatcher needs the ep_group fully NVLink-connected | ||
| (dict(tp=2, ep=8), "PACK", True), | ||
| # non-colocated generation parallelism overrides the training values | ||
| # (mirrors MegatronGeneration's megatron_cfg merge) | ||
| ( | ||
| dict(tp=8, mcore_overrides={"tensor_model_parallel_size": 2}), | ||
| "PACK", | ||
| False, | ||
| ), | ||
| # colocated reuses the training layout (overrides do not apply): | ||
| # no PACK strategy, span from the training config incl. its EP | ||
| (dict(tp=2, ep=8, colocated=True), None, True), | ||
| ], | ||
| ) | ||
| def test_megatron_init_cluster_placement_groups( | ||
| config_kwargs, expected_strategy, expected_unified | ||
| ): | ||
| """The NVLink-domain span is max(TP*CP, ETP*EP) of the operative config.""" | ||
| cluster = MagicMock(num_gpus_per_node=4) | ||
|
|
||
| MegatronGeneration.init_cluster_placement_groups( | ||
| cluster, _placement_policy_config(**config_kwargs) | ||
| ) | ||
|
|
||
| cluster._init_placement_groups.assert_called_once_with( | ||
| strategy=expected_strategy, | ||
| use_unified_pg=expected_unified, | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.