mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Replace AT_CHECK with TORCH_CHECK [shard 2/10]
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/20427 Reviewed By: jerryzh168 Differential Revision: D15318190 fbshipit-source-id: 15518a683d7b662ef00f255134aaf9dbd183f099
This commit is contained in:
committed by
Facebook Github Bot
parent
71af7c46bb
commit
5b45355431
@ -270,11 +270,11 @@ static void check_shape_forward(const at::Tensor& input,
|
|||||||
"Kernel size: (", kernel_ss.str(), "). Kernel size can't be greater than actual input size");
|
"Kernel size: (", kernel_ss.str(), "). Kernel size can't be greater than actual input size");
|
||||||
}
|
}
|
||||||
} else { // transposed
|
} else { // transposed
|
||||||
AT_CHECK(input.size(1) == weight_sizes[0],
|
TORCH_CHECK(input.size(1) == weight_sizes[0],
|
||||||
"Given transposed=", transposed, ", weight of size ", weight_sizes,
|
"Given transposed=", transposed, ", weight of size ", weight_sizes,
|
||||||
", expected input", input.sizes(), " to have ", weight_sizes[0],
|
", expected input", input.sizes(), " to have ", weight_sizes[0],
|
||||||
" channels, but got ", input.size(1), " channels instead");
|
" channels, but got ", input.size(1), " channels instead");
|
||||||
AT_CHECK(!bias.defined() || (bias.ndimension() == 1 && bias.size(0) == weight_sizes[1] * groups),
|
TORCH_CHECK(!bias.defined() || (bias.ndimension() == 1 && bias.size(0) == weight_sizes[1] * groups),
|
||||||
"Given transposed=", transposed, ", weight of size ", weight_sizes,
|
"Given transposed=", transposed, ", weight of size ", weight_sizes,
|
||||||
", expected bias to be 1-dimensional with ", weight_sizes[1] * groups, " elements",
|
", expected bias to be 1-dimensional with ", weight_sizes[1] * groups, " elements",
|
||||||
", but got bias of size ", bias.sizes(), " instead");
|
", but got bias of size ", bias.sizes(), " instead");
|
||||||
@ -282,14 +282,14 @@ static void check_shape_forward(const at::Tensor& input,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static auto view4d(const at::Tensor& tensor) -> at::Tensor {
|
static auto view4d(const at::Tensor& tensor) -> at::Tensor {
|
||||||
AT_CHECK(tensor.ndimension() == 3,
|
TORCH_CHECK(tensor.ndimension() == 3,
|
||||||
"expected 3D tensor, got tensor with ", tensor.ndimension(),
|
"expected 3D tensor, got tensor with ", tensor.ndimension(),
|
||||||
" dimensions instead");
|
" dimensions instead");
|
||||||
return tensor.unsqueeze(2);
|
return tensor.unsqueeze(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto view3d(const at::Tensor& tensor) -> at::Tensor {
|
static auto view3d(const at::Tensor& tensor) -> at::Tensor {
|
||||||
AT_CHECK(tensor.ndimension() == 4,
|
TORCH_CHECK(tensor.ndimension() == 4,
|
||||||
"expected 4D tensor, got tensor with ", tensor.ndimension(),
|
"expected 4D tensor, got tensor with ", tensor.ndimension(),
|
||||||
" dimensions instead");
|
" dimensions instead");
|
||||||
return tensor.squeeze(2);
|
return tensor.squeeze(2);
|
||||||
@ -378,7 +378,7 @@ at::Tensor _convolution(
|
|||||||
}
|
}
|
||||||
int64_t dim = k - 2;
|
int64_t dim = k - 2;
|
||||||
|
|
||||||
AT_CHECK(dim > 0, "weight should have at least three dimensions");
|
TORCH_CHECK(dim > 0, "weight should have at least three dimensions");
|
||||||
|
|
||||||
ConvParams params;
|
ConvParams params;
|
||||||
params.stride = expand_param_if_needed(stride_, "stride", dim);
|
params.stride = expand_param_if_needed(stride_, "stride", dim);
|
||||||
@ -409,10 +409,10 @@ at::Tensor _convolution(
|
|||||||
auto dilation = params.dilation;
|
auto dilation = params.dilation;
|
||||||
output = at::thnn_conv_depthwise2d(input, weight, kernel_size, bias, stride, padding, dilation);
|
output = at::thnn_conv_depthwise2d(input, weight, kernel_size, bias, stride, padding, dilation);
|
||||||
} else if (params.use_cudnn(input)) {
|
} else if (params.use_cudnn(input)) {
|
||||||
AT_CHECK(input.type() == weight.type(),
|
TORCH_CHECK(input.type() == weight.type(),
|
||||||
"Input type (", input.type().toString(), ") and weight type (", weight.type().toString(),
|
"Input type (", input.type().toString(), ") and weight type (", weight.type().toString(),
|
||||||
") should be the same");
|
") should be the same");
|
||||||
AT_CHECK(!bias.defined() || (input.type() == bias.type()),
|
TORCH_CHECK(!bias.defined() || (input.type() == bias.type()),
|
||||||
"Input type (", input.type().toString(), ") and bias type (", bias.type().toString(),
|
"Input type (", input.type().toString(), ") and bias type (", bias.type().toString(),
|
||||||
") should be the same");
|
") should be the same");
|
||||||
|
|
||||||
@ -426,10 +426,10 @@ at::Tensor _convolution(
|
|||||||
params.padding, params.stride, params.dilation, params.groups, params.benchmark, params.deterministic);
|
params.padding, params.stride, params.dilation, params.groups, params.benchmark, params.deterministic);
|
||||||
}
|
}
|
||||||
} else if (params.use_miopen(input)) {
|
} else if (params.use_miopen(input)) {
|
||||||
AT_CHECK(input.type() == weight.type(),
|
TORCH_CHECK(input.type() == weight.type(),
|
||||||
"Input type (", input.type().toString(), ") and weight type (", weight.type().toString(),
|
"Input type (", input.type().toString(), ") and weight type (", weight.type().toString(),
|
||||||
") should be the same");
|
") should be the same");
|
||||||
AT_CHECK(!bias.defined() || (input.type() == bias.type()),
|
TORCH_CHECK(!bias.defined() || (input.type() == bias.type()),
|
||||||
"Input type (", input.type().toString(), ") and bias type (", bias.type().toString(),
|
"Input type (", input.type().toString(), ") and bias type (", bias.type().toString(),
|
||||||
") should be the same");
|
") should be the same");
|
||||||
|
|
||||||
@ -444,10 +444,10 @@ at::Tensor _convolution(
|
|||||||
}
|
}
|
||||||
} else if (params.use_mkldnn(input)) {
|
} else if (params.use_mkldnn(input)) {
|
||||||
#if AT_MKLDNN_ENABLED()
|
#if AT_MKLDNN_ENABLED()
|
||||||
AT_CHECK(input.type() == weight.type(),
|
TORCH_CHECK(input.type() == weight.type(),
|
||||||
"Input type (", input.type().toString(), ") and weight type (", weight.type().toString(),
|
"Input type (", input.type().toString(), ") and weight type (", weight.type().toString(),
|
||||||
") should be the same");
|
") should be the same");
|
||||||
AT_CHECK(!bias.defined() || (input.type() == bias.type()),
|
TORCH_CHECK(!bias.defined() || (input.type() == bias.type()),
|
||||||
"Input type (", input.type().toString(), ") and bias type (", bias.type().toString(),
|
"Input type (", input.type().toString(), ") and bias type (", bias.type().toString(),
|
||||||
") should be the same");
|
") should be the same");
|
||||||
if (!input_is_mkldnn) {
|
if (!input_is_mkldnn) {
|
||||||
|
@ -6,11 +6,11 @@ namespace at {
|
|||||||
namespace native {
|
namespace native {
|
||||||
|
|
||||||
Tensor conv_tbc(const Tensor& self, const Tensor& weight, const Tensor& bias, int64_t pad) {
|
Tensor conv_tbc(const Tensor& self, const Tensor& weight, const Tensor& bias, int64_t pad) {
|
||||||
AT_CHECK(self.dim() == 3, "Input must have 3 dims: time, batch, "
|
TORCH_CHECK(self.dim() == 3, "Input must have 3 dims: time, batch, "
|
||||||
"in_channel");
|
"in_channel");
|
||||||
AT_CHECK(weight.dim() == 3, "Weight tensor must have 3 dims: kernel_width,"
|
TORCH_CHECK(weight.dim() == 3, "Weight tensor must have 3 dims: kernel_width,"
|
||||||
" in_channels, out_channels.");
|
" in_channels, out_channels.");
|
||||||
AT_CHECK(bias.dim() == 1, "Bias must be 1-D");
|
TORCH_CHECK(bias.dim() == 1, "Bias must be 1-D");
|
||||||
|
|
||||||
auto input_size = self.sizes();
|
auto input_size = self.sizes();
|
||||||
auto weight_size = weight.sizes();
|
auto weight_size = weight.sizes();
|
||||||
@ -27,9 +27,9 @@ Tensor conv_tbc(const Tensor& self, const Tensor& weight, const Tensor& bias, in
|
|||||||
// Input = (time, batch, in_channels)
|
// Input = (time, batch, in_channels)
|
||||||
// Weight = (kernel_width, in_channels, out_channels)
|
// Weight = (kernel_width, in_channels, out_channels)
|
||||||
// Bias = (out_channels)
|
// Bias = (out_channels)
|
||||||
AT_CHECK(inputPlanes == weight_size[1], "Input dim 2 (input channels) "
|
TORCH_CHECK(inputPlanes == weight_size[1], "Input dim 2 (input channels) "
|
||||||
"is not == dim 1 in the weight tensor");
|
"is not == dim 1 in the weight tensor");
|
||||||
AT_CHECK(weight_size[2] == bias.sizes()[0], "Bias size must equal dim 2 in "
|
TORCH_CHECK(weight_size[2] == bias.sizes()[0], "Bias size must equal dim 2 in "
|
||||||
"the weight tensor (output channels).");
|
"the weight tensor (output channels).");
|
||||||
|
|
||||||
// input * weights + bias -> output_features
|
// input * weights + bias -> output_features
|
||||||
|
@ -43,7 +43,7 @@ Tensor& _s_copy__cpu(Tensor& self, const Tensor& src, bool non_blocking) {
|
|||||||
if (self.scalar_type() == src.scalar_type()) {
|
if (self.scalar_type() == src.scalar_type()) {
|
||||||
copy_kernel_same_type(kCPU, self, src);
|
copy_kernel_same_type(kCPU, self, src);
|
||||||
} else {
|
} else {
|
||||||
AT_CHECK(self.numel() == src.numel(), "sizes do not match");
|
TORCH_CHECK(self.numel() == src.numel(), "sizes do not match");
|
||||||
copy_kernel_cast(kCPU, self, src);
|
copy_kernel_cast(kCPU, self, src);
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
|
@ -16,17 +16,17 @@ Tensor cross(const Tensor & input, const Tensor & other, const c10::optional<int
|
|||||||
|
|
||||||
Tensor & cross_out(Tensor & out, const Tensor & input, const Tensor & other, const c10::optional<int64_t> dimension) {
|
Tensor & cross_out(Tensor & out, const Tensor & input, const Tensor & other, const c10::optional<int64_t> dimension) {
|
||||||
auto device_res = input.type().device_type();
|
auto device_res = input.type().device_type();
|
||||||
AT_CHECK(device_res == kCPU || device_res == kCUDA, "cross only supports CPU and CUDA devices, out got: ", device_res);
|
TORCH_CHECK(device_res == kCPU || device_res == kCUDA, "cross only supports CPU and CUDA devices, out got: ", device_res);
|
||||||
auto device1 = input.type().device_type();
|
auto device1 = input.type().device_type();
|
||||||
AT_CHECK(device1 == kCPU || device1 == kCUDA, "cross only supports CPU and CUDA devices, input got: ", device1);
|
TORCH_CHECK(device1 == kCPU || device1 == kCUDA, "cross only supports CPU and CUDA devices, input got: ", device1);
|
||||||
auto device2 = other.type().device_type();
|
auto device2 = other.type().device_type();
|
||||||
AT_CHECK(device2 == kCPU || device2 == kCUDA, "cross only supports CPU and CUDA devices, other got: ", device2);
|
TORCH_CHECK(device2 == kCPU || device2 == kCUDA, "cross only supports CPU and CUDA devices, other got: ", device2);
|
||||||
AT_CHECK(device_res == device1, "out and input must have the same device type. out: ", device_res, " input: ", device1);
|
TORCH_CHECK(device_res == device1, "out and input must have the same device type. out: ", device_res, " input: ", device1);
|
||||||
AT_CHECK(device1 == device2, "input and other must have the same device type. input: ", device1, " other: ", device2);
|
TORCH_CHECK(device1 == device2, "input and other must have the same device type. input: ", device1, " other: ", device2);
|
||||||
AT_CHECK(!out.is_cuda() || out.get_device() == input.get_device(), "device of out (", input.get_device(), ") must match device of input (", other.get_device(), ")");
|
TORCH_CHECK(!out.is_cuda() || out.get_device() == input.get_device(), "device of out (", input.get_device(), ") must match device of input (", other.get_device(), ")");
|
||||||
AT_CHECK(!input.is_cuda() || input.get_device() == other.get_device(), "device of input (", input.get_device(), ") must match device of other (", other.get_device(), ")");
|
TORCH_CHECK(!input.is_cuda() || input.get_device() == other.get_device(), "device of input (", input.get_device(), ") must match device of other (", other.get_device(), ")");
|
||||||
AT_CHECK(input.dim() == other.dim(), "inconsistent tensors dimensions input: ", input.dim(), " other: ", other.dim());
|
TORCH_CHECK(input.dim() == other.dim(), "inconsistent tensors dimensions input: ", input.dim(), " other: ", other.dim());
|
||||||
AT_CHECK(input.sizes() == other.sizes(), "inconsistent tensors sizes input: ", input.sizes(), " other: ", other.sizes());
|
TORCH_CHECK(input.sizes() == other.sizes(), "inconsistent tensors sizes input: ", input.sizes(), " other: ", other.sizes());
|
||||||
|
|
||||||
int64_t dim = -1;
|
int64_t dim = -1;
|
||||||
if(!dimension.has_value()) {
|
if(!dimension.has_value()) {
|
||||||
@ -36,10 +36,10 @@ Tensor & cross_out(Tensor & out, const Tensor & input, const Tensor & other, con
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AT_CHECK(dim >= 0, "no dimension of size 3 in input");
|
TORCH_CHECK(dim >= 0, "no dimension of size 3 in input");
|
||||||
} else {
|
} else {
|
||||||
dim = maybe_wrap_dim(dimension.value(), input.dim());
|
dim = maybe_wrap_dim(dimension.value(), input.dim());
|
||||||
AT_CHECK(input.size(dim) == 3, "dimension ", dimension.value(), " does not have size 3");
|
TORCH_CHECK(input.size(dim) == 3, "dimension ", dimension.value(), " does not have size 3");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out.sizes() != input.sizes()) {
|
if (out.sizes() != input.sizes()) {
|
||||||
|
@ -17,28 +17,28 @@ Tensor pairwise_distance(const Tensor& x1, const Tensor& x2, double p, double ep
|
|||||||
|
|
||||||
// This is to guarantee that the contiguous memory is passed to the backward pass
|
// This is to guarantee that the contiguous memory is passed to the backward pass
|
||||||
Tensor pdist(const Tensor& self, const double p) {
|
Tensor pdist(const Tensor& self, const double p) {
|
||||||
AT_CHECK(self.dim() == 2,
|
TORCH_CHECK(self.dim() == 2,
|
||||||
"pdist only supports 2D tensors, got: ", self.dim(), "D");
|
"pdist only supports 2D tensors, got: ", self.dim(), "D");
|
||||||
AT_CHECK(at::isFloatingType(self.scalar_type()), "pdist only supports floating-point dtypes");
|
TORCH_CHECK(at::isFloatingType(self.scalar_type()), "pdist only supports floating-point dtypes");
|
||||||
AT_CHECK(p >= 0, "pdist only supports non-negative p values");
|
TORCH_CHECK(p >= 0, "pdist only supports non-negative p values");
|
||||||
return at::_pdist_forward(self.contiguous(), p);
|
return at::_pdist_forward(self.contiguous(), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tensor cdist(const Tensor& x1, const Tensor& x2, const double p) {
|
Tensor cdist(const Tensor& x1, const Tensor& x2, const double p) {
|
||||||
AT_CHECK(x1.dim() == 2, "cdist only supports 2D tensors, X1 got: ", x1.dim(), "D");
|
TORCH_CHECK(x1.dim() == 2, "cdist only supports 2D tensors, X1 got: ", x1.dim(), "D");
|
||||||
AT_CHECK(at::isFloatingType(x1.scalar_type()), "cdist only supports floating-point dtypes, X1 got: ", x1.scalar_type());
|
TORCH_CHECK(at::isFloatingType(x1.scalar_type()), "cdist only supports floating-point dtypes, X1 got: ", x1.scalar_type());
|
||||||
auto device1 = x1.type().device_type();
|
auto device1 = x1.type().device_type();
|
||||||
AT_CHECK(device1 == kCPU || device1 == kCUDA, "cdist only supports CPU and CUDA devices, X1 got: ", device1);
|
TORCH_CHECK(device1 == kCPU || device1 == kCUDA, "cdist only supports CPU and CUDA devices, X1 got: ", device1);
|
||||||
AT_CHECK(x2.dim() == 2, "cdist only supports 2D tensors, X2 got: ", x2.dim(), "D");
|
TORCH_CHECK(x2.dim() == 2, "cdist only supports 2D tensors, X2 got: ", x2.dim(), "D");
|
||||||
AT_CHECK(at::isFloatingType(x1.scalar_type()), "cdist only supports floating-point dtypes, X2 got: ", x2.scalar_type());
|
TORCH_CHECK(at::isFloatingType(x1.scalar_type()), "cdist only supports floating-point dtypes, X2 got: ", x2.scalar_type());
|
||||||
auto device2 = x2.type().device_type();
|
auto device2 = x2.type().device_type();
|
||||||
AT_CHECK(device2 == kCPU || device2 == kCUDA, "cdist only supports CPU and CUDA devices, X2 got: ", device2);
|
TORCH_CHECK(device2 == kCPU || device2 == kCUDA, "cdist only supports CPU and CUDA devices, X2 got: ", device2);
|
||||||
AT_CHECK(p >= 0, "cdist only supports non-negative p values");
|
TORCH_CHECK(p >= 0, "cdist only supports non-negative p values");
|
||||||
AT_CHECK(device1 == device2, "X1 and X2 must have the same device type. X1: ", device1, " X2: ", device2);
|
TORCH_CHECK(device1 == device2, "X1 and X2 must have the same device type. X1: ", device1, " X2: ", device2);
|
||||||
AT_CHECK(!x1.is_cuda() || x1.get_device() == x2.get_device(), "device of X1 (", x1.get_device(), ") must match device of X2 (", x2.get_device(), ")");
|
TORCH_CHECK(!x1.is_cuda() || x1.get_device() == x2.get_device(), "device of X1 (", x1.get_device(), ") must match device of X2 (", x2.get_device(), ")");
|
||||||
int64_t c1 = x1.size(-1);
|
int64_t c1 = x1.size(-1);
|
||||||
int64_t c2 = x2.size(-1);
|
int64_t c2 = x2.size(-1);
|
||||||
AT_CHECK(c1 == c2, "X1 and X2 must have the same number of columns. X1: ", c1, " X2: ", c2);
|
TORCH_CHECK(c1 == c2, "X1 and X2 must have the same number of columns. X1: ", c1, " X2: ", c2);
|
||||||
|
|
||||||
int64_t r1 = x1.size(-2);
|
int64_t r1 = x1.size(-2);
|
||||||
int64_t r2 = x2.size(-2);
|
int64_t r2 = x2.size(-2);
|
||||||
@ -54,24 +54,24 @@ Tensor cdist(const Tensor& x1, const Tensor& x2, const double p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tensor _cdist_backward(const Tensor& grad, const Tensor& x1, const Tensor& x2, const double p, const Tensor& cdist) {
|
Tensor _cdist_backward(const Tensor& grad, const Tensor& x1, const Tensor& x2, const double p, const Tensor& cdist) {
|
||||||
AT_CHECK(x1.is_contiguous(), "_cdist_backward requires X1 to be contiguous");
|
TORCH_CHECK(x1.is_contiguous(), "_cdist_backward requires X1 to be contiguous");
|
||||||
AT_CHECK(x2.is_contiguous(), "_cdist_backward requires X2 to be contiguous");
|
TORCH_CHECK(x2.is_contiguous(), "_cdist_backward requires X2 to be contiguous");
|
||||||
AT_CHECK(cdist.is_contiguous(), "_cdist_backward requires dist to be contiguous");
|
TORCH_CHECK(cdist.is_contiguous(), "_cdist_backward requires dist to be contiguous");
|
||||||
int64_t n = x1.size(-2);
|
int64_t n = x1.size(-2);
|
||||||
int64_t m = x1.size(-1);
|
int64_t m = x1.size(-1);
|
||||||
auto device1 = x1.type().device_type();
|
auto device1 = x1.type().device_type();
|
||||||
AT_CHECK(device1 == kCPU || device1 == kCUDA, "_cdist_backward only supports CPU and CUDA devices, X1 got: ", device1);
|
TORCH_CHECK(device1 == kCPU || device1 == kCUDA, "_cdist_backward only supports CPU and CUDA devices, X1 got: ", device1);
|
||||||
auto device2 = x2.type().device_type();
|
auto device2 = x2.type().device_type();
|
||||||
AT_CHECK(device2 == kCPU || device2 == kCUDA, "_cdist_backward only supports CPU and CUDA devices, X2 got: ", device2);
|
TORCH_CHECK(device2 == kCPU || device2 == kCUDA, "_cdist_backward only supports CPU and CUDA devices, X2 got: ", device2);
|
||||||
Tensor grad_x1 = at::empty({n, m}, x1.options());
|
Tensor grad_x1 = at::empty({n, m}, x1.options());
|
||||||
cdist_backward_stub(device1, grad_x1, grad, x1, x2, p, cdist);
|
cdist_backward_stub(device1, grad_x1, grad, x1, x2, p, cdist);
|
||||||
return grad_x1;
|
return grad_x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tensor _pdist_forward(const Tensor& self, const double p) {
|
Tensor _pdist_forward(const Tensor& self, const double p) {
|
||||||
AT_CHECK(self.is_contiguous(), "_pdist_forward requires contiguous input");
|
TORCH_CHECK(self.is_contiguous(), "_pdist_forward requires contiguous input");
|
||||||
auto device = self.type().device_type();
|
auto device = self.type().device_type();
|
||||||
AT_CHECK(device == kCPU || device == kCUDA, "_pdist_forward only supports CPU and CUDA devices, got: ", device);
|
TORCH_CHECK(device == kCPU || device == kCUDA, "_pdist_forward only supports CPU and CUDA devices, got: ", device);
|
||||||
Tensor result = at::empty({0}, self.options());
|
Tensor result = at::empty({0}, self.options());
|
||||||
if (self.size(0) <= 1) {
|
if (self.size(0) <= 1) {
|
||||||
result.resize_({0});
|
result.resize_({0});
|
||||||
@ -89,10 +89,10 @@ Tensor _pdist_forward(const Tensor& self, const double p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tensor _pdist_backward(const Tensor& grad, const Tensor& self, const double p, const Tensor& pdist) {
|
Tensor _pdist_backward(const Tensor& grad, const Tensor& self, const double p, const Tensor& pdist) {
|
||||||
AT_CHECK(self.is_contiguous(), "_pdist_backward requires self to be contiguous");
|
TORCH_CHECK(self.is_contiguous(), "_pdist_backward requires self to be contiguous");
|
||||||
AT_CHECK(pdist.is_contiguous(), "_pdist_backward requires pdist to be contiguous");
|
TORCH_CHECK(pdist.is_contiguous(), "_pdist_backward requires pdist to be contiguous");
|
||||||
auto device = self.type().device_type();
|
auto device = self.type().device_type();
|
||||||
AT_CHECK(device == kCPU || device == kCUDA, "_pdist_backward only supports CPU and CUDA devices, got: ", device);
|
TORCH_CHECK(device == kCPU || device == kCUDA, "_pdist_backward only supports CPU and CUDA devices, got: ", device);
|
||||||
Tensor result = at::empty_like(self);
|
Tensor result = at::empty_like(self);
|
||||||
pdist_backward_stub(device, result, grad, self, p, pdist);
|
pdist_backward_stub(device, result, grad, self, p, pdist);
|
||||||
return result;
|
return result;
|
||||||
|
@ -153,7 +153,7 @@ Tensor& bernoulli_tensor_cpu_(Tensor& self, const Tensor& p_, Generator* gen) {
|
|||||||
DEFINE_DISPATCH(bernoulli_mkl_stub);
|
DEFINE_DISPATCH(bernoulli_mkl_stub);
|
||||||
|
|
||||||
Tensor& bernoulli_scalar_cpu_(Tensor& self, double p, Generator* gen) {
|
Tensor& bernoulli_scalar_cpu_(Tensor& self, double p, Generator* gen) {
|
||||||
AT_CHECK(0 <= p && p <= 1, "bernoulli_ expects p to be in [0, 1], but got p=", p);
|
TORCH_CHECK(0 <= p && p <= 1, "bernoulli_ expects p to be in [0, 1], but got p=", p);
|
||||||
#if AT_MKL_ENABLED()
|
#if AT_MKL_ENABLED()
|
||||||
if (cpuinfo_initialize() && cpuinfo_vendor_intel == cpuinfo_get_processor(0)->core->vendor) {
|
if (cpuinfo_initialize() && cpuinfo_vendor_intel == cpuinfo_get_processor(0)->core->vendor) {
|
||||||
bernoulli_mkl_stub(kCPU, self, p, gen);
|
bernoulli_mkl_stub(kCPU, self, p, gen);
|
||||||
|
@ -10,7 +10,7 @@ using Ctype = typename std::conditional<inplace, Tensor&, Tensor>::type;
|
|||||||
|
|
||||||
Tensor make_feature_noise(const Tensor& input) {
|
Tensor make_feature_noise(const Tensor& input) {
|
||||||
auto input_sizes = input.sizes();
|
auto input_sizes = input.sizes();
|
||||||
AT_CHECK(input.dim() >= 2, "Feature dropout requires at least 2 dimensions in the input");
|
TORCH_CHECK(input.dim() >= 2, "Feature dropout requires at least 2 dimensions in the input");
|
||||||
std::vector<int64_t> sizes;
|
std::vector<int64_t> sizes;
|
||||||
sizes.reserve(input.dim());
|
sizes.reserve(input.dim());
|
||||||
sizes.push_back(input_sizes[0]);
|
sizes.push_back(input_sizes[0]);
|
||||||
@ -40,7 +40,7 @@ Tensor multiply(const Tensor& input, const Tensor& noise) {
|
|||||||
|
|
||||||
template<bool feature_dropout, bool alpha_dropout, bool inplace, typename T>
|
template<bool feature_dropout, bool alpha_dropout, bool inplace, typename T>
|
||||||
Ctype<inplace> _dropout_impl(T& input, double p, bool train) {
|
Ctype<inplace> _dropout_impl(T& input, double p, bool train) {
|
||||||
AT_CHECK(p >= 0 && p <= 1, "dropout probability has to be between 0 and 1, but got ", p);
|
TORCH_CHECK(p >= 0 && p <= 1, "dropout probability has to be between 0 and 1, but got ", p);
|
||||||
if (p == 0 || !train) {
|
if (p == 0 || !train) {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
@ -339,7 +339,7 @@ _embedding_bag_cpu(const Tensor &weight, const Tensor &indices,
|
|||||||
checkScalarTypes("embedding_bag", weight_arg, {kFloat, kDouble});
|
checkScalarTypes("embedding_bag", weight_arg, {kFloat, kDouble});
|
||||||
|
|
||||||
if (per_sample_weights.defined()) {
|
if (per_sample_weights.defined()) {
|
||||||
AT_CHECK(mode == MODE_SUM,
|
TORCH_CHECK(mode == MODE_SUM,
|
||||||
"embedding_bag: per_sample_weights only supported with mode='sum'");
|
"embedding_bag: per_sample_weights only supported with mode='sum'");
|
||||||
auto per_input_weights_arg = TensorArg(
|
auto per_input_weights_arg = TensorArg(
|
||||||
per_sample_weights,"per_sample_weights", 1);
|
per_sample_weights,"per_sample_weights", 1);
|
||||||
@ -624,7 +624,7 @@ Tensor _embedding_bag_per_sample_weights_backward_cpu_template(
|
|||||||
const Tensor& offsets,
|
const Tensor& offsets,
|
||||||
const Tensor& offset2bag,
|
const Tensor& offset2bag,
|
||||||
int64_t mode) {
|
int64_t mode) {
|
||||||
AT_CHECK(
|
TORCH_CHECK(
|
||||||
mode == MODE_SUM,
|
mode == MODE_SUM,
|
||||||
"embedding_bag_backward: per_sample_weights only supported for mode='sum'");
|
"embedding_bag_backward: per_sample_weights only supported for mode='sum'");
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ void fractional_max_pool2d_out_cpu_template(
|
|||||||
auto input = input_.contiguous();
|
auto input = input_.contiguous();
|
||||||
|
|
||||||
int ndims = input.ndimension();
|
int ndims = input.ndimension();
|
||||||
AT_CHECK(input.numel() > 0 && (ndims == 3 || ndims == 4),
|
TORCH_CHECK(input.numel() > 0 && (ndims == 3 || ndims == 4),
|
||||||
"non-empty 3D or 4D (batch mode) tensor expected for input, but got: ",
|
"non-empty 3D or 4D (batch mode) tensor expected for input, but got: ",
|
||||||
ndims);
|
ndims);
|
||||||
|
|
||||||
@ -160,10 +160,10 @@ void fractional_max_pool2d_out_cpu_template(
|
|||||||
int inputH = input.size(heightDim);
|
int inputH = input.size(heightDim);
|
||||||
int inputW = input.size(widthDim);
|
int inputW = input.size(widthDim);
|
||||||
|
|
||||||
AT_CHECK(outputH + poolSizeH - 1 <= inputH,
|
TORCH_CHECK(outputH + poolSizeH - 1 <= inputH,
|
||||||
"fractional_max_pool2d(): pool height ", poolSizeH,
|
"fractional_max_pool2d(): pool height ", poolSizeH,
|
||||||
" too large relative to input height ", inputH);
|
" too large relative to input height ", inputH);
|
||||||
AT_CHECK(outputW + poolSizeW - 1 <= inputW,
|
TORCH_CHECK(outputW + poolSizeW - 1 <= inputW,
|
||||||
"fractional_max_pool2d(): pool width ", poolSizeW,
|
"fractional_max_pool2d(): pool width ", poolSizeW,
|
||||||
" too large relative to input width ", inputW);
|
" too large relative to input width ", inputW);
|
||||||
|
|
||||||
@ -284,9 +284,9 @@ Tensor& fractional_max_pool2d_backward_out_cpu_template(
|
|||||||
/* get contiguous gradOutput */
|
/* get contiguous gradOutput */
|
||||||
auto gradOutput = gradOutput_.contiguous();
|
auto gradOutput = gradOutput_.contiguous();
|
||||||
|
|
||||||
AT_CHECK(outputW == gradOutput.size(widthDim),
|
TORCH_CHECK(outputW == gradOutput.size(widthDim),
|
||||||
"fractional_max_pool2d_backward(): gradOutput width unexpected");
|
"fractional_max_pool2d_backward(): gradOutput width unexpected");
|
||||||
AT_CHECK(outputH == gradOutput.size(heightDim),
|
TORCH_CHECK(outputH == gradOutput.size(heightDim),
|
||||||
"fractional_max_pool2d_backward(): gradOutput height unexpected");
|
"fractional_max_pool2d_backward(): gradOutput height unexpected");
|
||||||
|
|
||||||
/* resize */
|
/* resize */
|
||||||
|
@ -161,7 +161,7 @@ void fractional_max_pool3d_out_cpu_template(
|
|||||||
int64_t widthDim = 3;
|
int64_t widthDim = 3;
|
||||||
|
|
||||||
int64_t ndims = input_.ndimension();
|
int64_t ndims = input_.ndimension();
|
||||||
AT_CHECK(input_.numel() != 0 && (ndims == 4 || ndims == 5),
|
TORCH_CHECK(input_.numel() != 0 && (ndims == 4 || ndims == 5),
|
||||||
"fractional_max_pool3d_out(): non-empty 4D or 5D (batch mode) tensor ",
|
"fractional_max_pool3d_out(): non-empty 4D or 5D (batch mode) tensor ",
|
||||||
" expected for input, but got: ", ndims);
|
" expected for input, but got: ", ndims);
|
||||||
|
|
||||||
@ -179,13 +179,13 @@ void fractional_max_pool3d_out_cpu_template(
|
|||||||
int64_t inputH = input_.size(heightDim);
|
int64_t inputH = input_.size(heightDim);
|
||||||
int64_t inputW = input_.size(widthDim);
|
int64_t inputW = input_.size(widthDim);
|
||||||
|
|
||||||
AT_CHECK(outputT + poolSizeT - 1 < inputT,
|
TORCH_CHECK(outputT + poolSizeT - 1 < inputT,
|
||||||
"fractional_max_pool3d_out(): pool time ", poolSizeT,
|
"fractional_max_pool3d_out(): pool time ", poolSizeT,
|
||||||
" too large relative to input time ", inputT);
|
" too large relative to input time ", inputT);
|
||||||
AT_CHECK(outputW + poolSizeW - 1 < inputW,
|
TORCH_CHECK(outputW + poolSizeW - 1 < inputW,
|
||||||
"fractional_max_pool3d_out(): pool width ", poolSizeW,
|
"fractional_max_pool3d_out(): pool width ", poolSizeW,
|
||||||
" too large relative to input width ", inputW);
|
" too large relative to input width ", inputW);
|
||||||
AT_CHECK(outputH + poolSizeH - 1 < inputH,
|
TORCH_CHECK(outputH + poolSizeH - 1 < inputH,
|
||||||
"fractional_max_pool3d_out(): pool height ", poolSizeH,
|
"fractional_max_pool3d_out(): pool height ", poolSizeH,
|
||||||
" too large relative to input height ", inputH);
|
" too large relative to input height ", inputH);
|
||||||
|
|
||||||
@ -317,12 +317,12 @@ void fractional_max_pool3d_backward_out_cpu_template(
|
|||||||
int64_t inputH = input.size(heightDim);
|
int64_t inputH = input.size(heightDim);
|
||||||
int64_t inputW = input.size(widthDim);
|
int64_t inputW = input.size(widthDim);
|
||||||
|
|
||||||
AT_CHECK(outputT == gradOutput_.size(timeDim),
|
TORCH_CHECK(outputT == gradOutput_.size(timeDim),
|
||||||
"fractional_max_pool3d_backward_out(): gradOutput time unexpected");
|
"fractional_max_pool3d_backward_out(): gradOutput time unexpected");
|
||||||
AT_CHECK(outputH == gradOutput_.size(heightDim),
|
TORCH_CHECK(outputH == gradOutput_.size(heightDim),
|
||||||
"fractional_max_pool3d_backward_out(): ",
|
"fractional_max_pool3d_backward_out(): ",
|
||||||
"gradOutput height unexpected");
|
"gradOutput height unexpected");
|
||||||
AT_CHECK(outputW == gradOutput_.size(widthDim),
|
TORCH_CHECK(outputW == gradOutput_.size(widthDim),
|
||||||
"fractional_max_pool3d_backward_out(): gradOutput width unexpected");
|
"fractional_max_pool3d_backward_out(): gradOutput width unexpected");
|
||||||
|
|
||||||
/* get contiguous gradOutput */
|
/* get contiguous gradOutput */
|
||||||
|
@ -559,39 +559,39 @@ grid_sampler_3d_backward_cpu(const Tensor& grad_output, const Tensor& input, con
|
|||||||
|
|
||||||
Tensor grid_sampler(const Tensor& input, const Tensor& grid,
|
Tensor grid_sampler(const Tensor& input, const Tensor& grid,
|
||||||
int64_t interpolation_mode, int64_t padding_mode) {
|
int64_t interpolation_mode, int64_t padding_mode) {
|
||||||
AT_CHECK(
|
TORCH_CHECK(
|
||||||
input.defined() && grid.defined(),
|
input.defined() && grid.defined(),
|
||||||
"grid_sampler(): expected input and grid to not be undefined, but input "
|
"grid_sampler(): expected input and grid to not be undefined, but input "
|
||||||
"is ", input, " and grid is ", grid);
|
"is ", input, " and grid is ", grid);
|
||||||
auto input_opt = input.options();
|
auto input_opt = input.options();
|
||||||
auto grid_opt = grid.options();
|
auto grid_opt = grid.options();
|
||||||
AT_CHECK(
|
TORCH_CHECK(
|
||||||
input_opt.device() == grid_opt.device(),
|
input_opt.device() == grid_opt.device(),
|
||||||
"grid_sampler(): expected input and grid to be on same device, but input "
|
"grid_sampler(): expected input and grid to be on same device, but input "
|
||||||
"is on ", input_opt.device(), " and grid is on ", grid_opt.device());
|
"is on ", input_opt.device(), " and grid is on ", grid_opt.device());
|
||||||
AT_CHECK(
|
TORCH_CHECK(
|
||||||
input_opt.dtype() == grid_opt.dtype(),
|
input_opt.dtype() == grid_opt.dtype(),
|
||||||
"grid_sampler(): expected input and grid to have same dtype, but input "
|
"grid_sampler(): expected input and grid to have same dtype, but input "
|
||||||
"has ", input_opt.dtype(), " and grid has ", grid_opt.dtype());
|
"has ", input_opt.dtype(), " and grid has ", grid_opt.dtype());
|
||||||
AT_CHECK(
|
TORCH_CHECK(
|
||||||
input_opt.layout() == kStrided && grid_opt.layout() == kStrided,
|
input_opt.layout() == kStrided && grid_opt.layout() == kStrided,
|
||||||
"grid_sampler(): expected input and grid to have torch.strided layout, but "
|
"grid_sampler(): expected input and grid to have torch.strided layout, but "
|
||||||
"input has ", input_opt.layout(), " and grid has ", grid_opt.layout());
|
"input has ", input_opt.layout(), " and grid has ", grid_opt.layout());
|
||||||
AT_CHECK(
|
TORCH_CHECK(
|
||||||
(input.dim() == 4 || input.dim() == 5) && input.dim() == grid.dim(),
|
(input.dim() == 4 || input.dim() == 5) && input.dim() == grid.dim(),
|
||||||
"grid_sampler(): expected 4D or 5D input and grid with same number of "
|
"grid_sampler(): expected 4D or 5D input and grid with same number of "
|
||||||
"dimensions, but got input with sizes ", input.sizes(),
|
"dimensions, but got input with sizes ", input.sizes(),
|
||||||
" and grid with sizes ", grid.sizes());
|
" and grid with sizes ", grid.sizes());
|
||||||
AT_CHECK(
|
TORCH_CHECK(
|
||||||
input.size(0) == grid.size(0),
|
input.size(0) == grid.size(0),
|
||||||
"grid_sampler(): expected grid and input to have same batch size, but got "
|
"grid_sampler(): expected grid and input to have same batch size, but got "
|
||||||
"input with sizes ", input.sizes(), " and grid with sizes ", grid.sizes());
|
"input with sizes ", input.sizes(), " and grid with sizes ", grid.sizes());
|
||||||
AT_CHECK(
|
TORCH_CHECK(
|
||||||
grid.size(-1) == input.dim() - 2,
|
grid.size(-1) == input.dim() - 2,
|
||||||
"grid_sampler(): expected grid to have size ", input.dim() - 2, " in last "
|
"grid_sampler(): expected grid to have size ", input.dim() - 2, " in last "
|
||||||
"dimension, but got grid with sizes ", grid.sizes());
|
"dimension, but got grid with sizes ", grid.sizes());
|
||||||
for (int64_t i = 2; i < input.dim(); i++) {
|
for (int64_t i = 2; i < input.dim(); i++) {
|
||||||
AT_CHECK(input.size(i) > 0,
|
TORCH_CHECK(input.size(i) > 0,
|
||||||
"grid_sampler(): expected input to have non-empty spatial dimensions, "
|
"grid_sampler(): expected input to have non-empty spatial dimensions, "
|
||||||
"but input has sizes ", input.sizes(), " with dimension ", i, " being "
|
"but input has sizes ", input.sizes(), " with dimension ", i, " being "
|
||||||
"empty");
|
"empty");
|
||||||
|
@ -32,7 +32,7 @@ namespace native{
|
|||||||
|
|
||||||
Tensor cartesian_prod(TensorList tensors) {
|
Tensor cartesian_prod(TensorList tensors) {
|
||||||
for(const Tensor &t : tensors) {
|
for(const Tensor &t : tensors) {
|
||||||
AT_CHECK(t.dim() == 1, "Expect a 1D vector, but got shape ", t.sizes());
|
TORCH_CHECK(t.dim() == 1, "Expect a 1D vector, but got shape ", t.sizes());
|
||||||
}
|
}
|
||||||
if (tensors.size() == 1) {
|
if (tensors.size() == 1) {
|
||||||
return tensors[0];
|
return tensors[0];
|
||||||
@ -45,8 +45,8 @@ Tensor cartesian_prod(TensorList tensors) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tensor combinations(const Tensor& self, int64_t r, bool with_replacement) {
|
Tensor combinations(const Tensor& self, int64_t r, bool with_replacement) {
|
||||||
AT_CHECK(self.dim() == 1, "Expect a 1D vector, but got shape ", self.sizes());
|
TORCH_CHECK(self.dim() == 1, "Expect a 1D vector, but got shape ", self.sizes());
|
||||||
AT_CHECK(r > 0, "Expect a positive number, but got ", r);
|
TORCH_CHECK(r > 0, "Expect a positive number, but got ", r);
|
||||||
int64_t num_elements = self.numel();
|
int64_t num_elements = self.numel();
|
||||||
std::vector<Tensor> grids = at::meshgrid(std::vector<Tensor>(r, self));
|
std::vector<Tensor> grids = at::meshgrid(std::vector<Tensor>(r, self));
|
||||||
Tensor mask = _triu_mask(num_elements, r, with_replacement, self.options());
|
Tensor mask = _triu_mask(num_elements, r, with_replacement, self.options());
|
||||||
|
@ -38,7 +38,7 @@ namespace native {
|
|||||||
Tensor& lerp_cpu_tensor_out(Tensor& result, const Tensor& self,
|
Tensor& lerp_cpu_tensor_out(Tensor& result, const Tensor& self,
|
||||||
const Tensor& end, const Tensor& weight) {
|
const Tensor& end, const Tensor& weight) {
|
||||||
Tensor b_self, b_end, b_weight;
|
Tensor b_self, b_end, b_weight;
|
||||||
AT_CHECK(weight.dim() <= std::max(self.dim(), end.dim()),
|
TORCH_CHECK(weight.dim() <= std::max(self.dim(), end.dim()),
|
||||||
"weight should be of dimension max(self.dim(), end.dim()) or lesser");
|
"weight should be of dimension max(self.dim(), end.dim()) or lesser");
|
||||||
std::tie(b_self, b_end, b_weight) = expand_outplace(self, end, weight, "lerp_out_cpu");
|
std::tie(b_self, b_end, b_weight) = expand_outplace(self, end, weight, "lerp_out_cpu");
|
||||||
result.resize_as_(b_self);
|
result.resize_as_(b_self);
|
||||||
@ -62,10 +62,10 @@ Tensor& lerp_cpu_scalar_out(Tensor& result, const Tensor& self,
|
|||||||
Tensor& lerp_cpu_tensor_(Tensor& self, const Tensor& end, const Tensor& weight) {
|
Tensor& lerp_cpu_tensor_(Tensor& self, const Tensor& end, const Tensor& weight) {
|
||||||
Tensor b_self, b_end, b_weight;
|
Tensor b_self, b_end, b_weight;
|
||||||
std::tie(b_self, b_end, b_weight) = expand_outplace(self, end, weight, "lerp__cpu");
|
std::tie(b_self, b_end, b_weight) = expand_outplace(self, end, weight, "lerp__cpu");
|
||||||
AT_CHECK(b_self.sizes() == self.sizes(),
|
TORCH_CHECK(b_self.sizes() == self.sizes(),
|
||||||
"output with shape ", self.sizes(),
|
"output with shape ", self.sizes(),
|
||||||
" doesn't match the broadcast shape ", b_self.sizes());
|
" doesn't match the broadcast shape ", b_self.sizes());
|
||||||
AT_CHECK(weight.dim() <= std::max(self.dim(), end.dim()),
|
TORCH_CHECK(weight.dim() <= std::max(self.dim(), end.dim()),
|
||||||
"weight should be of dimension max(self.dim(), end.dim()) or lesser");
|
"weight should be of dimension max(self.dim(), end.dim()) or lesser");
|
||||||
AT_DISPATCH_FLOATING_TYPES(self.scalar_type(), "lerp__cpu", [&]{
|
AT_DISPATCH_FLOATING_TYPES(self.scalar_type(), "lerp__cpu", [&]{
|
||||||
lerp_cpu<scalar_t>(self, b_self, b_end, b_weight);
|
lerp_cpu<scalar_t>(self, b_self, b_end, b_weight);
|
||||||
@ -76,7 +76,7 @@ Tensor& lerp_cpu_tensor_(Tensor& self, const Tensor& end, const Tensor& weight)
|
|||||||
Tensor& lerp_cpu_scalar_(Tensor& self, const Tensor& end, Scalar weight) {
|
Tensor& lerp_cpu_scalar_(Tensor& self, const Tensor& end, Scalar weight) {
|
||||||
Tensor b_self, b_end;
|
Tensor b_self, b_end;
|
||||||
std::tie(b_self, b_end) = expand_outplace(self, end, "lerp__cpu");
|
std::tie(b_self, b_end) = expand_outplace(self, end, "lerp__cpu");
|
||||||
AT_CHECK(b_self.sizes() == self.sizes(),
|
TORCH_CHECK(b_self.sizes() == self.sizes(),
|
||||||
"output with shape ", self.sizes(),
|
"output with shape ", self.sizes(),
|
||||||
" doesn't match the broadcast shape ", b_self.sizes());
|
" doesn't match the broadcast shape ", b_self.sizes());
|
||||||
AT_DISPATCH_FLOATING_TYPES(self.scalar_type(), "lerp__cpu", [&]{
|
AT_DISPATCH_FLOATING_TYPES(self.scalar_type(), "lerp__cpu", [&]{
|
||||||
@ -87,7 +87,7 @@ Tensor& lerp_cpu_scalar_(Tensor& self, const Tensor& end, Scalar weight) {
|
|||||||
|
|
||||||
Tensor lerp_cpu_tensor(const Tensor& self, const Tensor& end, const Tensor& weight) {
|
Tensor lerp_cpu_tensor(const Tensor& self, const Tensor& end, const Tensor& weight) {
|
||||||
Tensor b_self, b_end, b_weight;
|
Tensor b_self, b_end, b_weight;
|
||||||
AT_CHECK(weight.dim() <= std::max(self.dim(), end.dim()),
|
TORCH_CHECK(weight.dim() <= std::max(self.dim(), end.dim()),
|
||||||
"weight should be of dimension max(self.dim(), end.dim()) or lesser");
|
"weight should be of dimension max(self.dim(), end.dim()) or lesser");
|
||||||
std::tie(b_self, b_end, b_weight) = expand_outplace(self, end, weight, "lerp_cpu");
|
std::tie(b_self, b_end, b_weight) = expand_outplace(self, end, weight, "lerp_cpu");
|
||||||
Tensor result = at::empty_like(b_self);
|
Tensor result = at::empty_like(b_self);
|
||||||
|
@ -33,7 +33,7 @@ Tensor linear(const Tensor& input, const Tensor& weight, const Tensor& bias) {
|
|||||||
static Tensor sumproduct_pair(const Tensor& left_, const Tensor& right_, IntArrayRef sum_dims_, bool keepdim) {
|
static Tensor sumproduct_pair(const Tensor& left_, const Tensor& right_, IntArrayRef sum_dims_, bool keepdim) {
|
||||||
// assumes that tensors have been pre-unsqueezed (so that all dimensions match - after broadcasting)
|
// assumes that tensors have been pre-unsqueezed (so that all dimensions match - after broadcasting)
|
||||||
// but makes no other assumptions on the order of dimensions
|
// but makes no other assumptions on the order of dimensions
|
||||||
AT_CHECK(left_.dim()==right_.dim(), "number of dimensions must match");
|
TORCH_CHECK(left_.dim()==right_.dim(), "number of dimensions must match");
|
||||||
if (sum_dims_.size() == 0)
|
if (sum_dims_.size() == 0)
|
||||||
return at::mul(left_, right_);
|
return at::mul(left_, right_);
|
||||||
int64_t dim = left_.dim();
|
int64_t dim = left_.dim();
|
||||||
@ -50,7 +50,7 @@ static Tensor sumproduct_pair(const Tensor& left_, const Tensor& right_, IntArra
|
|||||||
auto sr = right.size(i)>1;
|
auto sr = right.size(i)>1;
|
||||||
if (sum_dims[i]) { // first dimensions that will be summed over after multiplication
|
if (sum_dims[i]) { // first dimensions that will be summed over after multiplication
|
||||||
if (sl && sr) { // dimensions nontrivially in both left and right must be of the same size
|
if (sl && sr) { // dimensions nontrivially in both left and right must be of the same size
|
||||||
AT_CHECK(left.size(i)==right.size(i), "non-broadcast dimensions must match");
|
TORCH_CHECK(left.size(i)==right.size(i), "non-broadcast dimensions must match");
|
||||||
sum_size *= left.size(i);
|
sum_size *= left.size(i);
|
||||||
} else if (sl) { // if it is only in one of left and right, we can sum right away
|
} else if (sl) { // if it is only in one of left and right, we can sum right away
|
||||||
left = left.sum(i, true);
|
left = left.sum(i, true);
|
||||||
@ -59,7 +59,7 @@ static Tensor sumproduct_pair(const Tensor& left_, const Tensor& right_, IntArra
|
|||||||
}
|
}
|
||||||
} else if (sl && sr) { // now deal with dimensions dimensions that will be in the output
|
} else if (sl && sr) { // now deal with dimensions dimensions that will be in the output
|
||||||
// dimensions nontrivially in both left and right must be of the same size
|
// dimensions nontrivially in both left and right must be of the same size
|
||||||
AT_CHECK(left.size(i)==right.size(i), "non-broadcast dimensions must match");
|
TORCH_CHECK(left.size(i)==right.size(i), "non-broadcast dimensions must match");
|
||||||
lro.push_back(i);
|
lro.push_back(i);
|
||||||
lro_size *= left.size(i);
|
lro_size *= left.size(i);
|
||||||
} else if (sl) { // keep track of dimensions appearing only once
|
} else if (sl) { // keep track of dimensions appearing only once
|
||||||
@ -168,7 +168,7 @@ Tensor einsum(std::string eqn, TensorList tensors) {
|
|||||||
int64_t num_total_idxes = 0;
|
int64_t num_total_idxes = 0;
|
||||||
while (! eqn_stream.eof()) {
|
while (! eqn_stream.eof()) {
|
||||||
std::getline(eqn_stream, term, ','); // term = string with indices of current term
|
std::getline(eqn_stream, term, ','); // term = string with indices of current term
|
||||||
AT_CHECK((int64_t) tensors.size()>operand, "more operands in equation than tensors"); // we cannot have a longer equation than operands. We need to check here before we use the dimension
|
TORCH_CHECK((int64_t) tensors.size()>operand, "more operands in equation than tensors"); // we cannot have a longer equation than operands. We need to check here before we use the dimension
|
||||||
|
|
||||||
int64_t ell_char_count = 0; // handling of ellipsis '...' is a bit tedious, we count the '.'
|
int64_t ell_char_count = 0; // handling of ellipsis '...' is a bit tedious, we count the '.'
|
||||||
// if there is an ellipsis, the number of dimensions it represents must be total dim - letter dimensions
|
// if there is an ellipsis, the number of dimensions it represents must be total dim - letter dimensions
|
||||||
@ -178,7 +178,7 @@ Tensor einsum(std::string eqn, TensorList tensors) {
|
|||||||
for (auto &c : term) { // c = character with a single letter or '.'
|
for (auto &c : term) { // c = character with a single letter or '.'
|
||||||
if (c == '.') {
|
if (c == '.') {
|
||||||
ell_char_count++;
|
ell_char_count++;
|
||||||
AT_CHECK(ell_char_count <= 3, "can only have '.' in one ellispis '...' in term ", operand, " of the equation");
|
TORCH_CHECK(ell_char_count <= 3, "can only have '.' in one ellispis '...' in term ", operand, " of the equation");
|
||||||
if (ell_char_count == 3) { // this completes the ellipsis
|
if (ell_char_count == 3) { // this completes the ellipsis
|
||||||
if (num_ell_idxes == -1) { // if we have not seen an ellipsis before, keep track of indices and size
|
if (num_ell_idxes == -1) { // if we have not seen an ellipsis before, keep track of indices and size
|
||||||
first_ell_idx = num_total_idxes;
|
first_ell_idx = num_total_idxes;
|
||||||
@ -186,7 +186,7 @@ Tensor einsum(std::string eqn, TensorList tensors) {
|
|||||||
num_total_idxes += num_ell_idxes;
|
num_total_idxes += num_ell_idxes;
|
||||||
}
|
}
|
||||||
else { // we have seen an ellipsis before, so we check compatibility
|
else { // we have seen an ellipsis before, so we check compatibility
|
||||||
AT_CHECK(candidate_num_ell_idxes == num_ell_idxes,
|
TORCH_CHECK(candidate_num_ell_idxes == num_ell_idxes,
|
||||||
"ellipsis must represent ", num_ell_idxes, " dimensions in all terms");
|
"ellipsis must represent ", num_ell_idxes, " dimensions in all terms");
|
||||||
}
|
}
|
||||||
for (int64_t i = 0; i < num_ell_idxes; ++i) { // map ellipsis dimensions in operand to indices
|
for (int64_t i = 0; i < num_ell_idxes; ++i) { // map ellipsis dimensions in operand to indices
|
||||||
@ -196,8 +196,8 @@ Tensor einsum(std::string eqn, TensorList tensors) {
|
|||||||
dims_in_term += num_ell_idxes; // keep track of dimensions
|
dims_in_term += num_ell_idxes; // keep track of dimensions
|
||||||
}
|
}
|
||||||
} else { // a letter (hopefully)
|
} else { // a letter (hopefully)
|
||||||
AT_CHECK((ell_char_count == 0) || (ell_char_count == 3), "'.' must only occur in ellipsis, operand ", operand);
|
TORCH_CHECK((ell_char_count == 0) || (ell_char_count == 3), "'.' must only occur in ellipsis, operand ", operand);
|
||||||
AT_CHECK(('a' <= c) && (c <= 'z'), "only lowercase letters a-z allowed as indices");
|
TORCH_CHECK(('a' <= c) && (c <= 'z'), "only lowercase letters a-z allowed as indices");
|
||||||
int64_t letter_num = c-'a'; // letter_num = position in letter_mapping
|
int64_t letter_num = c-'a'; // letter_num = position in letter_mapping
|
||||||
if (letter_mapping[letter_num] == -1) { // new letter, add internal index and mapping
|
if (letter_mapping[letter_num] == -1) { // new letter, add internal index and mapping
|
||||||
letter_mapping[letter_num] = num_total_idxes;
|
letter_mapping[letter_num] = num_total_idxes;
|
||||||
@ -211,12 +211,12 @@ Tensor einsum(std::string eqn, TensorList tensors) {
|
|||||||
dims_in_term++;
|
dims_in_term++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AT_CHECK(dims_in_term == tensors[operand].dim(), "dimension mismatch for operand ", operand, ": equation ", dims_in_term, " tensor ", tensors[operand].dim());
|
TORCH_CHECK(dims_in_term == tensors[operand].dim(), "dimension mismatch for operand ", operand, ": equation ", dims_in_term, " tensor ", tensors[operand].dim());
|
||||||
input_op_idxes.push_back(std::move(current_op_idxes));
|
input_op_idxes.push_back(std::move(current_op_idxes));
|
||||||
operand++;
|
operand++;
|
||||||
}
|
}
|
||||||
// in the check below, we need ==, but > is captured above, so the error message can be specific that it is <.
|
// in the check below, we need ==, but > is captured above, so the error message can be specific that it is <.
|
||||||
AT_CHECK((int64_t) tensors.size()==operand, "more tensors than operands in equation");
|
TORCH_CHECK((int64_t) tensors.size()==operand, "more tensors than operands in equation");
|
||||||
|
|
||||||
// the following parses or infers output (right hand side)
|
// the following parses or infers output (right hand side)
|
||||||
// it also assigns the idxes_to_preprocessed_dims (index -> dimension in preprocessed / output tensors)
|
// it also assigns the idxes_to_preprocessed_dims (index -> dimension in preprocessed / output tensors)
|
||||||
@ -228,19 +228,19 @@ Tensor einsum(std::string eqn, TensorList tensors) {
|
|||||||
for (auto &c : eqn.substr(pos+2)) {
|
for (auto &c : eqn.substr(pos+2)) {
|
||||||
if (c == '.') { // '.' as part of ellipsis
|
if (c == '.') { // '.' as part of ellipsis
|
||||||
ell_char_count++;
|
ell_char_count++;
|
||||||
AT_CHECK(ell_char_count <= 3, "can only have '.' in one ellispis '...' in right hand side of the equation");
|
TORCH_CHECK(ell_char_count <= 3, "can only have '.' in one ellispis '...' in right hand side of the equation");
|
||||||
if (ell_char_count == 3) { // ellipsis complete
|
if (ell_char_count == 3) { // ellipsis complete
|
||||||
AT_CHECK(num_ell_idxes >= 0, "ellipsis '...' may only appear in right hand side if it does in left hand side");
|
TORCH_CHECK(num_ell_idxes >= 0, "ellipsis '...' may only appear in right hand side if it does in left hand side");
|
||||||
for (int64_t i = 0; i < num_ell_idxes; ++i) {
|
for (int64_t i = 0; i < num_ell_idxes; ++i) {
|
||||||
idxes_to_preprocessed_dims[first_ell_idx + i] = num_output_dims;
|
idxes_to_preprocessed_dims[first_ell_idx + i] = num_output_dims;
|
||||||
num_output_dims++;
|
num_output_dims++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (! isspace(c)) { // letter (hopefully)
|
} else if (! isspace(c)) { // letter (hopefully)
|
||||||
AT_CHECK((ell_char_count == 0) || (ell_char_count == 3), "'.' must only occur in ellipsis in the right hand side");
|
TORCH_CHECK((ell_char_count == 0) || (ell_char_count == 3), "'.' must only occur in ellipsis in the right hand side");
|
||||||
AT_CHECK(('a' <= c) && (c <= 'z'), "only lowercase letters a-z allowed as indices");
|
TORCH_CHECK(('a' <= c) && (c <= 'z'), "only lowercase letters a-z allowed as indices");
|
||||||
int64_t letter_num = c-'a';
|
int64_t letter_num = c-'a';
|
||||||
AT_CHECK(idxes_to_preprocessed_dims[letter_mapping[letter_num]] == -1, "index ", c, "occurs twice in output");
|
TORCH_CHECK(idxes_to_preprocessed_dims[letter_mapping[letter_num]] == -1, "index ", c, "occurs twice in output");
|
||||||
idxes_to_preprocessed_dims[letter_mapping[letter_num]] = num_output_dims;
|
idxes_to_preprocessed_dims[letter_mapping[letter_num]] = num_output_dims;
|
||||||
num_output_dims++;
|
num_output_dims++;
|
||||||
}
|
}
|
||||||
@ -293,11 +293,11 @@ Tensor einsum(std::string eqn, TensorList tensors) {
|
|||||||
size_of_dims[idx] = preprocessed_op.size(dim);
|
size_of_dims[idx] = preprocessed_op.size(dim);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
AT_CHECK(size_of_dims[idx] == preprocessed_op.size(dim), "size of dimension does not match previous size, operand ", op, ", dim ", i);
|
TORCH_CHECK(size_of_dims[idx] == preprocessed_op.size(dim), "size of dimension does not match previous size, operand ", op, ", dim ", i);
|
||||||
}
|
}
|
||||||
dim++;
|
dim++;
|
||||||
} else { // duplicate dimension in tensor --> take diagonal of idx_to_dim[dim_out] and dim and put the diagonal dimension to idx_to_dim[dim_out]
|
} else { // duplicate dimension in tensor --> take diagonal of idx_to_dim[dim_out] and dim and put the diagonal dimension to idx_to_dim[dim_out]
|
||||||
AT_CHECK(size_of_dims[idx] == preprocessed_op.size(dim), "size of dimension does not match previous size, operand ", op, ", dim ", i);
|
TORCH_CHECK(size_of_dims[idx] == preprocessed_op.size(dim), "size of dimension does not match previous size, operand ", op, ", dim ", i);
|
||||||
preprocessed_op = preprocessed_op.diagonal(0, idx_to_dim[dim_out], dim);
|
preprocessed_op = preprocessed_op.diagonal(0, idx_to_dim[dim_out], dim);
|
||||||
// diagonal moves the diagonal dimension to the back
|
// diagonal moves the diagonal dimension to the back
|
||||||
// now we permute the last dim back to idx_to_dim[dim_out]
|
// now we permute the last dim back to idx_to_dim[dim_out]
|
||||||
@ -367,7 +367,7 @@ Tensor _trilinear(const Tensor& i1_, const Tensor& i2_, const Tensor& i3_,
|
|||||||
IntArrayRef expand1_, IntArrayRef expand2_, IntArrayRef expand3_,
|
IntArrayRef expand1_, IntArrayRef expand2_, IntArrayRef expand3_,
|
||||||
IntArrayRef sumdim_, int64_t unroll_dim) {
|
IntArrayRef sumdim_, int64_t unroll_dim) {
|
||||||
int64_t total_dim = i1_.dim()+expand1_.size();
|
int64_t total_dim = i1_.dim()+expand1_.size();
|
||||||
AT_CHECK((unroll_dim >= 0) && (unroll_dim < total_dim), "unroll_dim must be in [0,", total_dim-1, "]");
|
TORCH_CHECK((unroll_dim >= 0) && (unroll_dim < total_dim), "unroll_dim must be in [0,", total_dim-1, "]");
|
||||||
auto expand1 = at::dim_list_to_bitset(expand1_, total_dim);
|
auto expand1 = at::dim_list_to_bitset(expand1_, total_dim);
|
||||||
auto expand2 = at::dim_list_to_bitset(expand2_, total_dim);
|
auto expand2 = at::dim_list_to_bitset(expand2_, total_dim);
|
||||||
auto expand3 = at::dim_list_to_bitset(expand3_, total_dim);
|
auto expand3 = at::dim_list_to_bitset(expand3_, total_dim);
|
||||||
@ -433,7 +433,7 @@ Tensor _trilinear(const Tensor& i1_, const Tensor& i2_, const Tensor& i3_,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tensor bilinear(const Tensor& input1, const Tensor& input2, const Tensor& weight, const Tensor& bias) {
|
Tensor bilinear(const Tensor& input1, const Tensor& input2, const Tensor& weight, const Tensor& bias) {
|
||||||
AT_CHECK(input1.dim() == input2.dim(), "bilinear(): input dimensions do not match: got ", input1.dim(), " and ", input2.dim());
|
TORCH_CHECK(input1.dim() == input2.dim(), "bilinear(): input dimensions do not match: got ", input1.dim(), " and ", input2.dim());
|
||||||
for (int64_t i = 0; i < input1.dim() - 1; i++) {
|
for (int64_t i = 0; i < input1.dim() - 1; i++) {
|
||||||
AT_CHECK(input1.size(i) == input2.size(i),
|
AT_CHECK(input1.size(i) == input2.size(i),
|
||||||
"bilinear(): input batch dimensions do not match at dim ", i, ": got ", input1.size(i), " and ", input2.size(i));
|
"bilinear(): input batch dimensions do not match at dim ", i, ": got ", input1.size(i), " and ", input2.size(i));
|
||||||
|
Reference in New Issue
Block a user