|
| 1 | +# FlashInfer Logging |
| 2 | + |
| 3 | +FlashInfer provides a logging feature to help debug issues, and reproduce crashes. This document describes all available logging levels and their features. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +Enable logging using two environment variables: |
| 8 | + |
| 9 | +```bash |
| 10 | +# Set logging level (0-5) |
| 11 | +export FLASHINFER_LOGLEVEL_DBG=3 |
| 12 | + |
| 13 | +# Set log destination (default is stdout) |
| 14 | +export FLASHINFER_LOGDEST_DBG=stdout # or stderr, or a file path like "flashinfer.log" |
| 15 | + |
| 16 | +# Run your code |
| 17 | +python train.py |
| 18 | +``` |
| 19 | + |
| 20 | +## Logging Levels |
| 21 | + |
| 22 | +| Level | Name | Features | Use Case | |
| 23 | +|-------|------|----------|----------| |
| 24 | +| **0** | Disabled (Default) | No logging (zero overhad) | Production | |
| 25 | +| **1** | Function Names | Function names only | Basic tracing | |
| 26 | +| **3** | Inputs/Outputs | Function names + arguments + outputs with metadata | Standard debugging | |
| 27 | +| **5** | Statistics | Level 3 + tensor statistics (min, max, mean, NaN/Inf counts) | Numerical analysis | |
| 28 | + |
| 29 | + |
| 30 | +## Environment Variables |
| 31 | + |
| 32 | +### Main Configuration |
| 33 | + |
| 34 | +| Variable | Type | Default | Description | |
| 35 | +|----------|------|---------|-------------| |
| 36 | +| `FLASHINFER_LOGLEVEL_DBG` | int | 0 | Logging level (0, 1, 3, 5) | |
| 37 | +| `FLASHINFER_LOGDEST_DBG` | str | `stdout` | Log destination: `stdout`, `stderr`, or file path | |
| 38 | + |
| 39 | +### Process ID Substitution |
| 40 | + |
| 41 | +Use `%i` in file paths for automatic process ID substitution (useful for multi-GPU training): |
| 42 | + |
| 43 | +```bash |
| 44 | +export FLASHINFER_LOGDEST_DBG="flashinfer_log_%i.txt" # → flashinfer_log_12345.txt |
| 45 | +``` |
| 46 | + |
| 47 | +This works for: |
| 48 | +- `FLASHINFER_LOGDEST_DBG` |
| 49 | + |
| 50 | +## Miscellaneous Notes and Examples |
| 51 | +### CUDA Graph Compatibility |
| 52 | + |
| 53 | +Level 5 statistics are **automatically skipped during CUDA graph capture** to avoid synchronization issues. |
| 54 | + |
| 55 | +```python |
| 56 | +# This works correctly - no synchronization errors |
| 57 | +with torch.cuda.graph(cuda_graph): |
| 58 | + result = mm_fp4(a, b, scales) # Level 5 logging active |
| 59 | + # Statistics automatically skipped during capture |
| 60 | +``` |
| 61 | + |
| 62 | +Output shows: `[statistics skipped: CUDA graph capture in progress]` |
| 63 | + |
| 64 | +### Process IDs for Multi-GPU Environments |
| 65 | + |
| 66 | +```bash |
| 67 | +# Use %i for process ID substitution |
| 68 | +export FLASHINFER_LOGLEVEL_DBG=3 |
| 69 | +export FLASHINFER_LOGDEST_DBG="logs/flashinfer_api_%i.log" |
| 70 | + |
| 71 | +torchrun --nproc_per_node=8 awesome_script_that_uses_FlashInfer.py |
| 72 | + |
| 73 | +# Creates separate logs: |
| 74 | +# logs/flashinfer_api_12345.log (rank 0) |
| 75 | +# logs/flashinfer_api_12346.log (rank 1) |
| 76 | +# ... |
| 77 | +``` |
| 78 | + |
| 79 | +## Frequently Asked Questions |
| 80 | + |
| 81 | +### Q: Does Level 0 really have zero overhead? |
| 82 | + |
| 83 | +**A: Yes.** At Level 0, the decorator returns the original function unchanged. No wrapper, no checks, no overhead. |
0 commit comments