| `profiler` | Profiler backend. Supported values: `torch`, `cuda`. Use `torch` for `trace.json`, Excel operator tables, and optional memory snapshots. Use `cuda` for Nsight Systems only. |
| `torch_profiler_dir` | Output directory for torch-profiler artifacts. Required when `profiler: torch`. |
| `torch_profiler_use_gzip` | Compress `trace_rank*.json` into `trace_rank*.json.gz`. |
| `torch_profiler_record_shapes` | Record input shapes and add a `by_shape` sheet to `ops_rank*.xlsx`. |
| `torch_profiler_with_stack` | Record call stacks, add a `by_stack` sheet to `ops_rank*.xlsx`, and export `stacks_cpu_rank*.txt` and `stacks_cuda_rank*.txt`. |
| `torch_profiler_with_memory` | Enable memory profiling and attempt to dump `memory_snapshot_rank*.pickle`. The pickle is only generated when the current backend supports memory history and snapshot APIs. |
| `torch_profiler_with_flops` | Enable FLOPs collection in `torch.profiler`. This does not add a separate output file. |
| `torch_profiler_dump_cuda_time_total` | Export an additional text summary `profiler_out_<rank>.txt` sorted by `self_cuda_time_total`. |
-`ops_rank*.xlsx` with `summary`, `by_shape`, and `by_stack`
-`stacks_cpu_rank*.txt`
-`stacks_cuda_rank*.txt`
Collect trace, operator tables, and memory snapshots:
```python
profiler_config={
"profiler":"torch",
"torch_profiler_dir":"./perf",
"torch_profiler_record_shapes":True,
"torch_profiler_with_stack":True,
"torch_profiler_with_memory":True,
}
```
Outputs:
-`trace_rank*.json`
-`ops_rank*.xlsx` with `summary`, `by_shape`, and `by_stack`
-`stacks_cpu_rank*.txt`
-`stacks_cuda_rank*.txt`
-`memory_snapshot_rank*.pickle` when supported by the current backend
### Full torch-profiler configuration
If you want to enable the commonly used torch-profiler options together:
```python
profiler_config={
"profiler":"torch",
"torch_profiler_dir":"./perf",
"torch_profiler_use_gzip":False,
"torch_profiler_record_shapes":True,
"torch_profiler_with_stack":True,
"torch_profiler_with_memory":True,
"torch_profiler_with_flops":False,
"torch_profiler_dump_cuda_time_total":False,
"delay_iterations":0,
"max_iterations":0,
"wait_iterations":0,
"warmup_iterations":0,
"active_iterations":0,
}
```
## 2. Profiling Diffusion with PyTorch Profiler
Single-stage diffusion models use `start_profile()` / `stop_profile()` controls. The profiler only writes artifacts after profiling has been started and then stopped.
For diffusion offline example scripts under `examples/offline_inference/`, pass `--profiler-config` as a JSON object. The script enables profiling when this argument is set and wraps generation with `start_profile()` / `stop_profile()`.
Then call `start_profile()` before the requests you want to capture and `stop_profile()` after them. The diffusion worker processes open and close the CUDA capture range themselves, so `nsys` sees the actual GPU work instead of only the parent process.
For lightweight per-stage pipeline timing such as `vae.decode` or `diffuse`, see [Diffusion Pipeline Profiler](model/adding_diffusion_model.md#diffusion-pipeline-profiler-performance-profiling). That utility logs stage durations only and does not generate torch-profiler artifacts such as `trace.json`, Excel tables, or memory snapshots.
For upstream background on the underlying vLLM profiling infrastructure, see the [vLLM profiling guide](https://docs.vllm.ai/en/stable/contributing/profiling/).