Skip to content

[examples] Read only the causal columns in chunk_fwd_A_diag_anchored - #3290

Open
tarinduj wants to merge 1 commit into
mainfrom
tarinduj/stack/4
Open

[examples] Read only the causal columns in chunk_fwd_A_diag_anchored#3290
tarinduj wants to merge 1 commit into
mainfrom
tarinduj/stack/4

Conversation

@tarinduj

@tarinduj tarinduj commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Stacked PRs:


[examples] Read only the causal columns in chunk_fwd_A_diag_anchored

The intra-chunk score matrix is causal, so everything above its diagonal is structurally zero, and chunk_fwd_A_diag_anchored_helion was computing it anyway: each BC_DIAG-row sub-block read all C columns and then masked most of the result away. It now reads only the columns that can be nonzero, 0 : (i + 1) * BC_DIAG for sub-block i, so the two matmuls span BC_DIAG * (1 + 2 + ... + NC) = C * (NC + 1) / 2 columns instead of NC * C. A and Akk arrive zeroed, so the skipped columns already hold zeros.

The diff reads as a manual unroll because a narrowing width has to be a literal: hl.arange rejects arithmetic on a specialized size, so each tier is written out and guarded on C. FLA's KDA does the same in chunk_intra.py. The tiers cover C of 32 and 64, the two chunk sizes FLA's KDA accepts, and the kernel asserts that.

kda and full_gla share the kernel across four call sites, two of them backward.

Benchmarks

%FLA = 100 * fla_ms / helion_ms on H100, autotuned with HELION_AUTOTUNE_EFFORT=full. Higher is faster than FLA. The baseline row is the same variant's table in #3200.

Forward:

variant B1_T8192_H96_D128 B2_T16384_H16_D128 B4_T2048_H16_D128 B4_T4096_H64_D128 B8_T2048_H32_D256 B8_T1024_H8_D64
kda (#3200) 118% 117% 109% 116% 109% 104%
kda 129% 126% 98% 128% 111% 95%
full_gla (#3200) 143% 161% 128% 145% 134% 115%
full_gla 154% 169% 130% 155% 137% 108%

Forward + backward:

variant B1_T8192_H96_D128 B2_T16384_H16_D128 B4_T2048_H16_D128 B4_T4096_H64_D128 B8_T2048_H32_D256 B8_T1024_H8_D64
kda (#3200) 117% 113% 114% 116% 109% 141%
kda 119% 115% 115% 119% 110% 130%
full_gla (#3200) 235% 248% 211% 243% 215% 139%
full_gla 240% 252% 200% 247% 216% 128%

The intra-chunk score matrix is causal, so everything above its diagonal is structurally zero, and `chunk_fwd_A_diag_anchored_helion` was computing it anyway: each `BC_DIAG`-row sub-block read all `C` columns and then masked most of the result away. It now reads only the columns that can be nonzero, `0 : (i + 1) * BC_DIAG` for sub-block `i`, so the two matmuls span `BC_DIAG * (1 + 2 + ... + NC) = C * (NC + 1) / 2` columns instead of `NC * C`. `A` and `Akk` arrive zeroed, so the skipped columns already hold zeros.

The diff reads as a manual unroll because a narrowing width has to be a literal: `hl.arange` rejects arithmetic on a specialized size, so each tier is written out and guarded on `C`. FLA's KDA does the same in `chunk_intra.py`. The tiers cover `C` of 32 and 64, the two chunk sizes FLA's KDA accepts, and the kernel asserts that.

`kda` and `full_gla` share the kernel across four call sites, two of them backward.

## Benchmarks
`%FLA = 100 * fla_ms / helion_ms` on H100, autotuned with `HELION_AUTOTUNE_EFFORT=full`. **Higher is faster than FLA.** The baseline row is the same variant's table in #3200.

Forward:

| variant | B1_T8192_H96_D128 | B2_T16384_H16_D128 | B4_T2048_H16_D128 | B4_T4096_H64_D128 | B8_T2048_H32_D256 | B8_T1024_H8_D64 |
|---|---|---|---|---|---|---|
| kda (#3200) | 118% | 117% | 109% | 116% | 109% | 104% |
| kda | 129% | 126% | 98% | 128% | 111% | 95% |
| full_gla (#3200) | 143% | 161% | 128% | 145% | 134% | 115% |
| full_gla | 154% | 169% | 130% | 155% | 137% | 108% |

Forward + backward:

| variant | B1_T8192_H96_D128 | B2_T16384_H16_D128 | B4_T2048_H16_D128 | B4_T4096_H64_D128 | B8_T2048_H32_D256 | B8_T1024_H8_D64 |
|---|---|---|---|---|---|---|
| kda (#3200) | 117% | 113% | 114% | 116% | 109% | 141% |
| kda | 119% | 115% | 115% | 119% | 110% | 130% |
| full_gla (#3200) | 235% | 248% | 211% | 243% | 215% | 139% |
| full_gla | 240% | 252% | 200% | 247% | 216% | 128% |

stack-info: PR: #3290, branch: tarinduj/stack/4
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 5, 2026
@tarinduj
tarinduj changed the base branch from tarinduj/stack/3 to main August 5, 2026 22:37
@tarinduj tarinduj changed the title [examples] Read only the causal columns in the anchored gram [examples] Read only the causal columns in chunk_fwd_A_diag_anchored Aug 5, 2026
@tarinduj
tarinduj changed the base branch from main to tarinduj/stack/3 August 5, 2026 22:37
@tarinduj
tarinduj requested a review from AmesingFlank August 6, 2026 15:56
@tarinduj
tarinduj marked this pull request as ready for review August 6, 2026 15:56
@tarinduj
tarinduj marked this pull request as draft August 6, 2026 23:31
@tarinduj
tarinduj changed the base branch from tarinduj/stack/3 to main August 6, 2026 23:31
@tarinduj
tarinduj changed the base branch from main to tarinduj/stack/3 August 6, 2026 23:32
@tarinduj
tarinduj marked this pull request as ready for review August 6, 2026 23:32
@tarinduj
tarinduj changed the base branch from tarinduj/stack/3 to main August 7, 2026 00:06
@tarinduj
tarinduj marked this pull request as draft August 7, 2026 00:23
@tarinduj
tarinduj marked this pull request as ready for review August 7, 2026 00:23
@tarinduj
tarinduj marked this pull request as draft August 7, 2026 00:31
@tarinduj
tarinduj marked this pull request as ready for review August 7, 2026 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants