Improved support for FP4 per_token/block quant - #1459
Open
learning-chip wants to merge 2 commits into
Open
Conversation
learning-chip
marked this pull request as ready for review
September 3, 2026 17:49
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PTOAS FP4 VMI lowering support
Needed for https://github.com/learning-chip/TileKernels-vmi/pull/47
Purpose
This change completes the PTOAS half of the logical-to-physical FP4 boundary needed by VMI
per_token_castandper_block_cast. TileLang deliberately emits logical packed-FP4 operations; PTOAS must then choose legal physical parts, layouts, and materialization sequences. The previous lowering treated every 8-bit source as a four-part value and assumed a contiguous result could always be formed directly. That was wrong for narrow FP4 pair carriers and for compact source layouts, causing conversion failures, wrong part selection, or unnecessary scratch traffic.The current quant audit confirms that these fixes solve the type/layout correctness failures and allow ASC-equivalent physical FP4 sequences to be generated. It does not yet prove that all remaining packed-store, TMA-scale, and FP32-carrier schedules match ASC latency; those require generated VPTO-guided optimization and fresh device measurements.
Base and scope
main@75e4a224d45bb81b7101df97edd1e4a98c0e1b9d.zjw/per_token_block_0903.c5ed27060(FP4→BF16 layout materialization) and8b66d922a(narrow FP4 layout and physical-part lowering).What is delivered
Type-aware FP4 pair lowering
f4x2 → bf16x2cast class instead of treating packed FP4 as a generic 8-bit conversion.Layout-aware physical part selection
P0, orP0/P2) when the source stride proves that only those parts exist.P0..P3expansion where required; accidentalP1use is no longer possible for aP0/P2source.Safe materialization and fallback
deint4ToContiguousmaterialization remains available when physical widths and types match; direct scratch-free lowering is selected when they do not require a reload.pto.vmioperation.Problems solved
These fixes address the failures seen when moving from ASC-equivalent physical references to logical VMI:
deinterleaved=4 → contiguousno longer fails for legal FP4→BF16 cases;UNPK4/vcvt(P0..P3)ordering matches the source layout;pto.vmiis left behind for the covered FP4 shapes.Validation and performance impact
The unified TileLang branch can now lower the packed FP4 frontend operations needed by the quant kernels. On CANN 9.1/device 0, the dependent BF16→E2M1 per-block H=128 case compiled, passed byte/scale correctness gates, and measured
1.048×ASC. The remaining slow FP4 rows are not unexplained lowering failures: packed pair-store assembly, TMA-column scale materialization, and FP32 carrier width choices still add physical work in specific schedules. Those rows are listed with concrete causes and next steps in the kernel PR and full coverage table.Follow-up
Use the ASC/CCE sequence and generated VPTO for each remaining slow row as a three-level reference ladder. The next PTOAS optimization should add direct scratch-free packed stores for the legal compact layouts, specialize TMA-column scale strides, and preserve the narrow FP32/E2M1 width choices while keeping the type-aware and layout-aware safeguards above.