Overview
Mini-SGLang supports distributed serving through Tensor Parallelism. By specifying the number of GPUs with the--tp flag, you can scale performance and handle larger models across multiple devices.
Tensor Parallelism is essential for serving large models (70B+ parameters) that exceed single GPU memory capacity. It also provides performance benefits through parallel computation.
How Tensor Parallelism Works
Weight Sharding
Model weights are split across GPUs. For linear layers, there are two main patterns: Column Parallel: Split output dimensionCommunication Patterns
Tensor parallelism requires collective communication between GPUs:- All-Reduce: Sum tensors from all GPUs and distribute result to all GPUs
- All-Gather: Concatenate tensors from all GPUs and distribute to all GPUs
Architecture
One Scheduler Per GPU
In a multi-GPU setup, there is one Scheduler Worker for each GPU, referred to as a TP Rank:Communication Flow
From/home/daytona/workspace/source/docs/structures.md:20:
- User sends a request to the API Server
- API Server forwards it to the Tokenizer
- Tokenizer converts text to tokens and sends them to the Scheduler (Rank 0)
- Scheduler (Rank 0) broadcasts the request to all other Schedulers
- All Schedulers schedule the request and trigger their local Engine to compute
- Engines communicate via NCCL to perform distributed computation
- Scheduler (Rank 0) collects the output token and sends it to the Detokenizer
- Detokenizer converts the token to text and sends it back to the API Server
- API Server streams the result back to the User
Only Rank 0 communicates with the tokenizer and detokenizer. Other ranks receive broadcasts from Rank 0 and participate in distributed computation.
Implementation
Distributed Communicator
Mini-SGLang provides aDistributedCommunicator abstraction:
PyTorch Distributed (Default)
PyNCCL (Optional)
Layer Implementation
Mini-SGLang implements TP-aware layers inminisgl.layers:
Column Parallel Linear
Splits the output dimension:- Attention QKV projections (split heads across GPUs)
- MLP up-projection (split intermediate dimension)
Row Parallel Linear
Splits the input dimension:- Attention output projection (reduce across heads)
- MLP down-projection (reduce across intermediate)
Embedding and LM Head
Embeddings and language model heads can also be parallelized:Performance Considerations
Communication Overhead
Tensor parallelism introduces communication overhead:- All-reduce: Required after row-parallel layers
- All-gather: Required for certain operations
- Latency: Network latency between GPUs affects performance
Scaling Efficiency
TP scaling efficiency depends on:- Model size: Larger models amortize communication overhead better
- Batch size: Larger batches improve arithmetic intensity
- Network topology: NVLink > PCIe for inter-GPU communication
- Sequence length: Longer sequences increase computation vs. communication ratio
When to Use TP
Good use cases:- Model doesn’t fit on single GPU (e.g., 70B, 405B parameter models)
- Low latency requirements (distribute computation)
- GPUs connected via high-bandwidth interconnect
- Pipeline Parallelism: For models that fit but need more throughput
- Quantization: Reduce memory footprint (e.g., INT8, INT4)
- Larger GPU: Single A100 (80GB) may be better than 2x A100 (40GB)
Configuration Examples
Small Model (Testing)
Medium Model
Large Model
Very Large Model
Custom Port
Benchmark Results
From Mini-SGLang’s online inference benchmark: Test Configuration:- Hardware: 4x H200 GPU, connected by NVLink
- Model: Qwen3-32B
- Dataset: Qwen trace, 1000 requests
Tensor parallelism enables serving large models with competitive performance.
Supported Models
Mini-SGLang currently supports TP for:- Llama-3 series: Llama-3.1-8B, Llama-3.1-70B, Llama-3.1-405B
- Qwen-3 series: Qwen3-0.6B, Qwen3-14B, Qwen3-32B (including MoE variants)
- Qwen-2.5 series: All sizes
Troubleshooting
NCCL Errors
If you see NCCL errors:GPU Visibility
Ensure all GPUs are visible:Out of Memory
If OOM occurs even with TP:Related Concepts
Architecture
Learn about the distributed system design
Chunked Prefill
Optimize memory usage in TP deployments
Radix Cache
Efficient KV cache management for TP
References
- Megatron-LM Paper: Original tensor parallelism technique
- NCCL Documentation: NVIDIA Collective Communications Library
- PyTorch Distributed: PyTorch distributed package