Skip to content

feat(runtime): add SGLang runtime backend (#974)#1059

Open
joryirving wants to merge 12 commits into
defilantech:mainfrom
joryirving:feat/issue-974-sglang-runtime-backend
Open

feat(runtime): add SGLang runtime backend (#974)#1059
joryirving wants to merge 12 commits into
defilantech:mainfrom
joryirving:feat/issue-974-sglang-runtime-backend

Conversation

@joryirving

@joryirving joryirving commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

What

Adds sglang as a first-class InferenceService.Spec.Runtime value,
alongside llamacpp / vllm / tgi / personaplex / generic.

A new typed SGLangConfig (with nested SGLangSpeculativeConfig) covers
sharding, memory, batching, quantization/KV-cache, attention, agentic glue
(tool/reasoning parsers, chat template), speculative decoding (EAGLE /
EAGLE3), and LoRA basics — mirroring the vLLM pattern. GPU vendor (NVIDIA
vs AMD) drives image selection, so the AMD ROCm image is picked automatically
when model.spec.hardware.gpu.vendor is amd.

SGLang launches via python3 -m sglang.launch_server (mirroring how
personaplex wraps a Python module). Probes target /health_generate for
startup + readiness (runs a token, accurate) and /health for liveness
(cheap). Startup tolerates 180 failures (~30 min) for cold-start model load.

Why

Fixes #974

Headline motivation is SGLang's RadixAttention automatic prefix caching.
A foreman agent's tool loop re-sends the same large shared prefix every turn
(system prompt + tool definitions + issue/repo context); SGLang serves that
shared prefix from cache instead of reprocessing it, which materially cuts
latency and raises throughput for the multi-turn, high-concurrency pattern
the foreman-agent generates. Today an operator who wants SGLang has to fall
back to the generic runtime and hand-write container config — losing the
auto-generated args, mode handling, and health wiring the first-class
backends get.

How

  • api/v1alpha1/inferenceservice_types.go: SGLangConfig +
    SGLangSpeculativeConfig structs, SGLangConfig field on
    InferenceServiceSpec, sglang added to the runtime enum.
  • internal/controller/runtime_sglang.go: SGLangBackend implementing
    RuntimeBackend + CommandBuilder + HPAMetricProvider +
    EnvBuilder. BuildArgs emits base flags + --served-model-name +
    typed fields in declaration order + auto-derived --tp + --is-embedding
    for mode + extraArgs last.
  • internal/controller/runtime_sglang_args.go: free-function helpers,
    one per flag. Mirrors runtime_vllm_args.go structure.
  • internal/controller/runtime.go: case RuntimeSGLANG in
    resolveBackend.
  • internal/controller/deployment_builder.go: resolveRuntimeImage
    picks ROCm image for AMD GPUs; otherwise CUDA.
  • make manifests + make chart-crds regenerated CRDs.
  • docs/contributors/adding-a-runtime.md, docs/site/concepts/comparison.md,
    docs/site/guides/model-matrix.md updated.

Out of scope (B3 followup): LoRA hot-loading, speculative perf tuning
(--speculative-accept-threshold-*), data-parallel rendezvous,
PodMonitor for /metrics, and remaining minor SGLang flags. Tracked as a
separate issue.

Checklist

  • Tests added/updated (TestSGLangBuildArgs table-driven +
    TestSGLangBuildCommand + TestSGLangProbes + TestSGLangBuildEnv +
    TestValidateSGLangConfig + dispatch + image-resolution tests)
  • make test passes locally
  • make lint passes locally
  • make lint-all passes locally (cross-arch)
  • Commit messages follow conventional commits
  • All commits are signed off (git commit -s)
  • AI assistance disclosed: this PR was produced by an AI coding agent
    working with a repo collaborator. The agent followed the
    docs/contributors/adding-a-runtime.md pattern, the design spec at
    docs/superpowers/specs/2026-07-10-sglang-runtime-backend-design.md
    (local agent scratch, not committed), and AGENTS.md conventions.
  • Documentation updated

joryirving and others added 11 commits July 10, 2026 08:56
Signed-off-by: Jory Irving <jory@jory.dev>
Signed-off-by: Jory Irving <jory@jory.dev>
Signed-off-by: Jory Irving <jory@jory.dev>
Signed-off-by: Jory Irving <jory@jory.dev>
Signed-off-by: Jory Irving <jory@jory.dev>
…missing)

Signed-off-by: Jory Irving <jory@defila.tech>
@joryirving joryirving requested a review from Defilan as a code owner July 10, 2026 17:17
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.71651% with 94 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
api/v1alpha1/zz_generated.deepcopy.go 0.00% 91 Missing and 1 partial ⚠️
internal/controller/runtime_sglang.go 98.07% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…ec errors

Signed-off-by: Jory Irving <jory@jory.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add an sglang InferenceService runtime backend

1 participant