> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sglang.io/llms.txt
> Use this file to discover all available pages before exploring further.

# DeepSeek-V4.1-Flash

## Introduction

DeepSeek-V4.1-Flash is a multimodal Mixture-of-Experts (MoE) model developed by DeepSeek, with 552B backbone
parameters and support for context lengths of up to one million tokens. It uses a Causal Encoder-Decoder architecture
and activates 8B parameters per token during prefill and 16B during decode. This guide uses language-model-only mode,
so image inputs are not enabled. For more model details, see the
[DeepSeek-V4.1-Flash technical report](https://huggingface.co/deepseek-ai/DeepSeek-V4.1-Flash).

This guide covers DeepSeek-V4.1-Flash deployment on A3 Series and 950PR/DT Series (A5) NPUs with SGLang.
Prefill and decode run in one service; Prefill-Decode (PD) disaggregation is not configured.

## Configuration summary

The following table summarizes the A3 and A5 script settings. For parameter details, see the Ascend
[Parameter Reference](https://docs.sglang.io/docs/hardware-platforms/ascend-npus/optimization/parameter_tuning.md#parameter-reference) and
[Feature Compatibility](https://docs.sglang.io/docs/hardware-platforms/ascend-npus/optimization/parameter_tuning.md#feature-compatibility).

| Area | A3 Series | 950PR/DT Series (A5) |
| - | - | - |
| Hardware | 16 NPUs per node | 8 NPUs per node |
| Attention | `--attention-backend dsv4` | `--attention-backend dsv4` |
| Tensor parallelism | `--tp-size "$TP_SIZE"` (`TP_SIZE` is set from the total NPU count) | `--tp-size "$TP_SIZE"` (`TP_SIZE` is set from the total NPU count) |
| Attention data parallelism | `--attn-dp-size "$DP_SIZE"` (`DP_SIZE` is set from the total NPU count) | `--attn-dp-size "$DP_SIZE"` (`DP_SIZE` is set from the total NPU count) |
| MoE communication | `--moe-a2a-backend deepep` and `--deepep-mode auto` | `--moe-a2a-backend deepep` and `--deepep-mode auto` |
| DP language-model head | `--enable-dp-lm-head` | `--enable-dp-lm-head` |
| NPU graph decode batch sizes | `--cuda-graph-bs-decode 1 2 4 8 16 25` | `--cuda-graph-bs-decode 1 2 4 8 16 25` |
| DSPARK | Disabled by default. When enabled, also sets draft-model quantization to `modelslim` and draft KV cache dtype to `bf16`. | Disabled by default; optional arguments are included in the script. |

## Prerequisites

### Environment

Prepare an A3 Series host with 16 NPUs per node or a 950PR/DT Series (A5) host with 8 NPUs per node. Install a
compatible Ascend driver, CANN, TorchNPU, ATB, and custom operators, then run the setup and launch commands inside the
prepared Ascend environment. Use an SGLang checkout that supports DeepSeek-V4.1-Flash and the dsv4 NPU attention
backend. Keep the same SGLang revision and model checkpoint available at the same paths on every node.

### Model weights

Select the checkpoint for your hardware: [DeepSeek-V4.1-Flash-1017-W8A8](https://www.modelscope.cn/models/Eco-Tech/DeepSeek-V4.1-Flash-1017-w8a8)
for A3, or the [DeepSeek-V4.1-Flash-1017 checkpoint](https://www.modelscope.cn/models/deepseek-ai/DeepSeek-V4.1-Flash-1017)
for A5 (950PR/DT Series). Set `MODEL_PATH` to the directory containing the selected checkpoint. Replace the placeholder
path in the script with the checkpoint directory available in your environment. For multi-node deployments, make the
checkpoint accessible at the same path on every node.

## Installation

> [!WARNING]
>
> Ensure sufficient disk space before pulling images. The Docker image requires at least **30GB** of free space.

The dependencies required for the NPU runtime environment are integrated into platform-specific Docker images. Pull the image for your hardware and create a container using the corresponding command below. For host setup and further container options, see the [SGLang Installation with NPU Support](https://docs.sglang.io/docs/hardware-platforms/ascend-npus/getting-started/installation.md#create-docker-container) guide.

> [tab] A3 Series
>
> ```bash theme={null}
>
> NAME=sglang-deepseek-v4.1-flash
>
> # pull image
> docker pull swr.cn-southwest-2.myhuaweicloud.com/base_image/dockerhub/lmsysorg/sglang:cann9.2.0-a3-dsv41-1
>
> # create container
> docker run -itd --shm-size=16g --name "$NAME" \
>     --privileged=true --net=host \
>     -e ASCEND_VISIBLE_DEVICES=0-15 \
>     -v /etc/ascend_install.info:/etc/ascend_install.info \
>     -v /usr/local/sbin:/usr/local/sbin \
>     -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \
>     -v /usr/local/Ascend/firmware:/usr/local/Ascend/firmware \
>     --entrypoint=bash \
>     swr.cn-southwest-2.myhuaweicloud.com/base_image/dockerhub/lmsysorg/sglang:cann9.2.0-a3-dsv41-1
>
> # enter container
> docker exec -it "$NAME" bash
> ```

> [tab] 950PR/DT Series
>
> ```bash theme={null}
>
> NAME=sglang-deepseek-v4.1-flash
>
> # pull image
> docker pull swr.cn-southwest-2.myhuaweicloud.com/base_image/dockerhub/lmsysorg/sglang:cann9.2.0-950-B061
>
> # create container
> docker run -itd --shm-size=16g --name "$NAME" \
>     --privileged=true --net=host \
>     -e ASCEND_VISIBLE_DEVICES=0-7 \
>     -v /etc/ascend_install.info:/etc/ascend_install.info \
>     -v /usr/local/sbin:/usr/local/sbin \
>     -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \
>     -v /usr/local/Ascend/firmware:/usr/local/Ascend/firmware \
>     --entrypoint=bash \
>     swr.cn-southwest-2.myhuaweicloud.com/base_image/dockerhub/lmsysorg/sglang:cann9.2.0-950-B061
>
> # enter container
> docker exec -it "$NAME" bash
> ```

> [!TIP]
>
> * If the model weights are stored on the host, mount their directory into the container, for example: `-v /path/to/models:/models`.
> * Set `NAME` to your preferred container name before running the commands.

## Online service deployment

<table>
  <thead>
    <tr>
      <th>Parameter</th>
      <th>Single-node deployment</th>
      <th>Multi-node deployment</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`MODEL_PATH`</td>
      <td>Download the checkpoint for your hardware from [Model weights](#model-weights), then set `MODEL_PATH` to its directory as accessible from inside the container. For multi-node deployments, make this path accessible inside every node's container.</td>
      <td>Same as the single-node deployment.</td>
    </tr>

    <tr>
      <td>`NODE_IPS`</td>
      <td>List the node's communication IP, for example `NODE_IPS=("192.168.25.209")`.</td>
      <td>List all node communication IPs in the same order on every node, for example `NODE_IPS=("192.168.25.209" "192.168.25.212")`. Do not include port numbers.</td>
    </tr>

    <tr>
      <td>`NODE_RANK`</td>
      <td>Set `NODE_RANK=0`.</td>
      <td>Set the rank separately on each node according to its position in `NODE_IPS`. For the example above, use `NODE_RANK=0` on `192.168.25.209` and `NODE_RANK=1` on `192.168.25.212`.</td>
    </tr>

    <tr>
      <td>`HCCL_IF`</td>
      <td>The single-node example uses `HCCL_IF="lo"`. To inspect available interfaces, run `ip -br addr`. To check the route to a peer, run `ip route get <peer-node-ip>`; use the interface shown after `dev` as `HCCL_IF`.</td>
      <td>Set `HCCL_IF` separately on each node to its local interface for HCCL communication. For example, configure the interface on `192.168.25.209` on that node, and the interface on `192.168.25.212` on the other node. Interface names may be the same or different, depending on the cluster configuration.</td>
    </tr>

    <tr>
      <td>`GLOO_SOCKET_IFNAME`</td>
      <td>The script defaults to `lo`. For multi-node deployments, set this to an available interface for GLOO communication, for example `export GLOO_SOCKET_IFNAME="<interface>"`.</td>
      <td>Set this separately on each node to that node's local interface for GLOO communication. Run `ip route get <peer-node-ip>` and use the interface shown after `dev`; set it with `export GLOO_SOCKET_IFNAME="<interface>"`. The interface can differ between nodes.</td>
    </tr>
  </tbody>
</table>

> [tab] A3 Series
>
> This script supports both single-node and multi-node deployments. Configure `NODE_IPS`, `NODE_RANK`, `HCCL_IF`, and `GLOO_SOCKET_IFNAME` as described above. Replace the SGLang source and model checkpoint paths with paths available in your environment.
>
> ```bash command theme={null}
> # Host settings
> if [[ -w /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]]; then
>   echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor >/dev/null
> fi
> sysctl -w vm.swappiness=0
> sysctl -w kernel.numa_balancing=0
>
> # Runtime environment variables
> export HCCL_OP_EXPANSION_MODE=AIV
> export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
> export STREAMS_PER_DEVICE=32
> export GLOO_SOCKET_IFNAME="${GLOO_SOCKET_IFNAME:-lo}"
> export SGLANG_SET_CPU_AFFINITY=1
> export TASK_QUEUE_ENABLE=1
> export INF_NAN_MODE_FORCE_DISABLE=1
> export HCCL_BUFFSIZE=400
>
> # Configure build caches for the modified SGLang code
> export TORCH_EXTENSIONS_DIR="$(mktemp -d /tmp/dsv41-jit.XXXXXX)"
> export CANN_OP_BUILDER_NO_FPRINT_CACHE=1
> source /usr/local/Ascend/ascend-toolkit/latest/set_env.sh
> source /usr/local/Ascend/nnal/atb/set_env.sh
>
> # Optional MemFabric settings
> if [[ -f /usr/local/memfabric_hybrid/set_env.sh ]]; then
>   source /usr/local/memfabric_hybrid/set_env.sh
> fi
>
> # DeepEP settings
> export DEEPEP_HCCL_BUFFSIZE=1800
> export DEEPEP_NORMAL_COMBINE_ENABLE_LONG_SEQ=1
> export DEEPEP_NORMAL_LONG_SEQ_ROUND=16
> export DEEPEP_NORMAL_LONG_SEQ_PER_ROUND_TOKENS=2048
> export SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK=150
>
> # DeepSeek-V4.1 optimization settings
> export SGLANG_OPT_FUSE_WQA_WKV=0
> export SGLANG_OPT_BF16_FP32_GEMM_ALGO=torch
> export SGLANG_OPT_USE_FUSED_HASH_TOPK=False
> export SGLANG_OPT_USE_TILELANG_MHC_PRE=False
> export SGLANG_OPT_DEEPGEMM_HC_PRENORM=False
> export SGLANG_OPT_USE_TILELANG_MHC_POST=False
> export SGLANG_OPT_FP8_WO_A_GEMM=False
>
> # Model and distributed deployment settings
> export MODEL_PATH="/path/to/DeepSeek-V4.1-Flash-1017-w8a8"
> SERVED_MODEL_NAME="dsv41"
> NUM_NPUS_PER_NODE=16
> PORT=30000
> DIST_PORT=5567
>
> # Single-node example
> NODE_IPS=("192.168.25.209")
> NODE_RANK=0
> HCCL_IF="lo"
> NNODES="${#NODE_IPS[@]}"
> if (( NNODES < 1 )); then
>   echo "ERROR: NODE_IPS must contain at least one IP" >&2
>   exit 1
> fi
> TOTAL_NPUS=$((NNODES * NUM_NPUS_PER_NODE))
> TP_SIZE="$TOTAL_NPUS"
> DP_SIZE="$TOTAL_NPUS"
> MASTER_ADDR="${NODE_IPS[0]}"
> DIST_INIT_ADDR="${MASTER_ADDR}:${DIST_PORT}"
> export HCCL_SOCKET_IFNAME="$HCCL_IF"
> DSPARK_ARGS=()
>
> # Speculative decoding (DSPARK)
> ENABLE_DSPARK="${ENABLE_DSPARK:-0}"
> if [[ "$ENABLE_DSPARK" == "1" ]]; then
>   export SGLANG_ENABLE_SPEC_V2=1
>   export SGLANG_RAGGED_VERIFY_MODE=static
>   export SGLANG_ENABLE_OVERLAP_PLAN_STREAM=1
>
>   DSPARK_ARGS+=(
>     --speculative-algorithm DSPARK
>     --speculative-draft-attention-backend ascend
>     --speculative-num-draft-tokens 6
>     --speculative-dspark-block-size 5
>     --speculative-draft-model-quantization modelslim
>     --speculative-draft-kv-cache-dtype bf16
>   )
> fi
>
> # Launch the SGLang server
> python3 -m sglang.launch_server \
>   --model-path "$MODEL_PATH" \
>   --served-model-name "$SERVED_MODEL_NAME" \
>   --host 0.0.0.0 \
>   --port "$PORT" \
>   --tp-size "$TP_SIZE" \
>   --nnodes "$NNODES" \
>   --node-rank "$NODE_RANK" \
>   --dist-init-addr "$DIST_INIT_ADDR" \
>   --page-size 128 \
>   --trust-remote-code \
>   --attention-backend dsv4 \
>   --device npu \
>   --attn-dp-size "$DP_SIZE" \
>   --enable-dp-lm-head \
>   --watchdog-timeout 9000 \
>   --max-running-requests 200 \
>   --mem-fraction-static 0.83 \
>   --max-prefill-tokens 131072 \
>   --chunked-prefill-size 131072 \
>   --kv-cache-dtype auto \
>   --json-model-override-args '{"architectures": ["DeepseekV4ForCausalLM"]}' \
>   --reasoning-parser deepseek-v4 \
>   --language-model-only \
>   --moe-a2a-backend deepep \
>   --deepep-mode auto \
>   --enable-metrics \
>   --cuda-graph-bs-decode 1 2 4 8 16 25 \
>   "${DSPARK_ARGS[@]}"
> ```

> [tab] 950PR/DT Series
>
> This script runs prefill and decode together in one SGLang service; it does not use PD disaggregation. Each node has 8 NPUs. Before launching, update the script's model path, node IP list, node rank, and HCCL and GLOO interfaces as described above. Set `NNODES` from the number of IP addresses in `NODE_IPS`; the script calculates `TP_SIZE` and `DP_SIZE` from the total number of NPUs. For a multi-node deployment, run the configured script on every node, using the same `NODE_IPS` list and the appropriate `NODE_RANK`, `HCCL_IF`, and `GLOO_SOCKET_IFNAME` for each node.
>
> ```bash theme={null}
>
> # Host settings
> if [[ -w /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]]; then
>   echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor >/dev/null
> fi
> sysctl -w vm.swappiness=0
> sysctl -w kernel.numa_balancing=0
>
> # Runtime environment variables
> unset https_proxy http_proxy HTTPS_PROXY HTTP_PROXY ASCEND_LAUNCH_BLOCKING || true
> export HCCL_OP_EXPANSION_MODE=AIV
> export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
> export STREAMS_PER_DEVICE=32
> export GLOO_SOCKET_IFNAME="${GLOO_SOCKET_IFNAME:-lo}"
> export SGLANG_SET_CPU_AFFINITY=1
> export TASK_QUEUE_ENABLE=1
> export INF_NAN_MODE_FORCE_DISABLE=1
> export HCCL_BUFFSIZE=400
>
> # Initialize CANN and ATB
> source /usr/local/Ascend/ascend-toolkit/latest/set_env.sh
> source /usr/local/Ascend/nnal/atb/set_env.sh
>
> # Optional MemFabric settings
> if [[ -f /usr/local/memfabric_hybrid/set_env.sh ]]; then
>   source /usr/local/memfabric_hybrid/set_env.sh
> fi
>
> # DeepEP settings
> export DEEPEP_HCCL_BUFFSIZE=1800
> export DEEPEP_NORMAL_COMBINE_ENABLE_LONG_SEQ=1
> export DEEPEP_NORMAL_LONG_SEQ_ROUND=16
> export DEEPEP_NORMAL_LONG_SEQ_PER_ROUND_TOKENS=2048
> export SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK=150
>
> # DeepSeek-V4.1 optimization settings
> export SGLANG_OPT_FUSE_WQA_WKV=0
> export SGLANG_OPT_BF16_FP32_GEMM_ALGO=torch
> export SGLANG_OPT_USE_FUSED_HASH_TOPK=False
> export SGLANG_OPT_USE_TILELANG_MHC_PRE=False
> export SGLANG_OPT_DEEPGEMM_HC_PRENORM=False
> export SGLANG_OPT_USE_TILELANG_MHC_POST=False
> export SGLANG_OPT_FP8_WO_A_GEMM=False
>
> # Model and distributed deployment settings
> export MODEL_PATH="/path/to/DeepSeek-V4.1-Flash-1017"
> SERVED_MODEL_NAME="dsv41"
> NUM_NPUS_PER_NODE=8
> PORT=30000
> DIST_PORT=5567
>
> # Single-node example
> NODE_IPS=("192.168.25.209")
> NODE_RANK=0
> HCCL_IF="lo"
> NNODES="${#NODE_IPS[@]}"
> if (( NNODES < 1 )); then
>   echo "ERROR: NODE_IPS must contain at least one IP" >&2
>   exit 1
> fi
> TOTAL_NPUS=$((NNODES * NUM_NPUS_PER_NODE))
> TP_SIZE="$TOTAL_NPUS"
> DP_SIZE="$TOTAL_NPUS"
> MASTER_ADDR="${NODE_IPS[0]}"
> DIST_INIT_ADDR="${MASTER_ADDR}:${DIST_PORT}"
> export HCCL_SOCKET_IFNAME="$HCCL_IF"
> DSPARK_ARGS=()
>
> # Speculative decoding (DSPARK)
> ENABLE_DSPARK="${ENABLE_DSPARK:-0}"
> if [[ "$ENABLE_DSPARK" == "1" ]]; then
>   export SGLANG_ENABLE_SPEC_V2=1
>   export SGLANG_RAGGED_VERIFY_MODE=static
>   export SGLANG_ENABLE_OVERLAP_PLAN_STREAM=1
>
>   DSPARK_ARGS+=(
>     --speculative-algorithm DSPARK
>     --speculative-draft-attention-backend ascend
>     --speculative-num-draft-tokens 6
>     --speculative-dspark-block-size 5
>   )
> fi
>
> # Launch the SGLang server
> python3 -m sglang.launch_server \
>   --model-path "$MODEL_PATH" \
>   --served-model-name "$SERVED_MODEL_NAME" \
>   --host 0.0.0.0 \
>   --port "$PORT" \
>   --tp-size "$TP_SIZE" \
>   --nnodes "$NNODES" \
>   --node-rank "$NODE_RANK" \
>   --dist-init-addr "$DIST_INIT_ADDR" \
>   --page-size 128 \
>   --trust-remote-code \
>   --attention-backend dsv4 \
>   --device npu \
>   --attn-dp-size "$DP_SIZE" \
>   --enable-dp-lm-head \
>   --watchdog-timeout 9000 \
>   --max-running-requests 200 \
>   --mem-fraction-static 0.83 \
>   --max-prefill-tokens 131072 \
>   --chunked-prefill-size 131072 \
>   --kv-cache-dtype auto \
>   --json-model-override-args '{"architectures": ["DeepseekV4ForCausalLM"]}' \
>   --reasoning-parser deepseek-v4 \
>   --language-model-only \
>   --moe-a2a-backend deepep \
>   --deepep-mode auto \
>   --enable-metrics \
>   --cuda-graph-bs-decode 1 2 4 8 16 25 \
>   "${DSPARK_ARGS[@]}"
> ```

## Functional verification

Once the server prints `The server is fired up and ready to roll!` in the terminal, it is ready to accept requests. For
more testing examples (health checks, Generate, Chat Completions, and port usage), see
[Testing the Service](https://docs.sglang.io/docs/hardware-platforms/ascend-npus/getting-started/installation.md#testing-the-service).

Send a chat completion request to the service endpoint on port `30000`:

```shell theme={null}
curl -i http://127.0.0.1:30000/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"dsv41","messages":[{"role":"user","content":"Hello"}]}'
```

Expected result: an HTTP 200 response containing a generated answer.

For a multi-node deployment, send the request to the service endpoint reachable from the client, typically on the
rank-0 node (`MASTER_ADDR`). The service output is displayed in the terminal on each node.

## Accuracy evaluation

A quick GSM8K accuracy check with `sgl-eval`:

```bash theme={null}
sgl-eval run gsm8k \
  --model /path/to/model-checkpoint \
  --base-url http://127.0.0.1:30000/v1 \
  --num-examples 10 \
  --max-tokens 16384
```

If the shell reports `sgl-eval: command not found`, install it with `pip install sgl-eval==0.1.3` and run the command again. If you do not want to change the server's Python environment, install it in an isolated venv instead;
Replace `/path/to/model-checkpoint` with the checkpoint path used by the server. For multi-node deployment, use the service address reachable from the client.

### Accuracy Tests

DeepSeek-V4.1 accuracy scores on Ascend A3 Series and 950PR/DT Series (A5):

<table>
  <colgroup>
    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Benchmark</th>

      <th>
        Ascend A3 Series
      </th>

      <th>
        Ascend A5 (950PR/DT Series)
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>GPQA-Diamond</td>
      <td>91.9</td>
      <td>91.4</td>
    </tr>

    <tr>
      <td>AIME26</td>
      <td>96.7</td>
      <td>100</td>
    </tr>
  </tbody>
</table>

The A5 results were obtained with DSPark and decode graph enabled. The A3 scores are reported for A3, but the
corresponding launch settings were not provided; they do not establish that the A3 tutorial or Cookbook launch recipe
was smoke-tested.

## Performance

A quick serving benchmark with random input and output lengths:

```bash theme={null}
python -m sglang.benchmark.serving \
  --dataset-name random \
  --backend sglang \
  --host 127.0.0.1 \
  --port 6688 \
  --max-concurrency 64 \
  --num-prompts 64 \
  --random-input-len 1000 \
  --random-output-len 100 \
  --random-range-ratio 1 \
  --seed 1
```

The `sglang` backend benchmarks the `/generate` endpoint. To benchmark the OpenAI-compatible chat endpoint, use
`--backend sglang-oai-chat`. For multi-node deployment, use the service address reachable from the benchmark client.
This tutorial does not provide DeepSeek-V4.1-Flash A3 or A5 performance results.

For performance data and benchmark commands, see [Performance Testing on Ascend NPU](https://docs.sglang.io/docs/hardware-platforms/ascend-npus/evaluation/performance_testing.md).

## Performance tuning

Use the Ascend [optimization and parameter tuning guide](https://docs.sglang.io/docs/hardware-platforms/ascend-npus/optimization/parameter_tuning.md)
to understand the launch parameters and tune them for your workload.

## FAQ

For common Ascend environment, installation, and runtime issues, see the [Ascend NPU FAQ](https://docs.sglang.io/docs/hardware-platforms/ascend-npus/faq.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.