DeepSeek-Math-V2

DeepSeek-Math-V2

이 문서는 DeepSeek의 고급 수학 추론 모델인 DeepSeek-Math-V2를 SGLang으로 배포하고 호출하는 방법을 설명해요. 이 모델은 강력한 정리 증명 능력을 갖추고 있으며, 수학 대회에서 탁월한 성능을 보여줘요. 원문 페이지에는 하드웨어 플랫폼, 추론 파서, DP Attention 옵션을 골라 명령을 자동 생성해 주는 대화형 선택기(Interactive Command Generator)가 포함되어 있어요.

출처: 문서

본문

1. 모델 소개

DeepSeek-Math-V2는 DeepSeek의 고급 수학 추론 모델로, 강력한 정리 증명 능력을 갖추고 있어요. 이 모델은 수학 대회에서 뛰어난 성능을 보여주며, IMO 2025와 CMO 2024에서 금메달 수준의 점수를 달성했고, 확장된 테스트 시점 연산(scaled test-time compute)으로 Putnam 2024에서 118/120이라는 거의 만점에 가까운 점수를 기록했어요.

주요 특징:

  • 강력한 정리 증명 (Strong Theorem-Proving): IMO 2025와 CMO 2024에서 금메달 수준 성능
  • 자가 검증 추론 (Self-Verifiable Reasoning): 정확도 향상을 위한 자가 검증 수학 추론 구현
  • 대회 수준 수학 (Competition-Level Math): Putnam 2024에서 거의 만점(118/120)
  • 대형 MoE 모델 (Large MoE Model): 약 6,710억(671B) 개의 총 파라미터, 고용량 GPU(B200 183GB 또는 B300 275GB) 필요

사용 가능한 모델:

라이선스: DeepSeek-Math-V2를 사용하려면 DeepSeek 커뮤니티 라이선스에 동의해야 해요. 자세한 내용은 LICENSE를 참고하세요.

2. SGLang 설치

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

3. 모델 배포

이 섹션은 서로 다른 하드웨어 플랫폼과 사용 사례에 최적화된 배포 설정을 제공해요.

3.1 기본 설정

대화형 명령 생성기 (Interactive Command Generator): 아래 설정 선택기를 사용해 하드웨어 플랫폼, 양자화 방법, 배포 전략에 맞는 배포 명령을 자동으로 생성할 수 있어요. (대화형 위젯은 원문 페이지에서 동작하므로, 기본 설정 기준 명령은 다음과 같아요.)

sglang serve --model-path deepseek-ai/DeepSeek-Math-V2 \
  --tp 8 \
  --ep 8 \
  --reasoning-parser deepseek-r1 \
  --host 0.0.0.0 \
  --port 30000

경고 DeepSeek-Math-V2는 DeepSeek-V3.2를 기반으로 하며 DSA sparse attention을 사용해요. 여기 있는 모든 레시피는 기본 --dsa-topk-backend sgl-kernel로 DSA indexer top-k를 실행해요. 다른 top-k 백엔드 선택은 이 모델에서 완전히 검증되지 않았어요.

3.2 설정 팁

하드웨어 요구 사항:

  • B200 (183GB): BF16 tp=8
  • B300 (275GB): BF16 tp=8

DP Attention:

  • 높은 처리량 시나리오에서는 DP attention을 활성화하세요
  • --dp 값은 일반적으로 --tp 값과 일치해요
  • 트레이드오프: 지연 시간이 약간 늘어나는 대신 처리량이 높아져요

4. 모델 호출

4.1 배포 명령

위에서 생성한 명령으로 모델을 배포하세요. B200 예시:

sglang serve --model-path deepseek-ai/DeepSeek-Math-V2 \
  --tp 8 \
  --ep 8 \
  --reasoning-parser deepseek-r1 \
  --host 0.0.0.0 \
  --port 30000

4.2 수학적 추론

DeepSeek-Math-V2는 단계별 추론을 통한 수학 문제 해결에 뛰어나요.

사고 과정이 포함된 스트리밍:

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:30000/v1",
    api_key="EMPTY"
)

# Mathematical reasoning problem
response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-Math-V2",
    messages=[
        {"role": "user", "content": "Prove that for any positive integer n, the sum 1 + 2 + 3 + ... + n = n(n+1)/2"}
    ],
    max_tokens=4096,
    stream=True
)

# Process the stream
thinking_started = False
has_thinking = False
has_answer = False

for chunk in response:
    if chunk.choices and len(chunk.choices) > 0:
        delta = chunk.choices[0].delta

        # Print thinking process
        if hasattr(delta, 'reasoning_content') and delta.reasoning_content:
            if not thinking_started:
                print("=============== Thinking =================", flush=True)
                thinking_started = True
            has_thinking = True
            print(delta.reasoning_content, end="", flush=True)

        # Print answer content
        if delta.content:
            if has_thinking and not has_answer:
                print("\n=============== Content =================", flush=True)
                has_answer = True
            print(delta.content, end="", flush=True)

print()

출력 예시:

=============== Thinking =================
We need to prove that for any positive integer n, the sum 1 + 2 + 3 + ... + n = n(n+1)/2.

This is a classic formula for the sum of the first n natural numbers. We can prove by induction.

Base case: n=1, LHS = 1, RHS = 1*(1+1)/2 = 1*2/2 = 1. Holds.

Inductive step: Assume true for n = k, i.e., 1 + 2 + ... + k = k(k+1)/2. Then for n = k+1, sum = 1 + 2 + ... + k + (k+1) = [k(k+1)/2] + (k+1) = (k(k+1) + 2(k+1))/2 = (k+1)(k+2)/2 = (k+1
)((k+1)+1)/2. So holds for k+1. By induction, holds for all positive integers n.

...
=============== Content =================
We can prove the well-known formula for the sum of the first \(n\) positive integers in several ways. Two of the most elementary are presented below.

---

### 1. Proof by mathematical induction

**Base case (\(n=1\))**:
\[
1 = \frac{1\cdot(1+1)}{2}= \frac{1\cdot2}{2}=1,
\]
so the formula holds for \(n=1\).

**Inductive hypothesis:**
Assume that for some positive integer \(k\) the formula is true, i.e.
\[
1+2+\dots+k = \frac{k(k+1)}{2}.
\]

**Inductive step (\(k \to k+1\))**:
Consider the sum up to \(k+1\):
\[
\begin{aligned}
1+2+\dots+k+(k+1) &= \bigl(1+2+\dots+k\bigr) + (k+1) \\[4pt]
&= \frac{k(k+1)}{2} + (k+1) \qquad\text{(by the induction hypothesis)}\\[4pt]
&= (k+1)\left(\frac{k}{2}+1\right)\\[4pt]
&= (k+1)\frac{k+2}{2}\\[4pt]
&= \frac{(k+1)(k+2)}{2}\\[4pt]
&= \frac{(k+1)\bigl((k+1)+1\bigr)}{2}.
\end{aligned}
\]
Thus the formula also holds for \(n=k+1\).

By the principle of mathematical induction,
\[
1+2+3+\dots+n = \frac{n(n+1)}{2}
\]
for every positive integer \(n\).

---

### 2. Proof by pairing (Gauss’s trick)

Let
\[
S = 1 + 2 + 3 + \dots + n.
\]

Write the same sum in reverse order:
\[
S = n + (n-1) + (n-2) + \dots + 1.
\]

Add the two equalities term‑by‑term:
\[
\begin{aligned}
2S &= (1+n) + \bigl(2+(n-1)\bigr) + \bigl(3+(n-2)\bigr) + \dots + (n+1)\\
    &= \underbrace{(n+1)+(n+1)+\dots+(n+1)}_{n\ \text{times}}\\
    &= n\,(n+1).
\end{aligned}
\]

Therefore
\[
S = \frac{n(n+1)}{2}.
\]

Both proofs are rigorous and show that the formula holds for all positive integers \(n\).

4.3 대회 수준 문제

예시: IMO 스타일 문제:

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:30000/v1",
    api_key="EMPTY"
)

# IMO-style problem
response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-Math-V2",
    messages=[
        {"role": "user", "content": "Let a, b, c be positive real numbers such that abc = 1. Prove that (a-1+1/b)(b-1+1/c)(c-1+1/a) <= 1."}
    ],
    max_tokens=8192,
    stream=True
)

# Process the stream
thinking_started = False
has_thinking = False
has_answer = False

for chunk in response:
    if chunk.choices and len(chunk.choices) > 0:
        delta = chunk.choices[0].delta

        if hasattr(delta, 'reasoning_content') and delta.reasoning_content:
            if not thinking_started:
                print("=============== Thinking =================", flush=True)
                thinking_started = True
            has_thinking = True
            print(delta.reasoning_content, end="", flush=True)

        if delta.content:
            if has_thinking and not has_answer:
                print("\n=============== Content =================", flush=True)
                has_answer = True
            print(delta.content, end="", flush=True)

print()

출력 예시:

=============== Thinking =================
We need to prove that for positive real numbers a,b,c with abc = 1, we have:

\[
(a - 1 + \frac{1}{b})(b - 1 + \frac{1}{c})(c - 1 + \frac{1}{a}) \le 1.
\]

We can rewrite the expressions: Since abc=1, we have 1/b = ac, 1/c = ab, 1/a = bc. Wait careful: abc=1 => 1/b = ac? Actually 1/b = ac? Let's check: abc=1 => ac = 1/b? Multiply both sides by something: abc=1 => (ac) b = 1 => ac = 1/b. Yes, because (ac) * b = 1 => ac = 1/b. Similarly, ab = 1/c, bc = 1/a. So we can rewrite:

...
=============== Content =================

We are given positive real numbers \(a,b,c\) with \(abc=1\). We must prove

\[
\Bigl(a-1+\frac1b\Bigr)\Bigl(b-1+\frac1c\Bigr)\Bigl(c-1+\frac1a\Bigr)\le 1 .
\]

---

### 1.  A convenient substitution

Because \(abc=1\), we can write

\[
a=\frac{x}{y},\qquad b=\frac{y}{z},\qquad c=\frac{z}{x}
\]

with positive numbers \(x,y,z\).
(For instance, take \(x=1,\;y=\frac1a,\;z=\frac1{ab}\); then indeed \(a=\frac{x}{y},\;b=\frac{y}{z}\) and, using \(abc=1\), we obtain \(c=\frac{z}{x}=\frac1{ab}=c\).)

---

### 2.  Rewriting the factors

\[
\begin{aligned}
a-1+\frac1b &=\frac{x}{y}-1+\frac{z}{y}= \frac{x+z-y}{y},\\[2mm]
b-1+\frac1c &=\frac{y}{z}-1+\frac{x}{z}= \frac{x+y-z}{z},\\[2mm]
c-1+\frac1a &=\frac{z}{x}-1+\frac{y}{x}= \frac{y+z-x}{x}.
\end{aligned}
\]

Hence the product becomes

\[
P=\Bigl(a-1+\frac1b\Bigr)\Bigl(b-1+\frac1c\Bigr)\Bigl(c-1+\frac1a\Bigr)
   =\frac{(x+z-y)(x+y-z)(y+z-x)}{xyz}.
\]

---

### 3.  Reducing to a known inequality

We have to show \(P\le1\), i.e.

\[
(x+z-y)(x+y-z)(y+z-x)\le xyz .
\tag{1}
\]

Set

\[
p=x+y+z,\qquad q=xy+yz+zx,\qquad r=xyz .
\]

Notice that

\[
x+z-y=p-2y,\quad x+y-z=p-2z,\quad y+z-x=p-2x .
\]

Therefore

\[
\begin{aligned}
(x+z-y)(x+y-z)(y+z-x)
&=(p-2x)(p-2y)(p-2z)\\
&=p^{3}-2p^{2}(x+y+z)+4p(xy+yz+zx)-8xyz\\
&=-p^{3}+4pq-8r .
\end{aligned}
\]

Inequality (1) is thus equivalent to

\[
-p^{3}+4pq-8r\le r\quad\Longleftrightarrow\quad 4pq-p^{3}\le 9r .
\tag{2}
\]

---

### 4.  Applying Schur’s inequality

Schur’s inequality of third degree states that for any non‑negative \(x,y,z\)

\[
p^{3}+9r\ge 4pq .
\]

Rearranged, this is exactly \(4pq-p^{3}\le 9r\), which is (2).
Since our \(x,y,z\) are positive, Schur’s inequality applies and (2) holds.

Consequently (1) is true, and we obtain \(P\le1\).

---

### 5.  Equality case

Equality in Schur’s inequality for positive numbers occurs only when \(x=y=z\).
Then \(a=b=c=1\), and indeed the product equals \(1\).

---

Thus for all positive \(a,b,c\) with \(abc=1\),

\[
\Bigl(a-1+\frac1b\Bigr)\Bigl(b-1+\frac1c\Bigr)\Bigl(c-1+\frac1a\Bigr)\le 1 .
\]

∎

5. 벤치마크

5.1 정확도 벤치마크

5.1.1 GSM8K 벤치마크

벤치마크 명령:

python3 benchmark/gsm8k/bench_sglang.py --num-questions 200 --port 30000

테스트 결과:

Accuracy: 0.975
Invalid: 0.000
Latency: 34.358 s
Output throughput: 540.162 token/s

5.2 속도 벤치마크

테스트 환경:

  • 하드웨어: NVIDIA B200 GPU (8x, 183GB each)
  • 모델: DeepSeek-Math-V2
  • 텐서 병렬화(Tensor Parallelism): 8
  • SGLang 버전: 0.5.8

5.2.1 지연 시간 벤치마크

벤치마크 명령:

python3 -m sglang.bench_serving \
  --backend sglang \
  --host 127.0.0.1 \
  --port 30000 \
  --model deepseek-ai/DeepSeek-Math-V2 \
  --random-input-len 1024 \
  --random-output-len 1024 \
  --num-prompts 10 \
  --max-concurrency 1

테스트 결과:

============ Serving Benchmark Result ============
Backend:                                 sglang
Traffic request rate:                    inf
Max request concurrency:                 1
Successful requests:                     10
Benchmark duration (s):                  53.34
Total input tokens:                      1972
Total input text tokens:                 1972
Total generated tokens:                  2784
Total generated tokens (retokenized):    2778
Request throughput (req/s):              0.19
Input token throughput (tok/s):          36.97
Output token throughput (tok/s):         52.19
Peak output token throughput (tok/s):    56.00
Peak concurrent requests:                3
Total token throughput (tok/s):          89.16
Concurrency:                             1.00
----------------End-to-End Latency----------------
Mean E2E Latency (ms):                   5330.72
Median E2E Latency (ms):                 5879.28
P90 E2E Latency (ms):                    8320.33
P99 E2E Latency (ms):                    9921.29
---------------Time to First Token----------------
Mean TTFT (ms):                          183.38
Median TTFT (ms):                        177.92
P99 TTFT (ms):                           217.64
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          17.96
Median TPOT (ms):                        18.39
P99 TPOT (ms):                           19.03
---------------Inter-Token Latency----------------
Mean ITL (ms):                           18.57
Median ITL (ms):                         18.63
P95 ITL (ms):                            19.26
P99 ITL (ms):                            19.48
Max ITL (ms):                            24.93
==================================================

5.2.2 처리량 벤치마크

벤치마크 명령:

python3 -m sglang.bench_serving \
  --backend sglang \
  --host 127.0.0.1 \
  --port 30000 \
  --model deepseek-ai/DeepSeek-Math-V2 \
  --random-input-len 1024 \
  --random-output-len 1024 \
  --num-prompts 1000 \
  --max-concurrency 100

테스트 결과:

============ Serving Benchmark Result ============
Backend:                                 sglang
Traffic request rate:                    inf
Max request concurrency:                 100
Successful requests:                     1000
Benchmark duration (s):                  217.36
Total input tokens:                      301701
Total input text tokens:                 301701
Total generated tokens:                  188375
Total generated tokens (retokenized):    187456
Request throughput (req/s):              4.60
Input token throughput (tok/s):          1388.05
Output token throughput (tok/s):         866.67
Peak output token throughput (tok/s):    2589.00
Peak concurrent requests:                109
Total token throughput (tok/s):          2254.72
Concurrency:                             89.81
----------------End-to-End Latency----------------
Mean E2E Latency (ms):                   19521.73
Median E2E Latency (ms):                 12076.76
P90 E2E Latency (ms):                    47248.87
P99 E2E Latency (ms):                    86862.79
---------------Time to First Token----------------
Mean TTFT (ms):                          790.40
Median TTFT (ms):                        456.81
P99 TTFT (ms):                           4223.33
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          106.52
Median TPOT (ms):                        107.24
P99 TPOT (ms):                           238.33
---------------Inter-Token Latency----------------
Mean ITL (ms):                           100.29
Median ITL (ms):                         38.34
P95 ITL (ms):                            237.00
P99 ITL (ms):                            347.49
Max ITL (ms):                            3642.56
==================================================