Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
#
# commit-msg hook: enforces [Tag] Description format on commit messages.
# Allowed tags: Feature, Fix, Refactor, Docs, Test, CI, Chore, Perf
# Minimum description length: 10 characters
#

COMMIT_MSG_FILE="$1"
COMMIT_MSG=$(head -1 "$COMMIT_MSG_FILE")

# Skip merge commits
if echo "$COMMIT_MSG" | grep -qE '^Merge '; then
exit 0
fi

# Reject Co-Authored-By or other trailers in the subject line
if echo "$COMMIT_MSG" | grep -qiE '(Co-Authored-By|Signed-off-by|Reviewed-by):'; then
echo ""
echo "ERROR: Trailer found in the commit subject line."
echo " Move 'Co-Authored-By:', 'Signed-off-by:', etc. to the commit body"
echo " (separated from the subject by a blank line)."
echo ""
echo " Example:"
echo " [Feature] Add new authentication flow"
echo " "
echo " Co-Authored-By: Name <email>"
echo ""
exit 1
fi

# Validate [Tag] Description format
PATTERN='^\[(Feature|Fix|Refactor|Docs|Test|CI|Chore|Perf)\] .{10,}'

if ! echo "$COMMIT_MSG" | grep -qE "$PATTERN"; then
echo ""
echo "ERROR: Commit message does not follow the required format."
echo ""
echo " Required: [Tag] Description (at least 10 characters)"
echo ""
echo " Allowed tags: [Feature], [Fix], [Refactor], [Docs], [Test], [CI], [Chore], [Perf]"
echo ""
echo " Examples:"
echo " [Feature] Add user authentication endpoint"
echo " [Fix] Resolve race condition in scheduler"
echo " [Refactor] Simplify model loading pipeline"
echo ""
echo " Your message: $COMMIT_MSG"
echo ""
exit 1
fi

exit 0
42 changes: 42 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
#
# pre-push hook: warns on direct pushes to main and validates last commit message.
#

REMOTE="$1"
BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null)

# Warn if pushing directly to main
if [ "$BRANCH" = "main" ] || [ "$BRANCH" = "master" ]; then
echo ""
echo "WARNING: You are pushing directly to '$BRANCH'."
echo " Consider using a feature branch and opening a pull request instead."
echo ""
fi

# Validate the last commit message format (catches --no-verify commits)
LAST_MSG=$(git log -1 --format='%s')

# Skip merge commits
if echo "$LAST_MSG" | grep -qE '^Merge '; then
exit 0
fi

PATTERN='^\[(Feature|Fix|Refactor|Docs|Test|CI|Chore|Perf)\] .{10,}'

if ! echo "$LAST_MSG" | grep -qE "$PATTERN"; then
echo ""
echo "ERROR: Last commit message does not follow the required format."
echo ""
echo " Required: [Tag] Description (at least 10 characters)"
echo " Allowed tags: [Feature], [Fix], [Refactor], [Docs], [Test], [CI], [Chore], [Perf]"
echo ""
echo " Last commit: $LAST_MSG"
echo ""
echo " Please amend your commit message before pushing:"
echo " git commit --amend"
echo ""
exit 1
fi

exit 0
3 changes: 3 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Summary
<!-- Describe what this PR does and why -->
-
45 changes: 45 additions & 0 deletions .github/workflows/pr-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: PR Lint

on:
pull_request:
types: [opened, edited, synchronize]

jobs:
validate-pr:
runs-on: ubuntu-latest
steps:
- name: Validate PR title
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
PATTERN='^\[(Feature|Fix|Refactor|Docs|Test|CI|Chore|Perf)\] .{10,}'
if ! echo "$PR_TITLE" | grep -qE "$PATTERN"; then
echo "::error::PR title must match format: [Tag] Description (at least 10 chars)"
echo ""
echo "Allowed tags: [Feature], [Fix], [Refactor], [Docs], [Test], [CI], [Chore], [Perf]"
echo ""
echo "Examples:"
echo " [Feature] Add user authentication endpoint"
echo " [Fix] Resolve race condition in scheduler"
echo ""
echo "Your title: $PR_TITLE"
exit 1
fi
echo "PR title is valid."

- name: Validate PR body
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
if ! echo "$PR_BODY" | grep -q '## Summary'; then
echo "::error::PR body must contain a '## Summary' section."
exit 1
fi

# Check that Summary section has content beyond the template placeholder
SUMMARY_CONTENT=$(echo "$PR_BODY" | sed -n '/## Summary/,/^## /p' | grep -v '## Summary' | grep -v '^## ' | grep -v '<!--.*-->' | sed '/^[[:space:]]*$/d' | sed '/^-$/d')
if [ -z "$SUMMARY_CONTENT" ]; then
echo "::error::PR Summary section must contain a description (not just the template placeholder)."
exit 1
fi
echo "PR body is valid."
55 changes: 16 additions & 39 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ SGLang is a high-performance serving framework for large language models (LLMs)
- **sgl-kernel/** — Optimized CUDA/C++ compute kernels
- **sgl-model-gateway/** — Rust-based routing/API gateway (OpenAI-compatible)

## Setup

After cloning, activate the git hooks:
```bash
bash setup-hooks.sh
```

## Commit & PR Conventions

All commit messages and PR titles must follow: `[Tag] Description` .

Allowed tags: `[Feature]`, `[Fix]`, `[Refactor]`, `[Docs]`, `[Test]`, `[CI]`, `[Chore]`, `[Perf]`

Trailers like `Co-Authored-By:` is not allowed to show nerither in the commit body or the subject line.

## Build & Development Commands

### Python package (main runtime)
Expand All @@ -23,11 +38,6 @@ cd sglang/sgl-kernel && make build
# Resource-limited: make build MAX_JOBS=2 CMAKE_ARGS="-DSGL_KERNEL_COMPILE_THREADS=1"
```

### sgl-model-gateway (Rust)
```bash
cd sglang/sgl-model-gateway && make build
```

### Running the server
```bash
python -m sglang.launch_server --model-path meta-llama/Llama-2-7b-hf
Expand All @@ -40,30 +50,8 @@ pre-commit run --all-files
```
Hooks: isort, ruff (F401/F821), black-jupyter, codespell, clang-format, nbstripout.

### Testing
```bash
# Single test file
python3 test/srt/test_srt_endpoint.py

# Single test case
python3 test/srt/test_srt_endpoint.py TestSRTEndpoint.test_simple_decode

# Test suite (per-commit)
python3 test/srt/run_suite.py --suite per-commit

# sgl-kernel tests
cd sglang/sgl-kernel && pytest tests/
```

## Architecture

### Frontend (`python/sglang/lang/`)
Language-level API for composing LLM programs. Key files:
- `api.py` — Public API exports (Engine, function, gen, etc.)
- `interpreter.py` — Program interpreter
- `ir.py` — Intermediate representation
- `backend/` — Backend connectors (OpenAI, Anthropic, LiteLLM, VertexAI, SGLang runtime)

### Serving Runtime (`python/sglang/srt/`)
The core inference engine. Major subsystems:
- **`entrypoints/`** — Engine entry points, gRPC server
Expand All @@ -83,9 +71,6 @@ The core inference engine. Major subsystems:
### sgl-kernel (`sgl-kernel/`)
CMake-based C++/CUDA project with Python bindings. Contains optimized kernels for attention, quantization, and other compute-intensive operations. Built via scikit-build-core.

### sgl-model-gateway (`sgl-model-gateway/`)
Rust async service (tokio/tonic) providing HTTP and gRPC routing, load balancing, and an OpenAI-compatible API layer. Has Python and Go bindings in `bindings/`.

### Key Design Patterns
- **RadixAttention**: Prefix-aware KV cache reuse across requests
- **Continuous batching**: Dynamic request scheduling for throughput
Expand All @@ -94,12 +79,4 @@ Rust async service (tokio/tonic) providing HTTP and gRPC routing, load balancing

## Version Management

Versions are managed via `setuptools-scm` from git tags. Generated gRPC files (`*_pb2.py`, `*_pb2_grpc.py`) are excluded from linting.

## Hardware Support

NVIDIA CUDA (primary), AMD ROCm/HIP, Intel Gaudi, Ascend NPU, Google TPU (experimental). Hardware-specific code lives in `srt/hardware_backend/`.

## Key Dependencies

PyTorch >= 2.8.0, Transformers 4.57.1, Flash Attention, Triton (kernels), FastAPI/Uvicorn (HTTP), tonic (gRPC/Rust), outlines/xgrammar/llguidance (structured generation).
Versions are managed via `setuptools-scm` from git tags. Generated gRPC files (`*_pb2.py`, `*_pb2_grpc.py`) are excluded from linting.
44 changes: 44 additions & 0 deletions configs/qwen3_coder_next_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"architectures": [
"Qwen3NextForCausalLM"
],
"attention_bias": false,
"attention_dropout": 0,
"bos_token_id": 151643,
"decoder_sparse_step": 1,
"eos_token_id": 151645,
"full_attention_interval": 4,
"head_dim": 256,
"hidden_act": "silu",
"hidden_size": 2048,
"initializer_range": 0.02,
"intermediate_size": 5120,
"linear_conv_kernel_dim": 4,
"linear_key_head_dim": 128,
"linear_num_key_heads": 16,
"linear_num_value_heads": 32,
"linear_value_head_dim": 128,
"max_position_embeddings": 262144,
"mlp_only_layers": [],
"model_type": "qwen3_next",
"moe_intermediate_size": 512,
"norm_topk_prob": true,
"num_attention_heads": 16,
"num_experts": 512,
"num_experts_per_tok": 10,
"num_hidden_layers": 48,
"num_key_value_heads": 2,
"output_router_logits": false,
"partial_rotary_factor": 0.25,
"rms_norm_eps": 1e-06,
"rope_scaling": null,
"rope_theta": 5000000,
"router_aux_loss_coef": 0.001,
"shared_expert_intermediate_size": 512,
"tie_word_embeddings": false,
"torch_dtype": "bfloat16",
"transformers_version": "4.57.0.dev0",
"use_cache": true,
"use_sliding_window": false,
"vocab_size": 151936
}
Loading
Loading