Skip to content

Commit

Permalink
Don't fallback for pow
Browse files Browse the repository at this point in the history
  • Loading branch information
qihqi committed Nov 22, 2023
1 parent 3fa035e commit e00bd7f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
23 changes: 23 additions & 0 deletions test/test_core_aten_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3295,6 +3295,29 @@ def test_aten_pow_Tensor_Scalar_2(self):
kwargs = dict()
run_export_and_compare(self, torch.ops.aten.pow.Tensor_Scalar, args, kwargs)

def test_aten_pow_Scalar_1(self):
args = (10000,
torch.Tensor([
0.0000, 0.0000, 0.0156, 0.0156, 0.0312, 0.0312, 0.0469, 0.0469,
0.0625, 0.0625, 0.0781, 0.0781, 0.0938, 0.0938, 0.1094, 0.1094,
0.1250, 0.1250, 0.1406, 0.1406, 0.1562, 0.1562, 0.1719, 0.1719,
0.1875, 0.1875, 0.2031, 0.2031, 0.2188, 0.2188, 0.2344, 0.2344,
0.2500, 0.2500, 0.2656, 0.2656, 0.2812, 0.2812, 0.2969, 0.2969,
0.3125, 0.3125, 0.3281, 0.3281, 0.3438, 0.3438, 0.3594, 0.3594,
0.3750, 0.3750, 0.3906, 0.3906, 0.4062, 0.4062, 0.4219, 0.4219,
0.4375, 0.4375, 0.4531, 0.4531, 0.4688, 0.4688, 0.4844, 0.4844,
0.5000, 0.5000, 0.5156, 0.5156, 0.5312, 0.5312, 0.5469, 0.5469,
0.5625, 0.5625, 0.5781, 0.5781, 0.5938, 0.5938, 0.6094, 0.6094,
0.6250, 0.6250, 0.6406, 0.6406, 0.6562, 0.6562, 0.6719, 0.6719,
0.6875, 0.6875, 0.7031, 0.7031, 0.7188, 0.7188, 0.7344, 0.7344,
0.7500, 0.7500, 0.7656, 0.7656, 0.7812, 0.7812, 0.7969, 0.7969,
0.8125, 0.8125, 0.8281, 0.8281, 0.8438, 0.8438, 0.8594, 0.8594,
0.8750, 0.8750, 0.8906, 0.8906, 0.9062, 0.9062, 0.9219, 0.9219,
0.9375, 0.9375, 0.9531, 0.9531, 0.9688, 0.9688, 0.9844, 0.9844
]))
kwargs = dict()
run_export_and_compare(self, torch.ops.aten.pow.Scalar, args, kwargs)

@unittest.skip
def test_aten_pow_Tensor_Tensor_0(self):
args = (
Expand Down
16 changes: 0 additions & 16 deletions torch_xla/csrc/aten_xla_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2305,36 +2305,20 @@ at::Tensor XLANativeFunctions::permute_copy(const at::Tensor& self,
at::Tensor XLANativeFunctions::pow(const at::Tensor& self,
const at::Scalar& exponent) {
TORCH_LAZY_FN_COUNTER_TIMED_TRACING("xla::");
// xla::Pow() doesn't support integer types.
if (!at::native::is_floating_point(self)) {
return at::native::call_fallback_fn<
&xla_cpu_fallback, ATEN_OP2(pow, Tensor_Scalar)>::call(self, exponent);
}
return bridge::AtenFromXlaTensor(
tensor_methods::pow(bridge::GetXlaTensor(self), exponent));
}

at::Tensor XLANativeFunctions::pow(const at::Tensor& self,
const at::Tensor& exponent) {
TORCH_LAZY_FN_COUNTER_TIMED_TRACING("xla::");
// xla::Pow() doesn't support integer types.
if (!at::native::is_floating_point(self)) {
return at::native::call_fallback_fn<
&xla_cpu_fallback, ATEN_OP2(pow, Tensor_Tensor)>::call(self, exponent);
}
return bridge::AtenFromXlaTensor(tensor_methods::pow(
bridge::GetXlaTensor(self), bridge::GetXlaTensor(exponent)));
}

at::Tensor XLANativeFunctions::pow(const at::Scalar& self,
const at::Tensor& exponent) {
TORCH_LAZY_FN_COUNTER_TIMED_TRACING("xla::");
// xla::Pow() doesn't support integer types.
if (!self.isFloatingPoint()) {
return at::native::call_fallback_fn<&xla_cpu_fallback,
ATEN_OP2(pow, Scalar)>::call(self,
exponent);
}
return bridge::AtenFromXlaTensor(
tensor_methods::pow(self, bridge::GetXlaTensor(exponent)));
}
Expand Down

0 comments on commit e00bd7f

Please sign in to comment.