Minimize the memory usage of the fused cross entropy kernel - #3273
Minimize the memory usage of the fused cross entropy kernel#3273ptrendx wants to merge 12 commits into
Conversation
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
for more information, see https://pre-commit.ci
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
for more information, see https://pre-commit.ci
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
for more information, see https://pre-commit.ci
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
|
/te-ci pytorch |
Greptile SummaryThe PR reduces fused cross-entropy memory usage by saving compact softmax statistics and reconstructing gradients during backward.
Confidence Score: 5/5The PR appears safe to merge because no blocking failure remains. No blocking failure remains. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant Autograd as CrossEntropyFunction
participant Forward as Triton forward
participant Collective as TP all-gather
participant Backward as Triton backward
Caller->>Autograd: logits, targets, options
Autograd->>Forward: launch forward kernel
alt Single GPU
Forward-->>Autograd: loss, saved input, max/denominator stats
else Tensor parallel
Forward->>Collective: gather local statistics
Collective-->>Forward: global statistics
Forward-->>Autograd: loss, saved input, global stats
end
Autograd-->>Caller: loss
Caller->>Autograd: backward(grad_output)
Autograd->>Backward: saved input, targets, stats, grad_output
Backward-->>Autograd: reconstructed input gradient
Autograd-->>Caller: logits gradient
Reviews (2): Last reviewed commit: "Add the guard against torch.compile when..." | Re-trigger Greptile |
|
Thanks for the fix. We validated commit 41157db on a downstream H100 TP=1 BF16 workload with 4096 × 128256 logits.
With destructive reuse enabled, peak memory matched the previous baseline exactly, with no throughput regression. The numerical fix from #3193 remained active. |
|
Torch.compile support triton kernels and adding overwrite_input=True can lead to silent incorectness under compile. |
|
Otherwise LGTM |
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
|
/te-ci pytorch |
|
@pggPL Addressed the torch.compile comment |
Description
The changes introduced in #3193, while fixing the numerical issue with the fused cross entropy kernel, introduced additional memory requirement. This PR aims to greatly reduce that additional memory usage while preserving the numerics and optimizing runtime performance.
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: