Transformers documentation
SGLang
시작하기
기본 클래스
모델
Preprocessors
추론
Pipeline API
Generate API
최적화
모델과 대화하기
서빙
학습
하드웨어
양자화
생태계 통합
리소스
API
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).
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 모델을 직접 사용하도록 지시합니다.
- PreTrainedConfig.from_pretrained() loads the model’s
config.jsonfrom the Hub or your Hugging Face cache. - AutoModel.from_config()는 config를 기반으로 모델 클래스를 결정합니다.
- 로드 중
_attn_implementation은"sglang"으로 설정됩니다. 이를 통해 attention 호출이 SGLang의 RadixAttention 커널을 통해 라우팅됩니다. - SGLang의 병렬 선형 클래스는 텐서 병렬성을 지원하기 위해 선형 레이어를 대체합니다.
- load_weights 함수는 safetensors 파일에서 가중치를 가져와 모델에 채웁니다.
Transformers 모델 구조를 사용하면서 SGLang의 모든 최적화 혜택을 누릴 수 있습니다.
호환되는 모델은 SGLang이 어텐션 실행을 제어할 수 있도록
_supports_attention_backend=True를 요구합니다. 자세한 내용은 추론용 호환 모델 백엔드 구축 가이드를 참고하세요.
리소스
- SGLang 문서에는 Transformers를 백엔드로 사용하는 방법에 대한 추가 사용 예시와 팁이 있습니다.
- Transformers backend integration in SGLang 블로그 포스트는 이 통합이 어떤 기능을 제공하는지 설명합니다.