quantization-dev

Reverse-engineer quantization contracts and verify bit-exact alignment of custom quantizers on Ascend NPU.

14|5|Updated Mar 30, 2026
One-click install
npx skills add https://github.com/Ascend/MindIE-SD --skill quantization-dev-ascend
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: quantization-dev
Source: https://github.com/Ascend/MindIE-SD/tree/main/.agents/skills/quantization-dev
Command: npx skills add https://github.com/Ascend/MindIE-SD --skill quantization-dev-ascend

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Custom quantization kernels often mismatch framework operators (aclnn) at the byte level even when outputs look statistically identical. This Skill reverse-engineers the undocumented numeric contract of a quantizer—scale granularity, rounding mode, saturation behavior, and degenerate-block rules—from device bytes, then guides bit-exact reimplementation and fusion of quantizers such as MXFP8 (e8m0), int8 per-block, and fp8 per-channel on Ascend NPU with torch_npu, CANN, and triton-ascend. ## Core Features & Use Cases - Contract Reverse Engineering: A six-step method (discriminative probes, marker-based layout detection, independent reference implementation, degenerate-input coverage, corrigendum of falsified formulas) to derive encoding formulas like byte = 119 + floor(log2(amax)) instead of guessing. - Bit-Level Comparison SOP: Same-process, same-data verification with separate payload/scale counting, adversarial inputs (all 165 e4m3 midpoints, subnormals, inf/nan, tail blocks), and md5-identity end-to-end gates. - Implementation Pitfall Rules: Load divisors from memory instead of recomputing in-kernel, use integer RNE bit tricks for bf16 rounding, and treat 8-bit casts as wrap-around rather than saturation. - Use Case: Your fused quantization kernel matches the framework operator on 99.9% of payload bytes but not exactly—use this Skill to identify whether the cause is scale granularity, rounding mode, strength-reduced division, or a silently eliminated bf16 cast, then fix it to reach 100% byte equality. ## Quick Start Ask the AI to reverse-engineer why your fused quantization kernel's output differs from the framework's quantization operator and produce a bit-exact reimplementation.

Frequently Asked Questions about quantization-dev

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make my custom quantization kernel bit-exact with the framework operator?

Run an independent reference implementation in the same process on the same data, count payload and scale bytes separately, and require 100% byte equality. Check the three universal rules first: load divisors from memory, use integer RNE bit tricks for bf16 rounding, and verify scale granularity before comparing rounding modes.

How do I reverse-engineer the MXFP8 e8m0 scale byte formula?

Use discriminative probes at points where candidate formulas disagree, such as amax values 450, 1000, and 230. The verified rule is byte = 119 + floor(log2(amax)) clamped to [0,254], implemented via the fp32 exponent field rather than log2; the intuitive ceil(log2(amax/448)) formula is falsified.

Why does my quantizer match 99.9% of bytes but fail bit-exact verification?

Small residual mismatches usually come from strength-reduced division (about 2 ulp error when the divisor is recomputed in-kernel), silently eliminated bf16 casts in triton-ascend, or wrong scale granularity. Each cause produces a characteristic residual pattern that identifies the root cause.

Does int8 conversion saturate or wrap around on overflow?

On this toolchain, 8-bit conversion wraps around rather than saturates, proven by forcing inv=1e5 and observing 256 roughly uniform output values. Removing clamps is only safe when normalization guarantees the range by construction, and that invariant must be documented in comments.

Can I reuse these quantization contracts on different hardware or CANN versions?

No. Every contract, parameter, and falsified formula is a snapshot of one specific chip, software stack, and model. On any new environment, rerun the six-step reverse-engineering method and bit-level comparison SOP, including retesting previously falsified formulas.

When should I not use this Skill for quantization questions?

Do not use it for choosing whether to enable quantization or which tier to use (that belongs to performance/feature selection), for operator-level performance tuning and DSL selection, or for diagnosing parallel-scope silent failures. This Skill only answers how a quantizer computes its values.