SyFI-ServingStudio

dev-llm-serving

Implement or review code in a real LLM or multimodal serving framework using the routed reference library. Under a parent workflow, follows its frozen trial.

SyFI-ServingStudio 1 1 Updated 1mo ago

Resources

3
GitHub

Install

npx skillscat add syfi-servingstudio/servingstudiosim/dev-llm-serving

Install via the SkillsCat registry.

SKILL.md

Dev LLM Serving

This skill bundles the curated reference material for LLM and multimodal serving-system development as a flat library of topic-focused notes under `references/`. Open the specific reference whose topic matches the task; do not preload everything.

How to use this skill

  1. Read this file once to learn what's covered.
  2. For the active task, identify the one or two topics that match it (use the index below).
  3. Open references/<topic>.md directly with your file-read tool. Each is self-contained.
  4. Some topics have follow-up files named references/<topic>-<sub>.md (e.g. cuda-graph-runner.md); the main <topic>.md says when to read them.
  5. For a broad orientation or a from-scratch build, read
    `OVERVIEW.md`.

When a parent workflow supplies a frozen trial brief, treat it as the source of
truth. Use this library to determine how to implement that trial, not to pick
a different optimization. Do not sweep parameters, substitute a favorite
backend, call the simulator, or judge the measured result unless the parent
explicitly assigns that work.

Kernel, fusion, and collective work

Route real kernel/backend implementation, producer-consumer fusion, and
collective or payload changes through dev-compose-kernel. It owns the six-step
workflow from measured target through isolated proof, production integration,
and full-server promotion. Keep this skill focused on the surrounding serving
system and its routed reference library.

Implementation mode — what the code may be made of

A parent workflow may also declare an implementation mode. It is not a style
preference; it decides what this library is used for.

  • Clean-room composition. Follow `OVERVIEW.md`'s reading order
    (A) Build a serving engine from scratch — not (B) Extend vLLM / SGLang /
    TensorRT-LLM. In this mode the engine source maps under
    `references/engines/` and any $SERVE_REPOS checkout are
    read-only architectural references: learn the architecture and public API
    behavior from them, but do not import, execute, link, vendor, copy, adapt, or
    mechanically translate their source. Public primitive libraries (PyTorch,
    Transformers weight loading, FlashInfer, FastAPI, Uvicorn) are allowed only as
    declared in the brief's dependency list.
    Before handing work back, run a source-hygiene self-check for the forbidden
    forms: engine imports (rg -n '^\s*(import|from)\s+(vllm|sglang|tensorrt_llm)'),
    sys.path injection pointing at an engine checkout, launching an engine as a
    subprocess, linking its binaries, and vendored or line-by-line-translated source.
  • Extend an existing framework — reading order (B) applies; work inside that
    framework.
  • Assemble around an existing runtime — only when the brief says so
    explicitly.

If the brief does not state a mode and the target has no runnable
implementation, ask the parent rather than assuming an existing engine may serve
as the runtime. The presence of a reference checkout is not authorization to
depend on it.

Baseline completeness checks (NVIDIA serving)

Three techniques every production serving system on NVIDIA ships with — confirm all three are in place before pursuing workload-specific optimizations:

  1. Continuous batching — see `references/algorithms/continuous-batching.md`. Skip only when the workload is single-batch by contract.
  2. Fused attention kernel — FlashInfer, FlashAttention, or SDPA. For the picker (workload → backend, plus the per-feature matrix), open `references/backends/attention-backend-comparison.md`; for deep usage, `references/backends/flashinfer.md`, `references/backends/flashattention.md`, or `references/backends/sdpa.md`. On NVIDIA, never skip a fused kernel.
  3. CUDA graphs — see `references/backends/cuda-graph.md`. Required for low-latency single-batch and high-throughput batched serving.

On AWS Trainium (Neuron) instead

Trainium is not a GPU — the floor is different. Start from `references/frameworks/neuron-pytorch.md` and `references/hardware/aws-trainium.md`. The defaults there: static-shape graphs (bucket prompt/decode lengths; neuronx-cc recompiles on new shapes), a persistent compile cache, BF16, on-device sampling, and continuous batching over static buffers. The decisive decode optimization is a device-resident, in-place KV cache — use NxD's KVCacheManager + ModelBuilder aliasing (`references/frameworks/nxd-kv-cache.md`); a from-scratch torch_neuronx.trace decode that passes the KV cache through the graph boundary every token is host-bound and slow. Flash attention is available here too — via the NKI kernel nki_flash_attn_func (`references/frameworks/neuron-flash-attention.md`); the FlashAttention/FlashInfer libraries are NVIDIA-only but the algorithm ships on Neuron, and it cuts the attention activation peak that drives the HBM OOM. For custom NeuronCore kernels use the bundled neuron-nki-* skills (the Trainium analog of FlashInfer/Triton kernels).

Reference index

Each entry below is one file under `references/`. The bracketed phrase shows what triggers it.

Model architectures

Serving algorithms

Kernel-library backends

Frameworks (PyTorch / Triton / MLX / Neuron)

  • `references/frameworks/mlx.md` — MLX framework for LLM serving on Apple Silicon — unified-memory array model, lazy evaluation and mx.eval, mx.compile, mx.fast kernels, mlx-lm reference serving path, native INT4/INT8 quantization via mx.quantize, custom Metal kernels via mx.fast.metal_kernel.

  • `references/frameworks/pytorch.md` — PyTorch idioms for LLM serving — nn.Module + weight loading, torch.compile (Dynamo / inductor / dynamic shapes / reduce-overhead), state_dict remapping, custom op registration with torch.library, NCCL setup, HF transformers integration, inference_mode.

  • `references/frameworks/neuron-pytorch.md` — PyTorch on AWS Trainium (Neuron) — torch-neuronx vs TorchNeuron Native, neuronx-cc compilation, static-shape bucketing, persistent compile cache, BF16, static KV cache, host-sync pitfalls, when to drop to NKI.

  • `references/frameworks/nxd-inference.md` — NxD Inference (NeuronX Distributed Inference) — AWS's Trainium inference library (NeuronConfig / ModelBuilder / generate); full-turnkey or as building blocks inside a bespoke server.

  • `references/frameworks/nxd-kv-cache.md` — NxD KVCacheManager — the device-resident, in-place KV cache for Trainium (resident nn.Parameter buffers + ModelBuilder input/output aliasing). The key decode optimization; what raw torch_neuronx.trace can't do.

  • `references/frameworks/neuron-flash-attention.md` — flash attention on Trainium via the NKI kernel nki_flash_attn_func. Flash attention is NOT NVIDIA-only — the algorithm ships on Neuron; use it instead of naive softmax(QKᵀ)V to cut the activation peak (and the HBM OOM that caps batch size).

  • `references/frameworks/triton.md` — Triton as a framework-level decision — when a custom Triton kernel pays off in serving vs reusing FlashInfer / FlashAttention / CUTLASS / liger / sgl-kernel.

Hardware specifics

Engine source maps

  • `references/engines/sglang.md` — SGLang serving engine source-code lookup — SRT runtime, scheduler/tokenizer managers, attention backends (FlashInfer, FlashInfer-MLA, CUTLASS-MLA, FA, FlashMLA, Triton), MoE routing/dispatch + EPLB, radix cache + HiCache, quantization, speculative decoding (EAGLE), disaggregated P/D, TP/PP/EP, CUDA graphs, sgl-kernel custom kernels.

  • `references/engines/trtllm.md` — TensorRT-LLM serving engine source-code lookup.

  • `references/engines/vllm.md` — vLLM serving engine source-code lookup.

API / benchmark / profiler tooling

  • `references/tooling/accuracy-checker.md` — Create an accuracy verification script that compares a custom generation implementation against HuggingFace model.generate() as the reference.

  • `references/tooling/fastapi-serving.md` — Create a production-ready FastAPI inference server for HuggingFace transformer models.

  • `references/tooling/io-handling.md` — Request-time I/O handling for LLM/multimodal serving — tokenization and chat templates, tool-call prompt formatting, image preprocessing (resize / tile / normalize / patchify), video frame sampling, audio feature extraction (log-mel), detokenization and UTF-8-safe streaming, tool-call parsing per model family, structured-output extraction.

  • `references/tooling/lora-serving.md` — Multi-adapter LoRA serving — single base model dispatching different LoRA adapters per request at serving throughput.

  • `references/tooling/openai-api.md` — OpenAI-compatible HTTP per modality — text (/v1/completions, /v1/chat/completions), image (/v1/images/generations), TTS (/v1/audio/speech), STT (/v1/audio/transcriptions), video (/v1/videos + async polling), realtime audio (WS /v1/realtime).

  • `references/tooling/profiler.md` — GPU performance profilers for LLM/multimodal serving: PyTorch Profiler (Python-level op aggregation, Chrome trace), Nsight Systems (nsys, system-timeline / launch-gap / NCCL diagnosis), Nsight Compute (ncu, kernel metrics / occupancy / roofline).

  • `references/tooling/serving-benchmark.md` — Benchmark an LLM serving endpoint — TTFT, TPOT, ITL, end-to-end latency, throughput, p50/p95/p99 across concurrency and ISL/OSL sweeps.

Out of scope

Kernel implementation (writing CUDA / Triton / CUTLASS). For that, use the separate agent-gpu-skills collection. Exception — NKI: writing NeuronCore kernels for AWS Trainium is in scope here, via the bundled neuron-nki-* skills (neuron-nki-writing, -docs, -debugging, -profiling, -profile-querying); there is no separate Trainium kernel collection.

Reference repos

The copied library intentionally does not vendor full vLLM, SGLang, or
TensorRT-LLM source trees. Engine-source-map references cite paths like
$SERVE_REPOS/<engine>/...; point SERVE_REPOS at an existing checkout. When
the exact implementation must be rediscovered or verified upstream, route that
read-only investigation through dev-explore-kernel.