Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ac032be
Add runtime physical columns for batched-sequence off-graph KV (ABI 2)
Gasoonjia Nov 20, 2026
b649b06
Address Claude review: inflight recovery, geometric growth, DFlash guard
Gasoonjia Nov 20, 2026
e87a870
Fix runtime-column admission, recovery, and CUDA coverage
Gasoonjia Nov 20, 2026
0f95624
Expose native KV probe diagnostics and run it before longer CUDA tests
Gasoonjia Nov 20, 2026
e19a789
Enable native CUDA logging for graph qualification
Gasoonjia Nov 20, 2026
47a2cd7
Compare split-decode reference tensors on the same device
Gasoonjia Nov 20, 2026
89714b7
Merge latest main and fix runtime-column lifecycle
Gasoonjia Nov 21, 2026
bd49b85
Clarify engine-thread maintenance and strengthen KV qualification
Gasoonjia Nov 21, 2026
670bafe
Merge current main before continuing the CUDA feature stack
Gasoonjia Nov 21, 2026
952486c
Keep CUDA KV recovery and graph qualification valid without logging
Gasoonjia Nov 21, 2026
a80ab38
Merge branch 'main' into runtime-columns-abi2-pr1
Gasoonjia Nov 23, 2026
73bce36
CUDA: pack private owner KV rows and share Ring staging
Gasoonjia Nov 21, 2026
dcdb1df
CUDA: harden private Ring ownership and amortize row growth
Gasoonjia Nov 21, 2026
1267eb4
[CUDA] Fit private attention pipelines and expose cache phase costs
Gasoonjia Nov 21, 2026
e0ea9f1
CUDA: qualify Ring geometry and compact reused owner spans
Gasoonjia Nov 22, 2026
97c0c55
Preserve Ring growth slack and runtime-owned KV compile placeholders
Gasoonjia Nov 22, 2026
9ace818
Preserve runtime KV constant extents and bounded compaction slack
Gasoonjia Nov 22, 2026
5b02ff4
Bound legacy KV contraction allocations and strengthen ABI 3 qualific…
Gasoonjia Nov 22, 2026
785257e
Reduce private KV copy and archive dispatch overhead
Gasoonjia Nov 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .ci/scripts/muse_glimmer_batching_workload.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class EvidenceExecutor final : public batching::Executor {
bool initialize() override {
return inner_.initialize();
}
void on_idle() override {
inner_.on_idle();
}
std::size_t preferred_batch_tokens() const override {
return inner_.preferred_batch_tokens();
}
Expand Down
6 changes: 6 additions & 0 deletions .ci/scripts/tests/muse_glimmer_batching_workload_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ void rejected(F action) {
class FakeExecutor final : public batching::Executor {
public:
bool succeeds = true;
int idle_calls = 0;
void on_idle() override {
++idle_calls;
}
std::optional<batching::SessionId> open_session() override {
return 1;
}
Expand Down Expand Up @@ -95,6 +99,8 @@ void workload_limits() {
void successful_batch_owners() {
FakeExecutor inner;
ci::EvidenceExecutor executor(inner);
executor.on_idle();
require(inner.idle_calls == 1);
batching::BatchOutput out;
require(executor.execute({{input(1), input(1)}}, out));
require(executor.execute({{input(2)}}, out));
Expand Down
143 changes: 143 additions & 0 deletions .ci/scripts/tests/test_muse_glimmer_batching_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import ast
import re
import subprocess
import unittest
Expand All @@ -23,6 +24,148 @@


class MuseGlimmerBatchingCITest(unittest.TestCase):
def test_private_buck_targets_include_the_imported_cuda_packages(self):
cuda = ROOT / "backends/cuda"
tree = ast.parse((cuda / "tests/targets.bzl").read_text())
targets = {}
for node in ast.walk(tree):
if isinstance(node, ast.Call):
fields = {keyword.arg: keyword.value for keyword in node.keywords}
name = fields.get("name")
if isinstance(name, ast.Constant) and name.value in (
"test_sdpa_varlen_private",
"test_private_kv_manifest",
):
targets[name.value] = fields
self.assertEqual(len(targets), 2)
packages = {
"executorch.backends.cuda.passes.": "//executorch/backends/cuda:cuda_passes",
"executorch.backends.cuda.triton.kernels.": "//executorch/backends/cuda:triton_kernels",
}
for name, fields in targets.items():
dependencies = ast.literal_eval(fields["deps"])
for source in ast.literal_eval(fields["srcs"]):
imports = ast.parse((cuda / "tests" / source).read_text())
for node in ast.walk(imports):
if isinstance(node, ast.ImportFrom) and node.module:
for prefix, dependency in packages.items():
if node.module.startswith(prefix):
with self.subTest(target=name, module=node.module):
self.assertIn(dependency, dependencies)

def test_imported_kernels_are_in_buck_package(self):
cuda = ROOT / "backends/cuda"
tree = ast.parse((cuda / "BUCK").read_text())
targets = [
node.value
for node in tree.body
if isinstance(node, ast.Expr)
and isinstance(node.value, ast.Call)
and any(
keyword.arg == "name"
and isinstance(keyword.value, ast.Constant)
and keyword.value.value == "triton_kernels"
for keyword in node.value.keywords
)
]
self.assertEqual(len(targets), 1)
sources = next(
ast.literal_eval(keyword.value)
for keyword in targets[0].keywords
if keyword.arg == "srcs"
)
imports = ast.parse((cuda / "passes/lower_offgraph_kv.py").read_text())
prefix = "executorch.backends.cuda."
for node in imports.body:
if isinstance(node, ast.ImportFrom) and node.module.startswith(
prefix + "triton.kernels."
):
source = node.module.removeprefix(prefix).replace(".", "/") + ".py"
with self.subTest(imported_module=node.module):
self.assertIn(source, sources)

def test_production_ring_geometry_is_qualified_separately(self):
workflow = (ROOT / ".github/workflows/cuda.yml").read_text()
job = workflow.split(" unittest-cuda-private-kv-mg-ring:", 1)[1].split(
" unittest-cuda-runtime:", 1
)[0]
self.assertIn("runner: mt-l-x86iavx512-11-125-a100", job)
self.assertIn("--profile mg-ring", job)
self.assertIn("'backends/aoti'", job)
self.assertIn("'extension/llm/batching'", job)
self.assertIn(
"PrivateVarlenTest::test_muse_glimmer_and_gemma_head_geometry", job
)
self.assertIn(
"PrivateVarlenTest::test_restored_ring_does_not_read_unwritten_nan_slot",
job,
)
self.assertIn("export PYTHONUNBUFFERED=1", job)
self.assertIn("-DEXECUTORCH_ENABLE_LOGGING=OFF", job)
self.assertIn("--target muse_glimmer_runtime_kv_probe --parallel", job)
self.assertIn('exit "${PRIVATE_KV_STATUS}"', job)
self.assertIn('"qualification.json", "probe.jsonl", "probe.stderr.log"', job)
shell = "\n".join(
line[8:] for line in job.split(" script: |\n", 1)[1].splitlines()
)
shell = re.sub(r"\$\{\{[^}]+\}\}", "ci-value", shell)
result = subprocess.run(["bash", "-n"], input=shell, text=True)
self.assertEqual(result.returncode, 0)

def test_runtime_owned_compile_buffer_tests_are_packaged_and_run(self):
cuda = ROOT / "backends/cuda"
targets = {}
for source in (cuda / "BUCK", cuda / "tests/targets.bzl"):
for node in ast.walk(ast.parse(source.read_text())):
if not isinstance(node, ast.Call):
continue
fields = {keyword.arg: keyword.value for keyword in node.keywords}
name = fields.get("name")
if isinstance(name, ast.Constant):
targets[name.value] = fields
self.assertIn(
"runtime_owned_kv.py",
ast.literal_eval(targets["runtime_owned_kv"]["srcs"]),
)
self.assertIn(
":runtime_owned_kv",
ast.literal_eval(targets["cuda_backend"]["deps"]),
)
self.assertIn(
"//executorch/backends/cuda:runtime_owned_kv",
ast.literal_eval(targets["test_runtime_owned_kv"]["deps"]),
)
workflow = (ROOT / ".github/workflows/cuda.yml").read_text()
job = workflow.split(" unittest-cuda-runtime:", 1)[1].split(
" unittest-cuda:", 1
)[0]
self.assertIn("backends/cuda/tests/test_runtime_owned_kv.py", job)

def test_noisy_timing_enforcement_requires_explicit_opt_in(self):
workflow = (ROOT / ".github/workflows/cuda.yml").read_text()
self.assertIn(" enforce_private_kv_performance:\n", workflow)
for name, end in (
("unittest-cuda-muse-glimmer-batching", "unittest-cuda-quantized-gemm"),
("unittest-cuda-private-kv-mg-ring", "unittest-cuda-runtime"),
):
job = workflow.split(f" {name}:\n", 1)[1].split(f" {end}:\n", 1)[0]
self.assertIn('PRIVATE_KV_TIMING_ARGS="--report-performance"', job)
self.assertIn('"${{ github.event_name }}" == "workflow_dispatch"', job)
self.assertIn(
'"${{ inputs.enforce_private_kv_performance }}" == "true"', job
)

def test_runtime_columns_probe_runs_in_cuda_ci(self):
workflow = (ROOT / ".github/workflows/cuda.yml").read_text()
job = workflow.split(" unittest-cuda-muse-glimmer-batching:", 1)[1].split(
" unittest-cuda-quantized-gemm:", 1
)[0]
self.assertIn("-DMUSE_GLIMMER_BUILD_RUNTIME_KV_PROBE=ON", job)
self.assertIn("muse_glimmer_runtime_kv_probe --parallel", job)
self.assertIn("tests/check_runtime_kv_columns.py", job)
self.assertIn("-DEXECUTORCH_ENABLE_LOGGING=OFF", job)
self.assertIn("cmake --build --preset llm-release-cuda-install", job)

def test_e2e_builds_smoke_before_running_it(self):
script = (SCRIPTS / "test_model_e2e.sh").read_text()
build = script.index("bash .ci/scripts/build_muse_glimmer_batching_smoke.sh")
Expand Down
124 changes: 118 additions & 6 deletions .github/workflows/cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ on:
required: false
type: string
default: "50"
enforce_private_kv_performance:
description: Fail private-KV qualification on more than 2% throughput regression
required: false
type: boolean
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
Expand Down Expand Up @@ -695,13 +700,19 @@ jobs:

# The normal serving binaries and the opt-in correctness tool share
# CudaExecutor; MG preparation tests also run on Linux.
make muse-glimmer-batching-cuda
# Capture qualification uses native counters in the release build.
cmake --preset llm-release-cuda -DEXECUTORCH_ENABLE_LOGGING=OFF
cmake --build --preset llm-release-cuda-install
BATCHING_BIN_DIR="${PWD}/cmake-out/examples/models/muse-glimmer-batching"
cmake -S "${PWD}/examples/models/muse-glimmer" -B "${BATCHING_BIN_DIR}" \
-DMUSE_GLIMMER_BUILD_BATCHING_TESTS=ON
cmake -S "${PWD}/examples/models/muse-glimmer" --preset muse-glimmer-cuda \
-B "${BATCHING_BIN_DIR}" -DMUSE_GLIMMER_BUILD_BATCHING=ON \
-DMUSE_GLIMMER_BUILD_BATCHING_TESTS=ON \
-DMUSE_GLIMMER_BUILD_RUNTIME_KV_PROBE=ON
bash .ci/scripts/build_muse_glimmer_batching_smoke.sh "${BATCHING_BIN_DIR}"
cmake --build "${BATCHING_BIN_DIR}" \
--target muse_glimmer_batching_test muse_glimmer_cuda_dflash_test --parallel
--target muse_glimmer_batching_runner muse_glimmer_batching_worker \
muse_glimmer_batching_test muse_glimmer_cuda_dflash_test \
muse_glimmer_runtime_kv_probe --parallel
ctest --test-dir "${BATCHING_BIN_DIR}" \
-R '^muse_glimmer_batching$' --output-on-failure --no-tests=error
test -x "${BATCHING_BIN_DIR}/muse_glimmer_batching_runner"
Expand All @@ -710,8 +721,12 @@ jobs:

# The batching export on a tiny model, and the CLI's backend dispatch.
pip install gguf
python examples/models/muse-glimmer/tests/check_runtime_kv_columns.py \
--probe "${BATCHING_BIN_DIR}/muse_glimmer_runtime_kv_probe" \
--output-dir "${RUNNER_TEMP:-/tmp}/muse_glimmer_runtime_kv_columns"
python -m pytest -v -o "addopts=" \
examples/models/muse-glimmer/tests/test_cuda_batching_pipeline.py \
examples/models/muse-glimmer/tests/test_private_kv_rows_gate.py \
examples/models/muse-glimmer/tests/test_cuda_dflash_packed.py \
examples/models/muse-glimmer/tests/test_dflash_token_sampler.py \
examples/models/muse-glimmer/tests/test_checkpoint_context.py
Expand All @@ -730,6 +745,18 @@ jobs:
exit 1
fi

# Automatic jobs report noisy timings; an explicit dispatch can enforce
# the 2% gate. Numerical/memory/graph checks always remain blocking.
PRIVATE_KV_TIMING_ARGS="--report-performance"
if [[ "${{ github.event_name }}" == "workflow_dispatch" && \
"${{ inputs.enforce_private_kv_performance }}" == "true" ]]; then
PRIVATE_KV_TIMING_ARGS=""
fi
python examples/models/muse-glimmer/tests/check_private_kv_rows.py \
--probe "${BATCHING_BIN_DIR}/muse_glimmer_runtime_kv_probe" \
--output-dir "${RUNNER_TEMP:-/tmp}/muse_glimmer_private_kv_rows" \
${PRIVATE_KV_TIMING_ARGS}

unittest-cuda-quantized-gemm:
name: unittest-cuda-quantized-gemm (${{ matrix.shard }})
needs: [changed-files, run-decision]
Expand Down Expand Up @@ -772,6 +799,88 @@ jobs:

python -m pytest ${{ matrix.tests }} -v -o "addopts=" --durations=20

unittest-cuda-private-kv-mg-ring:
name: unittest-cuda-private-kv-mg-ring
needs: [changed-files, run-decision]
if: |
contains(needs.changed-files.outputs.changed-files, 'backends/cuda') ||
contains(needs.changed-files.outputs.changed-files, 'backends/aoti') ||
contains(needs.changed-files.outputs.changed-files, 'extension/llm/batching') ||
contains(needs.changed-files.outputs.changed-files, 'extension/llm/cache') ||
contains(needs.changed-files.outputs.changed-files, 'examples/models/muse-glimmer') ||
contains(needs.changed-files.outputs.changed-files, '.github/workflows/cuda.yml') ||
needs.run-decision.outputs.is-full-run == 'true'
uses: pytorch/test-infra/.github/workflows/linux_job_v3.yml@main
permissions:
id-token: write
contents: read
with:
timeout: 180
# Production Ring geometry needs room for ABI 2's temporary replacement
# allocations as well as ABI 3's bounded host undo history.
runner: mt-l-x86iavx512-11-125-a100
gpu-arch-type: cuda
gpu-arch-version: "13.2"
submodules: recursive
upload-artifact: cuda-private-kv-mg-ring
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
script: |
set -eux
bash ./install_executorch.sh
conda install -y -c conda-forge 'libstdcxx-ng>=12'
export LD_LIBRARY_PATH=/opt/conda/lib:$LD_LIBRARY_PATH
pip install gguf
export PYTHONUNBUFFERED=1

python - <<'PY'
import torch

assert torch.cuda.get_device_capability() == (8, 0)
print(torch.cuda.get_device_properties(0))
PY

# A100 exercises D=256's unchanged multi-stage pipeline as well.
python -m pytest backends/cuda/tests/test_sdpa_varlen_private.py::PrivateVarlenTest::test_muse_glimmer_and_gemma_head_geometry backends/cuda/tests/test_sdpa_varlen_private.py::PrivateVarlenTest::test_restored_ring_does_not_read_unwritten_nan_slot -v -o "addopts="

cmake --preset llm-release-cuda -DEXECUTORCH_ENABLE_LOGGING=OFF
cmake --build --preset llm-release-cuda-install
BATCHING_BIN_DIR="${PWD}/cmake-out/examples/models/muse-glimmer-batching"
cmake -S "${PWD}/examples/models/muse-glimmer" --preset muse-glimmer-cuda \
-B "${BATCHING_BIN_DIR}" -DMUSE_GLIMMER_BUILD_BATCHING=ON \
-DMUSE_GLIMMER_BUILD_RUNTIME_KV_PROBE=ON
cmake --build "${BATCHING_BIN_DIR}" \
--target muse_glimmer_runtime_kv_probe --parallel

PRIVATE_KV_TIMING_ARGS="--report-performance"
if [[ "${{ github.event_name }}" == "workflow_dispatch" && \
"${{ inputs.enforce_private_kv_performance }}" == "true" ]]; then
PRIVATE_KV_TIMING_ARGS=""
fi
export PRIVATE_KV_PRODUCTION_DIR="${RUNNER_TEMP:-/tmp}/muse_glimmer_private_kv_mg_ring"
PRIVATE_KV_STATUS=0
python examples/models/muse-glimmer/tests/check_private_kv_rows.py \
--profile mg-ring \
--probe "${BATCHING_BIN_DIR}/muse_glimmer_runtime_kv_probe" \
--output-dir "${PRIVATE_KV_PRODUCTION_DIR}" \
${PRIVATE_KV_TIMING_ARGS} || PRIVATE_KV_STATUS=$?
# Keep diagnostics on failure without uploading generated model blobs.
python - <<'PY'
import os
import shutil
from pathlib import Path

source = Path(os.environ["PRIVATE_KV_PRODUCTION_DIR"])
destination = Path(os.environ["RUNNER_ARTIFACT_DIR"])
for path in source.rglob("*"):
if path.is_file() and path.name in (
"qualification.json", "probe.jsonl", "probe.stderr.log"
):
target = destination / path.relative_to(source)
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(path, target)
PY
exit "${PRIVATE_KV_STATUS}"

unittest-cuda-runtime:
name: unittest-cuda-runtime
needs: [changed-files, run-decision]
Expand Down Expand Up @@ -803,11 +912,12 @@ jobs:

python -m pytest \
backends/cuda/tests/test_cuda_weight_metadata.py \
backends/cuda/tests/test_runtime_owned_kv.py \
backends/cuda/tests/test_merge_ptes.py \
-v -o "addopts="

cmake --preset llm-release-cuda -DEXECUTORCH_BUILD_TESTS=ON
cmake --build cmake-out --target test_cuda_allocator test_cuda_allocator_exit test_cuda_mutable_state test_cuda_weight_cache test_cuda_output_copy test_cuda_backend_execute test_cuda_sort_rand test_cuda_current_stream test_cuda_kv_cache test_cuda_guard test_cuda_stream_guard test_step_plan test_cuda_executor -j$(nproc)
cmake --preset llm-release-cuda -DEXECUTORCH_BUILD_TESTS=ON -DEXECUTORCH_ENABLE_LOGGING=OFF
cmake --build cmake-out --target test_cuda_allocator test_cuda_allocator_exit test_cuda_mutable_state test_cuda_weight_cache test_cuda_output_copy test_cuda_backend_execute test_cuda_sort_rand test_cuda_current_stream test_cuda_ring_history test_cuda_private_row_layout test_cuda_kv_cache test_cuda_guard test_cuda_stream_guard test_step_plan test_cuda_executor -j$(nproc)
ctest --test-dir cmake-out -R test_cuda_allocator --output-on-failure -V
ctest --test-dir cmake-out -R test_cuda_mutable_state --output-on-failure -V
ctest --test-dir cmake-out -R test_cuda_weight_cache --output-on-failure -V
Expand All @@ -816,6 +926,8 @@ jobs:
ctest --test-dir cmake-out -R test_cuda_sort_rand --output-on-failure -V
ctest --test-dir cmake-out -R test_cuda_current_stream --output-on-failure -V
ctest --test-dir cmake-out -R test_cuda_kv_cache --output-on-failure -V
ctest --test-dir cmake-out -R '^test_cuda_ring_history$' --output-on-failure --no-tests=error -V
ctest --test-dir cmake-out -R '^test_cuda_private_row_layout$' --output-on-failure --no-tests=error -V
ctest --test-dir cmake-out -R test_step_plan --output-on-failure -V
# CudaExecutor end to end on a toy decoder, against its eager greedy
# output. The test skips without the model, so fail if it skipped.
Expand Down
12 changes: 11 additions & 1 deletion backends/aoti/aoti_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ def get_extra_aoti_compile_context_manager(
"""
return contextlib.nullcontext()

@classmethod
def get_aoti_program_compile_context_manager(cls, program, compile_specs):
"""Scope compilation to the final, lowered program's buffer identities.

Preserve existing subclasses' compile-spec-only context hook.
"""
return cls.get_extra_aoti_compile_context_manager(compile_specs)

@classmethod
def codesign_so(cls, so_path: str, compile_specs: List[CompileSpec]) -> None:
"""Sign the compiled .so before packing into .pte.
Expand Down Expand Up @@ -356,7 +364,9 @@ def preprocess(
# Compile with fallback kernel collection
with cls.collect_unsupported_fallback_kernels(
missing_fallback_kernels
), torch.no_grad(), cls.get_extra_aoti_compile_context_manager(compile_specs):
), torch.no_grad(), cls.get_aoti_program_compile_context_manager(
device_edge_program, compile_specs
):
paths = torch._inductor.aot_compile(
edge_program_module, tuple(user_input_placeholders), options=options
)
Expand Down
Loading
Loading