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

> Configure SGLang diffusion behavior with environment variables.

## Runtime

<table>
  <colgroup>
    <col />

    <col />

    <col />
  </colgroup>

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

  <tbody>
    <tr>
      <td>`SGLANG_EXTERNAL_MODEL_PACKAGE`</td>
      <td>not set</td>
      <td>Installed package that registers out-of-tree diffusion pipelines and component models. The package is imported once in every process.</td>
    </tr>

    <tr>
      <td>`SGLANG_DIFFUSION_PLATFORM_OVERRIDE`</td>
      <td>not set</td>
      <td>Select `cpu`, `cuda`, `rocm`, `mps`, `npu`, `musa`, or an installed `sglang.multimodal_gen.platforms` entry-point name. XPU remains automatic-only. When unset, SGLang Diffusion detects installed platform plugins before trying built-in platforms.</td>
    </tr>

    <tr>
      <td>`SGLANG_PLUGINS`</td>
      <td>not set</td>
      <td>Comma-separated allowlist for installed `sglang.multimodal_gen.plugins` hooks. When unset, all discovered diffusion hooks load.</td>
    </tr>

    <tr>
      <td>`SGLANG_DIFFUSION_ATTENTION_CONFIG`</td>
      <td>not set</td>
      <td>Path to attention backend configuration file (JSON/YAML)</td>
    </tr>

    <tr>
      <td>`SGLANG_DIFFUSION_STAGE_LOGGING`</td>
      <td>false</td>
      <td>Enable per-stage timing logs</td>
    </tr>

    <tr>
      <td>`SGLANG_DIFFUSION_TORCH_PROFILER_DIR`</td>
      <td>not set</td>
      <td>Directory for torch profiler traces (absolute path). Enables profiling when set</td>
    </tr>

    <tr>
      <td>`SGLANG_DIFFUSION_CACHE_ROOT`</td>
      <td>`~/.cache/sgl_diffusion`</td>
      <td>Root directory for cache files</td>
    </tr>

    <tr>
      <td>`SGLANG_DIFFUSION_IPC_A2A`</td>
      <td>`true`</td>
      <td>Enable CUDA-IPC all-to-all for eligible same-host, peer-accessible TP1 + two-rank Ulysses groups. Unsupported topology falls back to NCCL; set `0` to force NCCL.</td>
    </tr>

    <tr>
      <td>`SGLANG_DIFFUSION_IPC_A2A_TIMEOUT_MS`</td>
      <td>`10000`</td>
      <td>Peer-wait timeout in milliseconds. This is a hang backstop, not a per-step budget; raise it only for known long stalls such as layerwise offload.</td>
    </tr>

    <tr>
      <td>`SGLANG_DIFFUSION_IPC_A2A_MAX_BUFFERS`</td>
      <td>`16`</td>
      <td>Maximum cached IPC staging-buffer shape pairs. Cap this for multi-resolution serving to bound permanent staging memory.</td>
    </tr>

    <tr>
      <td>`SGLANG_DIFFUSION_ULYSSES_PIPELINE_GROUPS`</td>
      <td>`-1`</td>
      <td>Head groups for pipelining the Ulysses exchange against dense attention over the copy engine. `-1` picks the largest count that divides the heads per rank while each group still fills the GPU; `0` keeps the sequential exchange; `N` forces `N` groups. Results are bit-identical either way.</td>
    </tr>

    <tr>
      <td>`SGLANG_USE_RUNAI_MODEL_STREAMER`</td>
      <td>true</td>
      <td>Use Run:AI model streamer for model loading</td>
    </tr>

    <tr>
      <td>`SGLANG_DIFFUSION_CONVROT_INT8_BACKEND`</td>
      <td>`auto`</td>
      <td>Kernel backend for `convrot_int8`: `auto` takes SGLang's JIT-compiled ConvRot ops where they build and run (CC 9.0, 10.0, 12.0, 12.1 with nvcc) and `comfy_kitchen` otherwise; `jit` or `comfy_kitchen` forces one.</td>
    </tr>

    <tr>
      <td>`SGLANG_KITCHEN_INT8_MAX_ROWS`</td>
      <td>`0`</td>
      <td>Max activation rows per `convrot_int8` fused GEMM on the `comfy_kitchen` backend. `0` (default) issues one call; a positive value splits large-M GEMMs by rows.</td>
    </tr>

    <tr>
      <td>`SGLANG_KITCHEN_INT8_MIN_SPLIT_N`</td>
      <td>`8192`</td>
      <td>Minimum output features before `convrot_int8` (`comfy_kitchen` backend) splits large-M GEMMs when `SGLANG_KITCHEN_INT8_MAX_ROWS` is positive. Narrow outputs stay as a single call.</td>
    </tr>
  </tbody>
</table>

## Platform-Specific

### Apple MPS

<table>
  <colgroup>
    <col />

    <col />

    <col />
  </colgroup>

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

  <tbody>
    <tr>
      <td>`SGLANG_USE_MLX`</td>
      <td>not set</td>
      <td>SRT only: enables the MLX serving backend. It has no effect on SGLang Diffusion, which uses PyTorch MPS.</td>
    </tr>
  </tbody>
</table>

### ROCm (AMD GPUs)

<table>
  <colgroup>
    <col />

    <col />

    <col />
  </colgroup>

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

  <tbody>
    <tr>
      <td>`SGLANG_USE_ROCM_VAE`</td>
      <td>false</td>
      <td>Use AITer GroupNorm in VAE for improved performance on ROCm</td>
    </tr>

    <tr>
      <td>`SGLANG_USE_ROCM_CUDNN_BENCHMARK`</td>
      <td>false</td>
      <td>Enable MIOpen auto-tuning for VAE conv layers on ROCm</td>
    </tr>
  </tbody>
</table>

### Quantization

<table>
  <colgroup>
    <col />

    <col />

    <col />
  </colgroup>

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

  <tbody>
    <tr>
      <td>`SGLANG_DIFFUSION_FLASHINFER_FP4_GEMM_BACKEND`</td>
      <td>not set</td>
      <td>Optional FlashInfer FP4 GEMM backend override for diffusion NVFP4. When unset, SGLang uses `flashinfer_trtllm` (`auto` on SM120 GPUs).</td>
    </tr>

    <tr>
      <td>`SGLANG_DIFFUSION_ENABLE_W8A8_FP8_GEMM`</td>
      <td>false</td>
      <td>Experimental opt-in for fused W8A8 FP8 GEMM in diffusion weight-only FP8 linears. When disabled, FP8 weights are dequantized to the compute dtype before matmul. Enabling this dynamically quantizes activations to FP8 and may change output quality.</td>
    </tr>

    <tr>
      <td>`SGLANG_DIFFUSION_ENABLE_MXFP8_ATTENTION`</td>
      <td>false</td>
      <td>Enable Ascend MXFP8 FA for supported non-causal self-attention layers. Applies to online `MXFP8Config` and offline ModelSlim `W8A8_MXFP8` checkpoints. Unsupported calls continue to use the regular attention path.</td>
    </tr>

    <tr>
      <td>`SGLANG_DIFFUSION_MXFP8_FA_HEAD_CHUNK_SIZE`</td>
      <td>4</td>
      <td>Maximum number of attention heads processed by each Ascend MXFP8 FA call. Smaller chunks may improve performance for large workloads but add kernel launches; the optimal value depends on the model and input shape. Set to 0 to disable head splitting.</td>
    </tr>
  </tbody>
</table>

## Caching Acceleration

These variables configure caching acceleration for Diffusion Transformer (DiT) models.
SGLang supports multiple caching strategies - see [caching documentation](./caching-acceleration) for an overview.

### Cache-DiT Configuration

See [cache-dit documentation](https://docs.sglang.io/docs/sglang-diffusion/cache_dit.md) for detailed configuration.

<table>
  <colgroup>
    <col />

    <col />

    <col />
  </colgroup>

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

  <tbody>
    <tr>
      <td>`SGLANG_CACHE_DIT_ENABLED`</td>
      <td>false</td>
      <td>Enable Cache-DiT acceleration</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_FN`</td>
      <td>1</td>
      <td>First N blocks to always compute</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_BN`</td>
      <td>0</td>
      <td>Last N blocks to always compute</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_WARMUP`</td>
      <td>4</td>
      <td>Warmup steps before caching</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_RDT`</td>
      <td>0.24</td>
      <td>Residual difference threshold</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_MC`</td>
      <td>3</td>
      <td>Max continuous cached steps</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_TAYLORSEER`</td>
      <td>false</td>
      <td>Enable TaylorSeer calibrator</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_TS_ORDER`</td>
      <td>1</td>
      <td>TaylorSeer order (1 or 2)</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_DMD`</td>
      <td>false</td>
      <td>Enable the DMD (Dynamic Mode Decomposition) calibrator (mutually exclusive with TaylorSeer)</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_DMD_HISTORY`</td>
      <td>6</td>
      <td>DMD snapshot window length (5-6 typical; needs >= 4 uniformly spaced snapshots, otherwise DMD falls back to TaylorSeer)</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_DMD_RANK`</td>
      <td>0</td>
      <td>DMD SVD truncation rank (0 = automatic)</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_DMD_RIDGE`</td>
      <td>1e-8</td>
      <td>DMD Tikhonov regularization added to the inverted singular values</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_DMD_SVD_PRECISION`</td>
      <td>medium</td>
      <td>DMD SVD precision (low/medium/high)</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SCM_PRESET`</td>
      <td>none</td>
      <td>SCM preset (none/slow/medium/fast/ultra)</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SCM_POLICY`</td>
      <td>dynamic</td>
      <td>SCM caching policy</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SCM_COMPUTE_BINS`</td>
      <td>not set</td>
      <td>Custom SCM compute bins</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SCM_CACHE_BINS`</td>
      <td>not set</td>
      <td>Custom SCM cache bins</td>
    </tr>
  </tbody>
</table>

### Cache-DiT Secondary Transformer

For dual-transformer models (e.g., Wan2.2 with high/low-noise experts), these variables configure caching for the secondary transformer. Each falls back to its primary counterpart if not set.

<table>
  <colgroup>
    <col />

    <col />

    <col />
  </colgroup>

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

  <tbody>
    <tr>
      <td>`SGLANG_CACHE_DIT_SECONDARY_FN`</td>
      <td>(from primary)</td>
      <td>First N blocks to always compute</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SECONDARY_BN`</td>
      <td>(from primary)</td>
      <td>Last N blocks to always compute</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SECONDARY_WARMUP`</td>
      <td>(from primary)</td>
      <td>Warmup steps before caching</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SECONDARY_RDT`</td>
      <td>(from primary)</td>
      <td>Residual difference threshold</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SECONDARY_MC`</td>
      <td>(from primary)</td>
      <td>Max continuous cached steps</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SECONDARY_TAYLORSEER`</td>
      <td>(from primary)</td>
      <td>Enable TaylorSeer calibrator</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SECONDARY_TS_ORDER`</td>
      <td>(from primary)</td>
      <td>TaylorSeer order (1 or 2)</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SECONDARY_DMD`</td>
      <td>(from primary)</td>
      <td>Enable the DMD calibrator (mutually exclusive with TaylorSeer)</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SECONDARY_DMD_HISTORY`</td>
      <td>(from primary)</td>
      <td>DMD snapshot window length</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SECONDARY_DMD_RANK`</td>
      <td>(from primary)</td>
      <td>DMD SVD truncation rank (0 = automatic)</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SECONDARY_DMD_RIDGE`</td>
      <td>(from primary)</td>
      <td>DMD Tikhonov regularization term</td>
    </tr>

    <tr>
      <td>`SGLANG_CACHE_DIT_SECONDARY_DMD_SVD_PRECISION`</td>
      <td>(from primary)</td>
      <td>DMD SVD precision (low/medium/high)</td>
    </tr>
  </tbody>
</table>

## Cloud Storage

These variables configure S3-compatible cloud storage for automatically uploading generated images and videos.

<table>
  <colgroup>
    <col />

    <col />

    <col />
  </colgroup>

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

  <tbody>
    <tr>
      <td>`SGLANG_CLOUD_STORAGE_TYPE`</td>
      <td>not set</td>
      <td>Set to `s3` to enable cloud storage</td>
    </tr>

    <tr>
      <td>`SGLANG_S3_BUCKET_NAME`</td>
      <td>not set</td>
      <td>The name of the S3 bucket</td>
    </tr>

    <tr>
      <td>`SGLANG_S3_ENDPOINT_URL`</td>
      <td>not set</td>
      <td>Custom endpoint URL (for MinIO, OSS, etc.)</td>
    </tr>

    <tr>
      <td>`SGLANG_S3_REGION_NAME`</td>
      <td>us-east-1</td>
      <td>AWS region name</td>
    </tr>

    <tr>
      <td>`SGLANG_S3_ACCESS_KEY_ID`</td>
      <td>not set</td>
      <td>AWS Access Key ID</td>
    </tr>

    <tr>
      <td>`SGLANG_S3_SECRET_ACCESS_KEY`</td>
      <td>not set</td>
      <td>AWS Secret Access Key</td>
    </tr>
  </tbody>
</table>

## CUDA Crash Debugging

These variables enable kernel API logging and optional input/output dumps around diffusion CUDA kernel call boundaries. They are useful when tracking down CUDA crashes such as illegal memory access, device-side assert, or shape mismatches in custom kernels.

<table>
  <colgroup>
    <col />

    <col />

    <col />
  </colgroup>

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

  <tbody>
    <tr>
      <td>`SGLANG_KERNEL_API_LOGLEVEL`</td>
      <td>`0`</td>
      <td>Controls crash-debug kernel API logging. `1` logs API names, `3` logs tensor metadata, `5` adds tensor statistics, and `10` also writes dump snapshots.</td>
    </tr>

    <tr>
      <td>`SGLANG_KERNEL_API_LOGDEST`</td>
      <td>`stdout`</td>
      <td>Destination for crash-debug kernel API logs. Use `stdout`, `stderr`, or a file path. `%i` is replaced with the process PID.</td>
    </tr>

    <tr>
      <td>`SGLANG_KERNEL_API_DUMP_DIR`</td>
      <td>`sglang_kernel_api_dumps`</td>
      <td>Output directory for level-10 kernel API dumps. `%i` is replaced with the process PID.</td>
    </tr>

    <tr>
      <td>`SGLANG_KERNEL_API_DUMP_INCLUDE`</td>
      <td>not set</td>
      <td>Comma-separated wildcard patterns for kernel API names to include in level-10 dumps.</td>
    </tr>

    <tr>
      <td>`SGLANG_KERNEL_API_DUMP_EXCLUDE`</td>
      <td>not set</td>
      <td>Comma-separated wildcard patterns for kernel API names to exclude from level-10 dumps.</td>
    </tr>
  </tbody>
</table>


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