Skip to content

Commit a071556

Browse files
committed
Adding documentation updates
1 parent 3d11a48 commit a071556

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

LOGGING.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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.

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,20 @@ o = flashinfer.single_prefill_with_kv_cache(q, k, v, causal=False) # prefill att
169169

170170
Check out [documentation](https://docs.flashinfer.ai/) for usage of batch decode/append/prefill kernels and shared-prefix cascading kernels.
171171

172+
## API Logging
173+
174+
FlashInfer provides comprehensive API logging for debugging. Enable it using environment variables:
175+
176+
```bash
177+
# Enable logging (levels: 0=off (default), 1=basic, 3=detailed, 5=statistics)
178+
export FLASHINFER_LOGLEVEL_DBG=3
179+
180+
# Set log destination (stdout (default), stderr, or file path)
181+
export FLASHINFER_LOGDEST_DBG=stdout
182+
```
183+
184+
For detailed information about logging levels, configuration, and advanced features, see [LOGGING.md](LOGGING.md).
185+
172186
## Custom Attention Variants
173187

174188
Starting from FlashInfer v0.2, users can customize their own attention variants with additional parameters. For more details, refer to our [JIT examples](https://github.com/flashinfer-ai/flashinfer/blob/main/tests/utils/test_jit_example.py).

0 commit comments

Comments
 (0)