Skip to content

Commit 6351e86

Browse files
Merge branch 'main' into chcui/iris/optimize-nemotron-omni
Signed-off-by: adityavavreNVDA <avavre@nvidia.com>
2 parents fb58b1a + 5bc1ca7 commit 6351e86

111 files changed

Lines changed: 5995 additions & 615 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dev.commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b3b1e2d793c596c2fa61076d001ab93f294e4e87
1+
2f2f8ebaef90f4d62a18a43808398223b1fc5809

.github/scripts/test_docker_dependency_layers.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,18 @@ if ! grep -Fq \
252252
echo "Bridge's lock metadata must preserve the MCore TE extra" >&2
253253
exit 1
254254
fi
255-
if grep -q 'transformer-engine @ git+https://github.com/NVIDIA/TransformerEngine.git@' pyproject.toml || \
256-
grep -q '^name = "transformer-engine"$' pyproject.toml; then
257-
echo "Bridge must inherit the TransformerEngine source and metadata from the selected MCore ref" >&2
255+
if grep -q 'transformer-engine @ git+https://github.com/NVIDIA/TransformerEngine.git@' pyproject.toml; then
256+
echo "Bridge must inherit the TransformerEngine source from the selected MCore ref" >&2
257+
exit 1
258+
fi
259+
260+
if ! grep -Fq ' NVTE_SKIP_SUBMODULE_CHECKS_DURING_BUILD=1 \' "$dockerfile"; then
261+
echo "CI builds must disable TransformerEngine's recursive build-time submodule fetch" >&2
262+
exit 1
263+
fi
264+
if grep -R -qE 'git submodule update.*--recursive|git submodule update --init --recursive' \
265+
"$dockerfile" docker .github/actions; then
266+
echo "CI build surfaces must not fetch recursive submodules at build time" >&2
258267
exit 1
259268
fi
260269

.main.commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2a75ac12c54ba6a42b34024756820bf819a2e25f
1+
731b791469004f8fdcb896e65d610d6b1b0ebb32

3rdparty/Megatron-LM

Submodule Megatron-LM updated 320 files

docker/Dockerfile.ci

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ ENV PATH="/opt/venv/bin:/usr/local/bin:$PATH" \
5555
UV_VERSION="0.7.2" \
5656
UV_HTTP_TIMEOUT=120 \
5757
NVTE_BUILD_NUM_PHILOX_ROUNDS=3 \
58+
NVTE_SKIP_SUBMODULE_CHECKS_DURING_BUILD=1 \
5859
HYBRID_EP_MULTINODE=1 \
5960
RDMA_CORE_HOME=/opt/rdma-core/build \
6061
LD_LIBRARY_PATH="/usr/local/cuda/lib64/:$LD_LIBRARY_PATH"
@@ -192,7 +193,7 @@ COPY --chown=1000:1000 . /opt/Megatron-Bridge
192193
# prepared environment, and uses /nemo_run for runtime outputs. Keep those paths owned by the
193194
# existing unprivileged base-image user instead of relying on a root final user.
194195
RUN install -d -o 1000 -g 1000 -m 0755 /nemo_run /home/ubuntu/.cache && \
195-
chown 1000:1000 /opt/Megatron-Bridge
196+
chown -R 1000:1000 /opt/Megatron-Bridge
196197

197198
ENV HOME=/home/ubuntu
198199
USER 1000:1000

docker/Dockerfile.fw_base

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
# limitations under the License.
1414

1515
# Build layer variables
16-
# Supported mode: FW_DEP_BUILDER=base, FW_BASE_FINAL=fw_toolkit_builder
16+
# Supported mode: FW_DEP_BUILDER=base, FW_BASE_FINAL=fw_toolkit_builder,
17+
# VLLM_WHEEL_SRC=vllm_wheel_build|vllm_wheel_none
1718
# TRT-LLM stages are not present in this Dockerfile.
1819
ARG FW_DEP_BUILDER
1920
ARG FW_BASE_FINAL
21+
ARG VLLM_WHEEL_SRC=vllm_wheel_build
2022

2123
ARG NEMO_FW_BASE_IMAGE
2224
FROM ${NEMO_FW_BASE_IMAGE} AS base
@@ -31,7 +33,7 @@ ENV NVIDIA_PRODUCT_NAME="NeMo Framework" \
3133
##
3234
##############################################################################
3335

34-
FROM base AS vllm_wheel
36+
FROM base AS vllm_wheel_build
3537

3638
ARG VLLM_VERSION=v0.14.1
3739
ARG MAX_JOBS=4
@@ -47,6 +49,13 @@ RUN mkdir -p /src/vllm && \
4749
pip install -r requirements/build/cuda.txt && \
4850
pip wheel --no-deps --no-build-isolation -v .
4951

52+
# /src/vllm must exist for the install step's bind mount.
53+
FROM base AS vllm_wheel_none
54+
55+
RUN mkdir -p /src/vllm
56+
57+
FROM ${VLLM_WHEEL_SRC} AS vllm_wheel
58+
5059
##############################################################################
5160
##
5261
## Top layer of FW_BASE container
@@ -127,10 +136,14 @@ RUN --mount=type=bind,source=docker/common/install_nsys.sh,target=/opt/install_n
127136
# Copy Wheels
128137
RUN --mount=type=bind,from=vllm_wheel,source=/src/vllm/,target=/tmp/vllm/ \
129138
--mount=type=bind,source=docker/patches/vllm.patch,target=/opt/vllm.patch \
139+
if ! compgen -G "/tmp/vllm/vllm*.whl" >/dev/null; then \
140+
echo "No vLLM wheel produced; skipping vLLM install."; \
141+
else \
130142
pip install /tmp/vllm/vllm*.whl && \
131143
pushd /usr/local/lib/python3.12/dist-packages/vllm && \
132144
patch -p1 < /opt/vllm.patch && \
133-
popd
145+
popd; \
146+
fi
134147

135148
##############################################################################
136149
##

docker/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ docker build \
132132
| `FW_BASE_FINAL` | Output stage. `trtllm_install` (with TRT-LLM) or `fw_toolkit_builder` (without) |
133133
| `UV_VERSION` | uv version to install |
134134
| `VLLM_VERSION` | vLLM git tag to build |
135+
| `VLLM_WHEEL_SRC` | Stage supplying the vLLM wheel. `vllm_wheel_build` (default) builds it from source; `vllm_wheel_none` skips both the build and the install |
135136
| `TRT_LLM_COMMIT` | TensorRT-LLM git commit or tag |
136137
| `TRT_LLM_VERSION` | TensorRT-LLM version string embedded as an image environment variable |
137138
| `TRT_VER` | TensorRT version for the TRT-LLM install scripts |

docs/bridge-rl-integration.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,46 @@ Translate your RL framework config into Megatron Bridge's `ConfigContainer` for
7676

7777
```python
7878
import torch
79+
from megatron.bridge import AutoBridge
7980
from megatron.bridge.training.config import (
8081
ConfigContainer,
8182
TrainingConfig,
8283
OptimizerConfig,
8384
SchedulerConfig,
8485
DistributedDataParallelConfig,
8586
CheckpointConfig,
87+
LoggerConfig,
8688
TokenizerConfig,
8789
)
8890
from nemo_rl.models.policy import PolicyConfig # or your own policy cfg type
8991

9092
# Example: map your RL config to Megatron config
9193
def build_megatron_config(rl_cfg: PolicyConfig, pretrained_ckpt_dir: str) -> ConfigContainer:
92-
model_cfg = rl_cfg["megatron_cfg"].copy()
94+
bridge = AutoBridge.from_hf_pretrained(rl_cfg["model_name"])
95+
model_cfg = bridge.to_megatron_provider(load_weights=False)
96+
97+
# Keep framework-owned optimizer/scheduler/DDP mappings out of the model
98+
# provider. Apply only provider fields, with Bridge validating each name.
99+
provider_fields = (
100+
"tensor_model_parallel_size",
101+
"pipeline_model_parallel_size",
102+
"context_parallel_size",
103+
"expert_model_parallel_size",
104+
"expert_tensor_parallel_size",
105+
"sequence_parallel",
106+
"recompute_granularity",
107+
"recompute_method",
108+
"recompute_num_layers",
109+
)
110+
model_overrides = {name: rl_cfg["megatron_cfg"][name] for name in provider_fields if name in rl_cfg["megatron_cfg"]}
111+
93112
# Precision
94-
dtype = rl_cfg["precision"]
95-
model_cfg["bf16"] = dtype == "bfloat16"
96-
model_cfg["fp16"] = dtype == "float16"
113+
dtype = {
114+
"float32": torch.float32,
115+
"bfloat16": torch.bfloat16,
116+
"float16": torch.float16,
117+
}[rl_cfg["precision"]]
118+
model_cfg.apply_overrides_and_finalize(dtype=dtype, overrides=model_overrides)
97119

98120
checkpoint = CheckpointConfig(
99121
save_interval=100,
@@ -130,17 +152,19 @@ def build_megatron_config(rl_cfg: PolicyConfig, pretrained_ckpt_dir: str) -> Con
130152
tokenizer_model=rl_cfg["model_name"],
131153
)
132154

133-
return ConfigContainer(
155+
cfg = ConfigContainer(
134156
model=model_cfg,
135157
checkpoint=checkpoint,
136-
logger=None,
158+
logger=LoggerConfig(),
137159
train=train,
138160
optimizer=opt,
139161
ddp=ddp,
140162
scheduler=sch,
141163
dataset=None,
142164
tokenizer=tokenizer,
143165
)
166+
cfg.validate()
167+
return cfg
144168
```
145169

146170
Initialize Megatron-Core using a helper similar to `setup_megatron_model` from NeMo-RL:

docs/fern/versions/0.4.2/pages/bridge-rl-integration.mdx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,46 @@ Translate your RL framework config into Megatron Bridge's `ConfigContainer` for
7272

7373
```python
7474
import torch
75+
from megatron.bridge import AutoBridge
7576
from megatron.bridge.training.config import (
7677
ConfigContainer,
7778
TrainingConfig,
7879
OptimizerConfig,
7980
SchedulerConfig,
8081
DistributedDataParallelConfig,
8182
CheckpointConfig,
83+
LoggerConfig,
8284
TokenizerConfig,
8385
)
8486
from nemo_rl.models.policy import PolicyConfig # or your own policy cfg type
8587

8688
# Example: map your RL config to Megatron config
8789
def build_megatron_config(rl_cfg: PolicyConfig, pretrained_ckpt_dir: str) -> ConfigContainer:
88-
model_cfg = rl_cfg["megatron_cfg"].copy()
90+
bridge = AutoBridge.from_hf_pretrained(rl_cfg["model_name"])
91+
model_cfg = bridge.to_megatron_provider(load_weights=False)
92+
93+
# Keep framework-owned optimizer/scheduler/DDP mappings out of the model
94+
# provider. Apply only provider fields, with Bridge validating each name.
95+
provider_fields = (
96+
"tensor_model_parallel_size",
97+
"pipeline_model_parallel_size",
98+
"context_parallel_size",
99+
"expert_model_parallel_size",
100+
"expert_tensor_parallel_size",
101+
"sequence_parallel",
102+
"recompute_granularity",
103+
"recompute_method",
104+
"recompute_num_layers",
105+
)
106+
model_overrides = {name: rl_cfg["megatron_cfg"][name] for name in provider_fields if name in rl_cfg["megatron_cfg"]}
107+
89108
# Precision
90-
dtype = rl_cfg["precision"]
91-
model_cfg["bf16"] = dtype == "bfloat16"
92-
model_cfg["fp16"] = dtype == "float16"
109+
dtype = {
110+
"float32": torch.float32,
111+
"bfloat16": torch.bfloat16,
112+
"float16": torch.float16,
113+
}[rl_cfg["precision"]]
114+
model_cfg.apply_overrides_and_finalize(dtype=dtype, overrides=model_overrides)
93115

94116
checkpoint = CheckpointConfig(
95117
save_interval=100,
@@ -126,17 +148,19 @@ def build_megatron_config(rl_cfg: PolicyConfig, pretrained_ckpt_dir: str) -> Con
126148
tokenizer_model=rl_cfg["model_name"],
127149
)
128150

129-
return ConfigContainer(
151+
cfg = ConfigContainer(
130152
model=model_cfg,
131153
checkpoint=checkpoint,
132-
logger=None,
154+
logger=LoggerConfig(),
133155
train=train,
134156
optimizer=opt,
135157
ddp=ddp,
136158
scheduler=sch,
137159
dataset=None,
138160
tokenizer=tokenizer,
139161
)
162+
cfg.validate()
163+
return cfg
140164
```
141165

142166
Initialize Megatron-Core using a helper similar to `setup_megatron_model` from NeMo-RL:

docs/fern/versions/nightly/pages/bridge-rl-integration.mdx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,46 @@ Translate your RL framework config into Megatron Bridge's `ConfigContainer` for
7272

7373
```python
7474
import torch
75+
from megatron.bridge import AutoBridge
7576
from megatron.bridge.training.config import (
7677
ConfigContainer,
7778
TrainingConfig,
7879
OptimizerConfig,
7980
SchedulerConfig,
8081
DistributedDataParallelConfig,
8182
CheckpointConfig,
83+
LoggerConfig,
8284
TokenizerConfig,
8385
)
8486
from nemo_rl.models.policy import PolicyConfig # or your own policy cfg type
8587

8688
# Example: map your RL config to Megatron config
8789
def build_megatron_config(rl_cfg: PolicyConfig, pretrained_ckpt_dir: str) -> ConfigContainer:
88-
model_cfg = rl_cfg["megatron_cfg"].copy()
90+
bridge = AutoBridge.from_hf_pretrained(rl_cfg["model_name"])
91+
model_cfg = bridge.to_megatron_provider(load_weights=False)
92+
93+
# Keep framework-owned optimizer/scheduler/DDP mappings out of the model
94+
# provider. Apply only provider fields, with Bridge validating each name.
95+
provider_fields = (
96+
"tensor_model_parallel_size",
97+
"pipeline_model_parallel_size",
98+
"context_parallel_size",
99+
"expert_model_parallel_size",
100+
"expert_tensor_parallel_size",
101+
"sequence_parallel",
102+
"recompute_granularity",
103+
"recompute_method",
104+
"recompute_num_layers",
105+
)
106+
model_overrides = {name: rl_cfg["megatron_cfg"][name] for name in provider_fields if name in rl_cfg["megatron_cfg"]}
107+
89108
# Precision
90-
dtype = rl_cfg["precision"]
91-
model_cfg["bf16"] = dtype == "bfloat16"
92-
model_cfg["fp16"] = dtype == "float16"
109+
dtype = {
110+
"float32": torch.float32,
111+
"bfloat16": torch.bfloat16,
112+
"float16": torch.float16,
113+
}[rl_cfg["precision"]]
114+
model_cfg.apply_overrides_and_finalize(dtype=dtype, overrides=model_overrides)
93115

94116
checkpoint = CheckpointConfig(
95117
save_interval=100,
@@ -126,17 +148,19 @@ def build_megatron_config(rl_cfg: PolicyConfig, pretrained_ckpt_dir: str) -> Con
126148
tokenizer_model=rl_cfg["model_name"],
127149
)
128150

129-
return ConfigContainer(
151+
cfg = ConfigContainer(
130152
model=model_cfg,
131153
checkpoint=checkpoint,
132-
logger=None,
154+
logger=LoggerConfig(),
133155
train=train,
134156
optimizer=opt,
135157
ddp=ddp,
136158
scheduler=sch,
137159
dataset=None,
138160
tokenizer=tokenizer,
139161
)
162+
cfg.validate()
163+
return cfg
140164
```
141165

142166
Initialize Megatron-Core using a helper similar to `setup_megatron_model` from NeMo-RL:

0 commit comments

Comments
 (0)