-
Notifications
You must be signed in to change notification settings - Fork 581
feat: Enable API Logging for Better Debugging POC #2108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
18de631
First commit
bkryu ae44417
Adding benchmark. Applying pre-commit
bkryu 753e600
Log System Info
bkryu 6d0406b
Rename logging env vars. Set default dest to stdout
bkryu e984e1b
Allow %i substitution for process ID for multi-GPU environments. Loggβ¦
bkryu 62b6436
Add time stamps and space out levels
bkryu aed27cf
Cleanup and streamline
bkryu 5ec246b
Adding documentation updates
bkryu 8459eb1
Fix typo and apply pre-commit
bkryu 41ad558
Rename decorator and environment flags
bkryu 4a80fc4
Fix typo
bkryu a75c359
Add disclaimer to decorator docstring
bkryu 3bb0b73
Move logging.md to documentation
bkryu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # FlashInfer Logging | ||
|
|
||
| FlashInfer provides a logging feature to help debug issues, and reproduce crashes. This document describes all available logging levels and their features. | ||
|
|
||
| ## Quick Start | ||
|
|
||
| Enable logging using two environment variables: | ||
|
|
||
| ```bash | ||
| # Set logging level (0-5) | ||
| export FLASHINFER_LOGLEVEL=3 | ||
|
|
||
| # Set log destination (default is stdout) | ||
| export FLASHINFER_LOGDEST=stdout # or stderr, or a file path like "flashinfer.log" | ||
|
|
||
| # Run your code | ||
| python train.py | ||
| ``` | ||
|
|
||
| ## Logging Levels | ||
|
|
||
| | Level | Name | Features | Use Case | | ||
| |-------|------|----------|----------| | ||
| | **0** | Disabled (Default) | No logging (zero overhead) | Production | | ||
| | **1** | Function Names | Function names only | Basic tracing | | ||
| | **3** | Inputs/Outputs | Function names + arguments + outputs with metadata | Standard debugging | | ||
| | **5** | Statistics | Level 3 + tensor statistics (min, max, mean, NaN/Inf counts) | Numerical analysis | | ||
|
|
||
|
|
||
| ## Environment Variables | ||
|
|
||
| ### Main Configuration | ||
|
|
||
| | Variable | Type | Default | Description | | ||
| |----------|------|---------|-------------| | ||
| | `FLASHINFER_LOGLEVEL` | int | 0 | Logging level (0, 1, 3, 5) | | ||
| | `FLASHINFER_LOGDEST` | str | `stdout` | Log destination: `stdout`, `stderr`, or file path | | ||
|
|
||
| ### Process ID Substitution | ||
|
|
||
| Use `%i` in file paths for automatic process ID substitution (useful for multi-GPU training): | ||
|
|
||
| ```bash | ||
| export FLASHINFER_LOGDEST="flashinfer_log_%i.txt" # β flashinfer_log_12345.txt | ||
| ``` | ||
|
|
||
| This works for: | ||
| - `FLASHINFER_LOGDEST` | ||
|
|
||
| ## Miscellaneous Notes and Examples | ||
| ### CUDA Graph Compatibility | ||
|
|
||
| Level 5 statistics are **automatically skipped during CUDA graph capture** to avoid synchronization issues. | ||
|
|
||
| ```python | ||
| # This works correctly - no synchronization errors | ||
| with torch.cuda.graph(cuda_graph): | ||
| result = mm_fp4(a, b, scales) # Level 5 logging active | ||
| # Statistics automatically skipped during capture | ||
| ``` | ||
|
|
||
| Output shows: `[statistics skipped: CUDA graph capture in progress]` | ||
|
|
||
| ### Process IDs for Multi-GPU Environments | ||
|
|
||
| ```bash | ||
| # Use %i for process ID substitution | ||
| export FLASHINFER_LOGLEVEL=3 | ||
| export FLASHINFER_LOGDEST="logs/flashinfer_api_%i.log" | ||
|
|
||
| torchrun --nproc_per_node=8 awesome_script_that_uses_FlashInfer.py | ||
|
|
||
| # Creates separate logs: | ||
| # logs/flashinfer_api_12345.log (rank 0) | ||
| # logs/flashinfer_api_12346.log (rank 1) | ||
| # ... | ||
| ``` | ||
|
|
||
| ## Frequently Asked Questions | ||
|
|
||
| ### Q: Does Level 0 really have zero overhead? | ||
|
|
||
| **A: Yes.** At Level 0, the decorator returns the original function unchanged. No wrapper, no checks, no overhead. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we wanna organize this file in docs/ etc?
cc @yzh119
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or might be even better to convert this to an .rst so that it appears in the documentations
@yzh119 do you have suggestions on how I might convert and where I can place the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think placing it under docs/logging.rst and indexing it in docs/index.rst should be great.
I have tried pandoc before but I believe any existing llm (gemini/claude/gpt) could do a better job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yzh119, makes sense. I converted in the latest commit and built the sphinx documentation locally
Here is how the index page looks: See red marks for where I placed it:

and here is how the actual logging page looks:
