Skip to content

Upcast gradually when computing variance #4283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/Dialect/Torch/Transforms/DecomposeComplexOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9322,9 +9322,15 @@ static LogicalResult calculateVariance(OpTy op, PatternRewriter &rewriter,
op, "support floating-point type input only");
}

// Upcasting the input tensor to `F64` dtype for higher precision during the
// computation of the result.
if (inputTensorTy.getDtype().getIntOrFloatBitWidth() != 64) {
// Upcasting the input tensor to a double-bitwidth dtype for higher precision
// during the computation of the result.
unsigned bitwidth = inputTensorTy.getDtype().getIntOrFloatBitWidth();
if (bitwidth != 64) {
Type targetTy = rewriter.getF64Type();
if (bitwidth == 8)
targetTy = rewriter.getBF16Type();
else if (bitwidth == 16)
targetTy = rewriter.getF32Type();
self = convertTensorToDtype(rewriter, loc, self, rewriter.getF64Type());
inputTensorTy = cast<BaseTensorType>(self.getType());
}
Expand Down
Loading