Repository navigation
[CPU/MLAS] Add QMoE shared 4-bit expert layouts, AVX-512 kernels, and FileExpertStore - #33450
Open
Tianlei Wu (tianleiwu) wants to merge 5 commits into
Open
Tianlei Wu (tianleiwu) wants to merge 5 commits into
Tianlei Wu (tianleiwu) wants to merge 5 commits into
Conversation
Tianlei Wu (tianleiwu)
force-pushed
the
tlwu/20261019/qmoe-offload-p1-cpu-shared-layout
branch
from
October 19, 2026 09:00
a0d08bf to
7a92038
Compare
mirounga
self-requested a review
October 19, 2026 13:41
Tianlei Wu (tianleiwu)
force-pushed
the
tlwu/20261019/qmoe-offload-p1-cpu-shared-layout
branch
from
October 20, 2026 09:19
7a92038 to
7e3016c
Compare
Tianlei Wu (tianleiwu)
force-pushed
the
tlwu/20261019/qmoe-offload-p1-cpu-shared-layout
branch
from
October 20, 2026 10:09
7e3016c to
5f1dc94
Compare
Tianlei Wu (tianleiwu)
added this pull request to stack #33495
October 20, 2026 18:52
Tianlei Wu (tianleiwu)
force-pushed
the
tlwu/20261019/qmoe-offload-p1-cpu-shared-layout
branch
2 times, most recently
from
October 21, 2026 06:32
c4535f3 to
3c007ec
Compare
Tianlei Wu (tianleiwu)
marked this pull request as ready for review
October 21, 2026 18:12
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Memory-safety, mutable-initializer compatibility, numerical correctness, and portability defects remain unresolved.
7 open issues
INT4 SIMD range handling overruns partial column ranges · New Clang build fails without AVX-512 target configuration · New Worker creation failure terminates due to joinable threads · New Read-only mappings break mutable training initializers · New Rounding bias corrupts FP8 NaN lookup values · New BF16 narrowing converts low-payload NaNs to infinity · New Mapped-store test runs on unsupported macOS · New
What changed in this PR
Adds CPU infrastructure for the first stage of portable QMoE offloading.
Changes:
- Adds shared INT4/FP4 layouts, scalar and AVX-512 kernels, and bounded expert caching.
- Introduces topology-aware workers and shared read-only POSIX mappings.
- Integrates MLAS compilation and adds Python reference packers and tests.
| File | Description |
|---|---|
onnxruntime/test/python/transformers/test_qmoe_shared_layout.py |
Adds layout, kernel parity, and cache tests. |
onnxruntime/test/python/transformers/qmoe_shared_layout_ref.py |
Adds INT4 reference packing and computation. |
onnxruntime/core/platform/posix/env.cc |
Changes little-endian mappings to shared read-only storage. |
onnxruntime/core/mlas/lib/platform.cpp |
Implements AVX-512 capability query. |
onnxruntime/core/mlas/inc/mlas.h |
Declares the capability query. |
onnxruntime/contrib_ops/cuda/moe/qmoe_spin_pool.h |
Adds topology-aware workers and spin controls. |
onnxruntime/contrib_ops/cpu/moe/qmoe_shared_layout.h |
Declares layouts, stores, and kernel interfaces. |
onnxruntime/contrib_ops/cpu/moe/qmoe_shared_layout.cc |
Implements layouts, caching, scalar kernels, and dispatch. |
onnxruntime/contrib_ops/cpu/moe/qmoe_shared_layout_avx512.cc |
Adds vectorized expert kernels and conversions. |
cmake/onnxruntime_providers_cpu.cmake |
Adjusts ownership of QMoE source compilation. |
cmake/onnxruntime_mlas.cmake |
Adds offload option and separate AVX-512 compilation. |
Review effort: Balanced
Tianlei Wu (tianleiwu)
force-pushed
the
tlwu/20261019/qmoe-offload-p1-cpu-shared-layout
branch
from
October 22, 2026 01:25
3c007ec to
0cc4f64
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved storage-validation and mapping defects can permit out-of-bounds reads or silently change expert weights.
6 open issues
Reject zero-length tensor buffers before external range validation · New Exclude modified private mappings from file reload and discard · New Support cache alignments greater than 4096 bytes · New Retain Windows validation handle to prevent mixed model revisions · New Coalesce and bound duplicate pending prefetch requests · New Move large cache tables out of inline thread-local storage · New
7 resolved since last review
Read-only mappings break mutable training initializers Worker creation failure terminates due to joinable threads Clang build fails without AVX-512 target configuration INT4 SIMD range handling overruns partial column ranges Mapped-store test runs on unsupported macOS BF16 narrowing converts low-payload NaNs to infinity Rounding bias corrupts FP8 NaN lookup values
Review effort: Balanced
Tianlei Wu (tianleiwu)
requested review from
Akshay Sonawane (apsonawane),
kunal-vaishnavi and
Ti-Tai Wang (titaiwangms)
and
a balanced review from Copilot
October 23, 2026 23:38
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Incorrect legacy-weight prepacking, an allocation-failure data race, and CUDA tests that permit CPU fallback remain unresolved.
3 open issues
6 resolved since last review
Exclude modified private mappings from file reload and discard Reject zero-length tensor buffers before external range validation Move large cache tables out of inline thread-local storage Coalesce and bound duplicate pending prefetch requests Retain Windows validation handle to prevent mixed model revisions Support cache alignments greater than 4096 bytes
Review effort: Balanced
Comment on lines
+414
to
+416
| alignas(64) static __m512 fallback_lut[256]; | ||
| PopulateScaleFp4Lut2D(base_lut, global_scale, round_scale_bf16, fallback_lut); | ||
| return fallback_lut; |
|
|
||
| outs = [] | ||
| for model in (m_raw, m_pk): | ||
| sess = ort.InferenceSession(model, providers=["CUDAExecutionProvider"]) |
… FileExpertStore Add SharedExpertBlockV1/V2/V3 4-bit expert layouts (MXFP4/INT4/NVFP4), AVX-512/AVX-512-FP16/AVX2 CPU expert GEMV kernels, MLAS FP16 dispatch, FileExpertStore with bounded host-slot caching over MAP_SHARED/MAP_PRIVATE/heap-scale banks, and read-only MAP_SHARED external initializer mapping on little-endian POSIX. Address review feedback: - Fix scalar HalfToFloat subnormal exponent (127 - 14 - e) and add exhaustive scalar/SIMD FP16 bit-pattern tests. - Track regular-file vs heap backing in FileExpertStore, retain independent resident backing for accepted heap banks, and add IsFileBackedReadOnlyMapping / EvictFileBackedHostPages helpers with heap eviction safety tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Guard partial INT4 SIMD ranges, preserve NaNs and signed zero, fix Clang target scoping, and validate inferred storage offsets. Restore writable private POSIX mappings for mutable initializers and add focused kernel/cache/mapping regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…oE support - Reject null or zero-byte buffers in TensorExpertStore::Initialize before range validation. - Exclude private mappings (r--p) from IsFileBackedReadOnlyMapping and automatic /proc/self/maps file reloading so modified COW mappings are snapshotted or rejected rather than discarded. - Remove the 4096-byte cap in ComputePointerAlignment so alignments > 4096 work in MakeExpertBlockLease, TensorExpertStore, and FileExpertStore. - Retain an open Win32 HANDLE (FILE_SHARE_READ|WRITE|DELETE) across FileExpertStore lifetime and read with positional OVERLAPPED ReadFile. - Coalesce pending Prefetch requests by expert ID, refresh generations, and bound the pending queue to pre-reserved cache_slots. - Move the 16 KiB FP4 2D LUT cache entries out of inline TLS into a small per-thread handle with lazily allocated ways. - Gate onnxruntime_ENABLE_MLAS_QMOE_OFFLOAD off when onnxruntime_DISABLE_CONTRIB_OPS or minimal builds are enabled. - Add canonical INT4 QMoE view/kernels (row-major and block-major scales, SM80 prepacked and raw row-major weights, FP16/BF16) and support weights_prepacked=1 INT4 QMoE in QMoECPU. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Tianlei Wu (tianleiwu)
force-pushed
the
tlwu/20261019/qmoe-offload-p1-cpu-shared-layout
branch
from
October 24, 2026 03:59
dd0da0f to
ea94e4b
Compare
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.


Description
Part 1 of 3 in the Portable QMoE Offload series adds CPU shared INT4, MXFP4 and NVFP4 expert layouts, scalar/AVX-512
expert kernels, and
FileExpertStorewith bounded, pin-counted host-slot caching and asynchronous prefetch.The MLAS build owns the kernels by default, with a standalone/provider-owned compilation path when disabled.
Key changes
initializer mapping policy; caller-created immutable read-only mappings can still be used as expert banks.
Validation
Commands below were run from the repository root unless noted:
.venv/bin/python onnxruntime/test/python/transformers/test_qmoe_shared_layout.py:passed, 12 tests passed and 4 optional tests skipped.
/usr/local/bin/cmake --build build/pr33505_cpu/Release --target onnxruntime_common --parallel 8:passed; recompiles the actual POSIX mapping implementation.
/usr/local/bin/cmake --build build/pr33505_cpu/Release --target onnxruntime_mlas --parallel 8:passed, including the separate AVX-512 translation unit.
GCC and Clang each passed all 7 tests under Intel SDE
-skx; the production MLAS-linked executable alsopassed all 7 tests.
ORT_QMOE_FP4_GROUP8_MASK=15passed all 7 tests.--gtest_filter='FileIoTest.*:RandomAccessFileTest.*': passed all 14 tests, including writable COW mappings.lintrunner: passed.git diff --check: passed.The local AMD host lacks AVX-512, so SIMD correctness was verified by actual instruction emulation, not native
performance testing. CUDA golden/artifact tests and macOS execution were not run.
Motivation and Context
Cold experts need a portable CPU execution path and bounded host caching while retaining the same quantized storage
used by accelerator execution. Keeping checked geometry, reference execution and SIMD dispatch behind a shared
layout contract allows later offload integration without making immutable bank policy apply to mutable training tensors.
The review follow-up addresses all six applicable GitHub comments, adds regressions for two additional correctness
gaps, and confirms the spin-pool comment is obsolete because that file is no longer part of this PR.