Skip to content

Commit

Permalink
catch tensor.numel() == 0 in nan detector (pytorch#140741)
Browse files Browse the repository at this point in the history
Context: we are trying to pass an empty tensor through the system now (sometimes;... its an edge case); and it seems to cause all_reduce to seg fault, which is unexpected to me

Deep Shah and Pavan identified the issue, I'm just pushing for a fix :)

Test Plan: idk what i'm doing here, someone help

Reviewed By: shuqiangzhang

Differential Revision: D65956095

Pull Request resolved: pytorch#140741
Approved by: https://github.com/shuqiangzhang
  • Loading branch information
HarounH authored and pytorchmergebot committed Nov 15, 2024
1 parent 865a7c5 commit 8043e67
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions torch/csrc/distributed/c10d/NanCheck.cu
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ void checkForNan(const at::Tensor& tensor, at::cuda::CUDAStream& stream) {
const size_t numThreadsPerBlock =
std::min<size_t>(maxNumThreadsPerBlock, tensor.numel());

if (!(numThreadsPerBlock > 0)) {
return;
}

const size_t numBlocks = std::min<size_t>(
maxNumBlocks,
(tensor.numel() + numThreadsPerBlock - 1) / numThreadsPerBlock);
Expand Down

0 comments on commit 8043e67

Please sign in to comment.