Skip to content

About

SGLang with the HSA (Hierarchical Sparse Attention) backend for HiLS-Attention — for speed benchmarking

Resources

Code of conduct

Stars

6 stars

Watchers

0 watching

Forks

Repository files navigation

logo

PyPI PyPI - Downloads license issue resolution open issues Ask DeepWiki


🔍 This fork: HiLS-Attention — long-context serving in SGLang

This is a fork of SGLang that adds a serving backend for HiLS-Attention, a hierarchical sparse attention (HSA) mechanism for long-context inference. The backend is invoked as --attention-backend hsa. HiLS-Attention splits each sequence into fixed-size chunks, uses per-chunk landmark keys to select the top-k most relevant chunks per query (plus a local sliding window), and attends only to those — cost grows as O(N · topk · page_size) instead of dense O(N²), while staying closely aligned with the reference model. At 345M / 512K context it is ~13.5× faster prefill and ~15.7× faster decode than full attention, with parity around 16K.

Note: this fork is intended for speed benchmarking of HiLS-Attention, not fully-aligned production serving. Its alignment with the reference model is close but not exact — the reference masks the inserted landmark (LMK) tokens in its sliding-window (SWA) layers, which this backend does not yet replicate.

This fork ports HiLS-Attention into SGLang for inference — see the paper HiLS-Attention (arXiv:2607.02980) and the main repository Tencent-Hunyuan/HiLS-Attention for the method, training code, and reference implementation.

Full details, config fields, and the benchmark table: python/sglang/srt/layers/attention/hsa/README.md.

Run inference with HiLS-Attention

Step 1 — Download the weights. Grab the released HiLS-Attention checkpoint from the Hub:

huggingface-cli download tencent/HiLS-Attention-7B \
    --local-dir ./HiLS-Attention-7B

Step 2 — Transform the checkpoint. The released weights use the upstream HiLS* / hils_* naming; the SGLang HiLS-Attention backend expects the HSAForCausalLM / FlashHSAConfig schema. The weight tensors are already compatible — only config.json needs translating — so the converter just rewrites the config and symlinks the weights (pass --copy for a self-contained copy):

python scripts/convert_hils_checkpoint.py \
    --src ./HiLS-Attention-7B \
    --dst ./HiLS-Attention-7B-sglang

Step 3 — Run inference. Point the hsa backend at the converted directory and set the page size to the model's chunk size (64). Server:

python -m sglang.launch_server \
    --model-path ./HiLS-Attention-7B-sglang \
    --attention-backend hsa \
    --page-size 64 \
    --trust-remote-code
# then query the OpenAI-compatible endpoint at http://localhost:30000

Your own prompts (offline, no server) — scripts/run_hsa_infer.py wraps the offline engine and sets the backend knobs (--attention-backend hsa, --page-size 64) for you. Prompts come from positional args, --prompt, a --prompt-file (one per line), or stdin:

python scripts/run_hsa_infer.py --model-path ./HiLS-Attention-7B-sglang \
    "The capital of France is" "Water is made of hydrogen and"

python scripts/run_hsa_infer.py --model-path ./HiLS-Attention-7B-sglang \
    --prompt-file prompts.txt --max-new-tokens 128

It auto-sizes context_length to your prompts (override with --context-length for very long inputs).

Offline / single batch (benchmarking):

python -m sglang.bench_one_batch \
    --model-path ./HiLS-Attention-7B-sglang \
    --attention-backend hsa \
    --page-size 64 \
    --input-len 131072 --output-len 32 --batch-size 1 \
    --trust-remote-code

--page-size must equal the model's chunk_size (64). Both GQA (G>1) and MHA (G=1, e.g. the 7B checkpoint) prior-query checkpoints are supported. For bit-exact selection (consistency testing) set SGLANG_HSA_HEADWISE_TOPK_SOFTMAX=1; the default is the faster max-pool selection path.

Runtime behavior specific to the HiLS-Attention backend

The backend auto-configures two things at launch (you'll see a log line for each); you don't need to set any flags:

  • Single-sequence prefill. The HiLS-Attention prefill kernels process one sequence at a time, so the backend sets prefill_max_requests=1 — requests are prefilled one at a time. Decode is unaffected and stays fully batched, so throughput for many concurrent generations is not impacted.
  • Overlap scheduler disabled. HiLS-Attention decode interleaves virtual landmark (LMK) tokens whose next input must be chosen synchronously from the current sequence length; the overlap scheduler launches the next forward before that decision is made. The backend therefore sets disable_overlap_schedule=True. This does not change single-batch latency (the benchmark numbers above are unaffected); it can slightly reduce online-serving decode throughput because per-step CPU overhead is no longer hidden behind GPU compute.

Reproduce the speed benchmark

The sweep benches HiLS-Attention vs dense (full) attention across 8K–512K context on a single GPU with dummy weights (no checkpoint needed):

GPU=0 bash dev/sweep_8k_512k.sh   # writes /tmp/sweep_results.txt

Kernels live in dev/hsa-kernel-main/ops/ (tilelang); tilelang must be installed and importable.


Blog | Documentation | Roadmap | Join Slack | Weekly Dev Meeting | Slides

News

  • [2025/12] SGLang provides day-0 support for latest open models (MiMo-V2-Flash, Nemotron 3 Nano, Mistral Large 3, LLaDA 2.0 Diffusion LLM, MiniMax M2).
  • [2025/11] 🔥 SGLang Diffusion accelerates video and image generation (blog).
  • [2025/10] 🔥 SGLang now runs natively on TPU with the SGLang-Jax backend (blog).
  • [2025/09] Deploying DeepSeek on GB200 NVL72 with PD and Large Scale EP (Part II): 3.8x Prefill, 4.8x Decode Throughput (blog).
  • [2025/09] SGLang Day 0 Support for DeepSeek-V3.2 with Sparse Attention (blog).
  • [2025/08] SGLang x AMD SF Meetup on 8/22: Hands-on GPU workshop, tech talks by AMD/xAI/SGLang, and networking (Roadmap, Large-scale EP, Highlights, AITER/MoRI, Wave).
  • [2025/08] SGLang provides day-0 support for OpenAI gpt-oss model (instructions)
  • [2025/05] Deploying DeepSeek with PD Disaggregation and Large-scale Expert Parallelism on 96 H100 GPUs (blog).
More
  • [2025/10] PyTorch Conference 2025 SGLang Talk (slide).
  • [2025/10] SGLang x Nvidia SF Meetup on 10/2 (recap).
  • [2025/06] SGLang, the high-performance serving infrastructure powering trillions of tokens daily, has been awarded the third batch of the Open Source AI Grant by a16z (a16z blog).
  • [2025/06] Deploying DeepSeek on GB200 NVL72 with PD and Large Scale EP (Part I): 2.7x Higher Decoding Throughput (blog).
  • [2025/03] Supercharge DeepSeek-R1 Inference on AMD Instinct MI300X (AMD blog)
  • [2025/03] SGLang Joins PyTorch Ecosystem: Efficient LLM Serving Engine (PyTorch blog)
  • [2025/02] Unlock DeepSeek-R1 Inference Performance on AMD Instinct™ MI300X GPU (AMD blog)
  • [2025/01] SGLang provides day one support for DeepSeek V3/R1 models on NVIDIA and AMD GPUs with DeepSeek-specific optimizations. (instructions, AMD blog, 10+ other companies)
  • [2024/12] v0.4 Release: Zero-Overhead Batch Scheduler, Cache-Aware Load Balancer, Faster Structured Outputs (blog).
  • [2024/10] The First SGLang Online Meetup (slides).
  • [2024/09] v0.3 Release: 7x Faster DeepSeek MLA, 1.5x Faster torch.compile, Multi-Image/Video LLaVA-OneVision (blog).
  • [2024/07] v0.2 Release: Faster Llama3 Serving with SGLang Runtime (vs. TensorRT-LLM, vLLM) (blog).
  • [2024/02] SGLang enables 3x faster JSON decoding with compressed finite state machine (blog).
  • [2024/01] SGLang provides up to 5x faster inference with RadixAttention (blog).
  • [2024/01] SGLang powers the serving of the official LLaVA v1.6 release demo (usage).

About

SGLang is a high-performance serving framework for large language models and multimodal models. It is designed to deliver low-latency and high-throughput inference across a wide range of setups, from a single GPU to large distributed clusters. Its core features include:

  • Fast Runtime: Provides efficient serving with RadixAttention for prefix caching, a zero-overhead CPU scheduler, prefill-decode disaggregation, speculative decoding, continuous batching, paged attention, tensor/pipeline/expert/data parallelism, structured outputs, chunked prefill, quantization (FP4/FP8/INT4/AWQ/GPTQ), and multi-LoRA batching.
  • Broad Model Support: Supports a wide range of language models (Llama, Qwen, DeepSeek, Kimi, GLM, GPT, Gemma, Mistral, etc.), embedding models (e5-mistral, gte, mcdse), reward models (Skywork), and diffusion models (WAN, Qwen-Image), with easy extensibility for adding new models. Compatible with most Hugging Face models and OpenAI APIs.
  • Extensive Hardware Support: Runs on NVIDIA GPUs (GB200/B300/H100/A100/Spark), AMD GPUs (MI355/MI300), Intel Xeon CPUs, Google TPUs, Ascend NPUs, and more.
  • Active Community: SGLang is open-source and supported by a vibrant community with widespread industry adoption, powering over 400,000 GPUs worldwide.

Getting Started

Benchmark and Performance

Learn more in the release blogs: v0.2 blog, v0.3 blog, v0.4 blog, Large-scale expert parallelism, GB200 rack-scale parallelism.

Adoption and Sponsorship

SGLang has been deployed at large scale, generating trillions of tokens in production each day. It is trusted and adopted by a wide range of leading enterprises and institutions, including xAI, AMD, NVIDIA, Intel, LinkedIn, Cursor, Oracle Cloud, Google Cloud, Microsoft Azure, AWS, Atlas Cloud, Voltage Park, Nebius, DataCrunch, Novita, InnoMatrix, MIT, UCLA, the University of Washington, Stanford, UC Berkeley, Tsinghua University, Jam & Tea Studios, Baseten, and other major technology organizations across North America and Asia. As an open-source LLM inference engine, SGLang has become the de facto industry standard, with deployments running on over 400,000 GPUs worldwide. SGLang is currently hosted under the non-profit open-source organization LMSYS.

logo

Contact Us

For enterprises interested in adopting or deploying SGLang at scale, including technical consulting, sponsorship opportunities, or partnership inquiries, please contact us at sglang@lmsys.org

Acknowledgment

We learned the design and reused code from the following projects: Guidance, vLLM, LightLLM, FlashInfer, Outlines, and LMQL.

About

SGLang with the HSA (Hierarchical Sparse Attention) backend for HiLS-Attention — for speed benchmarking

Resources

Code of conduct

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages