Kimi-Linear

Kimi-Linear

Kimi Linear은 하이브리드 선형 어텐션(linear attention) 아키텍처로, 짧은 컨텍스트, 긴 컨텍스트, 강화학습(RL) 스케일링 영역 전반에서 전통적인 전체 어텐션(full attention)보다 뛰어난 성능을 보여줘요. 이 페이지에서는 SGLang에서 Kimi-Linear를 설치·배포·호출하는 방법과 벤치마크 결과를 단계별로 설명해요.

출처: 문서

본문

AMD GPU Support (AMD GPU 지원)

1. Model Introduction (모델 소개)

Kimi Linear는 하이브리드 선형 어텐션 아키텍처로, 짧은(short), 긴(long), 강화학습(RL) 스케일링 영역을 포함한 다양한 컨텍스트에서 전통적인 전체 어텐션보다 뛰어나요. 핵심에는 Gated DeltaNet을 정제한 **Kimi Delta Attention (KDA)**이 있으며, 유한 상태 RNN 메모리 사용을 최적화하는 더 효율적인 게이팅 메커니즘을 도입해요.

이번 세대는 전반에 걸쳐 포괄적인 업그레이드를 제공해요.

  • Kimi Delta Attention (KDA): 세밀한 게이팅(finegrained gating)으로 gated delta rule을 정제한 선형 어텐션 메커니즘.
  • Hybrid Architecture: 3:1 KDA-to-global MLA 비율로 메모리 사용량을 줄이면서 전체 어텐션의 품질을 유지하거나 능가해요.
  • Superior Performance: 공정한 비교로 1.4T 토큰 훈련 실행에서 long-context와 RL 스타일 벤치마크를 포함한 다양한 작업에서 전체 어텐션을 능가해요.
  • High Throughput: 최대 6배 빠른 디코딩과 출력 토큰당 시간(TPOT)의 큰 감소를 달성해요.

자세한 내용은 공식 Kimi Linear GitHub 리포지토리를 참고해요.

2. SGLang Installation (SGLang 설치)

SGLang은 여러 설치 방법을 제공해요. 하드웨어 플랫폼과 요구사항에 따라 가장 적합한 설치 방법을 선택할 수 있어요.

설치 지침은 공식 SGLang 설치 가이드를 참고해요.

3. Model Deployment (모델 배포)

이 섹션은 빠른 배포에서 성능 최적화까지 단계별로 안내하며, 다양한 수준의 사용자를 위한 내용을 담고 있어요.

3.1 Basic Configuration

인터랙티브 명령 생성기: 아래 설정 선택기를 사용해 하드웨어 플랫폼, 모델 변형, 배포 전략, 사고 기능에 맞는 배포 명령을 자동으로 생성해요.

4. Model Invocation (모델 호출)

4.1 Basic Usage

기본 API 사용법과 요청 예시는 다음 자료를 참고해요.

4.2 Advanced Usage

4.2.1 도커 실행하기

docker pull lmsysorg/sglang:v0.5.7-rocm700-mi30x
docker run -d -it --ipc=host --network=host --privileged \
  --cap-add=CAP_SYS_ADMIN \
  --device=/dev/kfd --device=/dev/dri --device=/dev/mem \
  --group-add video --cap-add=SYS_PTRACE \
  --security-opt seccomp=unconfined \
  -v /:/work \
  -e SHELL=/bin/bash \
  --name Kimi-linear \
  lmsysorg/sglang:v0.5.7-rocm700-mi30x \
  /bin/bash

4.2.2 도커 내부 사전 설치 단계

pip install sentencepiece tiktoken

4.2.3 서버 실행하기

export SGLANG_ROCM_FUSED_DECODE_MLA=0

SGLANG_ROCM_FUSED_DECODE_MLA=0 python3 -m sglang.launch_server \
  --model-path moonshotai/Kimi-Linear-48B-A3B-Instruct \
  --tokenizer-path  moonshotai/Kimi-Linear-48B-A3B-Instruct \
  --tp 4 \
  --trust-remote-code

5. Benchmark (벤치마크)

5.1 Speed Benchmark (속도 벤치마크)

테스트 환경:

  • Hardware: AMD MI300X GPU
  • Model: Kimi-Linear-48B-A3B-Instruct
  • Tensor Parallelism: 4
  • sglang version: 0.5.7

모델 배포

SGLANG_ROCM_FUSED_DECODE_MLA=0 python3 -m sglang.launch_server \
  --model-path moonshotai/Kimi-Linear-48B-A3B-Instruct \
  --tokenizer-path  moonshotai/Kimi-Linear-48B-A3B-Instruct \
  --tp 4 \
  --trust-remote-code

5.1.1 저동시성 (Latency-Optimized)

  • 벤치마크 명령:
python3 -m sglang.bench_serving \
  --backend sglang \
  --model moonshotai/Kimi-Linear-48B-A3B-Instruct \
  --dataset-name random \
  --random-input-len 1000 \
  --random-output-len 1000 \
  --num-prompts 10 \
  --max-concurrency 1 \
  --request-rate inf
  • 테스트 결과:
============ Serving Benchmark Result ============
Backend:                                 sglang
Traffic request rate:                    inf
Max request concurrency:                 1
Successful requests:                     10
Benchmark duration (s):                  23.86
Total input tokens:                      6101
Total input text tokens:                 6101
Total input vision tokens:               0
Total generated tokens:                  4220
Total generated tokens (retokenized):    4001
Request throughput (req/s):              0.42
Input token throughput (tok/s):          255.70
Output token throughput (tok/s):         176.86
Peak output token throughput (tok/s):    190.00
Peak concurrent requests:                2
Total token throughput (tok/s):          432.56
Concurrency:                             1.00
----------------End-to-End Latency----------------
Mean E2E Latency (ms):                   2383.93
Median E2E Latency (ms):                 1911.63
---------------Time to First Token----------------
Mean TTFT (ms):                          141.33
Median TTFT (ms):                        126.27
P99 TTFT (ms):                           294.76
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          5.32
Median TPOT (ms):                        5.33
P99 TPOT (ms):                           5.36
---------------Inter-Token Latency----------------
Mean ITL (ms):                           5.33
Median ITL (ms):                         5.32
P95 ITL (ms):                            5.44
P99 ITL (ms):                            5.58
Max ITL (ms):                            11.46
==================================================

5.1.2 중간 동시성 (Balanced)

  • 벤치마크 명령:
python3 -m sglang.bench_serving \
  --backend sglang \
  --model moonshotai/Kimi-Linear-48B-A3B-Instruct \
  --dataset-name random \
  --random-input-len 1000 \
  --random-output-len 1000 \
  --num-prompts 80 \
  --max-concurrency 16 \
  --request-rate inf
  • 테스트 결과:
============ Serving Benchmark Result ============
Backend:                                 sglang
Traffic request rate:                    inf
Max request concurrency:                 16
Successful requests:                     80
Benchmark duration (s):                  31.38
Total input tokens:                      39668
Total input text tokens:                 39668
Total input vision tokens:               0
Total generated tokens:                  40805
Total generated tokens (retokenized):    39667
Request throughput (req/s):              2.55
Input token throughput (tok/s):          1264.13
Output token throughput (tok/s):         1300.37
Peak output token throughput (tok/s):    1801.00
Peak concurrent requests:                21
Total token throughput (tok/s):          2564.50
Concurrency:                             14.13
----------------End-to-End Latency----------------
Mean E2E Latency (ms):                   5543.18
Median E2E Latency (ms):                 5755.31
---------------Time to First Token----------------
Mean TTFT (ms):                          175.25
Median TTFT (ms):                        137.87
P99 TTFT (ms):                           292.92
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          10.75
Median TPOT (ms):                        10.87
P99 TPOT (ms):                           16.74
---------------Inter-Token Latency----------------
Mean ITL (ms):                           10.54
Median ITL (ms):                         7.95
P95 ITL (ms):                            13.68
P99 ITL (ms):                            116.80
Max ITL (ms):                            299.89
==================================================

5.1.3 고동시성 (Throughput-Optimized)

  • 벤치마크 명령:
python3 -m sglang.bench_serving \
  --backend sglang \
  --model moonshotai/Kimi-Linear-48B-A3B-Instruct \
  --dataset-name random \
  --random-input-len 1000 \
  --random-output-len 1000 \
  --num-prompts 500 \
  --max-concurrency 100 \
  --request-rate inf
  • 테스트 결과:
============ Serving Benchmark Result ============
Backend:                                 sglang
Traffic request rate:                    inf
Max request concurrency:                 100
Successful requests:                     500
Benchmark duration (s):                  79.71
Total input tokens:                      249831
Total input text tokens:                 249831
Total input vision tokens:               0
Total generated tokens:                  252662
Total generated tokens (retokenized):    228448
Request throughput (req/s):              6.27
Input token throughput (tok/s):          3134.20
Output token throughput (tok/s):         3169.72
Peak output token throughput (tok/s):    6109.00
Peak concurrent requests:                110
Total token throughput (tok/s):          6303.92
Concurrency:                             94.80
----------------End-to-End Latency----------------
Mean E2E Latency (ms):                   15113.92
Median E2E Latency (ms):                 13851.52
---------------Time to First Token----------------
Mean TTFT (ms):                          564.46
Median TTFT (ms):                        226.04
P99 TTFT (ms):                           2683.14
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          29.63
Median TPOT (ms):                        31.28
P99 TPOT (ms):                           38.84
---------------Inter-Token Latency----------------
Mean ITL (ms):                           28.85
Median ITL (ms):                         16.29
P95 ITL (ms):                            123.42
P99 ITL (ms):                            157.80
Max ITL (ms):                            2481.11
==================================================

5.2 Accuracy Benchmark (정확도 벤치마크)

5.2.1 GSM8K Benchmark

  • 서버 명령
SGLANG_ROCM_FUSED_DECODE_MLA=0 python3 -m sglang.launch_server \
  --model-path moonshotai/Kimi-Linear-48B-A3B-Instruct \
  --tokenizer-path  moonshotai/Kimi-Linear-48B-A3B-Instruct \
  --tp 4 \
  --trust-remote-code
  • 벤치마크 명령
python3 -m sglang.test.few_shot_gsm8k --num-questions 200
  • 결과:
Accuracy: 0.705
Invalid: 0.000
Latency: 11.855 s
Output throughput: 3224.982 token/s

더 알아보기 (Learn more)