Repository navigation
feat(b12x): unify 5 public contracts, fix live defects, and retire contextual tuning - #194
Merged
Merged
Conversation
…ntextual tuning
Why:
Downstream callers in hyperflare-recipes and flare/ignition depended on 188
private b12x.*._* imports in production code, including inspect.getsource
probing, 38-arg dense GEMM wrapper cloning, 21-arg raw pointer tuples,
process-global B12X_PCIE_* environment mutations, out-of-session KDA kernel
compilation, and monkey-patching of compile_pool._initialize_worker. Those
private reach-ins coincided with live defects: a permanent VRAM leak in
_W13_NORMALIZED_STORAGES, missing _cuda_stream_context around dense epilogue
quantization, unwritten rows on island wide row reductions when
owner.blocks < layout.rows, stale Triton libdevice caching in _discovery.py,
and lockless JITFunction.compile mutation in compile_plan.py. Meanwhile,
b12x/preparation retained 1,151+ LOC of contextual/finalist tuning code with
zero runtime callers across all repositories.
What changed:
- Retired contextual/finalist tuning: deleted b12x/preparation/context.py
(341 LOC) and four test_contextual_*.py suites (810 LOC), and removed
Finalist*, ContextCandidate, ContextRaceResult, race_contexts, and
same_declaration_except_override from preparation/, docs, benchmarks, and tests.
- Fixed live defects:
- _discovery._compiler_context now keys on active Triton libdevice_path,
TRITON_LIBDEVICE_PATH, and live backend hash.
- _lib/compile_plan.py installs a thread-safe one-time ContextVar dispatch
wrapper on JITFunction.compile and makes register_native_triton_jit variadic.
- moe/fused_moe/_impl.py clears _W13_NORMALIZED_STORAGES in
clear_tp_moe_caches() and exports is_w13_normalized.
- Promoted 5 public b12x contracts:
1. Blockscaled epilogues (_epilogues.py with _cuda_stream_context around
quantize, DenseRopeRunner, TcGemvRopeRunner, SwiGLUDownQuery/plan/run) and
explicit SUPPORTS_* capability flags on blockscaled and wo_projection.
2. Explicit kwargs on PCIeAllReduce, PCIeHierarchicalAllReduce, PCIeDCPA2A,
and PCIeDCPA2APool; prepared island row reductions (_row_reductions.py)
and _island_v4_wide grid validation enforcing blocks >= rows; public
PCIe/RoCE collective adapters and PROXY_ABI_VERSION.
3. Public attention contracts (_window_contract.py, paged_kv_write.check_layout,
and exports across paged, paged_decode, dsa_indexer, mla_compress, qsa).
4. First-class PreparationSession plan plan_kda_fused_verify in
sequence/gdn_decode/_fused_verify.py and public sequence/MoE/mHC/loader/
PreparedExperts APIs.
5. Public register_worker_initializer / unregister_worker_initializer /
worker_initializers on compile_pool and preparation, plus public
PreparationSession, SelectionCache, and plan inspection APIs.
- Added unit tests in tests/experimental/b12x/test_public_contracts.py.
Claimed benefit and result:
- Eliminates the live VRAM leak, libdevice cache poisoning, lockless Triton
compile race, missing stream context, and unwritten island-row hazard while
giving hyperflare-recipes and flare/ignition five stable public b12x APIs
and removing 1,151+ LOC of dead contextual tuning code.
Supporting evidence and limitations:
- tests/experimental/b12x/test_public_contracts.py: 10 passed, 0 failed.
- test_registry.py (excluding pre-existing test_registry_matches_disk) +
preparation/{test_discovery_cache,test_session,test_scratch_limit,
test_collective_buckets}.py: 250 passed, 0 failed.
- moe/test_tp_moe_w13_layout.py + sequence/test_kda_fused_verify_contract.py:
62 passed, 5 skipped, 0 failed.
- Verified end-to-end on SM120 GPU 0 via hyperflare-recipes window staging
and window attention CUDA tests. Multi-GPU TP/EP CUDA collective tests were
not run in this single-GPU environment.
Signed-off-by: Luke Alonso <lalonso@gmail.com>
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.
Why
Across
local-inference-lab/hyperflare-recipesandNVIDIA/hyperflare-inference(ignition/), downstream callers depended on 188 privateb12x.*._*import statements in production code, includinginspect.getsourcesubstring probing onwo_prep.plan, 38-kwarg_get_compiled_dense_gemmcloning, 21-arg raw pointer tuples into_selected_forward, process-globalB12X_PCIE_*environment mutations, out-of-session compilation ofprepare_kda_fused_verify, and runtime monkey-patching ofcompile_pool._initialize_worker.These private reach-ins coincided with live correctness, memory, and concurrency defects:
_W13_NORMALIZED_STORAGESinmoe/fused_moe/_impl.pyretained strong tensor references and was never cleared byclear_tp_moe_caches()(permanent VRAM leak)._cuda_stream_contextaround quantize._island_v4_wide.pydid not enforceblocks >= rows, allowing unwritten rows whenowner.blocks < layout.rows._discovery._compiler_contextcached with@lru_cacheignored in-process Tritonlibdevice_pathswitches._lib/compile_plan.pymutatedJITFunction.compilelocklessly across threads.Meanwhile,
b12x/preparationretained 1,151+ LOC of contextual/finalist tuning (context.pyand 4test_contextual_*.pysuites) with zero runtime callers across all repositories.What Changed
flashinfer/experimental/b12x/preparation/context.py(341 LOC) and fourtests/experimental/b12x/preparation/test_contextual_*.pysuites (810 LOC).Finalist*,ContextCandidate,ContextRaceResult,race_contexts, andsame_declaration_except_overridefromb12x/preparation/{__init__,types,_cache,_collective,_measurement,session}.py, docs, benchmarks, and tests.b12x/preparation/_discovery.py: key_compiler_contexton activetriton.knobs.nvidia.libdevice_path,TRITON_LIBDEVICE_PATH, and live backend hash.b12x/_lib/compile_plan.py: install a thread-safe one-timeContextVardispatch wrapper onJITFunction.compileinstead of lockless attribute swapping; makeregister_native_triton_jit(*jit_fns)variadic.b12x/moe/fused_moe/_impl.py: clear_W13_NORMALIZED_STORAGESinclear_tp_moe_caches()and exposeis_w13_normalized.b12xcontracts:b12x/gemm/blockscaled/_epilogues.py(DenseRopeRunner,TcGemvRopeRunner,SwiGLUDownQuery,plan_swiglu_down,run_swiglu_down,_cuda_stream_contextaround quantize) and explicitSUPPORTS_*capability flags onblockscaledandwo_projection; promoted public exports onb12x.gemm.{blockscaled,wo_projection,bf16_gemv}andb12x.quantization.mxfp8.algorithm_override,hierarchical_deferred_consumption,hierarchical_threads,threads,block_limit) toPCIeAllReduce,PCIeHierarchicalAllReduce,PCIeDCPA2A, andPCIeDCPA2APool; addedb12x/comm/pcie/_row_reductions.py(supports_island_fused_rows,run_island_*) and_validate_wide_gridin_island_v4_wide.pyenforcingblocks >= rows; promoted publicb12x.comm.{pcie,roce}adapters andPROXY_ABI_VERSION.b12x/attention/paged/_window_contract.py(retiring 21-arg raw pointer tuples),paged_kv_write.check_layout, and public exports acrosspaged,paged_decode,dsa_indexer,mla_compress, andqsa.plan_kda_fused_verifyinb12x/sequence/gdn_decode/_fused_verify.pyas a first-classPreparationSessionPlan(usingCompileJob.DEVICE_ORDINAL); exposed publicPreparedExpertsproperties (w1_alphas,w2_alphas,a1_gscale,a2_gscale,release_weight_views, etc.) and public exports acrossb12x.sequence.*,b12x.moe.fused_moe,b12x.norm.mhc, andb12x.loader.register_worker_initializer,unregister_worker_initializer, andworker_initializersoncompile_pool/b12x.preparation; promotedSelectionCache.set_agreed_records,PreparationSession.{check_thread,synchronize,is_cancelled,selection_cache,scratch_limit,reclaim_programs},custom_plan,is_composite_plan,plan_variants,plan_memory_requirements, andplan_compile_jobs.tests/experimental/b12x/test_public_contracts.py(10 unit tests covering contextual retirement, libdevice switching, thread-safeJITFunction.compiledispatch,_W13_NORMALIZED_STORAGESrelease,blocks >= rowsgrid validation, explicit collective kwargs, worker initializers, capability flags,plan_kda_fused_verify, andpaged_kv_write.check_layout).Claimed Benefit and Result
_W13_NORMALIZED_STORAGESVRAM leak, Triton libdevice cache poisoning, locklessJITFunction.compilerace, missing quantize stream context, and unwritten island-row hazard.hyperflare-recipesandflare/ignitionto drop all 188 production privateb12x.*._*imports.Supporting Evidence and Limitations
tests/experimental/b12x/test_public_contracts.py: 10 passed, 0 failed.tests/experimental/b12x/test_registry.py -k "not test_registry_matches_disk"+tests/experimental/b12x/preparation/{test_discovery_cache,test_session,test_scratch_limit,test_collective_buckets}.py: 250 passed, 0 failed.tests/experimental/b12x/moe/test_tp_moe_w13_layout.py+tests/experimental/b12x/sequence/test_kda_fused_verify_contract.py: 62 passed, 5 skipped, 0 failed.hyperflare-recipesCUDA tests (test_window_staging_cuda.py::test_compiled_mutable_staging[8-128-1]andtest_window_attention_cuda.py::test_window_attention[kv_dtype0-False-1-4-0-None-False]) andflarepreparation suites (88 passedacrosstest_runtime_patches,test_tuning_shards,test_compile_pool,test_persistent).test_registry_matches_disk,test_island_native_override_preserves_fixed_declaration, andtest_output_aware_twoshot_size_band[True-655424|2097152]fail identically on untouchedlil/main @ 86c9f67a2. Multi-GPU TP/EP CUDA collective suites were not run on this single-GPU host.Paired PRs
Discord: lukealonso