Skip to content

helios,heliopause,selene,ignition: fleet-wide 2-way codec green contexts, R580/VMM fallbacks, packed dedup, graph SM bounds, and ScratchArena reserve_sms floor - #723

Merged
lukealonso merged 1 commit into
mainfrom
unify-cooperative-sm-and-green-conte
Dec 5, 2026
Merged

lukealonso merged 1 commit into
mainfrom
unify-cooperative-sm-and-green-conte

Conversation

@lukealonso

@lukealonso lukealonso commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Why this change is needed and why this approach

Five structural defects blocked safe Green Context GPU KV-codec isolation, CUDA 13.0/R580 compatibility, and cooperative SM budgeting across exported cores:

  1. Helios enabled reserve_codec_partition = true for --lossless-kv-compression gpu in helios/src/runtime_core/model.rs, but NativeResources::initialize and prepare_kernels in helios/src/runtime_core/mod.rs only retained a primary CUDA context and created a GreenContextPartition when persistent_workers was non-empty. Standard cores without persistent workers therefore shared SMs between GPU KV-codec kernels and full-grid cooperative graphs, risking scheduler contention and replay stalls.
  2. Exported graph manifests did not record per-graph minimum compute SM counts (min_compute_sms) or kernel cluster dimensions (max_cluster_size), so Green Context SM splitting could neither enforce co-residency floors nor reject cluster dimensions exceeding the compute partition's SM count or driver-reported co-scheduled alignment.
  3. CUDA 13.0 / R580 drivers (such as GB10 SM121 driver 580.173.02) export cuDevSmResourceSplitByCount and the other seven Green Context symbols without CUDA 13.1's cuDevSmResourceSplit, causing Green Context initialization to fail on R580. In addition, R580 segfaults inside cuMemcpyBatchAsync_v2 when copying from cuMemHostGetDevicePointer into a cuMemMap VMM range on a cuCtxFromGreenCtx stream, whereas cuMemcpyAsync succeeds on identical pointers and streams.
  4. On multi-rank deployments with --lossless-kv-compression gpu or cpu, Selene pre-populated location.packed per rank and skipped pack_shares deduplication, storing N identical compressed copies of replicated MLA pages across DRAM slabs, NVMe records, and pool exports instead of populating v4 PackedUnit.replicas.
  5. On the preparation side, ScratchArena tracked overlapping plans via register_parallel for disjoint workspace sizing only, carrying no cooperative SM reservation floor to fail closed when cooperative plans overlapped concurrent auxiliary-stream collectives.

Generalizing GreenContextPartition via a typed PartitionRequest enum to support 2-way (worker, compute), 2-way (codec, compute), and 3-way (worker, codec, compute) topologies isolates GPU KV-codec execution fleet-wide via shared runtime policy without model-identity branches. Adding a cuDevSmResourceSplitByCount fallback (placing compute in structured result[0] and refreshing three-way remainders through a temporary green context) and routing Green Context streams through cuMemcpyAsync in Stream::copy_batch restores CUDA 13.0/R580 support while keeping driver-reported co-scheduled alignment uninflated. Deduplicating byte-identical per-rank PackedUnit payloads into PackedUnit.replicas reuses Selene's existing v4 wire and decode contract to eliminate multi-rank capacity inflation across DRAM, disk, and pool tiers. Recording min_compute_sms and max_cluster_size as backward-compatible zero-default Protobuf fields lets Helios enforce hardware SM-floor and cluster-alignment invariants at load time, and bidirectional reserve_sms checks on ScratchArena fail closed during preparation.

What changed

  • Per-graph SM-budget manifest fields (helios/proto/{runtime_core,core}.proto, ignition/preparation/{runtime_core_pb2,capture,runtime_core}.py, heliopause/src/export/{mod,capture,core}.rs, helios/src/runtime_core/{format,protobuf,metadata,describe,protection,selection}.rs, helios/src/core/{cache,conversion,export,protection,schema}.rs):
    • Before: GraphIndex and Graph carried no SM-floor or cluster-dimension metadata; capture did not collect non-clamped co-resident SM floors or inspect CU_LAUNCH_ATTRIBUTE_CLUSTER_DIMENSION (attribute id 4).
    • After: added optional uint32 min_compute_sms = 7 and uint32 max_cluster_size = 8 (0 = unspecified for full compatibility with existing cores), regenerated runtime_core_pb2.py, wrapped graph capture in b12x._lib.utils.device.track_capture_min_compute_sms() (pinned on origin/main via pyproject.toml rev 3c5c7b1488, failing closed without a silent ImportError fallback), shared CU_LAUNCH_ATTRIBUTE_CLUSTER_DIMENSION and kernel_cluster_size_from_bytes in helios/src/runtime_core/format.rs across export and load, and preserved (0, 0) for unclustered graphs without folding max_cluster_size into min_compute_sms.
  • Fleet-wide Green Context partitioning, CUDA 13.0/R580 fallbacks, and load-time validation (helios/src/runtime_core/{driver,persistent_worker,mod,model}.rs, helios/src/cuda.rs):
    • Before: GreenCtxDriver required cuDevSmResourceSplit; plan_sm_split and GreenContextPartition::create required a PersistentWorker; NativeResources::initialize only retained a primary context for persistent-worker cores; Stream::copy_batch always invoked cuMemcpyBatchAsync_v2 when present.
    • After: replaced (Option<u32>, bool) with PartitionRequest (Worker, Codec, WorkerAndCodec) supporting 2-way (worker, compute), 2-way (codec, compute), and 3-way (worker, codec, compute) splits; added NativeResources::initialize_with_options(core, ordinal, reserve_codec_partition) invoked from model.rs when --lossless-kv-compression gpu is active; added optional cuDevSmResourceSplitByCount fallback in GreenCtxDriver and GreenContextPartition::create placing compute in structured result[0] and splitting three-way remainders via a temporary CUgreenCtx; assigned partition.compute_coscheduled_alignment = actual_compute_sm.sm_coscheduled_alignment directly (no .max(...) inflation) and validated it against required_compute_coscheduled (structured split) or max_cluster_size (count-based split); enforced min_compute_sms, max_cluster_size, and per-node cluster attributes in prepare_graphs with a shared CPU_CODEC_HINT; queried cuStreamGetGreenCtx once in Stream::open / Stream::open_lowest_priority and routed Green Context streams through cuMemcpyAsync in Stream::copy_batch.
  • Multi-rank packed unit deduplication (selene/src/{codec_copy,memory,disk_store}.rs):
    • Before: DirectSlabTarget::take_direct, AsyncCompressor, and build_packed_write stored duplicate copies of identical per-rank compressed packets, and complete_record skipped pack_shares for packed records.
    • After: deduplicated byte-identical per-rank PackedUnit entries sorted by (kind, logical_index, stored_rank) across GPU direct-slab capture, CPU async compression, and standalone disk capture, populating PackedUnit.replicas, compacting DRAM slabs tightly to release excess slabs, and accounting deduplicated packed records under stats.packed_records[0] while keeping raw record.replication unset for pool export compatibility.
  • Structural ScratchArena cooperative SM reservation contract & docs (ignition/preparation/scratch.py, docs/{runtime-core-design,core-format-design,prefix-cache-offload,core-design,preparation-development}.md, helios/manifest.md):
    • Before: ScratchArena.register_parallel tracked byte overlap only, and docs/runtime-core-design.md scoped Green Context partitioning to single-rank persistent-worker cores.
    • After: added min_reserve_sms=0, reserve_sms_floor, require_reserve_sms, resolve_reserve_sms, register_cooperative_plan, and register_parallel(*plans, reserve_sms=0) with bidirectional fail-closed checks, shared _validate_reserve_sms, weakest-link headroom tracking, and full reset in release_preparation(); updated all six normative docs to cover all three Green Context topologies, CUDA 13.0/R580 and VMM fallbacks, graph SM bounds, cross-rank packed deduplication, and ScratchArena SM-floor enforcement.
  • Tests (helios/src/runtime_core/{persistent_worker,protobuf}.rs, heliopause/src/export/capture.rs, selene/src/{codec_copy,memory}.rs, tests/preparation/{test_scratch,test_capture_graph_metadata}.py):
    • Added Rust CPU tests for PartitionRequest, 2-way/3-way plan_sm_split, plan_split_by_count, validate_actual_compute_partition (driver downgrade rejection and R580 TPC-2 handling), legacy wire-bytes decode of omitted fields 7/8, graph_sm_requirements, and 4-rank MLA/GQA packed deduplication (DirectSlabTarget, CaptureSlot, MemoryStore, and pool PackedOffer); added live SM120 CUDA tests for 2-way (codec, compute) isolation and the cuDevSmResourceSplitByCount fallback + Green Context Stream::copy_batch VMM path; added Python tests for ScratchArena and min_compute_sms capture/export metadata.

Claimed benefit and result

  • Enables disjoint CUDA Green Context isolation for --lossless-kv-compression gpu across non-worker and persistent-worker cores on both CUDA 13.1+ and CUDA 13.0/R580 drivers while rejecting under-provisioned compute partitions or downgraded cluster alignment at load time rather than deadlocking or faulting at replay time.
  • Eliminates R580 cuMemcpyBatchAsync_v2 VMM segfaults on Green Context streams via cuMemcpyAsync fallback.
  • Eliminates multi-rank duplicate storage for identical compressed KV units (4:1 on TP4 MLA, 2:1 on pairwise GQA) across DRAM slabs, disk records, and selene-manager exports using the existing v4 PackedUnit.replicas contract.
  • Preserves backward compatibility with existing exported cores (min_compute_sms == 0, max_cluster_size == 0).
  • Turns missing reserve_sms on cooperative plans overlapping concurrent collectives into an immediate preparation-time ValueError.
  • Companion PRs: fix(b12x,moe): unify cooperative SM budget and green-context grid-stride safety local-inference-lab/flashinfer#217 (merged; pinned via pyproject.toml rev 3c5c7b1488) and fix(moe,collectives): enforce ScratchArena reserve_sms contract across SM103/SM120 MoE and recipes local-inference-lab/hyperflare-recipes#157 (applying ScratchArena enforcement, Sm103RoutedExperts, and recipe reservation fixes).

Supporting evidence and limitations

Validated on Linux x86_64 with NVIDIA RTX PRO 6000 Blackwell Max-Q (SM120, 188 SMs, driver 620.73.04), rebased on origin/main (be4092d7):

  • cargo test --locked --release --manifest-path eos/Cargo.toml --target-dir flare-cli/target: 12 passed, 0 failed.
  • cargo test --locked --release --manifest-path selene/Cargo.toml --features test-support --target-dir flare-cli/target: 643 unit + 1 integration passed, 0 failed (including 4-rank MLA/GQA packed deduplication and PackedOffer layout validation).
  • cargo test --locked --release --manifest-path selene-manager/Cargo.toml --features test-support --target-dir flare-cli/target: 448 passed, 0 failed, 1 ignored.
  • cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target --lib -- runtime_core:: core:: cuda:: offload::: 561 passed, 0 failed, 33 ignored (full helios --lib suite with FLARE_TEST_TEMPLATE_DIR: 1,956 passed, 51 ignored, 6 failed solely due to absent Hugging Face model template fixtures in /tmp/flare-test-templates).
  • CUDA_VISIBLE_DEVICES=3 cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target --lib -- --ignored --nocapture --test-threads=1 codec_compute_partition three_way_gpu_codec cuda_split_by_count_fallback_partitions_two_way_and_three_way: 3 passed, 0 failed on SM120:
    • 3-way: worker=8 SMs, codec=8 SMs, compute=172 SMs | baseline_coop=7.5 us | concurrent_coop=137962 (137750.5/s) | gpu_codec_rounds=247 (encode+decode 262.0 MiB/s, ratio 5.98x)
    • 2-way: codec=8 SMs, compute=180 SMs (cosched=16) | concurrent_coop=73148 | gpu_codec_rounds=125
    • SplitByCount fallback: 2-way (codec, compute) and 3-way (worker, codec, compute) partitions plus Green Context Stream::copy_batch from registered host memory into a cuMemMap VMM allocation passed.
  • cargo test --locked --release --manifest-path flare/Cargo.toml --target-dir flare-cli/target: 255 passed, 0 failed, 4 ignored.
  • cargo test --locked --release --manifest-path flare-cli/Cargo.toml and cargo build --locked --release --manifest-path flare-cli/Cargo.toml: 254 passed, 0 failed, 3 ignored; release binary built cleanly.
  • cargo test --locked --release --manifest-path heliopause/Cargo.toml --target-dir flare-cli/target --lib: 251 passed, 0 failed, 6 ignored.
  • CUDA_VISIBLE_DEVICES=3 FLARE_RUN_CUDA_TESTS=1 pytest tests/preparation/{test_scratch,test_capture_graph_metadata,test_core_boundary,test_codec_layout,test_persistent_worker}.py tests/test_kv_codec.py tests/cli -q (with PYTHONPATH providing the worktree ignition and flashinfer#217 b12x): 314 passed, 0 failed.

Limitations:

  • Live SM103 and GB10 SM121 (R580 driver 580.173.02) hardware execution, multi-GPU ignition export + flare run --lossless-kv-compression gpu, and the 6 gated Hugging Face chat-template tests were not run locally on this host.
  • DeepSeek-V4.1 DSAFusedIndexerKernel (flashinfer/experimental/b12x/attention/dsa_indexer/fused_indexer.py) launches full-GPU non-cooperative software-barrier waves (spin_wait_global_ge_i32) in the separate local-inference-lab/flashinfer repository; fixing that kernel (cooperative launch clamping or SM-budget reservation) requires a companion PR in local-inference-lab/flashinfer followed by a pyproject.toml pin bump before TP4 DeepSeek-V4.1 serves safely under --lossless-kv-compression gpu.

Discord: lukealonso

@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 723.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot flare-autobot added area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. bug Something isn't working enhancement New feature or request performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:review Proposed change needs code review; this does not imply merge readiness. labels Dec 4, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The fleet-wide 2-way (codec, compute) Green Context split is at the right layer, model-agnostic and triggered by a serving option rather than model identity, with additive manifest fields and fail-closed load-time validation. But one verified defect defeats the PR's headline invariant: compute_coscheduled_alignment is laundered through .max(...), making half the create-time guard unsatisfiable and feeding a fabricated alignment into the per-node cluster check, so a driver-downgraded partition is accepted.

  • Blockers: 1 · Should fix: 5 · Subtract/Simplify: 6 · Nits: 5
Walkthrough
  • Manifest SM bounds. Graph/GraphIndex gain uint32 min_compute_sms = 7 and uint32 max_cluster_size = 8, documented 0 = unspecified (helios/proto/core.proto:251-254, helios/proto/runtime_core.proto:750-753); decode and pass-through in format.rs:219-228, protobuf.rs:583-600 and :1507-1520, describe.rs:543-545, plus struct-literal churn in helios/src/core/*.
  • Capture side. heliopause/src/export/capture.rs:463-500 parses CU_LAUNCH_ATTRIBUTE_CLUSTER_DIMENSION (id 4) as three little-endian u32s with checked_mul, folds max cluster size into the declared floor, and writes both into wire::GraphIndex at :3438-3449. Python capture wraps each graph in _track_capture_min_compute_sms() (ignition/preparation/capture.py:232-245); runtime_core.py:296-305 validates and attaches it to all three graph handle shapes.
  • Green contexts. requested_worker_sms: u32 → Option<u32>; plan_sm_split(device_sm, Option<u32>, reserve_codec_partition, min_compute_sms, max_cluster_size) builds an optional worker group, an optional one-minimal-partition codec group, and a backfill compute group (persistent_worker.rs:85-223); GreenContextPartition gains codec_green_ctx/codec_context/codec_sm_count with null-guarded teardown (:556-595); offload_context() returns the codec context when present, else the base context (mod.rs:1511-1516), and model.rs:1065 now uses it instead of execution_context().
  • Load-time validation. prepare_kernels aggregates max(min_compute_sms) and max(max_cluster_size) across non-worker graphs (mod.rs:795-808) and sizes the compute partition from both; prepare_graphs rejects graph.min_compute_sms > partition SMs with the --lossless-kv-compression cpu hint (:964-980) and rejects kernel cluster dimensions exceeding the partition SM count or co-scheduled alignment (:1067-1096).
  • ScratchArena adds min_reserve_sms, reserve_sms_floor, require_reserve_sms, resolve_reserve_sms, register_cooperative_plan, and register_parallel(..., reserve_sms=) with bidirectional checks (ignition/preparation/scratch.py:59-188); docs/prefix-cache-offload.md:59-66 and helios/manifest.md:111-135 document the new topology.
Merge Risk: High · up to 275b7a5
  • The blocking defect is in the exact code path the PR exists to harden, and it silently accepts a partition the PR claims to reject — the failure surfaces later as a replay-time cluster-launch fault on hardware the author did not test (SM103).
  • The SM-floor half is a silent no-op unless the pinned flashinfer-python rev already exports track_capture_min_compute_sms; pyproject.toml:47 is unchanged by this PR and still pins rev 1441ce86….
  • Every rank with prefix-cache offload + --lossless-kv-compression gpu now takes the primary-context/Green-Context path and can refuse to load (mod.rs:386-396, persistent_worker.rs:137-170, mod.rs:964-980, mod.rs:1079-1094), permanently withholding one aligned codec partition from compute (~8 SMs, ≈4.3% of a 188-SM SM120 card).
Pre-merge checks: ✅ 2 passed · ⚠️ 2 warnings

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

Want a frontier second opinion? If these findings look noisy, request a one-time SuperAgent Review on 275b7a5 (~3–4 min; re-adjudicates existing findings without re-running discovery).

To opt out, include #autobot:ignore in your post or comment.

@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The 2-way (codec, compute) Green Context generalization is a well-scoped, model-agnostic continuation of #709/#701, and its plan_sm_split arithmetic, 3D cluster-dimension checks, proto field numbering, and ScratchArena min reservation tracking are sound. Two verified blockers must be resolved first: an unpinned b12x dependency from companion flashinfer#217 that breaks the new test on pinned checkouts and silently zeroes min_compute_sms, and a .max(...) overwrite in GreenContextPartition::create that makes the post-creation alignment guard dead and masks driver downgrades.

  • Blockers: 2 · Should fix: 1 · Subtract/Simplify: 5 · Nits: 5
Walkthrough
  • Per-graph SM-budget manifest fields (helios/proto/{core,runtime_core}.proto, heliopause/src/export/{mod,capture,core}.rs, ignition/preparation/{capture,runtime_core,runtime_core_pb2}.py, helios/src/runtime_core/{format,protobuf,metadata,describe,protection,selection}.rs, helios/src/core/*.rs): Adds additive proto3 fields uint32 min_compute_sms = 7 and uint32 max_cluster_size = 8 (0 = unspecified) on Graph and GraphIndex, wraps capture_forwards in b12x._lib.utils.device.track_capture_min_compute_sms(), and computes per-graph (min_compute_sms, max_cluster_size) from CU_LAUNCH_ATTRIBUTE_CLUSTER_DIMENSION (4) merged with the declared floor in heliopause/src/export/capture.rs:463-500, 3438-3449.
  • 2-way (codec, compute) and 3-way (worker, codec, compute) Green Contexts (helios/src/runtime_core/{persistent_worker,mod,model}.rs): Generalizes plan_sm_split and GreenContextPartition::create from u32 to Option<u32> worker SMs with min_compute_sms/max_cluster_size bounds and no fallback below max_cluster_size; adds NativeResources::initialize_with_options invoked from model.rs:718-733 whenever offload + KvCompression::Gpu is active; enforces per-graph min_compute_sms and per-node cluster size / co-scheduled alignment in prepare_graphs (mod.rs:943-980, 1067-1096); guards null worker_context/worker_stream on setup and teardown.
  • ScratchArena cooperative SM reservation contract (ignition/preparation/scratch.py, tests/preparation/test_scratch.py): Adds min_reserve_sms, reserve_sms_floor, require_reserve_sms, resolve_reserve_sms, register_cooperative_plan, and register_parallel(..., reserve_sms=) with bidirectional fail-closed validation for companion hyperflare-recipes#157.
  • Docs & tests (docs/prefix-cache-offload.md, helios/manifest.md, helios/src/runtime_core/persistent_worker.rs, heliopause/src/export/capture.rs, tests/preparation/{test_scratch,test_capture_graph_metadata}.py): Updates offload and manifest docs for the 2-way (codec, compute) topology and adds CPU unit tests plus an #[ignore]d SM120 2-way GPU codec concurrency test.
Merge Risk: Medium · up to 275b7a5
  • Unpinned external dependency (pyproject.toml:47): Clean checkouts and CI pinned to flashinfer-python rev 1441ce86 (from #707 / FlashInfer #213) lack b12x._lib.utils.device.{track_capture_min_compute_sms, record_min_compute_sms}, breaking the new unit test at import time and silently zeroing min_compute_sms during capture.
  • Fleet-wide behavioral change on --lossless-kv-compression gpu: Every rank of every core (including standard non-worker and multi-rank cores) now retains the primary CUDA context, reserves one aligned codec partition (e.g., 8 SMs on SM103/SM120), and enforces fail-closed load checks for Green Context API availability, min_compute_sms, and kernel cluster dimensions.
  • Hardware coverage gap: The motivating bug (#701) was observed on SM103 under live multi-request serving, whereas validation consists of #[ignore]d SM120 component tests without full ignition export + flare run --lossless-kv-compression gpu or SM103/SM121 execution (disclosed in the PR's Limitations).
Pre-merge checks: ✅ 2 passed · ⚠️ 2 warnings
  • ✅ Security / malicious screen: No prompt-injection or instruction-like content; kernel attribute buffer length is validated to 64 bytes (helios/src/runtime_core/format.rs:592) before indexing bytes[0..12] (mod.rs:1068-1070); Discord: lukealonso present.
  • ⚠️ Charter & value fit: Core change is a model-agnostic, root-cause completion of P1 #701, and the four-part PR description + limitations are complete; however, relying on unpinned local-inference-lab/flashinfer#217 with a silent ImportError -> 0 fallback violates explicit pinning and fail-closed error handling (AGENTS.md:184-186), and docs/runtime-core-design.md:654-696 is left contradicting the new topology.
  • ✅ Related / duplicate / conflict check: Genuinely additive over merged #709 (which covered persistent-worker cores only); note semantic interaction with open #640 (rank 0 worker+codec 3-way vs peer rank 2-way yields asymmetric compute_sm_count across ranks) and textual overlap with open #314 on proto/capture files (informational only).
  • ⚠️ Tests & verification evidence: Substantial CPU suites and SM120 #[ignore]d CUDA tests reported, but test_capture_forwards_records_min_compute_sms_and_emits_only_when_nonzero imports an unpinned b12x symbol (test_capture_graph_metadata.py:599), no legacy wire-bytes decode test for omitted fields 7/8 was added, and SM103 / end-to-end flare run --lossless-kv-compression gpu remains unrun (disclosed).

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

@FujitsuPolycom

Copy link
Copy Markdown
Contributor

Tested the 3-PR Green Context and cooperative SM reservation stack (#723 @ 275b7a509a, local-inference-lab/hyperflare-recipes#157 @ 49814a2612, local-inference-lab/flashinfer#217 @ 530e247333) on SM120 (4× NVIDIA RTX PRO 6000 Blackwell Workstation Edition, 188 SMs/GPU, 96 GiB GDDR7, Driver 610.43.02 / CUDA 13.2, x86_64) and SM121 (NVIDIA GB10, 48 SMs/GPU, 128 GiB unified LPDDR5x, Driver 580.173.02 / CUDA 13.0, aarch64).

Methods

Results

Platform & Verification Scope Result
SM120 Rust, Python & GPU suites PASS: 3,428/3,428 Rust (eos 12 ∥ selene 586 ∥ selene-manager 445 ∥ helios 1,914 incl. codec_compute_partition & three_way_gpu_codec ∥ flare 247 ∥ flare-cli 224); Python/GPU: #723 1,345 tests/{cli,preparation} + 87 targeted ∥ local-inference-lab/flashinfer#217 10 coop + 140 b12x ∥ local-inference-lab/hyperflare-recipes#157 99 contract + 65 4-GPU PCIe
SM120 TP4 DeepSeek-V4.1-Flash (off vs gpu speculative decode) off PASS: < 1.5% parity vs main (C=1..16, 3,107-token prefill 91.10 vs 90.99 ms, 131,754 KV pages); cores without codec_layout fail fast (0.3 s). gpu DEADLOCK: HTTP 500 (120 s deadline) on B=1 at fence=10 (packed-speculative1x8-drafts3-tokens4, 100% SM / 0% DRAM on all 4 GPUs)
SM120 TP4 GKV1 isolated terminal_prefill (16 × 3,342 tokens) PASS (16/16 encodes 1.64 s ∥ 16/16 NVMe restores 0.56 s, 53,472 cached tokens, 0 errors; 131.19 vs 96.43 ms warm TTFT): host cache expands 3.10× DRAM (327.42 vs 105.70 MiB) & 3.21× NVMe (318.03 vs 99.15 MiB) because GKV1 skips 4:1 MLA dedup (0 packed / 32 per-rank vs 16 / 16 on off)
GB10 (SM121, R580 / 580.173.02) unmodified stack FAIL on R580: CPU/Python suites pass (heliopause 235 ∥ helios 525 ∥ #723 104 ∥ local-inference-lab/hyperflare-recipes#157 99 ∥ local-inference-lab/flashinfer#217 138), test_cooperative_sm_contract.py 9/10 (assert 48 > 160); 2-way/3-way CUDA tests panic (driver.green_ctx is None); flare run --lossless-kv-compression gpu fails at Initialize GPU
GB10 (SM121) with 3 R580/SM121 fixes below PASS: 10/10 test_cooperative_sm_contract.py + 250/250 flare-cli; 2-way (codec=8, compute=40 SMs, 81,543 coop / 121 codec rounds) & 3-way (8+8+32 SMs, 161,667 / 203 rounds, 214.7 MiB/s); Qwen4-35B-A3B gpu 84.73 tok/s C=1 (vs 83.32 off), 124.61 tok/s C=4 (0 #701 hangs), 529.8 -> 342.0 MiB GKV1 (956 MiB/s), Turn 2 1.22 s (1,004 cached tokens); 4× GB10 TP4 core without codec_layout fails fast (0.1 s) on gpu and serves off (57,628 KV pages, 0 failed)

Findings (5 Pre-Merge Blockers)

  1. SM120 DSAFusedIndexerKernel deadlock (fix(b12x,moe): unify cooperative SM budget and green-context grid-stride safety local-inference-lab/flashinfer#217 + helios,heliopause,selene,ignition: fleet-wide 2-way codec green contexts, R580/VMM fallbacks, packed dedup, graph SM bounds, and ScratchArena reserve_sms floor #723): flashinfer/experimental/b12x/attention/dsa_indexer/fused_indexer.py:1013,1679,3147-3176 reads multi_processor_count = 188 and launches 1024-thread (min_blocks_per_mp = 1) slice_major software-barrier waves (4, 47, 1) = 188, (3, 61, 1) = 183, and (188, 1, 1) = 188 (spin_wait_global_ge_i32) without CU_LAUNCH_ATTRIBUTE_COOPERATIVE. heliopause records min_compute_sms = 8..16 instead of 188, GreenContextPartition::create assigns codec = 8, compute = 180 SMs, and x-major dispatch places 4 × 45 = 180 CTAs (45 < 47 per row), deadlocking all 4 GPUs. Fix: use CU_LAUNCH_ATTRIBUTE_COOPERATIVE with grid-stride/SM-budget clamping (or reserve codec SM headroom during dsa_indexer preparation).
  2. TP4 GKV1 3.21× host capacity regression (selene/src/memory.rs:1254): --lossless-kv-compression gpu pre-populates location.packed per rank so self.index[key].location.packed.is_none() is false, skipping pack_shares 4:1 cross-rank deduplication on replicated MLA pages and storing 4 identical copies (327.42 vs 105.70 MiB DRAM; 318.03 vs 99.15 MiB NVMe). Fix: deduplicate byte-identical per-rank GKV1 page packets across TP ranks (reducing TP4 NVMe storage to ~79.5 MiB, ~20% below off).
  3. GB10 R580 (CUDA 13.0) missing cuDevSmResourceSplit (helios/src/runtime_core/driver.rs:206): Driver 580.173.02 exports cuDevSmResourceSplitByCount and the other 7 Green Context symbols, not CUDA 13.1's cuDevSmResourceSplit, leaving driver.green_ctx None and rejecting --lossless-kv-compression gpu at Initialize GPU. Fix: add a cuDevSmResourceSplitByCount fallback in GreenCtxDriver (refreshing intermediate remainders via a temporary CUgreenCtx + cuGreenCtxGetDevResource for 3-way splits).
  4. GB10 SM121 sm_coscheduled_alignment = 2 check (helios/src/runtime_core/persistent_worker.rs:490): On 48-SM GB10, cuDeviceGetDevResource reports min_sm_partition_size = 8, sm_coscheduled_alignment = 8, whereas cuGreenCtxGetDevResource on created CUgreenCtxs reports TPC granularity 2, failing actual_compute_sm.sm_coscheduled_alignment < baseline_coscheduled (2 < 8). Fix: reject only if actual_compute_sm.sm_coscheduled_alignment == 0 or partition.compute_coscheduled_alignment < baseline_coscheduled.max(required_compute_coscheduled) (also scale tests/experimental/b12x/moe/test_cooperative_sm_contract.py:440's assert full_sms > 160 for 48-SM SM121 in fix(b12x,moe): unify cooperative SM budget and green-context grid-stride safety local-inference-lab/flashinfer#217).
  5. GB10 R580 cuMemcpyBatchAsync_v2 VMM SIGSEGV (helios/src/cuda.rs:758,785,834): On 580.173.02, calling cuMemcpyBatchAsync_v2 from cuMemHostGetDevicePointer into a cuMemMap VMM allocation on a cuCtxFromGreenCtx stream segfaults inside libcuda.so.1 (reproduced in a 35-line C test; cuMemcpyAsync on identical pointers/stream returns CUDA_SUCCESS). Fix: query cuStreamGetGreenCtx once in Stream::open / Stream::open_lowest_priority and route Green Context streams through Stream::copy_batch's existing cuMemcpyAsync fallback.

…xts, R580/VMM fallbacks, packed dedup, graph SM bounds, and ScratchArena reserve_sms floor

1. Why this change is needed and why this approach

Five structural defects blocked safe Green Context GPU KV-codec isolation,
CUDA 13.0/R580 compatibility, and cooperative SM budgeting across exported
cores:

- Helios set `reserve_codec_partition = true` for `--lossless-kv-compression
  gpu` in `helios/src/runtime_core/model.rs`, but `NativeResources::initialize`
  and `prepare_kernels` in `helios/src/runtime_core/mod.rs` only retained a
  primary CUDA context and created a `GreenContextPartition` when
  `persistent_workers` was non-empty. Standard cores without persistent workers
  therefore shared SMs between GPU KV-codec kernels and full-grid cooperative
  graphs, risking scheduler contention and replay stalls.
- Exported graph manifests did not record per-graph minimum compute SM counts
  (`min_compute_sms`) or kernel cluster dimensions (`max_cluster_size`), so
  Green Context SM splitting could neither enforce co-residency floors nor
  reject cluster dimensions exceeding the compute partition's SM count or
  driver-reported co-scheduled alignment.
- CUDA 13.0 / R580 drivers (such as GB10 SM121 driver 580.173.02) export
  `cuDevSmResourceSplitByCount` and the other seven Green Context driver
  symbols without CUDA 13.1's `cuDevSmResourceSplit`, causing Green Context
  initialization to fail on R580. In addition, R580 segfaults inside
  `cuMemcpyBatchAsync_v2` when copying from `cuMemHostGetDevicePointer` into a
  `cuMemMap` VMM range on a `cuCtxFromGreenCtx` stream, whereas `cuMemcpyAsync`
  succeeds on identical pointers and streams.
- On multi-rank deployments with `--lossless-kv-compression gpu` or `cpu`,
  Selene pre-populated `location.packed` per rank and skipped `pack_shares`
  deduplication, storing N identical compressed copies of replicated MLA pages
  across DRAM slabs, disk records, and pool exports instead of using v4
  `PackedUnit.replicas`.
- During Python preparation, `ScratchArena` tracked overlapping plans via
  `register_parallel` for disjoint workspace sizing only, without enforcing a
  cooperative SM reservation floor against concurrent auxiliary-stream
  collectives.

Generalizing `GreenContextPartition` via a typed `PartitionRequest` enum to
support 2-way `(worker, compute)`, 2-way `(codec, compute)`, and 3-way
`(worker, codec, compute)` topologies isolates GPU KV-codec execution
fleet-wide via shared runtime policy without model-identity branches. Falling
back to `cuDevSmResourceSplitByCount` (with compute in `result[0]` and
three-way remainder refresh through a temporary green context) and routing
Green Context streams through `cuMemcpyAsync` in `Stream::copy_batch` restores
CUDA 13.0 / R580 support while keeping driver-reported co-scheduled alignment
uninflated. Deduplicating byte-identical per-rank `PackedUnit` payloads into
`PackedUnit.replicas` reuses Selene's existing v4 wire and decode contract to
eliminate multi-rank storage inflation across DRAM, disk, and pool tiers.
Recording `min_compute_sms` and `max_cluster_size` as zero-default Protobuf
fields preserves compatibility with existing cores while enforcing SM and
cluster bounds at load time, and bidirectional `reserve_sms` checks on
`ScratchArena` fail closed during preparation when cooperative plans lack
required SM headroom.

2. What changed

- Per-graph SM-budget manifest fields (`helios/proto/{runtime_core,core}.proto`,
  `ignition/preparation/{runtime_core_pb2,capture,runtime_core}.py`,
  `heliopause/src/export/{mod,capture,core}.rs`,
  `helios/src/runtime_core/{format,protobuf,metadata,describe,protection,selection}.rs`,
  `helios/src/core/{cache,conversion,export,protection,schema}.rs`):
  - Before: `GraphIndex` and `Graph` carried no SM-floor or cluster-dimension
    metadata; capture did not record co-resident SM floors or parse
    `CU_LAUNCH_ATTRIBUTE_CLUSTER_DIMENSION` (attribute id 4).
  - After: added optional `uint32 min_compute_sms = 7` and
    `uint32 max_cluster_size = 8` (`0` = unspecified for backward compatibility
    with existing cores), regenerated `runtime_core_pb2.py`, wrapped graph
    capture in `b12x._lib.utils.device.track_capture_min_compute_sms()` (pinned
    via `pyproject.toml` rev `3c5c7b1488`, failing closed without a silent
    `ImportError` fallback), exposed shared
    `CU_LAUNCH_ATTRIBUTE_CLUSTER_DIMENSION` and
    `kernel_cluster_size_from_bytes` in `helios/src/runtime_core/format.rs` for
    both export and load, and preserved `(0, 0)` for unclustered graphs without
    folding `max_cluster_size` into `min_compute_sms`.
- Fleet-wide Green Context partitioning, R580 fallback, and honest alignment
  checks (`helios/src/runtime_core/{driver,persistent_worker,mod,model}.rs`,
  `helios/src/cuda.rs`):
  - Before: `GreenCtxDriver` required `cuDevSmResourceSplit`; `plan_sm_split`
    and `GreenContextPartition::create` required a persistent worker;
    `NativeResources::initialize` only retained a primary context for
    persistent-worker cores; `Stream::copy_batch` always invoked
    `cuMemcpyBatchAsync_v2` when present.
  - After: replaced `(Option<u32>, bool)` with `PartitionRequest` supporting
    2-way `(worker, compute)`, 2-way `(codec, compute)`, and 3-way
    `(worker, codec, compute)` splits; invoked
    `NativeResources::initialize_with_options` from `model.rs` whenever
    `--lossless-kv-compression gpu` is active; added optional
    `cuDevSmResourceSplitByCount` fallback in `GreenCtxDriver` and
    `GreenContextPartition::create` placing compute in structured `result[0]`
    and refreshing three-way remainders via a temporary `CUgreenCtx`; recorded
    driver-reported `actual_compute_sm.sm_coscheduled_alignment` directly
    without `.max(...)` inflation and validated it against
    `required_compute_coscheduled` (structured split) or `max_cluster_size`
    (count-based split); enforced `min_compute_sms`, `max_cluster_size`, and
    per-node cluster attributes in `prepare_graphs` with a shared
    `CPU_CODEC_HINT`; queried `cuStreamGetGreenCtx` once in `Stream::open` and
    `Stream::open_lowest_priority` so `Stream::copy_batch` uses `cuMemcpyAsync`
    on Green Context streams.
- Multi-rank packed unit deduplication (`selene/src/{codec_copy,memory,disk_store}.rs`):
  - Before: `DirectSlabTarget::take_direct`, `AsyncCompressor`, and
    `build_packed_write` stored one copy of every rank's compressed packet even
    when per-rank bytes were identical, and `complete_record` skipped
    `pack_shares` for packed records.
  - After: deduplicated byte-identical per-rank `PackedUnit` entries sorted by
    `(kind, logical_index, stored_rank)` across all three paths, recording
    dropped ranks in `PackedUnit.replicas`, compacting DRAM slabs tightly when
    duplicates are eliminated to release trailing slabs, and counting
    deduplicated packed records under `stats.packed_records[0]` while keeping
    raw `record.replication` unset for pool compatibility.
- Structural `ScratchArena` cooperative SM floor
  (`ignition/preparation/scratch.py`) and normative documentation
  (`docs/{runtime-core-design,core-format-design,prefix-cache-offload,core-design,preparation-development}.md`,
  `helios/manifest.md`):
  - Before: `ScratchArena.register_parallel` tracked byte overlap only and
    `docs/runtime-core-design.md` scoped Green Contexts to single-rank
    persistent-worker cores.
  - After: added `min_reserve_sms=0`, `reserve_sms_floor`,
    `require_reserve_sms`, `resolve_reserve_sms`, `register_cooperative_plan`,
    and `register_parallel(*plans, reserve_sms=0)` with bidirectional
    validation, shared `_validate_reserve_sms`, weakest-link headroom tracking,
    and full reset in `release_preparation()`; updated all six normative
    documents to reflect the three Green Context topologies, R580/VMM
    fallbacks, graph SM bounds, packed cross-rank deduplication, and
    `ScratchArena` SM-floor enforcement.

3. Claimed benefit and result

- Isolates `--lossless-kv-compression gpu` in a disjoint Green Context across
  non-worker and persistent-worker cores on both CUDA 13.1+ and CUDA 13.0/R580
  drivers, avoids R580 `cuMemcpyBatchAsync_v2` VMM faults on Green Context
  streams, and rejects under-provisioned compute partitions or driver-downgraded
  cluster alignment at load time.
- Preserves backward compatibility with existing exported cores
  (`min_compute_sms == 0`, `max_cluster_size == 0`, verified by wire-decode
  tests and per-node cluster validation).
- Eliminates multi-rank duplicate storage for identical compressed KV units
  (e.g. 4:1 on TP4 MLA and 2:1 on pairwise GQA) across DRAM slabs, disk
  records, and `selene-manager` exports without changing the v4 wire format.
- Fails closed at preparation time when cooperative plans overlap concurrent
  collectives without sufficient `reserve_sms` headroom.

4. Supporting evidence and limitations

Validated on Linux x86_64 with NVIDIA RTX PRO 6000 Blackwell Max-Q (SM120,
188 SMs, driver 620.73.04), rebased on `origin/main` (`be4092d7`):
- `cargo test --locked --release --manifest-path eos/Cargo.toml --target-dir flare-cli/target`:
  12 passed, 0 failed.
- `cargo test --locked --release --manifest-path selene/Cargo.toml --features test-support --target-dir flare-cli/target`:
  643 unit + 1 integration passed, 0 failed (including new 4-rank MLA/GQA
  `direct_slab_capture_deduplicates_identical_and_pairwise_rank_packets`,
  `dedup_capture_slots_merges_identical_ranks_and_validates_layout`, and
  `packed_multi_rank_mla_capture_deduplicates_slabs_stats_and_pool_export`).
- `cargo test --locked --release --manifest-path selene-manager/Cargo.toml --features test-support --target-dir flare-cli/target`:
  448 passed, 0 failed, 1 ignored.
- `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target --lib -- runtime_core:: core:: cuda:: offload::`:
  561 passed, 0 failed, 33 ignored (including new `PartitionRequest`,
  `plan_split_by_count`, `validate_actual_compute_partition` downgrade and R580
  TPC-2 tests, and `legacy_graph_wire_bytes_omitting_sm_bounds_decode_to_zero`).
  Full `helios --lib` suite with `FLARE_TEST_TEMPLATE_DIR`: 1,956 passed,
  51 ignored, 6 failed solely due to absent Hugging Face model template
  fixtures in `/tmp/flare-test-templates`.
- `CUDA_VISIBLE_DEVICES=3 cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target --lib -- --ignored --nocapture --test-threads=1 codec_compute_partition three_way_gpu_codec cuda_split_by_count_fallback_partitions_two_way_and_three_way`:
  3 passed, 0 failed on SM120:
  - 3-way: `worker=8 SMs, codec=8 SMs, compute=172 SMs | baseline_coop=7.5 us | concurrent_coop=137962 (137750.5/s) | gpu_codec_rounds=247 (encode+decode 262.0 MiB/s, ratio 5.98x)`
  - 2-way: `codec=8 SMs, compute=180 SMs (cosched=16) | concurrent_coop=73148 | gpu_codec_rounds=125`
  - `SplitByCount` fallback: 2-way `(codec, compute)` and 3-way `(worker, codec, compute)` partitions plus Green Context `Stream::copy_batch` from registered host memory into a `cuMemMap` VMM allocation passed.
- `cargo test --locked --release --manifest-path flare/Cargo.toml --target-dir flare-cli/target`:
  255 passed, 0 failed, 4 ignored.
- `cargo test --locked --release --manifest-path flare-cli/Cargo.toml` and
  `cargo build --locked --release --manifest-path flare-cli/Cargo.toml`:
  254 passed, 0 failed, 3 ignored; release binary built cleanly.
- `cargo test --locked --release --manifest-path heliopause/Cargo.toml --target-dir flare-cli/target --lib`:
  251 passed, 0 failed, 6 ignored (including
  `graph_sm_requirements_extracts_cluster_dimension_and_preserves_unspecified_zero`).
- `CUDA_VISIBLE_DEVICES=3 FLARE_RUN_CUDA_TESTS=1 pytest tests/preparation/{test_scratch,test_capture_graph_metadata,test_core_boundary,test_codec_layout,test_persistent_worker}.py tests/test_kv_codec.py tests/cli -q`
  (with `PYTHONPATH` supplying the worktree `ignition` and `flashinfer#217` `b12x`):
  314 passed, 0 failed.

Limitations:
- Live SM103 and GB10 SM121 (R580 driver `580.173.02`) hardware execution,
  multi-GPU `ignition export` + `flare run --lossless-kv-compression gpu`, and
  the 6 gated Hugging Face chat-template tests were not run on this host.
- DeepSeek-V4.1 `DSAFusedIndexerKernel` (`flashinfer/experimental/b12x/attention/dsa_indexer/fused_indexer.py`)
  launches full-GPU non-cooperative software-barrier waves in the separate
  `local-inference-lab/flashinfer` repository; fixing that kernel (cooperative
  clamping or SM-budget reservation) requires a companion PR in
  `local-inference-lab/flashinfer` followed by a `pyproject.toml` pin bump.

Design-Signed-Off-By: Antigravity (Gemini); design-review=2e5b
Signed-off-by: Luke Alonso <lalonso@gmail.com>
@lukealonso
lukealonso force-pushed the unify-cooperative-sm-and-green-conte branch from 275b7a5 to d5d12ea Compare December 5, 2026 00:57
@lukealonso lukealonso changed the title helios,heliopause,ignition: fleet-wide 2-way codec green contexts, graph SM bounds, and ScratchArena reserve_sms floor helios,heliopause,selene,ignition: fleet-wide 2-way codec green contexts, R580/VMM fallbacks, packed dedup, graph SM bounds, and ScratchArena reserve_sms floor Dec 5, 2026
@lukealonso
lukealonso merged commit cfb7209 into main Dec 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. bug Something isn't working enhancement New feature or request performance Performance, latency, throughput, or memory-efficiency investigation or improvement. triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants