Skip to content
Agentmart
Submit a tool

debug-kernel-crash

Debug GPU kernel crashes in SGLang (CUDA and ROCm) using @debug_kernel_api logging — illegal memory access, device assert, NaN/Inf, wrong shapes.

Skill by yichiche

IndexedMIT★ 2
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/yichiche-debug-kernel-crash

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Debug GPU kernel crashes in SGLang (CUDA and ROCm) using @debug_kernel_api logging — illegal memory access, device assert, NaN/Inf, wrong shapes. Use when a server or kernel test crashes before normal debug output flushes.

Use cases: backend, testing

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/debug-kernel-crash

What's inside

Skill name
debug-kernel-crash
Description
Debug GPU kernel crashes in SGLang (CUDA and ROCm) using @debug_kernel_api logging — illegal memory access, device assert, NaN/Inf, wrong shapes. Use when a server or kernel test crashes before normal debug output flushes.
License
MIT
Instructions
119 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Debug Kernel Crashes with API Logging

Adapted from upstream `debug-cuda-crash` skill. Works on both CUDA and ROCm (ROCm reports device as `cuda:N` in PyTorch).

## Goal

When code crashes with illegal memory access, device-side assert, OOB, or NaN/Inf:

- Capture input tensors **before** the crash
- Track shapes, dtypes, values at the kernel boundary that triggered it
- Detect NaN/Inf or obviously wrong shapes

## Why kernel API logging?

CUDA/HIP errors often abort before stdout flushes. `@debug_kernel_api` logs inputs **before** execution.

## What is covered

- Custom ops via `register_custom_op(...)` / `register_custom_op_from_extern(...)`
- LLM attention, linear, quantization, multi-platform wrappers
- Selected `torch.ops.sglang.*` hotspots

Does **not** cover every pure PyTorch call — only decorated kernel boundaries.

## Step 1: Enable logging

### Level 1 — function names only

```bash
export SGLANG_KERNEL_API_LOGLEVEL=1
export SGLANG_KERNEL_API_LOGDEST=stdout

# launch server or run test
bash run_qwen3.5_mxfp4.sh 2>&1 | tee /tmp/kernel_api.log
```

### Level 3 — inputs with metadata (shapes, dtypes)

```bash
export SGLANG_KERNEL_API_LOGLEVEL=3
export SGLANG_KERNEL_API_LOGDEST=/tmp/debug.log
```

### Level 5 — tensor statistics (min/max/mean, nan_count, inf_count)

```bash
export SGLANG_KERNEL_API_LOGLEVEL=5
export SGLANG_KERNEL_API_LOGDEST=/tmp/debug.log
```

Start at level 3. Escalate to 5 only on the last few calls before crash (level 5 is slow).

## Step 2: Reproduce minimally

1. Reduce to smallest repro: single request, conc=1, short prompt
2. Disable cuda graph if crash is graph-specific:
   ```bash
   --disable-cuda-graph --disable-prefill-cuda-graph
   ```
3. On MI355, note which backend is active (`SGLANG_USE_AITER`, `_use_aiter` path)

## Step 3: Read the log

Find the **last successful kernel call** before crash. Check:

| Signal | Likely cause |
|--------|-------------|
| Wrong shape on last call | Dispatch bug, incorrect M/N/K |
| `nan_count > 0` or `inf_count > 0` | Numerical instability upstream |
| Shape jumps between calls | Batch composition change mid-forward |
| Missing expected call | Wrong code path taken (check `_use_aiter` / `_is_hip` gates) |

## Step 4: Bisect the call chain

If the crash is deep in aiter:

```bash
# Run aiter op_test in isolation
cd /sgl-workspace/aiter
python op_tests/test_<op>.py -v
```

If in SGLang Triton:

```python
# Minimal script at the failing M
import torch
# call kernel directly at M=1 and M=8
```

Use `/kl-consistency-test` standalone repro pattern (M=1 vs M=288) for batch-invariance crashes.

## Step 5: ROCm-specific notes

- HIP errors surface as `CUDA error` in PyTorch — same logging env vars work
- `rocgdb` / `HSA_ENABLE_DEBUG=1` for native HIP crashes outside Python
- Check `dmesg` for GPU page fault after hard crash
- Container OOM vs GPU OOM: `rocm-smi` shows VRAM; host shows if process was killed

## Common crash patterns on MI355

| Pattern | Check |
|---------|-------|
| MoE dispatch shape mismatch | `topk_ids` shape vs expert count, EP size |
| FP8 block scale wrong dims | `scale` tensor M/N alignment with CK kernel |
| Attention workspace too small | `max_seq_len`, page size, batch size interaction |
| aiter .so stale after rebuild | Re-run `python setup.py develop` in aiter |

## Related skills

| Skill | Use when |
|-------|----------|
| `/kl-consistency-test` | Crash during KL repro; batch-invariance |
| `/implement-kernel` | Fix identified after bisect |
| `/validate-pr` | Re-validate after fix |

Upstream reference: https://github.com/sgl-project/sglang/tree/main/.claude/skills/debug-cuda-crash

From yichiche/agent-box, MIT.

More from yichiche/agent-box

Signals

Stars
2
Forks
0
Open issues
0
Last commit (this folder)
Aug 21, 2026 (2 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from yichiche

Cite this page

debug-kernel-crash skill. Agent Mart. https://agentmart.dev/skills/yichiche-debug-kernel-crash (last updated 2026-10-24)