Migrate kernels with TensorOptions to C10 full dispatcher (#54539)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/54539
Codemod commands generated by https://github.com/pytorch/pytorch/pull/54468
ghstack-source-id: 125018630
# Facebook:
The following 2 files are changed on fb side:
```
// Should be hidden
```
Test Plan: buck build //caffe2/aten/...
Reviewed By: smessmer
Differential Revision: D27273744
fbshipit-source-id: 35c1bff63189477645008caaf0dc794096e3fcc4
diff --git a/aten/src/ATen/core/op_registration/hacky_wrapper_for_legacy_signatures.h b/aten/src/ATen/core/op_registration/hacky_wrapper_for_legacy_signatures.h
index cf7b589..8994402 100644
--- a/aten/src/ATen/core/op_registration/hacky_wrapper_for_legacy_signatures.h
+++ b/aten/src/ATen/core/op_registration/hacky_wrapper_for_legacy_signatures.h
@@ -29,6 +29,22 @@
* the creation of a default constructed tensor.
*/
+/*
+ * [Note: hacky wrapper removal for TensorOptions]
+ *
+ * The kernel implementation takes a TensorOptions argument but the dispatcher
+ * expects separate arguments for dtype, layout, device, pin_memory.
+ *
+ * To remove the hacky wrapper, the kernel implementation is changed to take
+ * the 4 arguments (dtype, layout, device, pin_memory), and assemble the
+ * TensorOptions value at the beginning of the function, e.g.:
+ * > TensorOptions options = TensorOptions().dtype(dtype).layout(layout)
+ * > .device(device).pinned_memory(pin_memory);
+ *
+ * We may want make the kernel handle these parameters directly without going
+ * through the creation of a TensorOptions value.
+ */
+
namespace c10 {
namespace impl {
diff --git a/aten/src/ATen/native/Activation.cpp b/aten/src/ATen/native/Activation.cpp
index feb7abb..d805efa 100644
--- a/aten/src/ATen/native/Activation.cpp
+++ b/aten/src/ATen/native/Activation.cpp
@@ -718,14 +718,26 @@
}
Tensor gelu_cpu(const Tensor& self) {
- Tensor Y = at::native::empty_like(self, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ Tensor Y = at::native::empty_like(
+ self,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
auto it = TensorIterator::unary_op(Y, self);
GeluKernel(kCPU, it);
return Y;
}
Tensor gelu_backward_cpu(const Tensor& grad, const Tensor& self) {
- Tensor dX = at::native::empty_like(self, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ Tensor dX = at::native::empty_like(
+ self,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
auto it = TensorIterator::binary_op(dX, grad, self);
GeluBackwardKernel(kCPU, it);
return dX;
diff --git a/aten/src/ATen/native/Blas.cpp b/aten/src/ATen/native/Blas.cpp
index bd6445b..7f82188 100644
--- a/aten/src/ATen/native/Blas.cpp
+++ b/aten/src/ATen/native/Blas.cpp
@@ -63,7 +63,11 @@
if (beta.toComplexDouble() == 0.0) {
result.zero_();
} else {
- at::cpu::mul_out(result, self, at::native::scalar_tensor(beta, at::device(at::kCPU).dtype(self.scalar_type())));
+ at::cpu::mul_out(
+ result,
+ self,
+ at::native::scalar_tensor(
+ beta, self.scalar_type(), c10::nullopt /* layout */, at::kCPU, c10::nullopt /* pin_memory */));
}
} else {
if (!result.is_same(self_)) {
diff --git a/aten/src/ATen/native/QuantizedLinear.cpp b/aten/src/ATen/native/QuantizedLinear.cpp
index 53e9c7d..aa0f751 100644
--- a/aten/src/ATen/native/QuantizedLinear.cpp
+++ b/aten/src/ATen/native/QuantizedLinear.cpp
@@ -244,7 +244,12 @@
q_params.precision = kPrecision;
Tensor quantized = at::native::empty_like(
- weight_contig, weight_contig.options().dtype(at::kChar), LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ weight_contig,
+ at::kChar,
+ weight_contig.options().layout_opt(),
+ weight_contig.options().device_opt(),
+ weight_contig.options().pinned_memory_opt(),
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
// Tensor quantized = at::native::empty_cpu(
// weight_contig.sizes(), weight_contig.options().dtype(at::kChar));
fbgemm::Quantize<int8_t, false /*LEGACY*/>(
@@ -256,7 +261,12 @@
// Calculate column offsets of the weight and store them away in a tensor.
// Similarly to quantization, this can be done once and cached.
Tensor col_offsets = at::empty(
- {weight_contig.size(0)}, weight_contig.options().dtype(at::kInt), LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ {weight_contig.size(0)},
+ at::kInt,
+ weight_contig.options().layout_opt(),
+ weight_contig.options().device_opt(),
+ weight_contig.options().pinned_memory_opt(),
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
CalcColOffsetsTranspose(
/*K=*/quantized.size(1),
/*N=*/quantized.size(0),
diff --git a/aten/src/ATen/native/SobolEngineOps.cpp b/aten/src/ATen/native/SobolEngineOps.cpp
index 1b2bd41..6cdaa20 100644
--- a/aten/src/ATen/native/SobolEngineOps.cpp
+++ b/aten/src/ATen/native/SobolEngineOps.cpp
@@ -163,7 +163,16 @@
/// Multiply each column of sobolstate by power of 2:
/// sobolstate * [2^(maxbit-1), 2^(maxbit-2),..., 2, 1]
- Tensor pow2s = at::pow(2, at::native::arange((MAXBIT - 1), -1, -1, sobolstate.options()));
+ Tensor pow2s = at::pow(
+ 2,
+ at::native::arange(
+ (MAXBIT - 1),
+ -1,
+ -1,
+ optTypeMetaToScalarType(sobolstate.options().dtype_opt()),
+ sobolstate.options().layout_opt(),
+ sobolstate.options().device_opt(),
+ sobolstate.options().pinned_memory_opt()));
sobolstate.mul_(pow2s);
return sobolstate;
}
diff --git a/aten/src/ATen/native/SoftMax.cpp b/aten/src/ATen/native/SoftMax.cpp
index 49e7084..e548280 100644
--- a/aten/src/ATen/native/SoftMax.cpp
+++ b/aten/src/ATen/native/SoftMax.cpp
@@ -120,7 +120,13 @@
Tensor softmax_cpu(const Tensor& input_, const int64_t dim_, const bool half_to_float) {
TORCH_CHECK(!half_to_float, "softmax with half to float conversion is not supported on CPU");
auto input = input_.contiguous();
- Tensor output = at::native::empty_like(input, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ Tensor output = at::native::empty_like(
+ input,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
int64_t dim = maybe_wrap_dim(dim_, input.dim());
if (input.numel() == 0) {
@@ -144,7 +150,13 @@
Tensor log_softmax_cpu(const Tensor& input_, const int64_t dim_, const bool half_to_float) {
TORCH_CHECK(!half_to_float, "softmax with half to float conversion is not supported on CPU");
auto input = input_.contiguous();
- Tensor output = at::native::empty_like(input, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ Tensor output = at::native::empty_like(
+ input,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
int64_t dim = maybe_wrap_dim(dim_, input.dim());
if (input.numel() == 0) {
@@ -175,7 +187,13 @@
int64_t dim = maybe_wrap_dim(dim_, grad_.dim());
auto grad = grad_.contiguous();
auto output = output_.contiguous();
- Tensor grad_input = at::native::empty_like(grad, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ Tensor grad_input = at::native::empty_like(
+ grad,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
if (output.numel() == 0) {
return grad_input;
@@ -207,7 +225,13 @@
int64_t dim = maybe_wrap_dim(dim_, grad_.dim());
auto grad = grad_.contiguous();
auto output = output_.contiguous();
- Tensor grad_input = at::native::empty_like(grad, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ Tensor grad_input = at::native::empty_like(
+ grad,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
if (output.numel() == 0) {
return grad_input;
diff --git a/aten/src/ATen/native/SpectralOps.cpp b/aten/src/ATen/native/SpectralOps.cpp
index d1ef0c5..6be24d8 100644
--- a/aten/src/ATen/native/SpectralOps.cpp
+++ b/aten/src/ATen/native/SpectralOps.cpp
@@ -508,7 +508,14 @@
return out.mul_(1.0 / (n * d)); // Slightly faster than div_(n*d)
}
-Tensor fft_fftfreq(int64_t n, double d, const TensorOptions& options) {
+Tensor fft_fftfreq(int64_t n, double d,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto out = at::empty({n}, options);
return native::fft_fftfreq_out(out, n, d);
}
@@ -522,7 +529,14 @@
return out.mul_(1.0 / (n * d)); // Slightly faster than div_(n*d)
}
-Tensor fft_rfftfreq(int64_t n, double d, const TensorOptions& options) {
+Tensor fft_rfftfreq(int64_t n, double d,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto out = at::empty({n/2 + 1}, options);
return native::fft_rfftfreq_out(out, n, d);
}
diff --git a/aten/src/ATen/native/SummaryOps.cpp b/aten/src/ATen/native/SummaryOps.cpp
index 3e38b28..4233475 100644
--- a/aten/src/ATen/native/SummaryOps.cpp
+++ b/aten/src/ATen/native/SummaryOps.cpp
@@ -37,7 +37,12 @@
const input_t* self_p = self.data_ptr<input_t>();
if (has_weights) {
- output = native::zeros({nbins}, weights.options());
+ output = native::zeros(
+ {nbins},
+ optTypeMetaToScalarType(weights.options().dtype_opt()),
+ weights.options().layout_opt(),
+ weights.options().device_opt(),
+ weights.options().pinned_memory_opt());
weights_t* output_p = output.data_ptr<weights_t>();
const weights_t* weights_p = weights.data_ptr<weights_t>();
for (int64_t i = 0; i < self_size; i++) {
diff --git a/aten/src/ATen/native/TensorConversions.cpp b/aten/src/ATen/native/TensorConversions.cpp
index d773de9..2669e07 100644
--- a/aten/src/ATen/native/TensorConversions.cpp
+++ b/aten/src/ATen/native/TensorConversions.cpp
@@ -54,11 +54,17 @@
Tensor to(
const Tensor& self,
- const TensorOptions& options_,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory,
bool non_blocking,
bool copy,
c10::optional<c10::MemoryFormat> optional_memory_format
) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options_ = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
TORCH_CHECK(
!(options_.has_memory_format() && optional_memory_format.has_value()),
"Cannot set memory_format both in TensorOptions and explicit argument; please delete "
diff --git a/aten/src/ATen/native/TensorFactories.cpp b/aten/src/ATen/native/TensorFactories.cpp
index 84e4fb9..e5e0a38 100644
--- a/aten/src/ATen/native/TensorFactories.cpp
+++ b/aten/src/ATen/native/TensorFactories.cpp
@@ -52,19 +52,34 @@
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ arange ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tensor arange(const Scalar& end, const TensorOptions& options) {
- return native::arange(/*start=*/0, end, options);
+Tensor arange(const Scalar& end,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::arange(/*start=*/0, end, dtype, layout, device, pin_memory);
}
-Tensor arange(const Scalar& start, const Scalar& end, const TensorOptions& options) {
- return native::arange(start, end, /*step=*/1, options);
+Tensor arange(const Scalar& start, const Scalar& end,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::arange(
+ start, end, /*step=*/1, dtype, layout, device, pin_memory);
}
Tensor arange(
const Scalar& start,
const Scalar& end,
const Scalar& step,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
bool set_to_integral_dtype = !options.has_dtype() &&
// bool inputs are considered integral
start.isIntegral(true) &&
@@ -160,9 +175,15 @@
Tensor empty(
IntArrayRef size,
- at::optional<DimnameList> names,
- const TensorOptions& options,
+ c10::optional<DimnameList> names,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory,
optional<MemoryFormat> optional_memory_format) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
if (!names.has_value()) {
return at::empty(size, options, optional_memory_format);
}
@@ -218,8 +239,14 @@
Tensor empty_like(
const Tensor& self,
- const TensorOptions& options_,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory,
c10::optional<c10::MemoryFormat> optional_memory_format) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options_ = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
TORCH_CHECK(
!(options_.has_memory_format() && optional_memory_format.has_value()),
@@ -341,19 +368,36 @@
const Tensor& self,
IntArrayRef size,
IntArrayRef stride,
- const TensorOptions& options
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory
) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
return at::empty_strided(size, stride, self.options().merge_in(options));
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ eye ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tensor eye(int64_t n, const TensorOptions& options) {
+Tensor eye(int64_t n,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
// the default value of `m` equals to `n`
- return native::eye(n, n, options);
+ return native::eye(n, n, dtype, layout, device, pin_memory);
}
-Tensor eye(int64_t n, int64_t m, const TensorOptions& options) {
+Tensor eye(int64_t n, int64_t m,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto tensor = at::empty({0}, options); // to be resized
return at::eye_out(tensor, n, m);
}
@@ -411,7 +455,14 @@
} // anonymous namespace
-Tensor full(IntArrayRef size, const Scalar& fill_value, const TensorOptions& options) {
+Tensor full(IntArrayRef size, const Scalar& fill_value,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
TORCH_CHECK(options.layout() != kSparse,
"full(...) is not implemented for sparse layout");
@@ -430,8 +481,14 @@
Tensor full_like(
const Tensor& self,
const Scalar& fill_value,
- const TensorOptions& options,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory,
c10::optional<c10::MemoryFormat> optional_memory_format) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto result = at::empty_like(self, options, optional_memory_format);
return result.fill_(fill_value);
}
@@ -440,8 +497,14 @@
const Tensor& self,
IntArrayRef size,
const Scalar& fill_value,
- const TensorOptions& options
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory
) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
return at::full(size, fill_value, self.options().merge_in(options));
}
@@ -477,7 +540,13 @@
const Scalar& start,
const Scalar& end,
c10::optional<int64_t> steps,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
const auto steps_ = steps.value_or(100);
TORCH_CHECK(steps_ >= 0, "number of steps must be non-negative");
auto result_options = linspace_logspace_infer_options(start, end, options);
@@ -492,7 +561,13 @@
const Scalar& end,
c10::optional<int64_t> steps,
double base,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
const auto steps_ = steps.value_or(100);
TORCH_CHECK(steps_ >= 0, "number of steps must be non-negative");
auto result_options = linspace_logspace_infer_options(start, end, options);
@@ -502,8 +577,12 @@
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ones ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tensor ones(IntArrayRef size, const TensorOptions& options) {
- return native::full(size, /*fill_value=*/1., options);
+Tensor ones(IntArrayRef size,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::full(size, /*fill_value=*/1., dtype, layout, device, pin_memory);
}
Tensor& ones_out(IntArrayRef size, Tensor& result) {
@@ -512,15 +591,25 @@
Tensor ones_like(
const Tensor& self,
- const TensorOptions& options,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory,
c10::optional<c10::MemoryFormat> optional_memory_format) {
- auto result = at::empty_like(self, options, optional_memory_format);
+ auto result = at::empty_like(self, dtype, layout, device, pin_memory, optional_memory_format);
return result.fill_(1.);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ scalar_tensor ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tensor scalar_tensor(const Scalar& s, const TensorOptions& options) {
+Tensor scalar_tensor(const Scalar& s,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
if (options.device() == at::kCPU) {
// This is a fast track to skip device dispatch for making scalar tensor on CPU.
// See https://github.com/pytorch/pytorch/pull/29915 for more detailed perf
@@ -539,11 +628,22 @@
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ rand ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tensor rand(IntArrayRef size, const TensorOptions& options) {
- return native::rand(size, static_cast<c10::optional<Generator>>(c10::nullopt), options);
+Tensor rand(IntArrayRef size,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::rand(size, static_cast<c10::optional<Generator>>(c10::nullopt), dtype, layout, device, pin_memory);
}
-Tensor rand(IntArrayRef size, c10::optional<Generator> generator, const TensorOptions& options) {
+Tensor rand(IntArrayRef size, c10::optional<Generator> generator,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto result = at::empty(size, options);
return result.uniform_(0, 1, generator);
}
@@ -559,32 +659,48 @@
Tensor rand_like(
const Tensor& self,
- const TensorOptions& options,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory,
c10::optional<c10::MemoryFormat> optional_memory_format) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto result = at::empty_like(self, options, optional_memory_format);
return result.uniform_(0, 1, c10::nullopt);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ randint ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tensor randint(int64_t high, IntArrayRef size, const TensorOptions& options) {
- return native::randint(high, size, c10::nullopt, options);
+Tensor randint(int64_t high, IntArrayRef size,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::randint(high, size, c10::nullopt /* generator*/, dtype, layout, device, pin_memory);
}
Tensor randint(
int64_t high,
IntArrayRef size,
c10::optional<Generator> generator,
- const TensorOptions& options) {
- return native::randint(0, high, size, generator, options);
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::randint(0, high, size, generator, dtype, layout, device, pin_memory);
}
Tensor randint(
int64_t low,
int64_t high,
IntArrayRef size,
- const TensorOptions& options) {
- return native::randint(low, high, size, c10::nullopt, options);
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::randint(low, high, size, c10::nullopt, dtype, layout, device, pin_memory);
}
Tensor randint(
@@ -592,7 +708,13 @@
int64_t high,
IntArrayRef size,
c10::optional<Generator> generator,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto result = at::empty(size, options);
return result.random_(low, high, generator);
}
@@ -625,8 +747,14 @@
Tensor randint_like(
const Tensor& self,
int64_t high,
- const TensorOptions& options,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory,
c10::optional<c10::MemoryFormat> optional_memory_format) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto result = at::empty_like(self, options, optional_memory_format);
return result.random_(0, high, c10::nullopt);
}
@@ -635,19 +763,36 @@
const Tensor& self,
int64_t low,
int64_t high,
- const TensorOptions& options,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory,
c10::optional<c10::MemoryFormat> optional_memory_format) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto result = at::empty_like(self, options, optional_memory_format);
return result.random_(low, high, c10::nullopt);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ randn ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tensor randn(IntArrayRef size, const TensorOptions& options) {
- return native::randn(size, static_cast<c10::optional<Generator>>(c10::nullopt), options);
+Tensor randn(IntArrayRef size,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::randn(size, static_cast<c10::optional<Generator>>(c10::nullopt), dtype, layout, device, pin_memory);
}
-Tensor randn(IntArrayRef size, c10::optional<Generator> generator, const TensorOptions& options) {
+Tensor randn(IntArrayRef size, c10::optional<Generator> generator,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto result = at::empty(size, options);
return result.normal_(0, 1, generator);
}
@@ -662,7 +807,14 @@
}
Tensor normal(double mean, double std, IntArrayRef size,
- c10::optional<Generator> generator, const TensorOptions& options) {
+ c10::optional<Generator> generator,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto result = at::empty(size, options);
return result.normal_(mean, std, generator);
}
@@ -675,8 +827,14 @@
Tensor randn_like(
const Tensor& self,
- const TensorOptions& options,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory,
c10::optional<c10::MemoryFormat> optional_memory_format) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto result = at::empty_like(self, options, optional_memory_format);
return result.normal_(0, 1, c10::nullopt);
}
@@ -707,11 +865,22 @@
}
} // namespace
-Tensor randperm(int64_t n, const TensorOptions& options) {
- return native::randperm(n, c10::nullopt, options);
+Tensor randperm(int64_t n,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::randperm(n, c10::nullopt, dtype, layout, device, pin_memory);
}
-Tensor randperm(int64_t n, c10::optional<Generator> generator, const TensorOptions& options) {
+Tensor randperm(int64_t n, c10::optional<Generator> generator,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto tensor = at::empty(n, options);
return at::randperm_out(tensor, n, generator);
}
@@ -741,7 +910,13 @@
const Scalar& start,
const Scalar& end,
const Scalar& step,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
Tensor result = at::empty({0}, options);
return at::range_out(result, start, end, step);
}
@@ -749,8 +924,11 @@
Tensor range(
const Scalar& start,
const Scalar& end,
- const TensorOptions& options) {
- return at::native::range(start, end, 1, options);
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return at::native::range(start, end, 1, dtype, layout, device, pin_memory);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ triangle ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -840,7 +1018,14 @@
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ zeros ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tensor zeros(IntArrayRef size, const TensorOptions& options) {
+Tensor zeros(IntArrayRef size,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto result = at::empty(size, options);
return result.zero_();
}
@@ -857,8 +1042,14 @@
Tensor zeros_like(
const Tensor& self,
- const TensorOptions& options,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory,
c10::optional<c10::MemoryFormat> optional_memory_format) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
if (options.layout() == kSparse && self.is_sparse()) {
TORCH_CHECK(
!(optional_memory_format.has_value()),
@@ -875,32 +1066,50 @@
Tensor new_zeros(
const Tensor& self,
IntArrayRef size,
- const TensorOptions& options
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory
) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
return at::zeros(size, self.options().merge_in(options));
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ bartlett_window ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tensor bartlett_window(int64_t window_length, const TensorOptions& options) {
- return native::bartlett_window(window_length, /*periodic=*/true, options);
+Tensor bartlett_window(int64_t window_length,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::bartlett_window(
+ window_length, /*periodic=*/true, dtype, layout, device, pin_memory);
}
Tensor bartlett_window(
int64_t window_length,
bool periodic,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
window_function_checks("bartlett_window", options, window_length);
if (window_length == 0) {
return at::empty({0}, options);
}
if (window_length == 1) {
- return native::ones({1}, options);
+ return native::ones({1}, dtype, layout, device, pin_memory);
}
if (periodic) {
window_length += 1;
}
- auto window = native::arange(window_length, options).mul_(2. / static_cast<double>(window_length - 1));
+ auto window = native::arange(window_length, dtype, layout, device, pin_memory)
+ .mul_(2. / static_cast<double>(window_length - 1));
const int64_t first_half_size = ((window_length - 1) >> 1) + 1;
window.narrow(0, first_half_size, window_length - first_half_size).mul_(-1).add_(2);
return periodic ? window.narrow(0, 0, window_length - 1) : window;
@@ -908,51 +1117,81 @@
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ blackman_window ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tensor blackman_window(int64_t window_length, const TensorOptions& options) {
- return native::blackman_window(window_length, /*periodic=*/true, options);
+Tensor blackman_window(int64_t window_length,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::blackman_window(
+ window_length, /*periodic=*/true, dtype, layout, device, pin_memory);
}
Tensor blackman_window(
int64_t window_length,
bool periodic,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
window_function_checks("blackman_window", options, window_length);
if (window_length == 0) {
return at::empty({0}, options);
}
if (window_length == 1) {
- return native::ones({1}, options);
+ return native::ones({1}, dtype, layout, device, pin_memory);
}
if (periodic) {
window_length += 1;
}
// from https://en.wikipedia.org/wiki/Window_function#Blackman_window
- auto window = native::arange(window_length, options).mul_(c10::pi<double> / static_cast<double>(window_length - 1));
+ auto window =
+ native::arange(window_length, dtype, layout, device, pin_memory)
+ .mul_(c10::pi<double> / static_cast<double>(window_length - 1));
window = window.mul(4).cos_().mul_(0.08) - window.mul(2).cos_().mul_(0.5) + 0.42;
return periodic ? window.narrow(0, 0, window_length - 1) : window;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ hamming_window ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tensor hamming_window(int64_t window_length, const TensorOptions& options) {
- return native::hamming_window(window_length, /*periodic=*/true, options);
+Tensor hamming_window(int64_t window_length,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::hamming_window(
+ window_length, /*periodic=*/true, dtype, layout, device, pin_memory);
}
Tensor hamming_window(
int64_t window_length,
bool periodic,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
return native::hamming_window(
- window_length, periodic, /*alpha=*/0.54, options);
+ window_length,
+ periodic,
+ /*alpha=*/0.54,
+ dtype,
+ layout,
+ device,
+ pin_memory);
}
Tensor hamming_window(
int64_t window_length,
bool periodic,
double alpha,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
return native::hamming_window(
- window_length, periodic, alpha, /*beta=*/0.46, options);
+ window_length, periodic, alpha, /*beta=*/0.46, dtype, layout, device, pin_memory);
}
Tensor hamming_window(
@@ -960,52 +1199,89 @@
bool periodic,
double alpha,
double beta,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
window_function_checks("hamming_window", options, window_length);
if (window_length == 0) {
return at::empty({0}, options);
}
if (window_length == 1) {
- return native::ones({1}, options);
+ return native::ones({1}, dtype, layout, device, pin_memory);
}
if (periodic) {
window_length += 1;
}
- auto window = native::arange(window_length, options);
+ auto window = native::arange(window_length, dtype, layout, device, pin_memory);
window.mul_(c10::pi<double> * 2. / static_cast<double>(window_length - 1)).cos_().mul_(-beta).add_(alpha);
return periodic ? window.narrow(0, 0, window_length - 1) : window;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ hann_window ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tensor hann_window(int64_t window_length, const TensorOptions& options) {
- return native::hann_window(window_length, /*periodic=*/true, options);
+Tensor hann_window(int64_t window_length,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::hann_window(window_length, /*periodic=*/true, dtype, layout, device, pin_memory);
}
Tensor hann_window(
int64_t window_length,
bool periodic,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
window_function_checks("hann_window", options, window_length);
return native::hamming_window(
- window_length, periodic, /*alpha=*/0.5, /*beta=*/0.5, options);
+ window_length, periodic, /*alpha=*/0.5, /*beta=*/0.5, dtype, layout, device, pin_memory);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kaiser_window ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tensor kaiser_window(int64_t window_length, const TensorOptions& options) {
- return native::kaiser_window(window_length, /*periodic=*/true, /*beta=*/12.0, options);
+Tensor kaiser_window(int64_t window_length,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::kaiser_window(
+ window_length,
+ /*periodic=*/true,
+ /*beta=*/12.0,
+ dtype,
+ layout,
+ device,
+ pin_memory);
}
-Tensor kaiser_window(int64_t window_length, bool periodic, const TensorOptions& options) {
- return native::kaiser_window(window_length, periodic, /*beta=*/12.0, options);
+Tensor kaiser_window(int64_t window_length, bool periodic,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::kaiser_window(window_length, periodic, /*beta=*/12.0, dtype, layout, device, pin_memory);
}
Tensor kaiser_window(
int64_t window_length,
bool periodic,
double beta,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
window_function_checks("kaiser_window", options, window_length);
if (window_length == 0) {
return at::empty({0}, options);
@@ -1076,12 +1352,19 @@
return at::detail::tensor_complex_backend(values, options);
}
-Tensor from_file(std::string filename, c10::optional<bool> shared, c10::optional<int64_t> size, const TensorOptions& options) {
+Tensor from_file(std::string filename, c10::optional<bool> shared, c10::optional<int64_t> size,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
TORCH_CHECK(!options.pinned_memory(), "tensors constructed from a file cannot be pinned");
int64_t my_size = size.value_or(0);
int flags = shared.value_or(false) ? TH_ALLOCATOR_MAPPED_SHARED : 0;
- auto dtype = options.dtype();
- size_t size_bytes = my_size * dtype.itemsize();
+ auto my_dtype = options.dtype();
+ size_t size_bytes = my_size * my_dtype.itemsize();
auto storage_impl = c10::make_intrusive<at::StorageImpl>(
c10::StorageImpl::use_byte_size_t(),
size_bytes,
@@ -1090,7 +1373,7 @@
/*allocator=*/nullptr,
/*resizable=*/false);
auto tensor = detail::make_tensor<at::TensorImpl>(
- storage_impl, at::DispatchKey::CPU, dtype);
+ storage_impl, at::DispatchKey::CPU, my_dtype);
tensor.unsafeGetTensorImpl()->set_sizes_contiguous({my_size});
return tensor;
}
@@ -1124,7 +1407,13 @@
IntArrayRef size,
const Scalar& fill_value,
optional<DimnameList> names,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
TORCH_CHECK(options.layout() != kSparse,
"full(...) is not implemented for sparse layout");
@@ -1136,29 +1425,48 @@
Tensor ones(
IntArrayRef size,
optional<DimnameList> names,
- const TensorOptions& options) {
- return native::full(size, /*fill_value=*/1., names, options);
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
+ return native::full(
+ size, /*fill_value=*/1., names, dtype, layout, device, pin_memory);
}
Tensor zeros(
IntArrayRef size,
optional<DimnameList> names,
- const TensorOptions& options) {
- return native::full(size, /*fill_value=*/0., names, options);
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::full(size, /*fill_value=*/0., names, dtype, layout, device, pin_memory);
}
Tensor randn(
IntArrayRef size,
optional<DimnameList> names,
- const TensorOptions& options) {
- return native::randn(size, c10::nullopt, names, options);
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::randn(size, c10::nullopt, names, dtype, layout, device, pin_memory);
}
Tensor randn(
IntArrayRef size,
c10::optional<Generator> generator,
optional<DimnameList> names,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto result = at::empty(size, names, options);
return result.normal_(0, 1, generator);
}
@@ -1166,15 +1474,24 @@
Tensor rand(
IntArrayRef size,
optional<DimnameList> names,
- const TensorOptions& options) {
- return native::rand(size, c10::nullopt, names, options);
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ return native::rand(size, c10::nullopt, names, dtype, layout, device, pin_memory);
}
Tensor rand(
IntArrayRef size,
c10::optional<Generator> generator,
optional<DimnameList> names,
- const TensorOptions& options) {
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto result = at::empty(size, names, options);
return result.uniform_(0, 1, generator);
}
diff --git a/aten/src/ATen/native/TensorShape.cpp b/aten/src/ATen/native/TensorShape.cpp
index d860cb3..fe8bb3c 100644
--- a/aten/src/ATen/native/TensorShape.cpp
+++ b/aten/src/ATen/native/TensorShape.cpp
@@ -369,7 +369,14 @@
}
auto sizes_copy = sizes.vec();
sizes_copy[wrapped] = cumulative_offset;
- return native::sparse_coo_tensor(idxs, vals, sizes_copy, tensors[0].options());
+ return native::sparse_coo_tensor(
+ idxs,
+ vals,
+ sizes_copy,
+ optTypeMetaToScalarType(tensors[0].options().dtype_opt()),
+ tensors[0].options().layout_opt(),
+ tensors[0].options().device_opt(),
+ tensors[0].options().pinned_memory_opt());
}
else {
// Catting along a dense dimension requires us to create new values.
@@ -406,16 +413,33 @@
zeros_sizes[0] = t._values().size(0);
zeros_sizes[values_dim] = cumulative_size;
cumulative_size += t._values().size(values_dim);
- auto z1 = native::zeros(zeros_sizes, t._values().options());
+ auto z1 = native::zeros(
+ zeros_sizes,
+ optTypeMetaToScalarType(t._values().options().dtype_opt()),
+ t._values().options().layout_opt(),
+ t._values().options().device_opt(),
+ t._values().options().pinned_memory_opt());
zeros_sizes[values_dim] = total_size - cumulative_size;
- auto z2 = native::zeros(zeros_sizes, t._values().options());
+ auto z2 = native::zeros(
+ zeros_sizes,
+ optTypeMetaToScalarType(t._values().options().dtype_opt()),
+ t._values().options().layout_opt(),
+ t._values().options().device_opt(),
+ t._values().options().pinned_memory_opt());
vals_pieces.push_back(native::cat({z1, t._values(), z2}, values_dim));
idxs_pieces.push_back(t._indices());
}
auto sizes_copy = sizes.vec();
sizes_copy[wrapped] = total_size;
// This can create an uncoalesced tensor
- return native::sparse_coo_tensor(native::cat(idxs_pieces, 1), native::cat(vals_pieces), sizes_copy, tensors[0].options());
+ return native::sparse_coo_tensor(
+ native::cat(idxs_pieces, 1),
+ native::cat(vals_pieces),
+ sizes_copy,
+ optTypeMetaToScalarType(tensors[0].options().dtype_opt()),
+ tensors[0].options().layout_opt(),
+ tensors[0].options().device_opt(),
+ tensors[0].options().pinned_memory_opt());
}
}
@@ -1059,7 +1083,15 @@
return new_values.sum(0);
}
} else {
- auto dimIndices = (arange(0, sparse_dim, self.device()) != dim).nonzero().view(-1);
+ auto dimIndices = (arange(
+ 0,
+ sparse_dim,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ self.device(),
+ c10::nullopt /* pin_memory */) != dim)
+ .nonzero()
+ .view(-1);
auto new_indices = indices.index_select(1, nzIndices).index_select(0, dimIndices);
return _sparse_coo_tensor_with_dims_and_tensors(
sparse_dim - 1, dense_dim, new_sizes, new_indices, new_values, self.options());
@@ -1831,11 +1863,15 @@
auto sizes = self.sizes().vec();
sizes.insert(sizes.begin() + dim, 1);
if (dim <= sparse_dim) {
- auto new_indices = native::cat({
- indices.narrow(0, 0, dim),
- native::zeros({1, indices.size(1)}, indices.options().dtype(kLong)),
- indices.narrow(0, dim, indices.size(0) - dim)
- });
+ auto new_indices = native::cat(
+ {indices.narrow(0, 0, dim),
+ native::zeros(
+ {1, indices.size(1)},
+ kLong,
+ indices.options().layout_opt(),
+ indices.options().device_opt(),
+ indices.options().pinned_memory_opt()),
+ indices.narrow(0, dim, indices.size(0) - dim)});
return _sparse_coo_tensor_with_dims_and_tensors(
sparse_dim + 1, dense_dim, sizes, new_indices, self._values(), self.options());
} else {
diff --git a/aten/src/ATen/native/UnaryOps.cpp b/aten/src/ATen/native/UnaryOps.cpp
index ae4d028..f8f2925 100644
--- a/aten/src/ATen/native/UnaryOps.cpp
+++ b/aten/src/ATen/native/UnaryOps.cpp
@@ -677,14 +677,29 @@
Tensor mvlgamma(const Tensor& self, int64_t p) {
mvlgamma_check(self, p);
- Tensor args = native::arange(-p / 2. + 0.5, 0.5, 0.5, self.options());
+ Tensor args = native::arange(
+ -p / 2. + 0.5,
+ 0.5,
+ 0.5,
+ optTypeMetaToScalarType(self.options().dtype_opt()),
+ self.options().layout_opt(),
+ self.options().device_opt(),
+ self.options().pinned_memory_opt());
args = args.add(self.unsqueeze(-1));
return args.lgamma_().sum(-1).add_(p * (p - 1) * std::log(c10::pi<double>) / 4.);
}
Tensor& mvlgamma_(Tensor& self, int64_t p) {
mvlgamma_check(self, p);
- Tensor args = native::arange(-p / 2. + 0.5, 0.5, 0.5, self.options());
+ auto dtype_opt = self.options().dtype_opt();
+ Tensor args = native::arange(
+ -p / 2. + 0.5,
+ 0.5,
+ 0.5,
+ optTypeMetaToScalarType(self.options().dtype_opt()),
+ self.options().layout_opt(),
+ self.options().device_opt(),
+ self.options().pinned_memory_opt());
args = args.add(self.unsqueeze(-1));
return self.copy_(args.lgamma_().sum(-1).add_(p * (p - 1) * std::log(c10::pi<double>) / 4.));
}
diff --git a/aten/src/ATen/native/cuda/Activation.cu b/aten/src/ATen/native/cuda/Activation.cu
index 75bbf15..9f74e8b 100644
--- a/aten/src/ATen/native/cuda/Activation.cu
+++ b/aten/src/ATen/native/cuda/Activation.cu
@@ -499,14 +499,26 @@
} // namespace
Tensor gelu_cuda(const Tensor& self) {
- Tensor Y = at::native::empty_like(self, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ Tensor Y = at::native::empty_like(
+ self,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
auto it = TensorIterator::unary_op(Y, self);
GeluCUDAKernelImpl(it);
return Y;
}
Tensor gelu_backward_cuda(const Tensor& grad, const Tensor& self) {
- Tensor dX = at::native::empty_like(self, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ Tensor dX = at::native::empty_like(
+ self,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
auto it = TensorIterator::binary_op(dX, grad, self);
GeluBackwardCUDAKernelImpl(it);
return dX;
diff --git a/aten/src/ATen/native/cuda/LinearAlgebra.cu b/aten/src/ATen/native/cuda/LinearAlgebra.cu
index 3443b38..380d358 100644
--- a/aten/src/ATen/native/cuda/LinearAlgebra.cu
+++ b/aten/src/ATen/native/cuda/LinearAlgebra.cu
@@ -137,7 +137,15 @@
}
// TODO: We could squeeze some perf by calling at::cuda::mul_out here instead, to bypass the dispatcher.
// That requires some fixing some internal build dependencies though.
- return at::mul_out(result, self, at::native::scalar_tensor(beta, at::device(at::kCPU).dtype(self.scalar_type())));
+ return at::mul_out(
+ result,
+ self,
+ at::native::scalar_tensor(
+ beta,
+ self.scalar_type(),
+ c10::nullopt /* layout */,
+ at::kCPU,
+ c10::nullopt /* pin_memory */));
}
AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES_AND2(at::ScalarType::Half, at::ScalarType::BFloat16, scalar_type, "addmm_cuda", [&] {
diff --git a/aten/src/ATen/native/cuda/MultinomialKernel.cu b/aten/src/ATen/native/cuda/MultinomialKernel.cu
index a354a81..278c567 100644
--- a/aten/src/ATen/native/cuda/MultinomialKernel.cu
+++ b/aten/src/ATen/native/cuda/MultinomialKernel.cu
@@ -359,12 +359,30 @@
// For sampling without replacement, we modify the distribution
// for subsequent samples in this space
- Tensor origDist = native::empty_like(self_v, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ Tensor origDist = native::empty_like(
+ self_v,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
origDist.copy_(self_v);
- Tensor normDist = native::empty_like(self_v, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ Tensor normDist = native::empty_like(
+ self_v,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
- Tensor prefixSum = native::empty_like(self_v, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ Tensor prefixSum = native::empty_like(
+ self_v,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
// Renorm along rows
normDist.copy_(origDist);
diff --git a/aten/src/ATen/native/cuda/SummaryOps.cu b/aten/src/ATen/native/cuda/SummaryOps.cu
index 68c7b79..eb8a18d 100644
--- a/aten/src/ATen/native/cuda/SummaryOps.cu
+++ b/aten/src/ATen/native/cuda/SummaryOps.cu
@@ -241,7 +241,12 @@
detail::TensorInfo<output_t, IndexType> pInfo(nullptr, 0, {}, {});
Tensor partial_output;
if (memType == CUDAHistogramMemoryType::MULTI_BLOCK) {
- partial_output = native::zeros({grid.x, nbins}, a.options());
+ partial_output = native::zeros(
+ {grid.x, nbins},
+ optTypeMetaToScalarType(a.options().dtype_opt()),
+ a.options().layout_opt(),
+ a.options().device_opt(),
+ a.options().pinned_memory_opt());
pInfo = detail::getTensorInfo<output_t, IndexType>(partial_output);
}
@@ -278,7 +283,12 @@
AT_ERROR("minlength should be >= 0");
}
if (self.dim() == 1 && self.numel() == 0) {
- return native::zeros({minlength}, device(kCUDA).dtype(kLong));
+ return native::zeros(
+ {minlength},
+ kLong,
+ c10::nullopt /* layout */,
+ kCUDA,
+ c10::nullopt /* pin_memory */);
}
if (self.dim() != 1 ||
(!std::is_same<input_t, uint8_t>::value &&
@@ -297,11 +307,21 @@
// alloc output counter on GPU
Tensor output;
if (has_weights) {
- output = native::zeros({nbins}, weights.options());
+ output = native::zeros(
+ {nbins},
+ optTypeMetaToScalarType(weights.options().dtype_opt()),
+ weights.options().layout_opt(),
+ weights.options().device_opt(),
+ weights.options().pinned_memory_opt());
auto ret = cuda::CUDA_tensor_histogram<weights_t, input_t, true>(
output, self, weights, nbins, minvalue, maxvalue);
} else {
- output = native::zeros({nbins}, device(DeviceType::CUDA).dtype(kLong));
+ output = native::zeros(
+ {nbins},
+ kLong,
+ c10::nullopt /* layout */,
+ DeviceType::CUDA,
+ c10::nullopt /* pin_memory */);
auto ret = cuda::CUDA_tensor_histogram<int64_t, input_t, false>(
output, self, weights, nbins, minvalue, maxvalue);
}
@@ -318,7 +338,12 @@
if (nbins <= 0) {
AT_ERROR("bins must be > 0");
}
- Tensor output = native::zeros({nbins}, device(DeviceType::CUDA).dtype(self.scalar_type()));
+ Tensor output = native::zeros(
+ {nbins},
+ self.scalar_type(),
+ c10::nullopt /* layout */,
+ DeviceType::CUDA,
+ c10::nullopt /* pin_memory */);
input_t minvalue = min;
input_t maxvalue = max;
if (min == max) {
diff --git a/aten/src/ATen/native/cuda/layer_norm_kernel.cu b/aten/src/ATen/native/cuda/layer_norm_kernel.cu
index 048d8b8..498f4d3 100644
--- a/aten/src/ATen/native/cuda/layer_norm_kernel.cu
+++ b/aten/src/ATen/native/cuda/layer_norm_kernel.cu
@@ -438,7 +438,13 @@
auto M = std::get<3>(inputs);
auto N = std::get<4>(inputs);
- Tensor Y = at::native::empty_like(X, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ Tensor Y = at::native::empty_like(
+ X,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
Tensor mean = at::empty({M}, X.options());
Tensor rstd = at::empty({M}, X.options());
if (M > 0) {
@@ -484,13 +490,45 @@
Tensor dgamma;
Tensor dbeta;
if (grad_input_mask[0]) {
- dX = at::native::empty_like(X, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ dX = at::native::empty_like(
+ X,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
}
if (grad_input_mask[1]) {
- dgamma = M > 0 ? at::native::empty_like(gamma, LEGACY_CONTIGUOUS_MEMORY_FORMAT) : at::native::zeros_like(gamma, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ dgamma = M > 0 ? at::native::empty_like(
+ gamma,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT)
+ : at::native::zeros_like(
+ gamma,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
}
if (grad_input_mask[2]) {
- dbeta = M > 0 ? at::native::empty_like(beta, LEGACY_CONTIGUOUS_MEMORY_FORMAT) : at::native::zeros_like(beta, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ dbeta = M > 0 ? at::native::empty_like(
+ beta,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT)
+ : at::native::zeros_like(
+ beta,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
}
if (M > 0) {
LayerNormBackwardKernelImpl(
diff --git a/aten/src/ATen/native/cudnn/ConvShared.cpp b/aten/src/ATen/native/cudnn/ConvShared.cpp
index 3fc54f2..c221a3c 100644
--- a/aten/src/ATen/native/cudnn/ConvShared.cpp
+++ b/aten/src/ATen/native/cudnn/ConvShared.cpp
@@ -518,8 +518,14 @@
weight_t,
output_t, // use output_t as z to satisfy CUDNN API
0, // alpha
- bias_t.has_value() ? bias_t.value()
- : zeros({output_t.size(1)}, output_t.options()),
+ bias_t.has_value()
+ ? bias_t.value()
+ : at::native::zeros(
+ {output_t.size(1)},
+ optTypeMetaToScalarType(output_t.options().dtype_opt()),
+ output_t.options().layout_opt(),
+ output_t.options().device_opt(),
+ output_t.options().pinned_memory_opt()),
stride,
padding,
dilation,
@@ -561,8 +567,14 @@
weight_t,
z_t,
alpha.has_value() ? alpha.value().to<float>() : 1.0,
- bias_t.has_value() ? bias_t.value()
- : zeros({output_t.size(1)}, output_t.options()),
+ bias_t.has_value()
+ ? bias_t.value()
+ : at::native::zeros(
+ {output_t.size(1)},
+ optTypeMetaToScalarType(output_t.options().dtype_opt()),
+ output_t.options().layout_opt(),
+ output_t.options().device_opt(),
+ output_t.options().pinned_memory_opt()),
stride,
padding,
dilation,
diff --git a/aten/src/ATen/native/cudnn/RNN.cpp b/aten/src/ATen/native/cudnn/RNN.cpp
index d0bcb43..790a864 100644
--- a/aten/src/ATen/native/cudnn/RNN.cpp
+++ b/aten/src/ATen/native/cudnn/RNN.cpp
@@ -48,7 +48,14 @@
AT_ERROR("_cudnn_rnn_backward: ATen not compiled with cuDNN support");
}
-Tensor _cudnn_init_dropout_state(double dropout, bool train, int64_t dropout_seed, const TensorOptions& options) {
+Tensor _cudnn_init_dropout_state(double dropout, bool train, int64_t dropout_seed,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
AT_ERROR("_cudnn_init_dropout_state: ATen not compiled with cuDNN support");
}
@@ -1317,7 +1324,14 @@
// as input. The codegen currently assumes that ALL factory functions
// take TensorOptions, so it's just a lot easier for this function to
// be bound if it also does it.
-Tensor _cudnn_init_dropout_state(double dropout, bool train, int64_t dropout_seed, const TensorOptions& options) {
+Tensor _cudnn_init_dropout_state(double dropout, bool train, int64_t dropout_seed,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
auto handle = getCudnnHandle();
DropoutDescriptor dropout_desc;
auto dropout_p = train ? dropout : 0;
diff --git a/aten/src/ATen/native/group_norm.cpp b/aten/src/ATen/native/group_norm.cpp
index f112c0e..dfe2097 100644
--- a/aten/src/ATen/native/group_norm.cpp
+++ b/aten/src/ATen/native/group_norm.cpp
@@ -28,7 +28,13 @@
const Tensor& gamma = c10::value_or_else(gamma_opt, [] {return Tensor();});
const Tensor& beta = c10::value_or_else(beta_opt, [] {return Tensor();});
- Tensor Y = at::native::empty_like(X, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ Tensor Y = at::native::empty_like(
+ X,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
Tensor mean = at::empty({N, group}, X.options());
Tensor rstd = at::empty({N, group}, X.options());
GroupNormKernel(
@@ -53,13 +59,31 @@
Tensor dgamma;
Tensor dbeta;
if (grad_input_mask[0]) {
- dX = at::native::empty_like(X, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ dX = at::native::empty_like(
+ X,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
}
if (grad_input_mask[1]) {
- dgamma = at::native::empty_like(gamma, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ dgamma = at::native::empty_like(
+ gamma,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
}
if (grad_input_mask[2]) {
- dbeta = at::native::empty_like(gamma, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
+ dbeta = at::native::empty_like(
+ gamma,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ LEGACY_CONTIGUOUS_MEMORY_FORMAT);
}
GroupNormBackwardKernel(
X.device().type(),
diff --git a/aten/src/ATen/native/layer_norm.cpp b/aten/src/ATen/native/layer_norm.cpp
index 82e25d2..623eff7 100644
--- a/aten/src/ATen/native/layer_norm.cpp
+++ b/aten/src/ATen/native/layer_norm.cpp
@@ -33,7 +33,13 @@
auto M = std::get<3>(inputs);
auto N = std::get<4>(inputs);
- Tensor Y = at::native::empty_like(X, at::MemoryFormat::Contiguous);
+ Tensor Y = at::native::empty_like(
+ X,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ at::MemoryFormat::Contiguous);
Tensor mean = at::empty({M}, X.options());
Tensor rstd = at::empty({M}, X.options());
if (M > 0) {
@@ -79,13 +85,45 @@
Tensor dgamma;
Tensor dbeta;
if (grad_input_mask[0]) {
- dX = at::native::empty_like(X, at::MemoryFormat::Contiguous);
+ dX = at::native::empty_like(
+ X,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ at::MemoryFormat::Contiguous);
}
if (grad_input_mask[1]) {
- dgamma = M > 0 ? at::native::empty_like(gamma, at::MemoryFormat::Contiguous) : at::native::zeros_like(gamma, at::MemoryFormat::Contiguous);
+ dgamma = M > 0 ? at::native::empty_like(
+ gamma,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ at::MemoryFormat::Contiguous)
+ : at::native::zeros_like(
+ gamma,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ at::MemoryFormat::Contiguous);
}
if (grad_input_mask[2]) {
- dbeta = M > 0 ? at::native::empty_like(beta, at::MemoryFormat::Contiguous) : at::native::zeros_like(beta, at::MemoryFormat::Contiguous);
+ dbeta = M > 0 ? at::native::empty_like(
+ beta,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ at::MemoryFormat::Contiguous)
+ : at::native::zeros_like(
+ beta,
+ c10::nullopt /* dtype */,
+ c10::nullopt /* layout */,
+ c10::nullopt /* device */,
+ c10::nullopt /* pin_memory */,
+ at::MemoryFormat::Contiguous);
}
if (M > 0) {
LayerNormBackwardKernel(
diff --git a/aten/src/ATen/native/native_functions.yaml b/aten/src/ATen/native/native_functions.yaml
index 32b7161..68423bd 100644
--- a/aten/src/ATen/native/native_functions.yaml
+++ b/aten/src/ATen/native/native_functions.yaml
@@ -151,7 +151,6 @@
CUDA: _cudnn_rnn_backward
- func: _cudnn_init_dropout_state(float dropout, bool train, int dropout_seed, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=False) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
dispatch:
CUDA: _cudnn_init_dropout_state
@@ -450,13 +449,10 @@
- func: any.dimname_out(Tensor self, Dimname dim, bool keepdim=False, *, Tensor(a!) out) -> Tensor(a!)
- func: arange(Scalar end, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: arange.start(Scalar start, Scalar end, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: arange.start_step(Scalar start, Scalar end, Scalar step, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: arange.out(Scalar end, *, Tensor(a!) out) -> Tensor(a!)
@@ -661,10 +657,8 @@
CUDA: baddbmm_out_cuda
- func: bartlett_window(int window_length, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: bartlett_window.periodic(int window_length, bool periodic, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: batch_norm(Tensor input, Tensor? weight, Tensor? bias, Tensor? running_mean, Tensor? running_var, bool training, float momentum, float eps, bool cudnn_enabled) -> Tensor
@@ -824,10 +818,8 @@
CPU, CUDA: logical_or_out
- func: blackman_window(int window_length, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: blackman_window.periodic(int window_length, bool periodic, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: bmm(Tensor self, Tensor mat2) -> Tensor
variants: function, method
@@ -1494,7 +1486,6 @@
CUDA: _embedding_bag_per_sample_weights_backward_cuda
- func: empty.names(int[] size, *, Dimname[]? names, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
device_guard: False
- func: empty.memory_format(int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=None) -> Tensor
@@ -1509,20 +1500,16 @@
variants: method
- func: new_empty_strided(Tensor self, int[] size, int[] stride, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
variants: method
- func: new_full(Tensor self, int[] size, Scalar fill_value, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
variants: method
- func: new_zeros(Tensor self, int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
variants: method
# other overrides are to provide a more helpful error message that dtype is required
- func: _empty_affine_quantized(int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, float scale=1, int zero_point=0, MemoryFormat? memory_format=contiguous_format) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
dispatch:
CPU: empty_affine_quantized_other_backends_stub
QuantizedCPU, QuantizedCUDA: empty_affine_quantized
@@ -1530,7 +1517,6 @@
# it's a factory function receiving a tensor argument, thus overriding explicitly
# other overrides are to provide a more helpful error message that dtype is required
- func: _empty_per_channel_affine_quantized(int[] size, *, Tensor scales, Tensor zero_points, int axis, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=contiguous_format) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
category_override: factory
dispatch:
CPU: empty_per_channel_affine_quantized_other_backends_stub
@@ -1554,7 +1540,6 @@
device_guard: False
- func: empty_like(Tensor self, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
device_guard: False
- func: empty_strided(int[] size, int[] stride, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
@@ -1644,10 +1629,8 @@
device_guard: False
- func: eye(int n, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: eye.m(int n, int m, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: eye.out(int n, *, Tensor(a!) out) -> Tensor(a!)
dispatch:
@@ -1739,19 +1722,15 @@
CPU, CUDA: frac_out
- func: full.names(int[] size, Scalar fill_value, *, Dimname[]? names, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
device_guard: False
- func: full(int[] size, Scalar fill_value, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: full.out(int[] size, Scalar fill_value, *, Tensor(a!) out) -> Tensor(a!)
- func: full_like(Tensor self, Scalar fill_value, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: from_file(str filename, bool? shared=None, int? size=0, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
dispatch:
CPU: from_file
@@ -1820,31 +1799,22 @@
CUDA: grid_sampler_3d_backward_cuda
- func: hann_window(int window_length, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: hann_window.periodic(int window_length, bool periodic, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: hamming_window(int window_length, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: hamming_window.periodic(int window_length, bool periodic, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: hamming_window.periodic_alpha(int window_length, bool periodic, float alpha, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: hamming_window.periodic_alpha_beta(int window_length, bool periodic, float alpha, float beta, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: kaiser_window(int window_length, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: kaiser_window.periodic(int window_length, bool periodic, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: kaiser_window.beta(int window_length, bool periodic, float beta, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: hinge_embedding_loss(Tensor self, Tensor target, float margin=1.0, int reduction=Mean) -> Tensor
@@ -2110,7 +2080,6 @@
- func: ldexp.out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)
- func: linspace(Scalar start, Scalar end, int? steps=None, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: linspace.out(Scalar start, Scalar end, int? steps=None, *, Tensor(a!) out) -> Tensor(a!)
dispatch:
@@ -2242,7 +2211,6 @@
CompositeExplicitAutograd: logdet
- func: logspace(Scalar start, Scalar end, int? steps=None, float base=10.0, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: logspace.out(Scalar start, Scalar end, int? steps=None, float base=10.0, *, Tensor(a!) out) -> Tensor(a!)
dispatch:
@@ -2776,16 +2744,13 @@
variants: function
- func: ones.names(int[] size, *, Dimname[]? names, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
device_guard: False
- func: ones(int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: ones.out(int[] size, *, Tensor(a!) out) -> Tensor(a!)
- func: ones_like(Tensor self, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: pairwise_distance(Tensor x1, Tensor x2, float p=2, float eps=1e-06, bool keepdim=False) -> Tensor
@@ -2894,40 +2859,30 @@
CompositeExplicitAutograd: deg2rad_out
- func: scalar_tensor(Scalar s, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: rand.names(int[] size, *, Dimname[]? names, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
device_guard: False
- func: rand.generator_with_names(int[] size, *, Generator? generator, Dimname[]? names, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
device_guard: False
- func: rand(int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: rand.generator(int[] size, *, Generator? generator, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: rand.out(int[] size, *, Tensor(a!) out) -> Tensor(a!)
- func: rand.generator_out(int[] size, *, Generator? generator, Tensor(a!) out) -> Tensor(a!)
- func: rand_like(Tensor self, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: randint(int high, int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: randint.generator(int high, int[] size, *, Generator? generator, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: randint.low(int low, int high, int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: randint.low_generator(int low, int high, int[] size, *, Generator? generator, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: randint.out(int high, int[] size, *, Tensor(a!) out) -> Tensor(a!)
@@ -2938,23 +2893,17 @@
- func: randint.low_generator_out(int low, int high, int[] size, *, Generator? generator, Tensor(a!) out) -> Tensor(a!)
- func: randint_like(Tensor self, int high, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: randint_like.low_dtype(Tensor self, int low, int high, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: randn(int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: randn.generator(int[] size, *, Generator? generator, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: randn.names(int[] size, *, Dimname[]? names, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
device_guard: False
- func: randn.generator_with_names(int[] size, *, Generator? generator, Dimname[]? names, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
device_guard: False
- func: randn.out(int[] size, *, Tensor(a!) out) -> Tensor(a!)
@@ -2962,13 +2911,10 @@
- func: randn.generator_out(int[] size, *, Generator? generator, Tensor(a!) out) -> Tensor(a!)
- func: randn_like(Tensor self, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: randperm(int n, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: randperm.generator(int n, *, Generator? generator, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: randperm.out(int n, *, Tensor(a!) out) -> Tensor(a!)
@@ -2978,10 +2924,8 @@
CUDA: randperm_out_cuda
- func: range.step(Scalar start, Scalar end, Scalar step=1, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: range(Scalar start, Scalar end, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: range.out(Scalar start, Scalar end, Scalar step=1, *, Tensor(a!) out) -> Tensor(a!)
dispatch:
@@ -3875,16 +3819,13 @@
variants: function
- func: zeros.names(int[] size, *, Dimname[]? names, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
device_guard: False
- func: zeros(int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: zeros.out(int[] size, *, Tensor(a!) out) -> Tensor(a!)
- func: zeros_like(Tensor self, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: _standard_gamma_grad(Tensor self, Tensor output) -> Tensor
variants: function
@@ -4278,16 +4219,12 @@
# FIXME: would be nicer if TensorOptions was optional based; not adding default arguments for options given
# the default would never make sense.
- func: sparse_coo_tensor.size(int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=False) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: sparse_coo_tensor.indices(Tensor indices, Tensor values, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: sparse_coo_tensor.indices_size(Tensor indices, Tensor values, int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: _sparse_coo_tensor_unsafe(Tensor indices, Tensor values, int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: _validate_sparse_coo_tensor_args(Tensor indices, Tensor values, int[] size) -> ()
@@ -4574,7 +4511,6 @@
# TensorOptions. Otherwise, an ambiguity error is thrown.
# See NOTE [ TensorOptions Constructors ].
- func: to.dtype_layout(Tensor self, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, bool non_blocking=False, bool copy=False, MemoryFormat? memory_format=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
variants: method
device_guard: False
@@ -6328,7 +6264,6 @@
CPU, CUDA: normal
- func: normal.float_float(float mean, float std, int[] size, *, Generator? generator=None, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
- func: normal.float_float_out(float mean, float std, int[] size, *, Generator? generator=None, Tensor(a!) out) -> Tensor(a!)
use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
@@ -8693,7 +8628,6 @@
variants: function
- func: fft_fftfreq(int n, float d=1.0, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
python_module: fft
variants: function
@@ -8703,7 +8637,6 @@
variants: function
- func: fft_rfftfreq(int n, float d=1.0, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None) -> Tensor
- use_c10_dispatcher: hacky_wrapper_for_legacy_signatures
python_module: fft
variants: function
diff --git a/aten/src/ATen/native/quantized/TensorFactories.cpp b/aten/src/ATen/native/quantized/TensorFactories.cpp
index a05026d..7a763fa 100644
--- a/aten/src/ATen/native/quantized/TensorFactories.cpp
+++ b/aten/src/ATen/native/quantized/TensorFactories.cpp
@@ -12,10 +12,16 @@
// change to use quantizer
Tensor empty_affine_quantized(
IntArrayRef size,
- const TensorOptions& options_,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory,
double scale,
int64_t zero_point,
c10::optional<c10::MemoryFormat> optional_memory_format) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options_ = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
TORCH_CHECK(
!(options_.has_memory_format() && optional_memory_format.has_value()),
"Cannot set memory_format both in TensorOptions and explicit argument; please delete "
@@ -36,8 +42,14 @@
const Tensor& scales,
const Tensor& zero_points,
int64_t axis,
- const TensorOptions& options_,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory,
c10::optional<c10::MemoryFormat> optional_memory_format) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options_ = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
TORCH_CHECK(
!(options_.has_memory_format() && optional_memory_format.has_value()),
"Cannot set memory_format both in TensorOptions and explicit argument; please delete "
@@ -57,7 +69,10 @@
// Provide better error message if dtype is wrong
Tensor empty_affine_quantized_other_backends_stub(
IntArrayRef,
- const TensorOptions&,
+ c10::optional<ScalarType>,
+ c10::optional<Layout>,
+ c10::optional<Device>,
+ c10::optional<bool>,
double,
int64_t,
c10::optional<c10::MemoryFormat>) {
@@ -69,7 +84,10 @@
const Tensor&,
const Tensor&,
int64_t,
- const TensorOptions&,
+ c10::optional<ScalarType>,
+ c10::optional<Layout>,
+ c10::optional<Device>,
+ c10::optional<bool>,
c10::optional<c10::MemoryFormat>) {
TORCH_CHECK(false, "Creation of quantized tensor requires quantized dtype like torch.quint8");
}
diff --git a/aten/src/ATen/native/quantized/cpu/qadd.cpp b/aten/src/ATen/native/quantized/cpu/qadd.cpp
index 2c85ff8..b5065bc 100644
--- a/aten/src/ATen/native/quantized/cpu/qadd.cpp
+++ b/aten/src/ATen/native/quantized/cpu/qadd.cpp
@@ -139,10 +139,13 @@
Tensor qy = at::native::empty_affine_quantized(
qa_contig.sizes(),
- at::device(kCPU).dtype(kQUInt8).memory_format(qa.suggest_memory_format()),
+ kQUInt8,
+ c10::nullopt /* layout */,
+ kCPU,
+ c10::nullopt /* pin_memory */,
scale,
zero_point,
- c10::nullopt);
+ qa.suggest_memory_format());
if (qa_contig.size(0) == 0) {
return qy;
diff --git a/aten/src/ATen/native/quantized/cpu/qchannel_shuffle.cpp b/aten/src/ATen/native/quantized/cpu/qchannel_shuffle.cpp
index f48baa4..c55a6b7 100644
--- a/aten/src/ATen/native/quantized/cpu/qchannel_shuffle.cpp
+++ b/aten/src/ATen/native/quantized/cpu/qchannel_shuffle.cpp
@@ -36,11 +36,13 @@
const Tensor self_nhwc = self.contiguous(MemoryFormat::ChannelsLast);
Tensor qy = at::native::empty_affine_quantized(
self_nhwc.sizes(),
- at::device(kCPU).dtype(kQUInt8).memory_format(MemoryFormat::ChannelsLast),
+ kQUInt8,
+ c10::nullopt /* layout */,
+ kCPU,
+ c10::nullopt /* pin_memory */,
self_nhwc.q_scale(),
self_nhwc.q_zero_point(),
- c10::nullopt
- );
+ MemoryFormat::ChannelsLast);
// Degenerate case of just copying.
if (groups == 1) {
diff --git a/aten/src/ATen/native/quantized/cpu/qconv.cpp b/aten/src/ATen/native/quantized/cpu/qconv.cpp
index effc6bd..c75ecb0 100644
--- a/aten/src/ATen/native/quantized/cpu/qconv.cpp
+++ b/aten/src/ATen/native/quantized/cpu/qconv.cpp
@@ -700,12 +700,13 @@
// Allocate output Tensor and a buffer for QNNPACK to use
at::Tensor output = at::native::empty_affine_quantized(
output_shape,
- at::device(c10::kCPU)
- .dtype(c10::kQUInt8)
- .memory_format(c10::MemoryFormat::ChannelsLast),
+ c10::kQUInt8,
+ c10::nullopt /* layout */,
+ c10::kCPU,
+ c10::nullopt /* pin_memory */,
output_scale,
output_zero_point,
- c10::nullopt);
+ c10::MemoryFormat::ChannelsLast);
pytorch_qnnp_status run_status;
if (transpose()) {
diff --git a/aten/src/ATen/native/sparse/SparseTensor.cpp b/aten/src/ATen/native/sparse/SparseTensor.cpp
index da99e2a..de91b79 100644
--- a/aten/src/ATen/native/sparse/SparseTensor.cpp
+++ b/aten/src/ATen/native/sparse/SparseTensor.cpp
@@ -127,7 +127,14 @@
}
/* Shape init */
-Tensor sparse_coo_tensor(ArrayRef<int64_t> size, const TensorOptions& options) {
+Tensor sparse_coo_tensor(IntArrayRef size,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
return at::_sparse_coo_tensor_with_dims(size.size(), 0, size, options.layout(at::kSparse));
}
@@ -146,7 +153,14 @@
}
}
-Tensor sparse_coo_tensor(const Tensor& indices, const Tensor& values_, const TensorOptions& options) {
+Tensor sparse_coo_tensor(const Tensor& indices, const Tensor& values_,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
Tensor values = expand_values_if_needed(values_);
// arg checking
@@ -235,12 +249,26 @@
}
// NB: Got rid of the sizes == NULL case
-Tensor sparse_coo_tensor(const Tensor& indices, const Tensor& values, ArrayRef<int64_t> size, const TensorOptions& options) {
+Tensor sparse_coo_tensor(const Tensor& indices, const Tensor& values, IntArrayRef size,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
// arg checking
TORCH_CHECK(!options.has_layout() || options.layout() == kSparse, "expected sparse layout, but got layout ", options.layout());
at::native::_validate_sparse_coo_tensor_args(indices, values, size);
- return at::native::_sparse_coo_tensor_unsafe(indices, values, size, options);
+ return at::native::_sparse_coo_tensor_unsafe(
+ indices,
+ values,
+ size,
+ optTypeMetaToScalarType(options.dtype_opt()),
+ options.layout_opt(),
+ options.device_opt(),
+ options.pinned_memory_opt());
}
// NOTE: _sparse_coo_tensor_unsafe() differs from sparse_coo_tensor()
@@ -249,7 +277,14 @@
// are guaranteed to be within bounds or if the caller is going to call
// _validate_sparse_coo_tensor_args before using the tensor.
// NB: Got rid of the size == NULL case
-Tensor _sparse_coo_tensor_unsafe(const Tensor& indices, const Tensor& values_, ArrayRef<int64_t> size, const TensorOptions& options) {
+Tensor _sparse_coo_tensor_unsafe(const Tensor& indices, const Tensor& values_, IntArrayRef size,
+ c10::optional<ScalarType> dtype,
+ c10::optional<Layout> layout,
+ c10::optional<Device> device,
+ c10::optional<bool> pin_memory) {
+ // See [Note: hacky wrapper removal for TensorOptions]
+ TensorOptions options = TensorOptions().dtype(dtype).layout(layout).device(device).pinned_memory(pin_memory);
+
Tensor values = expand_values_if_needed(values_);
int64_t sparse_dim = indices.size(0);
diff --git a/aten/src/ATen/native/sparse/SparseTensorMath.cpp b/aten/src/ATen/native/sparse/SparseTensorMath.cpp
index fb7f0d9..8f83cdc 100644
--- a/aten/src/ATen/native/sparse/SparseTensorMath.cpp
+++ b/aten/src/ATen/native/sparse/SparseTensorMath.cpp
@@ -1121,7 +1121,12 @@
int64_t t_nnz = t._nnz();
int64_t r_nnz = nnz * dim_k + t_nnz;
Tensor newi = at::empty({2, r_nnz}, kLong);
- Tensor newv = native::zeros({r_nnz}, values.options());
+ Tensor newv = native::zeros(
+ {r_nnz},
+ optTypeMetaToScalarType(values.options().dtype_opt()),
+ values.options().layout_opt(),
+ values.options().device_opt(),
+ values.options().pinned_memory_opt());
if (t_nnz != 0) {
Tensor narrowi = newi.narrow(1, 0, t_nnz);
diff --git a/torch/csrc/jit/runtime/register_special_ops.cpp b/torch/csrc/jit/runtime/register_special_ops.cpp
index e06e299..741a3e3 100644
--- a/torch/csrc/jit/runtime/register_special_ops.cpp
+++ b/torch/csrc/jit/runtime/register_special_ops.cpp
@@ -295,7 +295,10 @@
double,
at::native::scalar_tensor(
scalar_val,
- at::device(at::kCPU).dtype(c10::get_default_dtype())))
+ typeMetaToScalarType(c10::get_default_dtype()),
+ c10::nullopt /* layout */,
+ at::kCPU,
+ c10::nullopt /* pin_memory*/))
DEFINE_TORCH_TENSOR_OP(int, int64_t, at::scalar_to_tensor(scalar_val))
DEFINE_TORCH_TENSOR_OP(
bool,
@@ -306,8 +309,10 @@
c10::complex<double>,
at::native::scalar_tensor(
scalar_val,
- at::device(at::kCPU).dtype(
- c10::get_default_complex_dtype())))
+ typeMetaToScalarType(c10::get_default_complex_dtype()),
+ c10::nullopt /* layout */,
+ at::kCPU,
+ c10::nullopt /* pin_memory */))
// reference python implementation: internal_new_from_data in
// tensor_new.cpp
diff --git a/torch/csrc/jit/runtime/static/ops.cpp b/torch/csrc/jit/runtime/static/ops.cpp
index 6b394c6..53ab0dd 100644
--- a/torch/csrc/jit/runtime/static/ops.cpp
+++ b/torch/csrc/jit/runtime/static/ops.cpp
@@ -710,13 +710,23 @@
} else {
dtype = at::native::result_type(in0_t, p_node->Input(1).toScalar());
p_node->Output(0) = at::native::empty_like(
- in0_t, in0_t.options().dtype(dtype), at::MemoryFormat::Preserve);
+ in0_t,
+ dtype,
+ in0_t.options().layout_opt(),
+ in0_t.options().device_opt(),
+ in0_t.options().pinned_memory_opt(),
+ at::MemoryFormat::Preserve);
}
} else {
const auto& in1_t = p_node->Input(1).toTensor();
dtype = at::native::result_type(p_node->Input(0).toScalar(), in1_t);
p_node->Output(0) = at::native::empty_like(
- in1_t, in1_t.options().dtype(dtype), at::MemoryFormat::Preserve);
+ in1_t,
+ dtype,
+ in1_t.options().layout_opt(),
+ in1_t.options().device_opt(),
+ in1_t.options().pinned_memory_opt(),
+ at::MemoryFormat::Preserve);
}
}
auto& out_t = p_node->Output(0).toTensor();
diff --git a/torch/lib/c10d/reducer.cpp b/torch/lib/c10d/reducer.cpp
index a1e653b..bf4261f 100644
--- a/torch/lib/c10d/reducer.cpp
+++ b/torch/lib/c10d/reducer.cpp
@@ -579,8 +579,13 @@
// blocking work between now and the re-zeroing, so the danger is real.
//
// Defensively ensures local_used_maps_tmp is distinct from local_used_maps_[i]
- auto local_used_maps_tmp = at::native::empty_like(local_used_maps_[i],
- local_used_maps_[i].options().pinned_memory(true));
+ auto local_used_maps_tmp = at::native::empty_like(
+ local_used_maps_[i],
+ optTypeMetaToScalarType(
+ local_used_maps_[i].options().dtype_opt()),
+ local_used_maps_[i].options().layout_opt(),
+ local_used_maps_[i].options().device_opt(),
+ true /* pinned_memory */);
// Paranoid asserts here because in some workloads, the pinned allocator behaves in a way we
// don't understand, and may be bugged. See https://github.com/pytorch/pytorch/pull/54474
TORCH_INTERNAL_ASSERT(local_used_maps_tmp.is_pinned());