Skip to content
This repository was archived by the owner on Oct 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3709a45
fix(roce): accept torch.dtype at the oneshot launcher boundary
randomvariable Sep 14, 2026
5538c73
fix(preparation): annotate PCIe launcher closures and retain opaque v…
randomvariable Sep 14, 2026
c39c592
fix(pcie): attach program carrier to twoshot fp8 launcher
randomvariable Sep 15, 2026
71cadbc
feat(preparation): collective entry barrier for priming lockstep
randomvariable Sep 15, 2026
40be008
chore(preparation): drop unused Mapping import
randomvariable Sep 15, 2026
1702e4b
fix(preparation): key memory extension build by source hash
randomvariable Sep 15, 2026
d6c02e4
test: isolate collective barrier failure cases
randomvariable Sep 16, 2026
0660c60
docs: document prepared launcher closures
randomvariable Sep 16, 2026
97553a0
fix: contain collective barrier failures
randomvariable Sep 16, 2026
98f390f
fix: validate collective barrier deadlines
randomvariable Sep 16, 2026
129458b
fix(roce): fail unsupported dtypes alike at the launcher boundary
randomvariable Sep 21, 2026
db6bcaf
Preserve launcher ownership with scoped preparation caches
voipmonitor Sep 29, 2026
b39de28
Merge remote-tracking branch 'canonical/master' into review/kimi-prep…
voipmonitor Sep 30, 2026
b502365
Preserve prepared launcher ownership and collective priming barriers
voipmonitor Oct 3, 2026
a117fb6
Resolve optional collective deadlines when preparing a session
voipmonitor Oct 3, 2026
0313252
docs: link collective deadline release metadata to its beta merge
voipmonitor Oct 3, 2026
138f4f9
release: b12x-collective-barrier-timeout lists its models as in the K…
voipmonitor Oct 4, 2026
53de9c8
Merge commit 'e9d3c6d5aae7435241aff4d4f45d0a29646b208a' into review/f…
lukealonso Oct 6, 2026
a424418
docs(preparation): specify collective barrier callback lifetime
lukealonso Oct 6, 2026
f65ebd9
Merge commit 'c686f79072efaf0da46e905d94bc382f236b6d03' into review/f…
lukealonso Oct 6, 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
11 changes: 11 additions & 0 deletions .lil/changes/b12x-preparation-launch-ownership.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"schema": "local-inference-release-change/v1",
"id": "b12x-preparation-launch-ownership",
"category": "fix",
"summary": "Retain compiled collective launchers and coordinate cross-rank priming",
"models": ["all"],
"compatibility": "No user action required.",
"details": ["Preserves scoped program-cache reclamation and shared RoCE compile results, and rejects unsupported RoCE dtypes before launcher construction."],
"pull_requests": [384],
"requires": []
}
9 changes: 9 additions & 0 deletions b12x/_lib/compile_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from contextvars import ContextVar
from dataclasses import dataclass, field
from typing import Any
from types import FunctionType


@dataclass(frozen=True)
Expand Down Expand Up @@ -203,10 +204,12 @@ def launch_triton(kernel, grid, *args, **kwargs):


def planning() -> bool:
"""Report whether the caller is collecting compiler program identities."""
return _PLANNING.get() is not None


def record_program(program: ProgramKey, owner: Any = None) -> None:
"""Record a compiled program identity for active planning observers."""
captured = _PLANNING.get()
if captured is not None:
captured.add(program)
Expand All @@ -219,6 +222,7 @@ def record_program(program: ProgramKey, owner: Any = None) -> None:


def program_keys(value: Any) -> tuple[ProgramKey, ...]:
"""Return compiler program identities retained by ``value``."""
if value is None or isinstance(value, (str, int, float, bool)) or type(value).__module__ == "torch":
return ()
if isinstance(value, Mapping):
Expand All @@ -228,6 +232,11 @@ def program_keys(value: Any) -> tuple[ProgramKey, ...]:
keys = getattr(value, "__b12x_programs__", None)
if keys is not None:
return tuple(keys)
if isinstance(value, FunctionType):
# A launch closure produced outside a compile factory carries no
# program identity of its own; retain it rather than failing an
# unrelated sweep.
return ()
from triton.compiler.compiler import CompiledKernel
if isinstance(value, CompiledKernel):
return (ProgramKey("triton", value.hash, value.name),)
Expand Down
13 changes: 13 additions & 0 deletions b12x/comm/pcie/_dcp_a2a_cute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from collections.abc import Callable, Sequence

from b12x._lib.compile_plan import attach_programs
import cuda.bindings.driver as cuda
import cutlass
import cutlass.cute as cute
Expand Down Expand Up @@ -1865,6 +1866,7 @@ def _get_compiled_lse_reduce_scatter(
threads: int,
device_slot_selection: bool,
) -> Callable:
"""Compile and retain one LSE reduce-scatter launcher specialization."""
launch = _LseReduceScatterLaunch(
world_size,
rank,
Expand Down Expand Up @@ -1934,6 +1936,7 @@ def run(
slot_delta_256b: int,
blocks: int,
) -> None:
"""Launch the compiled LSE reduce-scatter with runtime arguments."""
stages = _pad_ptrs(staging_ptrs, world_size)
signals = _pad_ptrs(signal_ptrs, world_size)
raw(
Expand Down Expand Up @@ -1966,6 +1969,7 @@ def _gather_launcher_key(
threads: int,
device_slot_selection: bool,
) -> tuple[object, ...]:
"""Return the cache key for an all-gather-heads launcher."""
return (
int(world_size),
int(rank),
Expand Down Expand Up @@ -1995,6 +1999,7 @@ def _get_compiled_all_gather_heads(
threads: int,
device_slot_selection: bool,
) -> Callable:
"""Compile and retain one all-gather-heads launcher specialization."""
launch = _AllGatherHeadsLaunch(
world_size,
rank,
Expand Down Expand Up @@ -2047,6 +2052,7 @@ def run(
slot_delta_256b: int,
blocks: int,
) -> None:
"""Launch the compiled all-gather-heads kernel with runtime arguments."""
row_bytes = int(head_dim) * int(element_size)
if row_bytes % 16:
raise ValueError("DCP gather rows must be a multiple of 16 bytes")
Expand Down Expand Up @@ -2077,6 +2083,7 @@ def _pair_launcher_key(
device_slot_selection: bool,
kimi_topk: bool,
) -> tuple[object, ...]:
"""Return the cache key for a paired all-gather launcher."""
return (
int(world_size),
int(rank),
Expand Down Expand Up @@ -2110,6 +2117,7 @@ def _get_compiled_all_gather_pair(
device_slot_selection: bool,
kimi_topk: bool = False,
) -> Callable:
"""Compile and retain one paired all-gather launcher specialization."""
launch = _AllGatherPairLaunch(
world_size,
rank,
Expand Down Expand Up @@ -2176,6 +2184,7 @@ def run(
second_packs: int,
slot_delta_256b: int,
) -> None:
"""Launch the compiled paired all-gather kernel with runtime arguments."""
stages = _pad_ptrs(staging_ptrs, world_size)
signals = _pad_ptrs(signal_ptrs, world_size)
raw(
Expand Down Expand Up @@ -2203,11 +2212,13 @@ def run(


def is_kimi_topk16_prepared(threads: int = 256) -> bool:
"""Report whether the Kimi top-16 launcher is prepared for ``threads``."""
return int(threads) in _PREPARED_KIMI_TOPK_LAUNCHERS


@program_cache
def _get_compiled_kimi_topk16(threads: int = 256) -> Callable:
"""Compile and retain one Kimi top-16 launcher specialization."""
normalized_threads = int(threads)
if normalized_threads not in (128, 256, 512):
raise ValueError("Kimi top-16 threads must be 128, 256, or 512")
Expand Down Expand Up @@ -2242,6 +2253,7 @@ def run(
output_ids_ptr: int,
rows: int,
) -> None:
"""Launch the compiled Kimi top-16 kernel for ``rows`` router rows."""
raw(
_f32_ptr(router_logits_ptr),
_f32_ptr(correction_bias_ptr),
Expand Down Expand Up @@ -2280,6 +2292,7 @@ def lse_reduce_scatter(
blocks: int,
launcher: Callable | None = None,
) -> None:
"""Reduce attention LSE values across PCIe ranks using a prepared launcher."""
slot_delta_256b = _slot_delta_256b(slot_delta_bytes)
if launcher is None:
launcher = _get_compiled_lse_reduce_scatter(
Expand Down
5 changes: 4 additions & 1 deletion b12x/comm/pcie/_dcp_topk_cute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from b12x._lib.program_cache import program_cache
from collections.abc import Callable, Sequence

from b12x._lib.compile_plan import attach_programs
import cuda.bindings.driver as cuda
import cutlass
import cutlass.cute as cute
Expand Down Expand Up @@ -272,6 +273,7 @@ def _get_compiled_topk_stage(
topk: int,
threads: int,
) -> Callable:
"""Compile and retain one owner top-k staging launcher specialization."""
launch = _TopKOwnerStageLaunch(world_size, rank, topk, threads)
key = (int(world_size), int(rank), int(topk), int(threads))
raise_if_kernel_resolution_frozen(
Expand Down Expand Up @@ -313,6 +315,7 @@ def run(
blocks: int,
wait_for_prior_consumer: bool,
) -> None:
"""Launch the compiled owner top-k staging kernel with runtime arguments."""
candidates = _pad_ptrs(candidate_ptrs, world_size)
signals = _pad_ptrs(signal_ptrs, world_size)
raw(
Expand Down Expand Up @@ -353,6 +356,6 @@ def run(
current_cuda_stream(),
)

return run
return attach_programs(run, raw)


2 changes: 2 additions & 0 deletions b12x/comm/pcie/_hierarchical_cute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from b12x._lib.program_cache import program_cache
from collections.abc import Callable, Sequence

from b12x._lib.compile_plan import attach_programs
import cuda.bindings.driver as cuda
import cutlass
import cutlass.cute as cute
Expand Down Expand Up @@ -878,6 +879,7 @@ def run(
elements: int,
blocks: int,
) -> None:
"""Launch the compiled hierarchical collective with runtime arguments."""
if len(slab_addresses) != world_size:
raise ValueError(
f"expected {world_size} slab addresses, got {len(slab_addresses)}"
Expand Down
2 changes: 2 additions & 0 deletions b12x/comm/pcie/_island_rs_cute.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from collections.abc import Callable, Sequence
from typing import Tuple

from b12x._lib.compile_plan import attach_programs
import cuda.bindings.driver as cuda
import cutlass
import cutlass.cute as cute
Expand Down Expand Up @@ -641,6 +642,7 @@ def run(
blocks: int,
stream: object = None,
) -> None:
"""Launch the compiled island reduce-scatter with runtime arguments."""
if len(slab_addresses) != world_size:
raise ValueError(
f"expected {world_size} slab addresses, got {len(slab_addresses)}"
Expand Down
7 changes: 4 additions & 3 deletions b12x/comm/pcie/_twoshot_cute.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from b12x._lib.compiler import KernelCompileSpec
from b12x._lib.compiler import compile as b12x_compile
from b12x._lib.compile_plan import attach_programs
from b12x._lib.intrinsics import (
cvt_e4m3x4_to_f32x4,
ld_global_nc_f32,
Expand Down Expand Up @@ -746,6 +747,7 @@ def get_twoshot_launcher(
row_elems: int,
device_index: int,
) -> Callable[..., None]:
"""Compile and retain one static two-shot launcher specialization."""
process_key = _twoshot_process_key(
operation,
world_size,
Expand All @@ -756,8 +758,6 @@ def get_twoshot_launcher(
row_elems,
device_index,
)
"""Compile and return one static world/operation/thread specialization."""

del device_index # part of the process-local cache key
if world_size not in (2, 4, 8):
raise ValueError(f"unsupported world size {world_size}")
Expand Down Expand Up @@ -844,6 +844,7 @@ def run(
row_elems: int,
grid_x: int,
) -> None:
"""Launch the compiled two-shot collective with runtime arguments."""
if len(staging_addresses) != 8 or len(signal_addresses) != 8:
raise ValueError("two-shot scalar pointer ABI requires eight peers")
raw_args = (
Expand Down Expand Up @@ -895,6 +896,6 @@ def run(
)
raw(*raw_args)

return run
return attach_programs(run, raw)

__all__ = ["get_twoshot_launcher"]
2 changes: 2 additions & 0 deletions b12x/comm/pcie/_vocab_argmax_cute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from b12x._lib.program_cache import program_cache
from collections.abc import Callable, Sequence

from b12x._lib.compile_plan import attach_programs
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
import cuda.bindings.driver as cuda
import cutlass
import cutlass.cute as cute
Expand Down Expand Up @@ -598,6 +599,7 @@ def run(
bias_row_stride: int,
batch: int,
) -> None:
"""Launch the compiled vocabulary argmax kernel with runtime arguments."""
if len(slab_addresses) != world_size:
raise ValueError(
f"expected {world_size} slab addresses, got {len(slab_addresses)}"
Expand Down
13 changes: 12 additions & 1 deletion b12x/comm/roce/_oneshot_cute.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import cutlass
import cutlass.cute as cute
from cutlass import Int32, Int64, Uint32
import torch

from b12x._lib.compiler import KernelCompileSpec
from b12x._lib.compiler import compile as b12x_compile
Expand Down Expand Up @@ -65,6 +66,11 @@

PACK_BYTES = 16
_DTYPE_PACK_ELEMS = {"float32": 4, "float16": 8, "bfloat16": 8}
_DTYPE_NAMES = {
torch.float16: "float16",
torch.bfloat16: "bfloat16",
torch.float32: "float32",
}
_PREPARED_LAUNCHERS: set[tuple[object, ...]] = set()


Expand Down Expand Up @@ -350,7 +356,7 @@ def is_launcher_prepared(*key) -> bool:

@program_cache
def get_launcher(
dtype_name: str,
dtype_name: str | torch.dtype,
world_size: int,
rank: int,
threads: int,
Expand All @@ -360,6 +366,11 @@ def get_launcher(
device_index: int,
) -> Callable[..., None]:
"""Compile the launcher for ``key`` once and return it."""
if isinstance(dtype_name, torch.dtype):
try:
dtype_name = _DTYPE_NAMES[dtype_name]
except KeyError:
raise ValueError(f"unsupported RoCE one-shot dtype {dtype_name!r}") from None
process_key = _process_key(
dtype_name,
world_size,
Expand Down
4 changes: 2 additions & 2 deletions b12x/preparation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Declarative configuration and session-prepared plans."""
from .device import DetectedDevice, detect_device
from .session import PreparationJob, PreparationSession
from .session import CollectiveBarrierTimeout, PreparationJob, PreparationSession
from .session import prepare_default
from ._progress import PreparationDisplay
from .tuning import (
Expand All @@ -16,7 +16,7 @@

__all__ = [
"prepare_default",
"BackendConfig", "CollectiveRequirement", "DetectedDevice", "DeviceIdentity",
"BackendConfig", "CollectiveBarrierTimeout", "CollectiveRequirement", "DetectedDevice", "DeviceIdentity",
"EligiblePlan", "FrozenMapping", "Knob", "MemoryRequirements", "ParameterBinding",
"ParameterSpace", "PersistentMemory", "Plan", "PreparationProgress",
"PreparationJob", "PreparationSession", "PreparationDisplay",
Expand Down
11 changes: 9 additions & 2 deletions b12x/preparation/_memory.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
"""Allocator counters and cleanup of retired preparation graph pools."""
from __future__ import annotations

import hashlib
from functools import lru_cache
from pathlib import Path


@lru_cache(maxsize=1)
def _counter():
"""Load the CUDA allocation counter under a source-derived extension name."""
from torch.utils.cpp_extension import CUDA_HOME, load

if CUDA_HOME is None:
raise RuntimeError("preparation memory accounting requires CUDA headers; set CUDA_HOME")
# Key the build directory by source content: torch's staleness check is
# mtime-based and does not survive a persisted TORCH_EXTENSIONS_DIR, so a
# changed .cpp next to an old cached .so silently loaded stale symbols.
source = Path(__file__).with_suffix(".cpp")
digest = hashlib.sha1(source.read_bytes()).hexdigest()[:12]
return load(
name="b12x_preparation_memory",
sources=[str(Path(__file__).with_suffix(".cpp"))],
name=f"b12x_preparation_memory_{digest}",
sources=[str(source)],
extra_include_paths=[str(Path(CUDA_HOME) / "include")],
extra_ldflags=["-lc10_cuda", "-ltorch_cuda"],
with_cuda=False,
Expand Down
Loading