Skip to content

Fix reduction axis and column scaling in the transposed projection - #74

Merged
GeorgeWu1204 merged 1 commit into
mainfrom
fix/projection-reduction-axis
Aug 8, 2026
Merged

Fix reduction axis and column scaling in the transposed projection#74
GeorgeWu1204 merged 1 commit into
mainfrom
fix/projection-reduction-axis

Conversation

@Shreyas8612

Copy link
Copy Markdown
Collaborator

Bug: Incorrect column indexing and reduction axis in projection ASM

projection_asm already uses blen * mlen for the matrix operand's column index in its main loop, matching the row-granular projection ABI documented by the emulator in matrix_machine.rs. Two sibling call sites, _emit_projection_chunk and projection_T_asm, were never updated and still scale by blen alone, so they address the wrong column group at any geometry with more than one tile per MLEN.

projection_T_asm also reduces over the wrong axis. The weight tile is stored as (out_features, in_features), so the reduction must run down its columns, which requires M_TMM with the operands swapped. Using M_MM instead pairs the activation's hidden dimension with out_features, which is incorrect.

With M_MM, the logits correlate 0.003 with the reference. With M_TMM, the correlation is 0.998.

projection_asm already uses blen * mlen for the matrix operand's column index
in its main loop, matching the row-granular projection ABI the emulator
documents in matrix_machine.rs. Two sibling call sites, _emit_projection_chunk
and projection_T_asm, were never updated and still scale by blen, so they
address the wrong column group at any geometry with more than one tile per
MLEN.

projection_T_asm also reduces over the wrong axis. The weight tile is stored
(out_features, in_features), so the reduction runs down its columns and needs
M_TMM with the operands swapped; M_MM pairs the activation's hidden dimension
with out_features instead. With M_MM the logits correlate 0.003 with the
reference, and 0.998 with M_TMM.
Copilot AI lite review requested due to automatic review settings August 7, 2026 23:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect addressing and reduction behavior in the transposed projection ASM template so that weight tiles are indexed with the correct per-MLEN column stride and the dot-product reduction runs over the intended axis (weight columns).

Changes:

  • Correct matrix-SRAM within-group column offset scaling from * blen to * blen * mlen in _emit_projection_chunk and projection_T_asm.
  • Switch the transposed projection inner loop from M_MM to M_TMM and swap operand order to match the Vector @ Matrix^T semantics.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@GeorgeWu1204
GeorgeWu1204 merged commit 718b2af into main Aug 8, 2026
5 checks passed
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.

3 participants