मुख्य सामग्री पर जाएँ
Zubnet AIसीखेंWiki › SGLang
टूल्स

SGLang

इसे भी कहा जाता है: SGLang Runtime, SRT
SGLang large language models के लिए open-source serving engine है, जिसे production scale पर inference तेज़ तथा सस्ते में चलाने के लिए बनाया गया है। इसे UC Berkeley और LMSYS team से जुड़े researchers ने 2024 में release किया, और इसका signature idea RadixAttention है, ऐसी technique जो shared prompt prefixes वाली requests में cached computation reuse करती है। vLLM के साथ यह दो dominant open LLM serving stacks में से एक है।

यह क्यों मायने रखता है

Production में LLMs चलाते समय अधिकतर पैसा inference में जाता है और serving engine तय करता है कि हर request में कितना GPU burn होगा। SGLang का prefix reuse तथा fast structured decoding shared system prompts, multi-turn chats या JSON output वाले workloads में cost और latency तेज़ी से घटा सकता है। Very large open models, जिनमें DeepSeek-scale mixture-of-experts deployments शामिल हैं जहाँ naive serving टूट जाती है, को serve करने के लिए भी यह common choice बन गया है।

गहन अध्ययन

SGLang समझने के लिए हर इन्फ़ेरेंस engine की problem समझना helpful है। Autoregressive decoding एक समय में एक token generate करती है, और हर token को model के full weights तथा अब तक generate हर चीज़ का KV Cache पढ़ना पड़ता है, जिससे decoding compute-bound के बजाय memory-bandwidth-bound होती है। इसलिए महत्वपूर्ण lever raw FLOPs नहीं बल्कि कितनी requests साथ batch हो सकती हैं और redundant work कितना कम होता है। SGLang दोनों sides पर काम करता है: किसी modern engine की तरह requests efficiently batch तथा schedule करता है, और यह पहचानकर आगे जाता है कि real production traffic shared structure — वही system prompt, वही few-shot examples और वही chat history — से भरा है जिसे naive engines हर single request में शुरुआत से recompute करते हैं।

RadixAttention और Prefix Reuse

RadixAttention SGLang का defining contribution है। Engine KV cache को token sequences से keyed radix tree में रखता है, इसलिए recently computed चीज़ से prefix share करने वाली नई request आने पर — system prompt, document या conversation का earlier turn — engine उसे recompute करने के बजाय existing cache entries reuse करता है। SGLang इसे cache-aware scheduling के साथ जोड़ता है जो overlapping prefixes वाली requests को same replica पर चलाना prefer करता है, जिससे cache hit rates बढ़ती हैं। Long shared prompts या heavy multi-turn traffic वाले workloads में यह stateless serving के मुकाबले latency काफ़ी घटा और throughput बढ़ा सकता है। Idea API providers द्वारा Prompt Caching के रूप में बेची चीज़ से related है, लेकिन यहाँ यह automatically engine के भीतर होता है और vLLM समेत दूसरे engines ने तब से अपने prefix-reuse mechanisms अपनाए हैं।

तेज़ Structured Output

SGLang का दूसरा headline feature fast स्ट्रक्चर्ड आउटपुट है। Constrained decoding हर step पर illegal tokens mask करके model को grammar या JSON schema follow करने को मजबूर करती है, और naive implementations noticeable per-token overhead जोड़ती हैं। SGLang इसे grammar के compressed finite-state machine और output के deterministic हिस्सों — fixed keys, brackets और whitespace — में आगे jump करने वाली technique से optimize करता है, एक बार में एक के बजाय कई tokens emit करके। यह जितना लगता है उससे अधिक मायने रखता है: agent pipelines, Function Calling और data-extraction jobs JSON की enormous volumes generate करते हैं, और उस decoding पर 2–5x speedup सीधे सस्ते तथा snappier agents में बदलता है।

SGLang बनाम vLLM

स्पष्ट comparison दूसरे dominant open-source vLLM, यानी Model Serving engine, से है। दोनों Python-based हैं, continuous batching, GPUs में tensor parallelism, quantization तथा speculative decoding करते हैं और OpenAI-compatible API expose करते हैं। vLLM बड़ा ecosystem रखने वाला पुराना project है और PagedAttention, KV cache memory management का block-based approach, के इर्द-गिर्द बना है; SGLang अक्सर RadixAttention तथा constrained-decoding stack के कारण prefix-heavy traffic तथा structured output में आगे निकलता है। दोनों के benchmarks हर release, model family और hardware generation के साथ बदलते हैं, इसलिए practitioner answer boring लेकिन सच है: दोनों को shortlist करके अपने workload पर measure करें। कई inference platforms ठीक इसी कारण दोनों backends quietly support करते हैं।

Faster का अर्थ Smarter नहीं

एक आम गलतफ़हमी है कि serving engines switch करने से model की capabilities बदलती हैं। ऐसा नहीं है। SGLang serving layer है, model या training framework नहीं — SGLang, vLLM या किसी अन्य engine से serve किए same weights लगभग same answers बनाते हैं। Engine switch के बाद model के "better" या "worse" होने की reports में वास्तविक कारण आम तौर पर अलग क्वांटाइज़ेशन settings, truncated context window या temperature जैसे बदले sampling defaults होते हैं। Good engine efficiency खरीदता है: per GPU अधिक requests, lower time-to-first-token और higher tokens per second। यह cost तथा product-latency की कहानी है, capability की नहीं, और इसीलिए engine choice model-quality decision के बजाय infrastructure decision है।

DeepSeek Effect

Very large मिक्सचर ऑफ़ एक्सपर्ट्स models, खासकर DeepSeek के V3 तथा R1, आने पर SGLang का profile तेज़ी से बढ़ा, क्योंकि इन्हें serve करना बेहद कठिन है: hundreds of billions total parameters, कई GPUs में expert parallelism और older serving stacks में बनी assumptions तोड़ने वाला attention design। SGLang ने इन models को अच्छी तरह support करने में जल्दी और भारी investment किया और open community तथा inference providers, दोनों में DeepSeek-scale deployments का go-to engine बन गया। वह reputation बनी रही: जब कोई large new open-weights model आता है, SGLang में first-day support अब वैसी चीज़ है जिसे practitioners actively देखते हैं, जैसे vLLM support देखते हैं। LMSYS ecosystem — Chatbot Arena के पीछे वही community — में project की origins ने उसे पहले दिन से research crowd में credibility भी दी।

← सभी शब्द
ESC