Skip to content

Fix packed K/V head interleaving in LayerWeightsPtrs::Fixup. - #1093

Merged
copybara-service[bot] merged 1 commit into
devfrom
test_1028149897
Nov 24, 2026
Merged

copybara-service[bot] merged 1 commit into
devfrom
test_1028149897

Conversation

@copybara-service

Copy link
Copy Markdown

Fix packed K/V head interleaving in LayerWeightsPtrs::Fixup.

LayerWeightsPtrs::Fixup interleaved qkv_einsum_w2 K/V heads using Stride() * ElementBytes() and RowBytes(), which assumes byte-addressable elements. For block-packed formats (kQ4_0, kMXFP4, kI8, kNUQ), ElementBytes() is 1, reading past the source buffer and writing out of bounds. Placing interleaving inside the non-kI8 branch also skipped SplitAttW1I8 outputs.

Extract InterleaveKVHeads to copy packed rows via PackedEnd(type, cols) and copy unpacked rows directly from the prior MatPtr without a temporary buffer. Run InterleaveKVHeads after both SplitAttW1I8 and SplitAttW1.

@copybara-service
copybara-service Bot force-pushed the test_1028149897 branch 3 times, most recently from f050bb2 to 3da6418 Compare November 24, 2026 20:23
`LayerWeightsPtrs::Fixup` interleaved `qkv_einsum_w2` K/V heads using `Stride() * ElementBytes()` and `RowBytes()`, which assumes byte-addressable elements. For block-packed formats (`kQ4_0`, `kMXFP4`, `kI8`, `kNUQ`), `ElementBytes()` is 1, reading past the source buffer and writing out of bounds. Placing interleaving inside the non-`kI8` branch also skipped `SplitAttW1I8` outputs.

Extract `InterleaveKVHeads` to copy packed rows via `PackedEnd(type, cols)` and copy unpacked rows directly from the prior `MatPtr` without a temporary buffer. Run `InterleaveKVHeads` after both `SplitAttW1I8` and `SplitAttW1`.

PiperOrigin-RevId: 1029255827
@copybara-service
copybara-service Bot merged commit 551f7e2 into dev Nov 24, 2026
9 of 11 checks passed
@copybara-service
copybara-service Bot deleted the test_1028149897 branch November 24, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant