> ## 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.

# Environment Variables

SGLang supports various environment variables related to Ascend NPU that can be used to configure its runtime behavior.
This document provides a list of commonly used environment variables and aims to stay updated over time.

## Directly Used in SGLang

<table>
  <thead>
    <tr>
      <th>Environment Variable</th>
      <th>Description</th>
      <th>Default Value</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`SGLANG_NPU_USE_MLAPO`</td>
      <td>Adopts the `MLAPO` fusion operator in the attention \
      &#x20;preprocessing stage of the MLA model.</td>
      <td>`false`</td>
    </tr>

    <tr>
      <td>`SGLANG_USE_FIA_NZ`</td>
      <td>Reshapes KV Cache for FIA NZ format.</td>
      <td>`false`</td>
    </tr>

    <tr>
      <td>`SGLANG_NPU_USE_FLASH_MLA`</td>
      <td>Enables FlashMLA for target-model MLA attention during DSPARK verification, such as Kimi-K3. Applies to eager execution and graph replay. Does not enable FlashMLA on draft workers or ordinary non-speculative decode.</td>
      <td>`false`</td>
    </tr>

    <tr>
      <td>`ASCEND_USE_PAGED_MTP`</td>
      <td>Enables `paged_mtp_attention_decode` for draft-model MHA attention in DSPARK, such as the Kimi-K3 DSpark draft model. Applies to eager execution and graph replay. Does not change target-model attention or ordinary non-speculative decode.</td>
      <td>`false`</td>
    </tr>

    <tr>
      <td>`SGLANG_NPU_USE_MULTI_STREAM`</td>
      <td>Enable dual-stream computation of shared experts \
      &#x20;and routing experts in DeepSeek models.\
      &#x20;Enable dual-stream computation in DeepSeek DSA Indexer.</td>
      <td>`false`</td>
    </tr>

    <tr>
      <td>`SGLANG_NPU_DISABLE_ACL_FORMAT_WEIGHT`</td>
      <td>Disable casting model weight tensor to a specific NPU \
      &#x20;ACL format.</td>
      <td>`false`</td>
    </tr>

    <tr>
      <td>`SGLANG_DEEPEP_NUM_MAX_DISPATCH_TOKENS_PER_RANK`</td>
      <td>The maximum number of dispatched tokens on each rank.</td>
      <td>`128`</td>
    </tr>

    <tr>
      <td>`SGLANG_SCHEDULER_SKIP_ALL_GATHER`</td>
      <td>Skips the scheduler's cross-DP-rank metadata all-gather on every step. \
      &#x20;Safe only when every DP rank sees the same forward mode and token \
      &#x20;counts (balanced DP load); there is no startup guard for uneven load.</td>
      <td>`false`</td>
    </tr>

    <tr>
      <td>`SGLANG_ENABLE_OVERLAP_PLAN_STREAM`</td>
      <td>Runs speculative batch-preparation kernels (draft-extend metadata, \
      &#x20;KV-location planning) on a dedicated stream, overlapped with other work. \
      &#x20;Incompatible with LoRA under EAGLE/NEXTN/EAGLE3 speculative decoding.</td>
      <td>`false`</td>
    </tr>

    <tr>
      <td>`SGLANG_USE_AG_AFTER_QLORA`</td>
      <td>Delays the attention all-gather until after the low-rank Q projection, \
      &#x20;so fewer bytes are gathered. Requires a model with `q_lora_rank` and \
      &#x20;`--enable-attn-tp-input-scattered`. The scattered-input layout is \
      &#x20;disabled under attention DP, a MoE all-to-all backend, or prefill context \
      &#x20;parallelism, and only prefill (extend) batches use it; outside those \
      &#x20;conditions the variable has no effect.</td>
      <td>`false`</td>
    </tr>

    <tr>
      <td>`SGLANG_SET_CPU_AFFINITY`</td>
      <td>Binds each TP rank's scheduler process to dedicated CPU cores, \
      &#x20;avoiding cross-core migration overhead.</td>
      <td>`false`</td>
    </tr>
  </tbody>
</table>

### Kimi-K3 speculative attention

Use these switches to optimize DSPARK target verification and draft attention on Ascend NPUs.
Install a version of `sgl-kernel-npu` that exports `flash_mla`, `flash_mla_metadata`, and
`paged_mtp_attention_decode` from `sgl_kernel_npu.operators.attention` for your NPU.
Set the variables in the server environment on every rank before launching with
`--speculative-algorithm DSPARK`:

```bash theme={null}
export SGLANG_NPU_USE_FLASH_MLA=1
export ASCEND_USE_PAGED_MTP=1
```

You can enable either kernel independently. To also avoid CPU sequence-length mirror and host
attention-parameter updates in these speculative paths, enable both kernels and set
`SGLANG_NPU_ATTN_BACKEND_NEEDS_CPU_SEQ_LENS=0`. Its default is `1`; the two kernel switches
alone do not disable CPU mirrors. Setting either kernel switch to `0` keeps the existing
attention path for that worker.

## Profiling

Used by the built-in PyTorch Profiler — see
[Performance Profiling](https://docs.sglang.io/docs/hardware-platforms/ascend-npus/optimization/profiling.md).

<table>
  <thead>
    <tr>
      <th>Environment Variable</th>
      <th>Description</th>
      <th>Default Value</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`SGLANG_TORCH_PROFILER_DIR`</td>
      <td>Output directory for profiler trace files.</td>
      <td>`/tmp`</td>
    </tr>

    <tr>
      <td>`SGLANG_PROFILE_WITH_STACK`</td>
      <td>Record Python call stacks in profiler traces. An explicit `false` here or in the API parameter disables it.</td>
      <td>`true`</td>
    </tr>

    <tr>
      <td>`SGLANG_PROFILE_RECORD_SHAPES`</td>
      <td>Record operator input shapes in profiler traces. An explicit `false` here or in the API parameter disables it.</td>
      <td>`true`</td>
    </tr>
  </tbody>
</table>

## Used in DeepEP Ascend

<table>
  <thead>
    <tr>
      <th>Environment Variable</th>
      <th>Description</th>
      <th>Default Value</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`DEEPEP_NORMAL_LONG_SEQ_PER_ROUND_TOKENS`</td>
      <td>Enable long-sequence token pipelining in dispatch stage. Indicates \
      &#x20;the number of tokens transmitted per round on each rank.</td>
      <td>`8192`</td>
    </tr>

    <tr>
      <td>`DEEPEP_NORMAL_LONG_SEQ_ROUND`</td>
      <td>Enable long-sequence token pipelining in dispatch stage. Indicates \
      &#x20;the number of rounds transmitted on each rank.</td>
      <td>`1`</td>
    </tr>

    <tr>
      <td>`DEEPEP_NORMAL_COMBINE_ENABLE_LONG_SEQ`</td>
      <td>Enable long-sequence token pipelining in combine stage. \
      &#x20;The value `0` means disabled.</td>
      <td>`0`</td>
    </tr>

    <tr>
      <td>`MOE_ENABLE_TOPK_NEG_ONE`</td>
      <td>Needs to be enabled when the expert ID to be processed by \
      &#x20;DEEPEP contains -1.</td>
      <td>`0`</td>
    </tr>

    <tr>
      <td>`DEEP_NORMAL_MODE_USE_INT8_QUANT`</td>

      <td>
        **Deprecated — will be removed in a future release.**

        When set to `1`, quantizes intermediate activations to INT8 in
        \
        the DeepEP dispatch operator during normal mode, reducing communication
        \
        volume for W8A8-quantized MoE models. This variable will become a no-op;
        \
        the quantization behavior will be inferred automatically.
      </td>

      <td>`0`</td>
    </tr>

    <tr>
      <td>`DEEPEP_HCCL_BUFFSIZE`</td>
      <td>Configures the HCCL buffer size (in MB) for the process groups used by \
      &#x20;DeepEP MoE All-to-All communication (the default group and `moe`-named \
      &#x20;groups), allowing the MoE communication buffer to be tuned independently from \
      &#x20;non-MoE groups. If unset, falls back to `HCCL_BUFFSIZE`, then to `200`. \
      &#x20;A larger buffer reduces All-to-All latency at the cost of more HBM usage.</td>
      <td>`200`</td>
    </tr>
  </tbody>
</table>

## Others

<table>
  <thead>
    <tr>
      <th>Environment Variable</th>
      <th>Description</th>
      <th>Default Value</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`TASK_QUEUE_ENABLE`</td>
      <td>Used to control the optimization level of the dispatch queue\
      &#x20;for the task\_queue operator. [Detail](https://www.hiascend.com/document/detail/zh/Pytorch/730/comref/Envvariables/docs/zh/environment_variable_reference/TASK_QUEUE_ENABLE.md)</td>
      <td>`1`</td>
    </tr>

    <tr>
      <td>`INF_NAN_MODE_ENABLE`</td>
      <td>Controls whether the chip uses saturation mode or INF\_NAN mode. [Detail](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/800alpha001/apiref/envref/envref_07_0056.html)</td>
      <td>`1`</td>
    </tr>

    <tr>
      <td>`STREAMS_PER_DEVICE`</td>
      <td>Configures the maximum number of streams for the stream pool. [Detail](https://www.hiascend.com/document/detail/zh/Pytorch/720/comref/Envvariables/Envir_041.html)</td>
      <td>`32`</td>
    </tr>

    <tr>
      <td>`PYTORCH_NPU_ALLOC_CONF`</td>
      <td>Controls the behavior of the cache allocator. \
      This variable changes memory usage and may cause performance fluctuations. [Detail](https://www.hiascend.com/document/detail/zh/Pytorch/700/comref/Envvariables/Envir_012.html)</td>

      <td />
    </tr>

    <tr>
      <td>`ASCEND_MF_STORE_URL`</td>
      <td>The address of config store in MemFabric during PD separation, \
      which is generally set to the IP address of the P primary node\
      &#x20;with an arbitrary port number.</td>

      <td />
    </tr>

    <tr>
      <td>`ASCEND_LAUNCH_BLOCKING`</td>
      <td>Controls whether synchronous mode is enabled during operator execution. [Detail](https://www.hiascend.com/document/detail/zh/Pytorch/710/comref/Envvariables/Envir_006.html)</td>
      <td>`0`</td>
    </tr>

    <tr>
      <td>`HCCL_OP_EXPANSION_MODE`</td>
      <td>Configures the expansion position for communication algorithm scheduling. [Detail](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/800alpha001/apiref/envref/envref_07_0094.html)</td>

      <td />
    </tr>

    <tr>
      <td>`HCCL_BUFFSIZE`</td>
      <td>Controls the size of the buffer area for shared data between two NPUs. \
      The unit is MB, and the value must be greater than or equal to 1. [Detail](https://www.hiascend.com/document/detail/zh/Pytorch/60RC3/ptmoddevg/trainingmigrguide/performance_tuning_0047.html)</td>
      <td>`200`</td>
    </tr>

    <tr>
      <td>`HCCL_SOCKET_IFNAME`</td>
      <td>Configures the name of the network card used by the Host \
      during HCCL initialization. [Detail](https://www.hiascend.com/document/detail/zh/canncommercial/81RC1/apiref/envvar/envref_07_0075.html)</td>

      <td />
    </tr>

    <tr>
      <td>`GLOO_SOCKET_IFNAME`</td>
      <td>Configures the network interface name for GLOO communication.</td>

      <td />
    </tr>
  </tbody>
</table>


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