Debug quantized kernel accuracy

From tensormux/kernel-skills · View interactive version

Debug quantized kernel accuracy is an AI agent skill from the GitHub repository tensormux/kernel-skills. Guide the agent through a systematic process for diagnosing and isolating accuracy degradation in a quantized (INT8, FP8, or low-bit) kernel, from measuring the error to identifying the specific compu

How to use this skill

Skill file

Skill: Debug Quantized Kernel Accuracy

Purpose

Guide the agent through a systematic process for diagnosing and isolating accuracy degradation in a quantized (INT8, FP8, or low-bit) kernel, from measuring the error to identifying the specific computational step responsible.

Use this when

Do not use this when

Inputs the agent should gather first

Required reasoning process

  1. Measure the error precisely. Do not characterize accuracy failures as "wrong" without quantifying them:
  1. Isolate the quantization step responsible. The quantization pipeline is:

```

fp32 input → quantize → int8 input

int8 GEMM (or other op) with int32 accumulation

int32 accumulation → dequantize → fp32/fp16 output

```

Test each boundary:

  1. Check scale computation for outliers. A single large-magnitude input value can dominate the scale computation for a per-tensor or per-row quantization scheme, causing all other values to be mapped to a narrow range of INT8 values (near zero). This is called the outlier problem:
  1. Verify zero-point handling for asymmetric quantization. Zero-point bugs produce systematic bias in the output:
  1. Verify accumulation dtype is INT32. INT8 accumulation overflows for dot products of length > ~10 with typical INT8 values. Symptoms: outputs are wildly wrong and the error grows with K (the reduction dimension). Verify by reading the kernel source and confirming the accumulator variable is int32_t, not int8_t or int16_t.
  1. Check scale application order for per-channel / per-token quantization. The scale must be applied along the correct dimension:
  1. Check INT32 accumulation overflow. For very long dot products with INT8 inputs, INT32 can overflow:
  1. Check the dequantization epilogue sequence. The order of operations in the epilogue matters:
  1. Check for shape-dependent failures. If the kernel is correct on some shapes but wrong on others, the likely causes are:

Kernel design rules

Correctness requirements

Performance requirements

Output format

The agent should produce:

  1. Error characterization: a table showing max absolute error, mean absolute error, relative error, and SNR (if applicable) compared to the fp32 reference.
  2. Error distribution analysis: a statement of whether the error is uniform or structured (row/column/block-wise), with evidence (e.g., per-row error norms).
  3. Isolation test results: results of the quant-dequant roundtrip test, the INT32 accumulation test, and the dequantization epilogue test, each compared to their expected values.
  4. Root cause statement: a single-sentence identification of the specific bug (e.g., "scale is applied to the M dimension instead of the N dimension" or "zero-point subtraction has the wrong sign").
  5. Fix implementation: the corrected code with a comment explaining what was wrong and why the fix is correct.
  6. Regression test: a minimal test case that would have caught this bug, added to the test suite.

Common failure modes

Review checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.