Transformers documentation

SGLang

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.22.2).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

SGLang

SGLang은 대규모 언어 모델(LLM)을 위한 저지연, 고처리량 추론 엔진입니다. 에이전트 워크플로우를 구축하기 위한 프론트엔드 언어도 포함합니다.

model_impl="transformers"를 설정하여 Transformers 모델링 백엔드를 로드합니다.

import sglang as sgl

llm = sgl.Engine("meta-llama/Llama-3.2-1B-Instruct", model_impl="transformers")
print(llm.generate(["The capital of France is"], {"max_new_tokens": 20})[0])

온라인 서빙을 위해 sglang.launch_server 명령에 --model-impl transformers를 전달하세요.

python3 -m sglang.launch_server \
  --model-path meta-llama/Llama-3.2-1B-Instruct \
  --model-impl transformers \
  --host 0.0.0.0 \
  --port 30000

Transformers 통합

model_impl="transformers"를 설정하면 SGLang은 네이티브 모델 매칭을 건너뛰고 Transformers 모델을 직접 사용하도록 지시합니다.

  1. PreTrainedConfig.from_pretrained() loads the model’s config.json from the Hub or your Hugging Face cache.
  2. AutoModel.from_config()는 config를 기반으로 모델 클래스를 결정합니다.
  3. 로드 중 _attn_implementation은 "sglang"으로 설정됩니다. 이를 통해 attention 호출이 SGLang의 RadixAttention 커널을 통해 라우팅됩니다.
  4. SGLang의 병렬 선형 클래스는 텐서 병렬성을 지원하기 위해 선형 레이어를 대체합니다.
  5. load_weights 함수는 safetensors 파일에서 가중치를 가져와 모델에 채웁니다.

Transformers 모델 구조를 사용하면서 SGLang의 모든 최적화 혜택을 누릴 수 있습니다.

호환되는 모델은 SGLang이 어텐션 실행을 제어할 수 있도록 _supports_attention_backend=True를 요구합니다. 자세한 내용은 추론용 호환 모델 백엔드 구축 가이드를 참고하세요.

리소스

Update on GitHub