Skip to content

Conversation

bdhirsh
Copy link
Collaborator

@bdhirsh bdhirsh commented May 21, 2021

This PR deletes the inplace implementations of all lowerings that can be auto-generated from the codegen, removing ~1000 LoC.

It applies to any operator that XLA already has a functional lowering for (e.g. add.Tensor), and that has a "trio" of operators in the pytorch codebase (in this case, add.Tensor, add_.Tensor, and add.out are all valid pytorch ops). For example, it doesn't apply to relu_, because we don't have a relu.out operator in PyTorch.

@JackCaoG Other than a small test change that I had to make, all of the tests are still passing. One thing that's worth double checking after this lands is that you don't see any major perf divergences in the performance dashboard. I don't think we should expect a perf change, since the generated kernels are all implemented by just calling the functional operator, followed by a call to at::_copy_from() to move the result into self. But definitely worth confirming.

For each inplace lowering, I removed:

  • the yaml entry: xla_native_functions.yaml
  • the lowering kernel: aten_xla_type.cpp
  • the XLATensor declaration: tensor.h
  • the XLATensor definition: tensor_methods.cpp

You can see the full list of inplace kernels that I removed in xla_native_functions.yaml, but the list is:

abs_
acos_
add_.Scalar
acosh_
asinh_
atanh_
asin_
atan_
atan2_
baddbmm_
celi_
clamp_
clamp_max_
cos_
cosh_
div_.Tensor
div_.Tensor_mode
div_.Scalar
erf_
erfinv_
erfc_
exp_
expm1_
floor_
frac_
log_
log10_
log1p_
Log2_
log_base_
mul_.Tensor
mul_.Scalar
reciprocal_
neg_
round_
relu_
rsqrt_
sigmoid_
hardsigmoid_
sin_
sinh_
sqrt_
tan_
tanh_
hardtanh_
threshold_
trunc_
sub_.Tensor
sub_.Scalar
eq_.Scalar
eq_.Tensor
fmod_.Tensor
fmod_.Scalar
remainder_.Scalar
remainder_.Tensor
ne_.Scalar
ne_.Tensor
ge_.Scalar
ge_.Tensor
le_.Scalar
le_.Tensor
lt_.Scalar
lt_.Tensor
gt_.Scalar
gt_.Tensor
addcmul_u
sign_
pow_.Scalar
pow_.Tensor
leaky_relu_

@bdhirsh bdhirsh force-pushed the remove_inplace_kernels branch from 9e91c22 to a285fcb Compare May 24, 2021 14:26
@bdhirsh bdhirsh requested review from JackCaoG and ailzhang May 24, 2021 14:36
@bdhirsh bdhirsh force-pushed the make_codegen_backend_agnostic_minus_fallbacks branch from 49791eb to c223040 Compare May 24, 2021 21:54
@bdhirsh bdhirsh force-pushed the remove_inplace_kernels branch from a285fcb to dc43fe2 Compare May 24, 2021 22:12
Copy link
Collaborator

@JackCaoG JackCaoG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM, some minor questions.

at::Tensor input = at::zeros({32, 20, 4, 4}, at::TensorOptions(at::kFloat));
at::Tensor one = at::tensor(1.0, at::TensorOptions(at::kFloat));
at::Tensor output = input.view({-1, 320});
at::Tensor output = input.view({-1, 8});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why change 320->8. Is it just a performance issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that was a mistake, I changed it when I was debugging and forgot to put it back 😛 it's fixed now.

@bdhirsh bdhirsh force-pushed the remove_inplace_kernels branch from dc43fe2 to 5990200 Compare May 25, 2021 14:46
Copy link
Collaborator

@JackCaoG JackCaoG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bdhirsh !

Base automatically changed from make_codegen_backend_agnostic_minus_fallbacks to master May 26, 2021 20:23
@bdhirsh bdhirsh force-pushed the remove_inplace_kernels branch from f60faf9 to c967eb1 Compare May 26, 2021 22:49
@bdhirsh bdhirsh merged commit 18b2716 into master May 27, 2021
@bdhirsh bdhirsh deleted the remove_inplace_kernels branch May 27, 2021 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants