Skip to content

Elimination of the graph break in compiled version of Vanilla sLSTM - #16

Merged
danilyef merged 4 commits into
mainfrom
1.0.8
Sep 14, 2026
Merged

danilyef merged 4 commits into
mainfrom
1.0.8

Conversation

@danilyef

@danilyef danilyef commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Removing if/else branching and instead using pytorch torch.where function, which eliminates breaks in the graph of the compiled version.

Benchmarking

Times of flashrnn_forward_pointwise under @torch.compile

Batch Version before (mean ms) Version PR (mean ms) Speedup Max diff
1 3.536 2.059 1.72× 0.0e+00
32 7.246 5.014 1.45× 0.0e+00
64 12.117 9.558 1.27× 0.0e+00
96 15.849 12.770 1.24× 0.0e+00

@danilyef

Copy link
Copy Markdown
Member Author

We might also think to switch to torch.where(n == 0,...), because n at the beginning of inference is almost always 0.
But I implemented safer option

else:
mnew = torch.max(iraw, logfplusm)

mnew = torch.where(torch.all(n == 0.0), iraw, torch.max(iraw, logfplusm))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

mnew = torch.where(n == 0.0, iraw, torch.max(iraw, logfplusm))

It's fine to use the torch.all, that way we remove the reduction operation and the pointwise kernel should be quite a bit faster.

@danilyef
danilyef merged commit 0b84fc3 into main Sep 14, 2026
1 check passed
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 14, 2026
@daidahao
daidahao deleted the 1.0.8 branch September 14, 2026 12:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants