Mistral Small 4

Mistral Small 4

Mistral Small 4는 Mistral AI의 강력한 하이브리드 모델로, Instruct, Reasoning(이전 Magistral), Agentic(이전 Devstral)이라는 세 모델 계열의 기능을 하나로 통합한 모델이에요. 이 페이지에서는 SGLang에서 Mistral Small 4를 설치·배포·호출하는 방법과 벤치마크, EAGLE 추측 디코딩까지 상세히 안내해요.

출처: 문서

본문

1. Model Introduction (모델 소개)

Mistral Small 4는 Mistral AI의 강력한 하이브리드 모델로, 세 가지 서로 다른 모델 계열 — Instruct, Reasoning(이전 이름 Magistral), Agentic(이전 이름 Devstral) — 의 기능을 단일 통합 모델로 합쳤어요.

멀티모달 기능, 효율적인 MoE 아키텍처, 유연한 모드 전환 덕분에 Mistral Small 4는 거의 모든 작업에 적합한 범용 모델이에요. 지연-최적화(latency-optimized) 설정에서는 end-to-end 완료 시간이 40% 줄고, 처리량-최적화(throughput-optimized) 설정에서는 Mistral Small 3에 비해 초당 요청이 3배 많아져요.

주요 특징:

  • 하이브리드 추론: 즉시 응답 모드와 깊은 추론/사고 모드를 전환 — 추론 강도는 요청마다 설정 가능
  • 비전: 텍스트와 이미지 입력을 모두 받아 시각적 내용을 바탕으로 통찰 제공
  • 함수 호출: 네이티브 툴 호출과 JSON 출력 지원, 최고 수준의 에이전트 기능
  • 다국어: 영어, 프랑스어, 스페인어, 독일어, 중국어, 일본어, 한국어, 아랍어 등 수십 개 언어 지원
  • 컨텍스트 윈도우: 256K
  • 효율적 MoE: 총 119B 파라미터, 128 experts, 토큰당 4개 활성(활성화 6.5B 파라미터)
  • Apache 2.0 라이선스: 오픈소스로 상업·비상업 목적 사용·수정 가능
  • 지원되는 reasoning effort는 "none"과 "high"뿐이에요

아키텍처:

  • Mistral 3와 같은 일반 아키텍처
  • MoE: 128 experts, 토큰당 4개 활성
  • 총 119B 파라미터, 토큰당 6.5B 활성화
  • 멀티모달 입력: 텍스트 + 이미지

모델:

2. SGLang Installation (SGLang 설치)

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

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

Mistral Small 4 지원은 [sgl-project/sglang#20708](https://github.com/sgl-project/sglang/pull/20708)에서 추가되어 `main`에 병합되었어요. 더 이상 모델 전용 Docker 이미지가 필요하지 않아요. [공식 설치 가이드](../../../docs/get-started/install)의 표준 SGLang 설치 방법을 사용해요.

3. Model Deployment (모델 배포)

3.1 Basic Configuration

인터랙티브 명령 생성기: 아래 설정 선택기를 사용해 Mistral Small 4용 실행 명령을 생성해요.

3.2 Configuration Tips

  • Tensor Parallelism: Mistral Small 4 FP8(약 119 GB)은 Hopper(H100/H200)에서 tp=2, Blackwell(B200/B300)에서 tp=1이 필요해요. NVFP4(약 60 GB, Blackwell 전용)는 tp=1로 실행돼요.
  • 추론 강도: reasoning_effort("none", "high")로 요청마다 추론 깊이를 설정할 수 있어요. 재시작 없이 호출마다 전환 가능해요.
  • 컨텍스트 길이와 메모리: 모델은 256K 컨텍스트 윈도우를 가져요. 메모리가 부족하면 --context-length(예: 32768)를 낮춰 시작하고 안정되면 늘려요.
  • 툴 호출: --tool-call-parser mistral을 활성화해 네이티브 함수 호출을 지원해요.
  • 추론 파서: --reasoning-parser mistral을 활성화하면 reasoning_content를 메인 응답 콘텐츠와 분리해요.
  • 추측 디코딩 (EAGLE): EAGLE 가중치--speculative-algorithm EAGLE --speculative-draft-model-path mistralai/Mistral-Small-4-119B-2603-eagle을 활성화해 지연 시간을 낮춰요.

4. Model Invocation (모델 호출)

4.1 Thinking Mode

Mistral Small 4는 하이브리드 추론 모델이에요. 기본적으로 추론 응답을 생성하지 않아요. --reasoning_effort high로 추론을 켜요.

from openai import OpenAI

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

response = client.chat.completions.create(
    model="mistralai/Mistral-Small-4-119B-2603",
    messages=[
        {"role": "user", "content": "Solve step by step: what is 17 × 23 + 144 / 12?"},
    ],
    extra_body={"reasoning_effort": "high"},
)

print("Reasoning:", response.choices[0].message.reasoning_content)
print("Answer:", response.choices[0].message.content)

출력:

Reasoning: First, I'll break down the problem into two parts: the multiplication and
the division. According to the order of operations (PEMDAS/BODMAS), multiplication and
division are performed from left to right before addition.

17 × 23 = 17 × (20 + 3) = (17 × 20) + (17 × 3) = 340 + 51 = 391
144 / 12 = 12

Finally, add the results: 391 + 12 = 403

Answer: The solution to the problem is as follows:

1. First, perform the multiplication: 17 × 23.
   - 17 × 20 = 340
   - 17 × 3 = 51
   - 340 + 51 = 391

2. Then, perform the division: 144 / 12 = 12.

3. Finally, add the results:
   - 391 + 12 = 403

**Answer:** \boxed{403}

4.2 Instruct Mode (Reasoning Off)

추론 트레이스를 건너뛰고 빠른 직접 응답을 받으려면 reasoning_effort"none"으로 설정해요.

from openai import OpenAI

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

response = client.chat.completions.create(
    model="mistralai/Mistral-Small-4-119B-2603",
    messages=[
        {"role": "user", "content": "Write a Python function to reverse a string."},
    ],
    extra_body={"reasoning_effort": "none"},
)

print(response.choices[0].message.content)

출력:

# Python Function to Reverse a String

Here are several ways to write a Python function to reverse a string:

## Method 1: Using String Slicing (Most Pythonic)
```python
def reverse_string(s):
    """Reverse a string using slicing."""
    return s[::-1]
```

## Method 2: Using a Loop
```python Example
def reverse_string(s):
    """Reverse a string using a loop."""
    reversed_str = ""
    for char in s:
        reversed_str = char + reversed_str
    return reversed_str
```

## Method 3: Using reversed() function
```python Example
def reverse_string(s):
    """Reverse a string using reversed() function."""
    return ''.join(reversed(s))
```

The first method using string slicing (`s[::-1]`) is generally the most efficient and
recommended approach in Python.

Example usage:
```python Example
original = "Hello, World!"
reversed_str = reverse_string(original)
print(reversed_str)  # Output: "!dlroW ,olleH"
```

4.3 Streaming with Reasoning

from openai import OpenAI

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

stream = client.chat.completions.create(
    model="mistralai/Mistral-Small-4-119B-2603",
    messages=[
        {"role": "user", "content": "Explain the difference between async and threading in Python."},
    ],
    extra_body={"reasoning_effort": "high"},
    stream=True,
)

print("=== Reasoning ===")
for chunk in stream:
    delta = chunk.choices[0].delta
    if hasattr(delta, "reasoning_content") and delta.reasoning_content:
        print(delta.reasoning_content, end="", flush=True)
    elif delta.content:
        print("\n=== Response ===")
        print(delta.content, end="", flush=True)
print()

출력:

=== Reasoning ===
Okay, the user is asking about the difference between async and threading in Python.
I need to break this down clearly, covering the key aspects of both, like their
purposes, performance characteristics, and use cases...
=== Response ===
In Python, **`async`/`asyncio`** and **`threading`** are two different concurrency
models, each suited for specific use cases. Here's a breakdown of their key differences:

### 1. Model of Concurrency
- **Threading**: Based on preemptive multitasking using OS threads.
- **Async** (`asyncio`): Based on cooperative multitasking. Tasks voluntarily yield...

4.4 Tool Calling

Mistral Small 4는 네이티브 함수 호출을 지원해요. --tool-call-parser mistral로 활성화해요.

from openai import OpenAI

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

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get the current weather for a city",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {"type": "string", "description": "City name"},
                    "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
                },
                "required": ["location"],
            },
        },
    }
]

response = client.chat.completions.create(
    model="mistralai/Mistral-Small-4-119B-2603",
    messages=[{"role": "user", "content": "What's the weather in Paris?"}],
    tools=tools,
    tool_choice="auto",
)

tool_calls = response.choices[0].message.tool_calls
for tc in tool_calls:
    print(f"Tool: {tc.function.name}")
    print(f"Args: {tc.function.arguments}")

출력:

Tool: get_weather
Args: {"location": "Paris"}

4.5 Vision (Image Input)

Mistral Small 4는 텍스트와 함께 이미지 입력을 받아요.

from openai import OpenAI

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

response = client.chat.completions.create(
    model="mistralai/Mistral-Small-4-119B-2603",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Describe what you see in this image."},
                {
                    "type": "image_url",
                    "image_url": {"url": "https://raw.githubusercontent.com/sgl-project/sglang/main/assets/logo.png"},
                },
            ],
        }
    ],
)

print(response.choices[0].message.content)

출력:

The image is a copyright symbol, represented by a stylized version of the lowercase
letter "c" inside a circle. The "c" is depicted in a white or light-colored font, and
the circle is orange. The design is simple yet striking, using oval and elliptical
shapes to create a distinct symbol which signifies copyright protection.

5. Benchmarks (벤치마크)

5.1 Accuracy Benchmarks

GSM8K

python3 benchmark/gsm8k/bench_sglang.py --port 30000

결과:

TODO

MMLU

python3 benchmark/mmlu/bench_sglang.py --port 30000

결과:

TODO

5.2 Speed Benchmarks

Latency (Low Concurrency)

python3 -m sglang.bench_serving \
  --backend sglang \
  --num-prompts 10 \
  --max-concurrency 1 \
  --random-input-len 1024 \
  --random-output-len 512 \
  --port 30000

결과:

TODO

Throughput (High Concurrency)

python3 -m sglang.bench_serving \
  --backend sglang \
  --num-prompts 1000 \
  --max-concurrency 100 \
  --random-input-len 1024 \
  --random-output-len 512 \
  --port 30000

결과:

TODO

더 알아보기 (Learn more)