Model-agnostic optimization engine
This design is the engineering boundary for the InferCrane optimization PoC. It is intentionally operator- and workload-driven. A model name can select a reviewed recipe, but it can never establish that an optimization is compatible, correct, or faster.Scope and claim
The generic flow works for any immutable open-weight model that a supported runtime can load and expose through the serving contract. Specialized optimizations work only when InferCrane can discover the model’s operators, match an exact runtime/hardware capability, and collect the required evidence. Unsupported architecture features produce a conservative baseline and an explicit missing-capability result—not a guessed recipe. The initial custom-kernel compiler set is NVIDIA-only. The planner boundary is extensible to ROCm, TPU, and other accelerators, but those backends must acquire their own exact capability and qualification evidence before they can emit experiments.Workload contract
Optimization begins with a distribution, not a benchmark slogan:- input/output token distributions, request rate, concurrency, arrival pattern, streaming, tool use, structured output, multimodal inputs, and prefix reuse;
- TTFT, inter-token latency, end-to-end latency, goodput, error rate, quality, cost, energy, and memory constraints;
- prefill/decode mix, batch size, context growth, KV-cache residency, and request cancellation behavior;
- exact model revision, tokenizer, runtime/image, accelerator, driver/CUDA, topology, and region; and
- metadata-only, redacted replay, or in-customer-boundary data policy.
Search dimensions
No candidate family is universally beneficial. For example, prefix caching has
no value without reusable prefixes; speculative decoding loses when acceptance
is low; quantization can violate quality; tensor parallelism can lose to
communication; and a faster microkernel may not move end-to-end latency.
Candidate-generation algorithm
- Freeze identity. Hash model revision, tokenizer, runtime image, hardware, workload contract, evaluation set, and policy.
- Create controls. Produce at least one conservative vendor/runtime baseline. Never compare only optimized candidates with one another.
- Discover capability. Read model configuration and runtime support, then observe the actual operator graph and serving phases. Feature detection wins over family-name matching.
- Generate one-change candidates. Start with scheduler, cache, precision, decoding, topology, and hardware candidates whose preconditions are true. Preserve interactions as later composite candidates rather than changing everything at once.
- Reject cheaply. Apply compatibility, memory, quality-risk, cost, and historical-rejection filters. Use analytical roofline and Amdahl bounds.
- Screen. Run small deterministic correctness and performance lanes on the exact target accelerator. Failed candidates become durable search evidence.
- Profile the best control. Attribute prefill, decode, communication, CPU, queue, memory, and kernel time. Kernel work begins only here.
- Search kernels. Translate a measured operator hotspot into a typed problem, generate candidates through reviewed compiler backends, and verify them against the runtime reference on randomized/adversarial shapes.
- Qualify the Pareto set. Repeat AIPerf replay and customer quality tests; compare confidence intervals, SLO-qualified goodput, and landed cost.
- Promote separately. A human-approved Release Guard action creates a canary. Monitoring invalidates evidence when workload or identity drifts.
Kernel opportunity gate
The newkernelplanner accepts a profile manifest with typed operator hotspots.
It is independent of the model repository name. Supported initial families are:
- residual-add + RMSNorm;
- quantized linear/dequant + GEMM or GEMV;
- SwiGLU activation;
- prefill and decode attention;
- KV-cache append/quantization;
- MoE routing/grouped GEMM; and
- token sampling.
f, the maximum possible end-to-end speedup is:
S, the kernel itself must reach:
tools/kernel-lab/fused_residual_rmsnorm.py. Its dependency-free laptop path
emulates the fused dataflow. Its optional Triton path performs exact-GPU parity
and a microbenchmark. tools/kernel-lab/fused_residual_rmsnorm_cuda.py applies
the same contract to visible handwritten CUDA C++ through NVRTC. On the measured
H100 shapes that CUDA candidate was correct but slower than both Triton and the
vLLM vendor operator, so it was rejected. The result remains operator-level
evidence until a runtime-level AIPerf campaign passes.
Compiler/backend strategy
InferCrane owns the typed problem, evidence, and selection policy—not a single kernel language:- Triton for productive fusion and shape specialization;
- CUTLASS/CuTe DSL for Tensor Core GEMM, grouped GEMM, low precision, and architecture-specific control;
- FlashInfer as the vendor-grade attention/GEMM/MoE/sampling baseline and reusable generator;
- CUDA C++ or CUDA Rust when low-level SIMT control, a Rust systems stack, or Tile portability justifies it;
- KernelBench task and correctness methodology for generated-kernel evaluation; and
- Mirage as a later whole-graph or persistent-megakernel search backend, never as automatic evidence authority.
Technique evidence map
The search space is grounded in primary work and maintained implementations:- FlashAttention: IO-aware exact attention.
- PagedAttention/vLLM: paged KV-cache memory management and serving throughput.
- SGLang/RadixAttention: structured-program execution and prefix reuse.
- Sarathi-Serve: chunked prefill and stall-free scheduling.
- Speculative decoding and EAGLE: verified parallel token generation.
- GPTQ, AWQ, and SmoothQuant: weight-only and W8A8 post-training quantization families.
- KIVI: asymmetric low-bit KV-cache quantization.
- vLLM, SGLang, and TensorRT-LLM: production references for runtime, scheduling, precision, graph, speculative, and distributed paths.
Kernel registry and search order
internal/kernelplanner owns a reviewed registry of implementation sources.
The registry is not a live GitHub crawler and it does not import code into the
API process. Each entry records the project, HTTPS source, license, backend,
operator families, hardware and dtype filters, revision policy, trust status,
and execution boundary.
Search is deterministic and existing-first:
- measure the implementation bundled in the pinned vLLM or SGLang image;
- inspect compatible specialized/vendor libraries such as FlashInfer and CUTLASS/CuTe;
- adapt or specialize a reviewed Triton/CuTe implementation;
- generate handwritten CUDA only after the prior candidates lose and the profiler-backed Amdahl ceiling justifies the experiment.
POST /api/v1/optimization/kernel-opportunities endpoint
returns this bounded plan with code_execution: false, provider_mutation: false, and performance_claims: false.
Deploy, observe, improve
Deployment and optimization are one lifecycle:starting_point. It is selected
from compatibility and declared objective fit, not an unmeasured speed claim.
After deployment, GET /api/v1/endpoints/{name}/optimization-readiness turns
fresh request aggregates into a conservative stage diagnosis such as queueing,
prefill/first-token, or decode/generation pressure. Request telemetry never
opens the kernel gate: exact target-GPU profiling and the Amdahl policy remain
mandatory.
Process boundary
Do not move compiler, profiler, or arbitrary candidate-source execution into the InferCrane API server.- InferCrane control plane: workload identity, registry metadata, policy, plans, approvals, budget leases, evidence, Release Guard, and audit.
- Brezel worker: isolated source checkout, license/provenance inspection, agent planning, CPU-side compilation and semantic tests, artifact signing, and lifecycle receipts. Network access is deny-by-default and source commits are explicit allowlisted inputs.
- GPU worker: exact-SM build when required, correctness, sanitizers, Nsight, microbenchmarks, AIPerf replay, quality tests, and teardown under the campaign lease.
internal/brezelexecutor is the implemented adapter boundary. It creates or
adopts a sandbox from a pinned Brezel environment revision, writes a typed
content-addressed job manifest, invokes only the baked-in
/opt/infercrane/bin/run-optimization-job entrypoint, validates a typed result,
deletes the sandbox, and retains the lifecycle receipt. Manifests cannot carry
shell commands, environment variables, credentials, or an alternate runner.
Brezel egress remains disabled; approved source access belongs in Brezel
connector policy.