Skip to content

Commit fa59e15

Browse files
committed
Merge origin/main into ModelOpt real-quant export
Signed-off-by: Meng Xin <164952785+mxinO@users.noreply.github.com>
2 parents be00179 + d1bc63d commit fa59e15

189 files changed

Lines changed: 13904 additions & 3720 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.

‎.main.commit‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ef8cd10b8e34a94c9ad7452e7851f58337f353a0
1+
441a987409b8fdd2b90b463f7999bac970109a43

‎3rdparty/Megatron-LM‎

Submodule Megatron-LM updated 231 files

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ Megatron Bridge provides out-of-the-box bridges and training recipes for a wide
229229
230230
| Family | Supported variants |
231231
|----------------|--------------------|
232+
| [**BAGEL**](docs/models/bagel/bagel.md) | BAGEL-7B-MoT (requires the tested MCore `dev` revision and `bagel` extra) |
232233
| [**Bailing**](docs/models/bailing/index.md) | Ling 2.0 / Ling MoE V2 (Bailing) |
233234
| [**BERT**](docs/models/bert/index.md) | Megatron-Style BERT (`MegatronBertForMaskedLM`) |
234235
| [**DeepSeek**](docs/models/deepseek/index.md) | DeepSeek V2 / V2 Lite (deprecated), DeepSeek V3, DeepSeek V4 / V4 Flash |
@@ -246,6 +247,7 @@ Megatron Bridge provides out-of-the-box bridges and training recipes for a wide
246247
| [**Mistral**](docs/models/mistral/index.md) | Mistral 7B / Small 3 24B (deprecated), Ministral 3 (3B/8B/14B) |
247248
| [**Xiaomi-MiMo**](docs/models/mimo/index.md) | Xiaomi-MiMo, MiMo-V2-Flash |
248249
| [**Moonlight**](docs/models/moonlight/index.md) | Moonlight |
250+
| [**Muse Glimmer**](docs/models/muse_glimmer/muse-glimmer.md) | Muse Glimmer 30B |
249251
| [**Nemotron**](docs/models/nemotron/index.md) | Nemotron H v1 (deprecated), Nemotron Nano v2 (deprecated), Nemotron-3 Nano, Nemotron-3 Super, Nemotron-3 Ultra, Llama Nemotron (deprecated), Nemotron Nano v2 VL (deprecated), Nemotron-3 Nano Omni |
250252
| [**OLMoE**](docs/models/olmoe/index.md) | OLMoE |
251253
| [**Qwen**](docs/models/qwen/index.md) | Qwen2 / Qwen2.5, Qwen3, Qwen3-MoE, Qwen3 Next, Qwen3.5 (dense/MoE), Qwen2.5-VL, Qwen3-VL, Qwen3.5-VL, Qwen3.6-VL, Qwen2 Audio, Qwen2.5-Omni, Qwen3-Omni, Qwen3-ASR |

‎docker/Dockerfile.ci‎

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
1+
# Copyright (c) 2025-2026, NVIDIA CORPORATION. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -13,7 +13,29 @@
1313
# limitations under the License.
1414

1515
ARG BASE_IMAGE=nvcr.io/nvidia/pytorch:26.08-py3
16-
FROM ${BASE_IMAGE} AS megatron_bridge
16+
FROM ${BASE_IMAGE} AS base
17+
18+
ENV PATH="/opt/venv/bin:/usr/local/bin:$PATH" \
19+
UV_PROJECT_ENVIRONMENT=/opt/venv \
20+
VIRTUAL_ENV=/opt/venv \
21+
UV_LINK_MODE=copy \
22+
UV_VERSION="0.7.2" \
23+
UV_HTTP_TIMEOUT=120
24+
25+
RUN curl -LsSf https://astral.sh/uv/${UV_VERSION}/install.sh | sh && \
26+
install -m 0755 /root/.local/bin/uv /usr/local/bin/uv && \
27+
uv venv ${UV_PROJECT_ENVIRONMENT} --system-site-packages
28+
29+
# Cache the native wheel independently of Bridge's other dependencies. Both CPU
30+
# platforms use the same base runtime as the final image and build both GPU targets.
31+
FROM base AS mok-wheel
32+
ARG MOK_COMMIT=a2ad2d0ce2366c1817d15498cdbaf8ead5966117
33+
ARG MOK_ARCH=ALL
34+
RUN --mount=type=bind,source=docker/common/install_mok.sh,target=/opt/install_mok.sh \
35+
--mount=type=bind,source=docker/patches/mok.patch,target=/opt/mok.patch \
36+
MOK_ARCH=${MOK_ARCH} bash /opt/install_mok.sh "${MOK_COMMIT}" /opt/mok.patch /opt/mok-wheels
37+
38+
FROM base AS megatron_bridge
1739
WORKDIR /opt/Megatron-Bridge
1840

1941
ARG APPLY_PYTORCH_LIBRARY_FINALIZER_PATCH=False
@@ -50,12 +72,6 @@ ARG REINSTALL_NVSHMEM=True
5072
ARG PRESERVE_BASE_RUNTIME=False
5173

5274
ENV MBRIDGE_PRESERVE_BASE_RUNTIME=${PRESERVE_BASE_RUNTIME} \
53-
PATH="/opt/venv/bin:/usr/local/bin:$PATH" \
54-
UV_PROJECT_ENVIRONMENT=/opt/venv \
55-
VIRTUAL_ENV=/opt/venv \
56-
UV_LINK_MODE=copy \
57-
UV_VERSION="0.7.2" \
58-
UV_HTTP_TIMEOUT=120 \
5975
NVTE_BUILD_NUM_PHILOX_ROUNDS=3 \
6076
NVTE_SKIP_SUBMODULE_CHECKS_DURING_BUILD=1 \
6177
HYBRID_EP_MULTINODE=1 \
@@ -97,9 +113,6 @@ EOF
97113
ARG DEEPEP_NVCC_THREADS
98114

99115
RUN --mount=type=bind,source=docker/patches/deepep.patch,target=/opt/deepep.patch \
100-
curl -LsSf https://astral.sh/uv/${UV_VERSION}/install.sh | sh && \
101-
install -m 0755 /root/.local/bin/uv /usr/local/bin/uv && \
102-
uv venv ${UV_PROJECT_ENVIRONMENT} --system-site-packages && \
103116
apt-get update && apt install -y --only-upgrade gnupg openssl libssl3t64 && \
104117
apt-get clean && \
105118
rm -rf /var/lib/apt/lists/* && \
@@ -264,6 +277,12 @@ RUN --mount=type=cache,target=/root/.cache/uv \
264277
fi && \
265278
chown -R 1000:1000 ${UV_PROJECT_ENVIRONMENT}
266279

280+
# Install after every uv sync so the Docker-only package is retained. Bind-mount
281+
# the wheel to avoid retaining a second archive in the final image.
282+
RUN --mount=type=bind,from=mok-wheel,source=/opt/mok-wheels,target=/opt/mok-wheels \
283+
uv pip install --python "${UV_PROJECT_ENVIRONMENT}/bin/python" --no-deps --no-cache /opt/mok-wheels/*.whl && \
284+
chown -R 1000:1000 ${UV_PROJECT_ENVIRONMENT}
285+
267286
COPY --chown=1000:1000 . /opt/Megatron-Bridge
268287

269288
RUN python /opt/preserve_base_runtime.py check /opt/base-runtime-packages.json
@@ -274,5 +293,8 @@ RUN python /opt/preserve_base_runtime.py check /opt/base-runtime-packages.json
274293
RUN install -d -o 1000 -g 1000 -m 0755 /nemo_run /home/ubuntu/.cache && \
275294
chown -R 1000:1000 /opt/Megatron-Bridge
276295

296+
# Remove the Nsight Systems EFA metrics plugin to address CVE-2026-27143.
297+
RUN rm -rf /usr/local/cuda-*/NsightSystems-cli-*/target-linux-x64/plugins/efa_metrics/
298+
277299
ENV HOME=/home/ubuntu
278300
USER 1000:1000

‎docker/README.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,35 @@ docker build \
2727
.
2828
```
2929

30+
The image installs [Mixture of Kittens](https://github.com/QiZhangNV/mixture-of-kittens)
31+
on both `linux/amd64` and `linux/arm64`. Each platform's native wheel includes
32+
GB200/B200 (`sm_100a`) and GB300/B300 (`sm_103a`) kernels by default. This does not
33+
enable MoK kernels on other GPUs or select MoK as a training backend.
34+
35+
The `mok-wheel` stage builds against the same base image's Python, PyTorch, and CUDA
36+
as the final image, independently of the other Bridge dependencies. BuildKit caches
37+
it by platform, base image, source revision, GPU targets, installer, and patch; registry
38+
caches must export intermediate stages with `mode=max` (as Bridge CI already does).
39+
The build checks that the wheel contains every requested GPU target without requiring
40+
a GPU. The pinned source needs `scripts/prepare_thunderkittens.sh` and the compatibility
41+
patch in `docker/patches/mok.patch`; revisit both workarounds when updating the source.
42+
43+
Build only the MoK wheel stage on either native builder, for example:
44+
45+
```bash
46+
docker buildx build \
47+
--platform linux/arm64 \
48+
-f docker/Dockerfile.ci \
49+
--target mok-wheel \
50+
-t megatron-bridge-mok-wheel:arm64 \
51+
--load \
52+
.
53+
```
54+
55+
Use `--platform linux/amd64` on an AMD64 builder. Full image builds use the existing
56+
`megatron_bridge` target and install the wheel after dependency syncing. MoK is a
57+
Docker-only dependency, outside `pyproject.toml` and `uv.lock`.
58+
3059
| Argument | Description |
3160
|---|---|
3261
| `BASE_IMAGE` | Base container |
@@ -204,6 +233,8 @@ docker build \
204233
| `APPLY_PYTORCH_LIBRARY_FINALIZER_PATCH` | Set to `True` to apply the torch.library finalizer patch; `False` for base images it does not apply against (e.g. Rubin) |
205234
| `INSTALL_DEEPEP` | Set to `True` to build and install DeepEP and nvshmem |
206235
| `DEEPEP_COMMIT` | DeepEP git commit SHA |
236+
| `MOK_COMMIT` | Full Mixture of Kittens source commit SHA; defaults to `a2ad2d0ce2366c1817d15498cdbaf8ead5966117` |
237+
| `MOK_ARCH` | GPU targets in each CPU platform's MoK wheel: `ALL` (default, GB200 and GB300), `SM100` (GB200/B200), or `SM103` (GB300/B300) |
207238
| `REINSTALL_NVSHMEM` | Set to `True` to reinstall nvshmem (`nvidia-nvshmem-cu13`) over the base image version; only applied when `INSTALL_DEEPEP=True` |
208239
| `MCORE_TRIGGERED_TESTING` | Skip uv lockfile check for cross-version Megatron-LM testing |
209240
| `INSTALL_DIFFUSION_DEPS` | Install the test-only WAN diffusion dependencies; defaults to `false` for Framework/release images |
@@ -230,9 +261,11 @@ docker build \
230261
| `common/install_cublas.sh` | Reinstall cuBLAS and cuBLASLt from the public NVIDIA CUDA apt repo |
231262
| `common/install_nccl.sh` | Reinstall NCCL from the public NVIDIA CUDA apt repo |
232263
| `common/install_cudnn.sh` | Reinstall cuDNN from the public NVIDIA CUDA apt repo |
264+
| `common/install_mok.sh` | Build and verify the pinned Mixture of Kittens wheel |
233265
| `common/install_nsys.sh` | Reinstall Nsight Systems from the public NVIDIA CUDA apt repo |
234266
| `common/install_mamba.sh` | Build the locked Mamba sdist with the local C++ standard patch |
235267
| `common/preserve_base_runtime.py` | Record and check selected base package metadata for opt-in runtime preservation |
236268
| `patches/deepep.patch` | Patch applied to DeepEP during CI image build |
269+
| `patches/mok.patch` | MoK dual GPU target build support and PyTorch/CUDA namespace compatibility fix |
237270
| `patches/mamba.patch` | Let Mamba's CUDA extension inherit PyTorch's C++ standard |
238271
| `patches/vllm.patch` | Patch applied to vLLM after install in fw-base |

‎docker/common/fw_pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ override-dependencies = [
6767
"packaging>=25.0",
6868
"nvidia-pytriton>=0.7.0",
6969
"flashinfer-python==0.6.18.post1", # Match flashinfer-cubin installed by MBridge
70+
"nvidia-cudnn-frontend==1.29.0", # Match MBridge; override PyPI MCore's older dev pin
7071
"urllib3>=2.0.7",
7172
"sh==2.2.4",
7273
"jupyter-core==5.8.1",

‎docker/common/import_check_skip.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PyNvVideoCodec # dlopens libnvidia-encode.so.1 (NVENC)
2222
deep_ep
2323
deep_ep_cpp
2424
hybrid_ep_cpp
25+
mok # native extension links libcuda.so.1
2526
torch_tensorrt
2627
quack # imports nvidia-cutlass-dsl MLIR libs, which dlopen libcuda at import
2728
peft # transitively imports optional CUDA-backed modules that dlopen libcuda

‎docker/common/install_mok.sh‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -euxo pipefail
17+
18+
MOK_REVISION="${1:?Usage: install_mok.sh <git commit> <patch> <wheel directory>}"
19+
PATCH_FILE=$(realpath "${2:?Usage: install_mok.sh <git commit> <patch> <wheel directory>}")
20+
WHEEL_DIR=$(realpath -m "${3:?Usage: install_mok.sh <git commit> <patch> <wheel directory>}")
21+
PYTHON="${UV_PROJECT_ENVIRONMENT:-/opt/venv}/bin/python"
22+
23+
if [[ ! "${MOK_REVISION}" =~ ^[0-9a-f]{40}$ ]]; then
24+
echo "MOK_COMMIT must be a full Git commit" >&2
25+
exit 1
26+
fi
27+
28+
# ALL includes both GPU architectures supported by the pinned source.
29+
export MOK_ARCH="${MOK_ARCH:-ALL}"
30+
case "${MOK_ARCH}" in
31+
ALL) MOK_CUBINS=(sm_100a sm_103a) ;;
32+
SM100) MOK_CUBINS=(sm_100a) ;;
33+
SM103) MOK_CUBINS=(sm_103a) ;;
34+
*)
35+
echo "Unsupported MOK_ARCH '${MOK_ARCH}'; expected ALL, SM100 or SM103" >&2
36+
exit 1
37+
;;
38+
esac
39+
40+
WORK_DIR=$(mktemp -d)
41+
trap 'rm -rf "${WORK_DIR}"' EXIT
42+
43+
git init "${WORK_DIR}"
44+
git -C "${WORK_DIR}" remote add origin https://github.com/QiZhangNV/mixture-of-kittens.git
45+
git -C "${WORK_DIR}" fetch --depth 1 origin "${MOK_REVISION}"
46+
git -C "${WORK_DIR}" checkout --detach "${MOK_REVISION}"
47+
git -C "${WORK_DIR}" apply --check "${PATCH_FILE}"
48+
git -C "${WORK_DIR}" apply "${PATCH_FILE}"
49+
bash "${WORK_DIR}/scripts/prepare_thunderkittens.sh"
50+
51+
export NVCC="${CUDA_HOME:-/usr/local/cuda}/bin/nvcc"
52+
export MOK_NVCC="${NVCC}"
53+
# Docker builds have no GPU driver. Stubs are link inputs, never runtime libraries.
54+
export LIBRARY_PATH="${CUDA_HOME:-/usr/local/cuda}/lib64/stubs${LIBRARY_PATH:+:${LIBRARY_PATH}}"
55+
uv build --python "${PYTHON}" --wheel --no-build-isolation --no-cache --out-dir "${WHEEL_DIR}" "${WORK_DIR}"
56+
uv pip install --python "${PYTHON}" --no-deps --no-cache "${WHEEL_DIR}"/*.whl
57+
58+
# Inspect the installed wheel without loading libcuda on GPU-less image builders.
59+
MOK_EXTENSION=$(uv run --no-project --no-sync --python "${PYTHON}" python - <<'PY'
60+
import sys
61+
from importlib.metadata import distribution
62+
from sysconfig import get_config_var
63+
64+
extension = distribution("mixture-of-kittens").locate_file("mok/_C" + get_config_var("EXT_SUFFIX"))
65+
assert extension.is_file(), f"MoK native extension missing: {extension}"
66+
sys.stdout.write(str(extension))
67+
PY
68+
)
69+
"${CUDA_HOME:-/usr/local/cuda}/bin/cuobjdump" --list-elf "${MOK_EXTENSION}" > "${WORK_DIR}/cubins.txt"
70+
cat "${WORK_DIR}/cubins.txt"
71+
for MOK_CUBIN in "${MOK_CUBINS[@]}"; do
72+
grep -Fq ".${MOK_CUBIN}.cubin" "${WORK_DIR}/cubins.txt"
73+
done

‎docker/patches/mok.patch‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
diff --git a/Makefile b/Makefile
2+
index 58bebae..1c8eb2a 100644
3+
--- a/Makefile
4+
+++ b/Makefile
5+
@@ -29,12 +29,18 @@ NVCCFLAGS += -ltorch_python -ltorch_cuda -ltorch_cpu -ltorch -lc10_cuda -lc10
6+
NVCCFLAGS += -shared -fPIC
7+
NVCCFLAGS += -diag-suppress 3189 # for warnings generated by PyTorch C++ headers
8+
9+
-ifeq ($(ARCH),SM103)
10+
+ifeq ($(ARCH),ALL)
11+
+# MoK uses the BF16/MXFP8 features shared by SM100 and SM103.
12+
+NVCCFLAGS += --threads=2
13+
+NVCCFLAGS += -DKITTENS_SM100
14+
+NVCCFLAGS += -gencode arch=compute_100a,code=sm_100a
15+
+NVCCFLAGS += -gencode arch=compute_103a,code=sm_103a
16+
+else ifeq ($(ARCH),SM103)
17+
NVCCFLAGS += -DKITTENS_SM103 -gencode arch=compute_103a,code=sm_103a
18+
else ifeq ($(ARCH),SM100)
19+
NVCCFLAGS += -DKITTENS_SM100 -gencode arch=compute_100a,code=sm_100a
20+
else
21+
-$(error Unsupported ARCH '$(ARCH)'; expected SM100 or SM103)
22+
+$(error Unsupported ARCH '$(ARCH)'; expected ALL, SM100 or SM103)
23+
endif
24+
25+
all: $(OUT)
26+
diff --git a/csrc/megakernel/grouped_gemm.cuh b/csrc/megakernel/grouped_gemm.cuh
27+
index 02f3899..07ba154 100644
28+
--- a/csrc/megakernel/grouped_gemm.cuh
29+
+++ b/csrc/megakernel/grouped_gemm.cuh
30+
@@ -291,7 +291,7 @@ static __device__ __forceinline__ void expert_grouped_gemm_kernel(
31+
update_phasebit<0>(gemm_bitfield, input_ring);
32+
input_ring = ring_advance<config::MLP_LOAD_PIPE_DEPTH>(input_ring);
33+
}
34+
- detail::tcgen05::commit<config::CLUSTER_SIZE>(gemm_outputs_arrived);
35+
+ kittens::detail::tcgen05::commit<config::CLUSTER_SIZE>(gemm_outputs_arrived);
36+
}
37+
} else {
38+
using epilogue_group = group<WARPGROUP_WARPS>;

0 commit comments

Comments
 (0)