Skip to content
Merged
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
13 changes: 10 additions & 3 deletions aten/src/ATen/native/mps/operations/TensorCompare.mm
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,16 @@ Tensor where_mps(const Tensor& condition,
MPSGraphTensor* subZeroTensor = [mpsGraph lessThanWithPrimaryTensor: nanFreeTensor
secondaryTensor: [mpsGraph constantWithScalar: 0.0 dataType: self_dtype]
name: nil];
// the cast is a workaround for the issue #103149520 (crash when bool and fp16 passed to binary ops)
MPSGraphTensor* isNegInfTensor = [mpsGraph logicalANDWithPrimaryTensor: [mpsGraph castTensor: subZeroTensor toType: self_dtype name: @"castTensor"]
secondaryTensor: [mpsGraph isInfiniteWithTensor: nanFreeTensor name:nil]
MPSGraphTensor* isInfTensor = [mpsGraph isInfiniteWithTensor: nanFreeTensor name:nil];
// workaround for Monterey; On Ventura the output of lessThan() is always Boolean
if (subZeroTensor.dataType != MPSDataTypeBool) {
subZeroTensor = castMPSTensor(mpsGraph, subZeroTensor, kBool);
}
if (isInfTensor.dataType != MPSDataTypeBool) {
isInfTensor = castMPSTensor(mpsGraph, isInfTensor, kBool);
}
MPSGraphTensor* isNegInfTensor = [mpsGraph logicalANDWithPrimaryTensor: subZeroTensor
secondaryTensor: isInfTensor
name: nil];
MPSGraphTensor* negInfFreeTensor = [mpsGraph selectWithPredicateTensor: isNegInfTensor
truePredicateTensor: newCachedGraph->negInfReplacementTensor
Expand Down