| title | Debugging |
|---|---|
| weight | 50 |
Tools and techniques for debugging FlagGems-vllm operators.
FlagGems-vllm uses Python's standard logging module.
import logging
logging.basicConfig(level=logging.DEBUG)
import flaggems_vllm
# Now see detailed logsLog only FlagGems-vllm messages:
import logging
logger = logging.getLogger('flaggems_vllm')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)Symptom: Operator raises NotImplementedError for your input.
Cause: Unsupported dtype, shape, or configuration.
Solution:
- Check operator documentation for supported configurations
- This is by design (NO_TORCH_COMPUTE_FALLBACK rule)
- Implement support for your configuration or use a different operator
Example:
try:
result = flaggems_vllm.my_operator(x)
except NotImplementedError as e:
print(f"Unsupported: {e}")
# Handle explicitly (e.g., use torch fallback)Symptom: Results differ from reference implementation.
Cause: Floating-point precision, different algorithms, or bugs.
Solution:
-
Check tolerance:
import torch diff = (result - expected).abs().max() rel_diff = ((result - expected).abs() / expected.abs()).max() print(f"Max abs diff: {diff}, max rel diff: {rel_diff}")
-
Verify input data:
print(f"Input shape: {x.shape}, dtype: {x.dtype}, device: {x.device}") print(f"Input range: [{x.min()}, {x.max()}]")
-
Test with simpler inputs:
# Identity case x = torch.eye(4, device='cuda') # Small random x = torch.randn(4, 4, device='cuda') * 0.1
Symptom: FlagGems-vllm slower than the vLLM baseline.
Cause: Missing autotune, poor shape, or cold start.
Solution:
-
Warm up before benchmarking:
for _ in range(10): # Warmup flaggems_vllm.my_operator(x) import time torch.cuda.synchronize() start = time.time() result = flaggems_vllm.my_operator(x) torch.cuda.synchronize() print(f"Time: {time.time() - start}")
-
Check autotune config exists:
grep "my_operator" src/flaggems_vllm/runtime/backend/_nvidia/tune_configs.yaml -
Profile (see below)
Symptom: ImportError: cannot import name 'my_operator'
Cause: Operator not exported or not installed.
Solution:
-
Check operator is exported:
grep "my_operator" src/flaggems_vllm/ops/__init__.py grep "my_operator" src/flaggems_vllm/__init__.py
-
Reinstall in editable mode:
pip install --no-build-isolation -e .
Triton has built-in profiling:
import triton
with triton.profiler.Profile() as prof:
result = flaggems_vllm.my_operator(x)
prof.print()Profile CUDA kernels:
ncu --set full -o profile python script.pyOpen profile.ncu-rep in Nsight Compute GUI.
import torch
from torch.profiler import profile, ProfilerActivity
with profile(activities=[ProfilerActivity.CUDA], record_shapes=True) as prof:
result = flaggems_vllm.my_operator(x)
print(prof.key_averages().table(sort_by="cuda_time_total"))
prof.export_chrome_trace("trace.json")View trace.json in Chrome at chrome://tracing.
Triton supports tl.device_print():
import triton
import triton.language as tl
@triton.jit
def my_kernel(x_ptr, ...):
pid = tl.program_id(0)
tl.device_print("Block", pid, "processing")
# ...Note: Device prints can be slow. Remove in production.
Set TRITON_DEBUG=1 to see compilation logs:
TRITON_DEBUG=1 python script.pyTest with a single config:
from flaggems_vllm.utils import libtuner
@libtuner(configs=[{"BLOCK_SIZE": 128}], key=[], strategy=[])
@triton.jit
def my_kernel(...):
...Use tests/accuracy_utils.py:
from tests.accuracy_utils import to_reference, gems_assert_close
ref_input = to_reference(cuda_input)
ref_output = reference_impl(ref_input)
result = flaggems_vllm.my_operator(cuda_input)
gems_assert_close(result, ref_output, rtol=1e-3, atol=1e-5)Test operator in isolation:
import torch
import flaggems_vllm
x = torch.randn(128, 256, device='cuda', dtype=torch.float16)
# Direct call (no other operators involved)
result = flaggems_vllm.my_operator(x)
print(result.shape, result.dtype)If you're stuck:
- Check documentation: Operator may have known limitations
- Search issues: Someone may have hit the same problem
- Create minimal reproducer: Simplify to smallest failing case
- Open an issue: Include:
- FlagGems-vllm version
- PyTorch version
- Hardware (GPU model, driver version)
- Minimal code to reproduce
- Error message and stack trace