---
title: Qwen3.8-27Bをllama.cpp on DGX Sparkで動かし、Claude Codeから使用するメモ
summary: DGX Sparkでllama.cppによりQwen3.8-27Bをローカル実行しClaude Codeから利用する方法を解説。ビルド、systemd設定、Jinjaテンプレート、Claude Code連携までを網羅しています。
tags: ["DGX Spark", "ASUS Ascent GX10", "llama.cpp"]
categories: ["HomeLab", "DGXSpark"]
date: 2026-08-17T06:03:34.858Z
updated: 2026-08-17T07:47:59.523Z
---

<blockquote class="twitter-tweet"><p lang="und" dir="ltr">on DGX Spark:<br><br>llama serve \<br> -hf ggml-org/Qwen3.8-27B-GGUF:Q4_K_M \<br> -hfd ggml-org/Qwen3.8-27B-GGUF:Q4_0 \<br> --spec-default \<br> --spec-type draft-mtp \<br> --reasoning-preserve --agent</p>&mdash; Georgi Gerganov (@ggerganov) <a href="https://x.com/ggerganov/status/2088340681701925253?ref_src=twsrc%5Etfw">August 14, 2026</a></blockquote> <script async src="https://platform.x.com/widgets.js" charset="utf-8"></script>


### llama.cppのビルド

```bash
mkdir -p ~/git
cd ~/git
git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp
sudo apt update
sudo apt install libcurl4-openssl-dev libssl-dev -y
rm -rf build
mkdir -p build
cmake -B build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES="121" -DBUILD_SHARED_LIBS=OFF
cmake --build build --config Release -j 20 --clean-first
```

```bash
$ ./build/bin/llama --version
version: 0.1.0-dev (build 10454, commit 4df29be4f)
built with GNU 13.3.0 for Linux aarch64
```

### サービスの登録と起動


```bash
cat <<EOF | sudo tee /etc/systemd/system/llama-server.service > /dev/null
[Unit]
Description=llama server
After=network.target

[Service]
User=$USER
Group=$USER
WorkingDirectory=$HOME/git/llama.cpp/build

ExecStart=$HOME/git/llama.cpp/build/bin/llama serve \\
  -hf ggml-org/Qwen3.8-27B-GGUF:Q4_K_M \\
  -hfd ggml-org/Qwen3.8-27B-GGUF:Q4_0 \\
  --spec-default \\
  --spec-type draft-mtp \\
  --reasoning-preserve \\
  --reasoning-effort low \\
  --agent \\
  --chat-template-file $HOME/.config/llama.cpp/qwen3.8-midsystem.jinja \\
  --host 0.0.0.0 \\
  --port 8888

Restart=always
RestartSec=5
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
EOF
```


`--chat-template-file `に以下のjijaテンプレートを設定しないと、Claude Codeからは次のエラーメッセージが出ました。

```
  While executing CallExpression at line 106, column 32 in source:                                                                                                                                                                                                                                      
    ...first %}↵            {{- raise_exception('System message must be at the beginnin...                                                                                                                                                                                                              
                                               ^                                                                                                                                                                                                                                                        
    Error: Jinja Exception: System message must be at the beginning. This is a server-side issue, usually temporary — try again in a moment.
```


```python
mkdir -p $HOME/.config/llama.cpp
cat <<'EOF' > $HOME/.config/llama.cpp/qwen3.8-midsystem.jinja
{%- set image_count = namespace(value=0) %}
{%- set video_count = namespace(value=0) %}
{%- macro render_content(content, do_vision_count, is_system_content=false) %}
    {%- if content is string %}
        {{- content }}
    {%- elif content is iterable and content is not mapping %}
        {%- for item in content %}
            {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
                {%- if is_system_content %}
                    {{- raise_exception('System message cannot contain images.') }}
                {%- endif %}
                {%- if do_vision_count %}
                    {%- set image_count.value = image_count.value + 1 %}
                {%- endif %}
                {%- if add_vision_id %}
                    {{- 'Picture ' ~ image_count.value ~ ': ' }}
                {%- endif %}
                {{- '<|vision_start|><|image_pad|><|vision_end|>' }}
            {%- elif 'video' in item or item.type == 'video' %}
                {%- if is_system_content %}
                    {{- raise_exception('System message cannot contain videos.') }}
                {%- endif %}
                {%- if do_vision_count %}
                    {%- set video_count.value = video_count.value + 1 %}
                {%- endif %}
                {%- if add_vision_id %}
                    {{- 'Video ' ~ video_count.value ~ ': ' }}
                {%- endif %}
                {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
            {%- elif 'text' in item %}
                {{- item.text }}
            {%- else %}
                {{- raise_exception('Unexpected item type in content.') }}
            {%- endif %}
        {%- endfor %}
    {%- elif content is none or content is undefined %}
        {{- '' }}
    {%- else %}
        {{- raise_exception('Unexpected content type.') }}
    {%- endif %}
{%- endmacro %}
{%- if not messages %}
    {{- raise_exception('No messages provided.') }}
{%- endif %}
{%- set reasoning_instructions = '' %}
{%- if enable_thinking is undefined or enable_thinking is true %}
    {%- set resolved_reasoning_effort = reasoning_effort|default('xhigh') %}
    {%- if resolved_reasoning_effort not in ('xhigh', 'medium', 'low') %}
        {{- raise_exception('Unexpected reasoning effort ' ~ reasoning_effort ~ '. Supported types are xhigh (default), medium, and low.') }}
    {%- endif %}
    {%- if resolved_reasoning_effort == 'xhigh' %}
        {%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %}
    {%- elif resolved_reasoning_effort == 'low' %}
        {%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
    {%- endif %}
{%- endif %}
{%- if tools and tools is iterable and tools is not mapping %}
    {{- '<|im_start|>system\n' }}
    {%- if reasoning_instructions %}
        {{- reasoning_instructions + '\n\n' }}
    {%- endif %}
    {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
    {%- for tool in tools %}
        {{- "\n" }}
        {{- tool | tojson }}
    {%- endfor %}
    {{- "\n</tools>" }}
    {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
    {%- if messages[0].role == 'system' %}
        {%- set content = render_content(messages[0].content, false, true)|trim %}
        {%- if content %}
            {{- '\n\n' + content }}
        {%- endif %}
    {%- endif %}
    {{- '<|im_end|>\n' }}
{%- else %}
    {%- if messages[0].role == 'system' %}
        {%- set content = render_content(messages[0].content, false, true)|trim %}
        {%- if content %}
            {{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '')  + content + '<|im_end|>\n' }}
        {%- elif reasoning_instructions %}
            {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
        {%- endif %}
    {%- elif reasoning_instructions %}
        {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
    {%- endif %}
{%- endif %}
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
{%- for message in messages[::-1] %}
    {%- set index = (messages|length - 1) - loop.index0 %}
    {%- if ns.multi_step_tool and message.role == "user" %}
        {%- set content = render_content(message.content, false)|trim %}
        {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
            {%- set ns.multi_step_tool = false %}
            {%- set ns.last_query_index = index %}
        {%- endif %}
    {%- endif %}
{%- endfor %}
{%- if ns.multi_step_tool %}
    {{- raise_exception('No user query found in messages.') }}
{%- endif %}
{%- for message in messages %}
    {%- set content = render_content(message.content, true)|trim %}
    {%- if message.role == "system" %}
        {%- if not loop.first and content %}
            {{- '<|im_start|>system\n' + content + '<|im_end|>' + '\n' }}
        {%- endif %}
    {%- elif message.role == "user" %}
        {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
    {%- elif message.role == "assistant" %}
        {%- set reasoning_content = '' %}
        {%- if message.reasoning_content is string %}
            {%- set reasoning_content = message.reasoning_content %}
        {%- endif %}
        {%- set reasoning_content = reasoning_content|trim %}
        {%- if preserve_thinking is undefined or preserve_thinking is true or loop.index0 > ns.last_query_index %}
            {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
        {%- else %}
            {{- '<|im_start|>' + message.role + '\n' + content }}
        {%- endif %}
        {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
            {%- for tool_call in message.tool_calls %}
                {%- if tool_call.function is defined %}
                    {%- set tool_call = tool_call.function %}
                {%- endif %}
                {%- if loop.first %}
                    {%- if content|trim %}
                        {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
                    {%- else %}
                        {{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
                    {%- endif %}
                {%- else %}
                    {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
                {%- endif %}
                {%- if tool_call.arguments is defined and tool_call.arguments != '' %}
                    {%- for args_name, args_value in tool_call.arguments|items %}
                        {{- '<parameter=' + args_name + '>\n' }}
                        {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}
                        {{- args_value }}
                        {{- '\n</parameter>\n' }}
                    {%- endfor %}
                {%- endif %}
                {{- '</function>\n</tool_call>' }}
            {%- endfor %}
        {%- endif %}
        {{- '<|im_end|>\n' }}
    {%- elif message.role == "tool" %}
        {%- if loop.previtem and loop.previtem.role != "tool" %}
            {{- '<|im_start|>user' }}
        {%- endif %}
        {{- '\n<tool_response>\n' }}
        {{- content }}
        {{- '\n</tool_response>' }}
        {%- if not loop.last and loop.nextitem.role != "tool" %}
            {{- '<|im_end|>\n' }}
        {%- elif loop.last %}
            {{- '<|im_end|>\n' }}
        {%- endif %}
    {%- else %}
        {{- raise_exception('Unexpected message role.') }}
    {%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
    {{- '<|im_start|>assistant\n' }}
    {%- if enable_thinking is defined and enable_thinking is false %}
        {{- '<think>\n\n</think>\n\n' }}
    {%- else %}
        {{- '<think>\n' }}
    {%- endif %}
{%- endif %}
EOF
```


```bash
sudo systemctl daemon-reload
sudo systemctl enable llama-server
sudo systemctl start llama-server
sudo systemctl status llama-server
```

### OpenAI APIの動作確認

```bash
curl -s http://localhost:8888/v1/chat/completions \
  --json '{
   "model": "ggml-org/Qwen3.8-27B-GGUF:Q4_K_M",
   "messages": [
      {"role": "user", "content": "Give me a joke."}
   ]
 }' | jq .
```

```json
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Why don't scientists trust atoms?\n\nBecause they make up everything.",
        "reasoning_content": "The user wants a joke. Let me think of a good one that's clean, clever, and has a solid punchline. I'll go with a classic setup-punchline format that works well in text.\n"
      }
    }
  ],
  "created": 1786945345,
  "model": "ggml-org/Qwen3.8-27B-GGUF:Q4_K_M",
  "system_fingerprint": "b10454-4df29be4f",
  "object": "chat.completion",
  "usage": {
    "completion_tokens": 61,
    "prompt_tokens": 45,
    "total_tokens": 106,
    "prompt_tokens_details": {
      "cached_tokens": 0
    }
  },
  "id": "chatcmpl-KUxmfxMsgQjQEgmeRdwgvHYl29kEMqYN",
  "timings": {
    "cache_n": 0,
    "prompt_n": 45,
    "prompt_ms": 2131.847,
    "prompt_per_token_ms": 47.37437777777778,
    "prompt_per_second": 21.108456657536866,
    "predicted_n": 61,
    "predicted_ms": 2220.93,
    "predicted_per_token_ms": 37.015499999999996,
    "predicted_per_second": 27.01570963515284,
    "draft_n": 57,
    "draft_n_accepted": 42
  }
}
```

### Claude Codeから動作確認

```bash
cat <<'EOF' > ~/cc-qwen.sh
#!/bin/bash
unset ANTHROPIC_API_KEY

export ANTHROPIC_BASE_URL=http://localhost:8888
export ANTHROPIC_AUTH_TOKEN=local
export ANTHROPIC_MODEL=ggml-org/Qwen3.8-27B-GGUF:Q4_K_M[256k]

export ANTHROPIC_CUSTOM_MODEL_OPTION=$ANTHROPIC_MODEL
export ANTHROPIC_DEFAULT_SONNET_MODEL=$ANTHROPIC_MODEL
export ANTHROPIC_DEFAULT_HAIKU_MODEL=$ANTHROPIC_MODEL
export ANTHROPIC_DEFAULT_OPUS_MODEL=$ANTHROPIC_MODEL
export CLAUDE_CODE_SUBAGENT_MODEL=$ANTHROPIC_MODEL

export ANTHROPIC_CUSTOM_MODEL_OPTION=$ANTHROPIC_MODEL
export ANTHROPIC_CUSTOM_MODEL_OPTION_NAME=$ANTHROPIC_MODEL
export ANTHROPIC_CUSTOM_MODEL_OPTION_DESCRIPTION=$ANTHROPIC_MODEL

export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
export CLAUDE_CODE_DISABLE_NONSTREAMING_FALLBACK=1
export CLAUDE_STREAM_IDLE_TIMEOUT_MS=600000
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=500000
echo "Model: $ANTHROPIC_MODEL"
set -ex
claude --dangerously-skip-permissions $@
EOF

chmod +x ~/cc-qwen.sh
```

```bash
~/cc-qwen.sh
```


![pasted-image.png](https://s3.ik.am/ikam/_/1786946357484_pasted-image.png)
