Use Fused Kernels for Depthwise Striding Subsampler: up to 1.5x faster training - #16114
Use Fused Kernels for Depthwise Striding Subsampler: up to 1.5x faster training#16114MahmoudAshraf97 wants to merge 12 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a972c7eda8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| sync_max_audio_length: bool = True, | ||
| rope_base: float = 10000.0, | ||
| rotary_fraction: float = 1.0, | ||
| use_triton: bool | None = None, |
There was a problem hiding this comment.
Document the Triton default and YAML opt-out
For every existing dw_striding configuration in an environment with Triton installed, this new option silently changes the default execution path, yet none of the user-facing ASR documentation or example YAML configurations explains that behavior or shows use_triton: false. Add the new default, eligibility constraints, and opt-out to the relevant FastConformer documentation/config examples so users can discover and control the behavior.
AGENTS.md reference: AGENTS.md:L58-L63
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
this is similar to the use_pytorch_sdpa option, where it only exists in the module docstring and the configs only, not the documentation
There was a problem hiding this comment.
yes please add to docs. we should have added use_pytorch_sdpa info to docs as well.
There was a problem hiding this comment.
added the documentation
| mel_freq, | ||
| pad_start, | ||
| ) | ||
| relu_out = tl.dot(conv_taps, feats) + conv_bias[:, None] |
There was a problem hiding this comment.
Respect the caller's disabled-TF32 setting
When an fp32 caller disables TF32 through torch.backends.cudnn.allow_tf32 = False and torch.backends.cuda.matmul.allow_tf32 = False for numerical accuracy, this tl.dot still uses Triton's default TF32 input precision. Because the Triton path is now enabled automatically, such callers silently receive reduced-precision convolution results despite explicitly disabling TF32; select IEEE input precision or fall back to the PyTorch path when TF32 is disabled.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Most training is in either mixed precision or half precision, where TF32 has no effect at all, regardless leaving this for the maintainers call
Signed-off-by: MahmoudAshraf97 <hassouna97.ma@gmail.com>
Signed-off-by: MahmoudAshraf97 <hassouna97.ma@gmail.com>
Signed-off-by: MahmoudAshraf97 <hassouna97.ma@gmail.com>
Signed-off-by: MahmoudAshraf97 <hassouna97.ma@gmail.com>
Signed-off-by: MahmoudAshraf97 <hassouna97.ma@gmail.com>
Signed-off-by: MahmoudAshraf97 <hassouna97.ma@gmail.com>
Signed-off-by: MahmoudAshraf97 <hassouna97.ma@gmail.com>
Signed-off-by: MahmoudAshraf97 <hassouna97.ma@gmail.com>
a972c7e to
bbe6e87
Compare
nithinraok
left a comment
There was a problem hiding this comment.
Great work, couple of comments.
| sync_max_audio_length: bool = True, | ||
| rope_base: float = 10000.0, | ||
| rotary_fraction: float = 1.0, | ||
| use_triton: bool | None = None, |
There was a problem hiding this comment.
yes please add to docs. we should have added use_pytorch_sdpa info to docs as well.
| use_triton = TRITON_AVAILABLE | ||
| self.conv.fuse_triton = ( | ||
| use_triton and subsampling == 'dw_striding' and self._sampling_num >= 2 and isinstance(activation, nn.ReLU) | ||
| ) |
There was a problem hiding this comment.
but if user requests use_triton and striding, then code currently silently skips use of triton. Could you raise warning instead.
There was a problem hiding this comment.
added a warning for all non-eligible configs
| from torch.nn import LayerNorm | ||
|
|
||
| from nemo.collections.asr.parts.submodules.causal_convs import CausalConv1D, CausalConv2D | ||
| from nemo.collections.asr.parts.triton.depthwise_conv import dw_conv2d |
There was a problem hiding this comment.
wouldn;t this raise error, when triton is not available?
There was a problem hiding this comment.
No, since all triton code in that file are guarded with TRITON_AVAILABLE flag, the alternative is to remove the gating and gate this import only
There was a problem hiding this comment.
rewritten the files to follow the same pattern used in the ngram triton implementation, the indentation is gone and it raises on the first forward if use_triton=True was explicitly requested
Signed-off-by: MahmoudAshraf97 <hassouna97.ma@gmail.com>
Signed-off-by: MahmoudAshraf97 <hassouna97.ma@gmail.com>
Important
The
Update branchbutton must only be pressed in very rare occassions.An outdated branch is never blocking the merge of a PR.
Please reach out to the automation team before pressing that button.
What does this PR do ?
This PR implements triton kernels for the subsampler in
ConformerEncoder, profiling showed that the subsampler is heavily bottlenecked by memory bandwidth, so the fused kernels focus on reducing memory bandwidth by removing intermediary tensorsThe first kernel implements:
it cuts memory bandwidth by more than 350x and even more in causal mode since it includes an extra padding layer, this fusion is not possible with
torch.compilesince it does not fuse the activation, the bias, or the masking into the convolution kernels, this kernel is most of the speedupThe second kernel is a general depthwise
conv2dkernel, it's faster than torch kernel in forward since it fuses the pre and post masking and the causal padding, it has the most impact on M and L models, almost no impact on XL models because the encoder layers dominate the runtime, it is also faster than torch backward by 2x for the same reasonbelow are the speedup numbers expressed in relative speedup in E2E encoder step fwd+bwd, it uses the optimization in #16052 in both arms of the comparison
Eager
torch.compile (max-autotune-no-cudagraphs)
Collection: ASR
Usage
Defaults to enabled if triton is installed, otherwise disabled, can also be controlled using the training config:
GitHub Actions CI
The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.
Trusted PRs run automatically through copy-pr-bot. For an untrusted PR, a maintainer can trigger CI by commenting
/ok to test <head-sha>; repeat this after a new push if the PR remains untrusted.Before your PR is "Ready for review"
Pre checks:
PR Type:
If you haven't finished some of the above items you can still open "Draft" PR.
Who can review?
@pzelasko @nithinraok