Use upstream shape functions directly.

Now that upstream exposes them nicely, we can use them.

I noticed that we had added stuff into the upstream_shape_helpers.py
file (which was supposed to stay pristine), so some more shape functions
need to be upstreamed.

Going forward, all shape functions should be upstreamed similar to
https://github.com/pytorch/pytorch/pull/76889 instead of added in this
file.
pull/915/head
Sean Silva 2022-06-06 23:53:21 +00:00
parent 22c0893ec6
commit e1b38e74dd
2 changed files with 5495 additions and 2098 deletions

File diff suppressed because it is too large Load Diff

View File

@ -12,13 +12,14 @@ import inspect
import torch
from torch import device, Tensor
import torch.jit._shape_functions as upstream_shape_functions
from torch_mlir.dialects.torch.importer.jit_ir import ModuleBuilder
from torch_mlir.passmanager import PassManager
import torch_mlir.all_passes_registration
from .registry import Registry
import torch_mlir.dialects.torch.importer.jit_ir.build_tools.upstream_shape_helpers as upstream_shape_helpers
# ==============================================================================
# Shape function testing infrastructure.
@ -284,178 +285,178 @@ def not_present_in_registry(f):
# ==============================================================================
def atentanh(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenerf(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atensigmoid(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenhardsigmoid(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atensquare(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenhardswish(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atensilu(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenexp(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atensin(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atencos(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenhardtanh(self: List[int], min_val: float = -1, max_val: float = 1) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atensqrt(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenneg(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenfloor(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atendetach(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenlog2(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenrsqrt(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenabs(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenreciprocal(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atentanh_backward(grad_output: List[int], output: List[int]) -> List[int]:
return upstream_shape_helpers.unary(grad_output)
return upstream_shape_functions.unary(grad_output)
def atengelu_backward(grad_output: List[int], self: List[int], approximate: str = "none") -> List[int]:
return upstream_shape_helpers.unary(grad_output)
return upstream_shape_functions.unary(grad_output)
def atenceil(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenlog(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenrelu(self: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def aten_softmax(self: List[int], dim: int, half_to_float: bool) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atensoftmaxint(self: List[int], dim: int, dtype: Optional[int] = None) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def aten_log_softmax(self: List[int], dim: int, half_to_float: bool) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenlog_softmaxint(self: List[int], dim: int, dtype: Optional[int] = None) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenclamp(self: List[int], min: Optional[float] = None, max: Optional[float] = None) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenclamp_min(self: List[int], min: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenclamp_max(self: List[int], max: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenrsubScalar(self: List[int], other: float, alpha: float = 1) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atentodtype(self: List[int], dtype: int, non_blocking: bool = False, copy: bool = False, memory_format: Optional[int] = None) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atentodtype_layout(self: List[int], dtype: Optional[int] = None, layout: Optional[int] = None, device: Optional[device] = None, pin_memory: Optional[bool] = None, non_blocking: bool = False, copy: bool = False, memory_format: Optional[int] = None) -> List[int]:
return self
def atentoother(self: List[int], other: List[int], non_blocking: bool = False, copy: bool = False, memory_format: Optional[int] = None) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atentype_as(self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atendropout(input: List[int], p: float, train: bool) -> List[int]:
return upstream_shape_helpers.unary(input)
return upstream_shape_functions.unary(input)
def atengelu(self: List[int], approximate: str = "none") -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atencontiguous(self: List[int], memory_format: int = 0) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenclone(self: List[int], memory_format: Optional[int] = None) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def aten_log_softmax_backward_data(grad_output: List[int], output: List[int], dim: int, input_dtype: int) -> List[int]:
return upstream_shape_helpers.unary(grad_output)
return upstream_shape_functions.unary(grad_output)
def ateneqScalar(self: List[int], other: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenneScalar(self: List[int], other: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atengtScalar(self: List[int], other: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atengeScalar(self: List[int], other: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenleScalar(self: List[int], other: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenltScalar(self: List[int], other: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenaddScalar(self: List[int], other: float, alpha: float = 1) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atensubScalar(self: List[int], other: float, alpha: float = 1) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenmulScalar(self: List[int], other: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atendivScalar(self: List[int], other: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenfloor_divideScalar(self: List[int], other: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenpowTensor_Scalar(self: List[int], exponent: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenrsubScalar(self: List[int], other: float, alpha: float = 1) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenleaky_relu(self: List[int], negative_slope: float = 0.01) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atengather(self: List[int], dim: int, index: List[int], sparse_grad: bool = False) -> List[int]:
return upstream_shape_helpers.unary(index)
return upstream_shape_functions.unary(index)
def atenlayer_norm(input: List[int], normalized_shape: List[int], weight: Optional[List[int]] = None, bias: Optional[List[int]] = None, eps: float = 1.0000000000000001e-05, cudnn_enable: bool = True) -> List[int]:
return upstream_shape_helpers.unary(input)
return upstream_shape_functions.unary(input)
def aten_softmax_backward_data(grad_output: List[int], output: List[int], dim: int, input_dtype: int) -> List[int]:
return upstream_shape_helpers.unary(output)
return upstream_shape_functions.unary(output)
def atenany(self: List[int]) -> List[int]:
return []
@ -479,7 +480,7 @@ def atenstd(self: List[int], unbiased: bool = True) -> List[int]:
return []
def _reduce_along_dim(self: List[int], dim: int, keepdim: bool):
dim = upstream_shape_helpers.maybe_wrap_dim(dim, len(self))
dim = upstream_shape_functions.maybe_wrap_dim(dim, len(self))
out: List[int] = []
for i, self_dim in enumerate(self):
if i == dim:
@ -511,29 +512,29 @@ def atenmaxdim(self: List[int], dim: int, keepdim: bool = False) -> Tuple[
return reduced_shape, reduced_shape
def atenmeandim(self: List[int], dim: List[int], keepdim: bool = False, dtype: Optional[int] = None) -> List[int]:
return upstream_shape_helpers.mean_dim(self, dim, keepdim, dtype)
return upstream_shape_functions.mean_dim(self, dim, keepdim, dtype)
def atensumdim_IntList(self: List[int], dim: List[int], keepdim: bool = False, dtype: Optional[int] = None) -> List[int]:
return upstream_shape_helpers.mean_dim(self, dim, keepdim, dtype)
return upstream_shape_functions.mean_dim(self, dim, keepdim, dtype)
def atenpermute(self: List[int], dims: List[int]) -> List[int]:
return upstream_shape_helpers.permute(self, dims)
return upstream_shape_functions.permute(self, dims)
def atentransposeint(self: List[int], dim0: int, dim1: int) -> List[int]:
return upstream_shape_helpers.transpose(self, dim0, dim1)
return upstream_shape_functions.transpose(self, dim0, dim1)
def atent(self: List[int]) -> List[int]:
return upstream_shape_helpers.transpose(self, 0, 1)
return upstream_shape_functions.transpose(self, 0, 1)
def atenmatmul(self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.matmul(self, other)
return upstream_shape_functions.matmul(self, other)
def atenmm(self: List[int], mat2: List[int]) -> List[int]:
return upstream_shape_helpers.mm(self, mat2)
return upstream_shape_functions.mm(self, mat2)
def atenaddmm(self: List[int], mat1: List[int], mat2: List[int], beta: float = 1, alpha: float = 1) -> List[int]:
return upstream_shape_helpers.addmm(self, mat1, mat2, beta, alpha)
return upstream_shape_functions.addmm(self, mat1, mat2, beta, alpha)
@check_shape_function([
Invocation(TensorOfShape(2, 3, 4), TensorOfShape(2, 4, 5)), # Basic case.
@ -557,25 +558,25 @@ def atenbaddbmm(self: List[int], batch1: List[int], batch2: List[int], beta:
return [batch1[0], batch1[1], batch2[2]]
def atenembedding(weight: List[int], indices: List[int], padding_idx: int = -1, scale_grad_by_freq: bool = False, sparse: bool = False) -> List[int]:
return upstream_shape_helpers.embedding(weight, indices, padding_idx, scale_grad_by_freq, sparse)
return upstream_shape_functions.embedding(weight, indices, padding_idx, scale_grad_by_freq, sparse)
def atenexpand(self: List[int], size: List[int], implicit: bool = False) -> List[int]:
return upstream_shape_helpers.expand(self, size)
return upstream_shape_functions.expand(self, size)
def atenexpand_as(self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.unary(other)
return upstream_shape_functions.unary(other)
def atenbroadcast_to(self: List[int], size: List[int]) -> List[int]:
return upstream_shape_helpers.expand(self, size)
return upstream_shape_functions.expand(self, size)
def atenview(self: List[int], size: List[int]) -> List[int]:
return upstream_shape_helpers.view(self, size)
return upstream_shape_functions.view(self, size)
def atenreshape(self: List[int], shape: List[int]) -> List[int]:
return upstream_shape_helpers.view(self, shape)
return upstream_shape_functions.view(self, shape)
def aten_reshape_alias(self: List[int], size: List[int], stride: List[int]) -> List[int]:
return upstream_shape_helpers.view(self, size)
return upstream_shape_functions.view(self, size)
def aten_unsafe_view(self: List[int], size: List[int]) -> List[int]:
return size
@ -584,26 +585,70 @@ def atenresize_(self: List[int], size: List[int], memory_format: Optional[int
return size
def atenmax_pool2d(self: List[int], kernel_size: List[int], stride: List[int] = (), padding: List[int] = (0, 0), dilation: List[int] = (1, 1), ceil_mode: bool = False) -> List[int]:
return upstream_shape_helpers.max_pool2d(self, kernel_size, stride, padding, dilation, ceil_mode)
return upstream_shape_functions.max_pool2d(self, kernel_size, stride, padding, dilation, ceil_mode)
def atenmax_pool2d_with_indices(self: List[int], kernel_size: List[int], stride: List[int] = (), padding: List[int] = (0, 0), dilation: List[int] = (1, 1), ceil_mode: bool = False) -> Tuple[List[int], List[int]]:
maxpool2d = indices = upstream_shape_helpers.max_pool2d(self, kernel_size, stride, padding, dilation, ceil_mode)
maxpool2d = indices = upstream_shape_functions.max_pool2d(self, kernel_size, stride, padding, dilation, ceil_mode)
return maxpool2d, indices
def atenmax_pool2d_with_indices_backward(grad_output: List[int], self: List[int], kernel_size: List[int], stride: List[int], padding: List[int], dilation: List[int], ceil_mode: bool, indices: List[int]) -> List[int]:
return self
# TODO: This should be upstreamed.
# See https://github.com/pytorch/pytorch/pull/76889 for an example.
def avg_pool2d(input: List[int], kernel_size: List[int], stride: List[int], padding: List[int], ceil_mode: bool, count_include_pad: bool, divisor_override: Optional[int]):
assert len(kernel_size) == 1 or len(kernel_size) == 2, "avg_pool2d: kernel_size must either be a single int, or a tuple of two ints"
kH = kernel_size[0]
kW = kH if len(kernel_size) == 1 else kernel_size[1]
assert len(stride) == 0 or len(stride) == 1 or len(stride) == 2, "avg_pool2d: stride must either be omitted, a single int, or a tuple of two ints"
dH = kH if len(stride) == 0 else stride[0]
if len(stride) == 0:
dW = kW
elif len(stride) == 1:
dW = dH
else:
dW = stride[1]
assert len(padding) == 1 or len(padding) == 2, "avg_pool2d: padding must be either be a single int, or a tuple of two ints"
padH = padding[0]
padW = padH if len(padding) == 1 else padding[1]
dilationH = 1
dilationW = 1
assert len(input) == 3 or len(input) == 4
nbatch = input[-4] if len(input) == 4 else 1
nInputPlane = input[-3]
inputHeight = input[-2]
inputWidth = input[-1]
outputHeight = upstream_shape_functions.pooling_output_shape(
inputHeight, kH, padH, dH, dilationH, ceil_mode)
outputWidth = upstream_shape_functions.pooling_output_shape(
inputWidth, kW, padW, dW, dilationW, ceil_mode)
upstream_shape_functions.pool2d_shape_check(
input, kH, kW, dH, dW, padH, padW, dilationH, dilationW, nInputPlane,
inputHeight, inputWidth, outputHeight, outputWidth)
if len(input) == 3:
return [nInputPlane, outputHeight, outputWidth]
else:
return [nbatch, nInputPlane, outputHeight, outputWidth]
def atenavg_pool2d(self: List[int], kernel_size: List[int], stride: List[int] = (), padding: List[int] = (0, 0), ceil_mode: bool = False, count_include_pad: bool = True, divisor_override: Optional[int] = None) -> List[int]:
return upstream_shape_helpers.avg_pool2d(self, kernel_size, stride, padding, ceil_mode, count_include_pad, divisor_override)
return avg_pool2d(self, kernel_size, stride, padding, ceil_mode, count_include_pad, divisor_override)
def atenadaptive_avg_pool2d(self: List[int], output_size: List[int]) -> List[int]:
return upstream_shape_helpers.adaptive_avg_pool2d(self, output_size)
return upstream_shape_functions.adaptive_avg_pool2d(self, output_size)
def atenflattenusing_ints(self: List[int], start_dim: int = 0, end_dim: int = -1) -> List[int]:
return upstream_shape_helpers.flatten(self, start_dim, end_dim)
return upstream_shape_functions.flatten(self, start_dim, end_dim)
def atenlinear(input: List[int], weight: List[int], bias: Optional[List[int]] = None) -> List[int]:
return upstream_shape_helpers.linear(input, weight, bias)
return upstream_shape_functions.linear(input, weight, bias)
@check_shape_function([
Invocation([2, 3]),
@ -624,13 +669,13 @@ def atenfull_like(self: List[int], fill_value: float, dtype: Optional[int] =
return self
def atenzeros_like(self: List[int], dtype: Optional[int] = None, layout: Optional[int] = None, device: Optional[device] = None, pin_memory: Optional[bool] = None, memory_format: Optional[int] = None) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenones_like(self: List[int], dtype: Optional[int] = None, layout: Optional[int] = None, device: Optional[device] = None, pin_memory: Optional[bool] = None, memory_format: Optional[int] = None) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenempty_like(self: List[int], dtype: Optional[int] = None, layout: Optional[int] = None, device: Optional[device] = None, pin_memory: Optional[bool] = None, memory_format: Optional[int] = None) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atennew_zeros(self: List[int], size: List[int], dtype: Optional[int] = None, layout: Optional[int] = None, device: Optional[device] = None, pin_memory: Optional[bool] = None) -> List[int]:
return size
@ -642,10 +687,10 @@ def atennew_empty(self: List[int], size: List[int], dtype: Optional[int] = No
return size
def aten_to_copy(self: List[int], dtype: Optional[int] = None, layout: Optional[int] = None, device: Optional[device] = None, pin_memory: Optional[bool] = None, non_blocking: bool = False, memory_format: Optional[int] = None) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenmasked_fillScalar(self: List[int], mask: List[int], value: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
@not_present_in_registry
def atenzero(self: List[int]) -> List[int]:
@ -660,7 +705,7 @@ def atenfillScalar(self: List[int], value: float) -> List[int]:
@not_present_in_registry
def atencopy(self: List[int], src: List[int], non_blocking: bool = False) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
@not_present_in_registry
def atenuniform(self: List[int], from_: float = 0., to: float = 1., generator: Any = None) -> List[int]:
@ -676,7 +721,7 @@ def atenbernoulliTensor(self: List[int], p: List[int], generator: Any = No
@not_present_in_registry
def atenindex_put_impl(self: List[int], indices: List[Optional[List[int]]], values: List[int], accumulate: bool = False, unsafe: bool = False) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenbernoulli(self: List[int], generator: Any = None) -> List[int]:
return self
@ -685,13 +730,13 @@ def atenrand_like(self: List[int], dtype: Optional[int] = None, layout: Optio
return self
def atenarangestart_step(start: float, end: float, step: float, dtype: Optional[int] = None, layout: Optional[int] = None, device: Optional[device] = None, pin_memory: Optional[bool] = None) -> List[int]:
return upstream_shape_helpers.arange_start_step(start, end, step, dtype, layout, device, pin_memory)
return upstream_shape_functions.arange_start_step(start, end, step, dtype, layout, device, pin_memory)
def atenarangestart(start: float, end: float, dtype: Optional[int] = None, layout: Optional[int] = None, device: Optional[device] = None, pin_memory: Optional[bool] = None) -> List[int]:
return upstream_shape_helpers.arange_start(start, end, dtype, layout, device, pin_memory)
return upstream_shape_functions.arange_start(start, end, dtype, layout, device, pin_memory)
def atenarange(end: float, dtype: Optional[int] = None, layout: Optional[int] = None, device: Optional[device] = None, pin_memory: Optional[bool] = None) -> List[int]:
return upstream_shape_helpers.arange_end(end, dtype, layout, device, pin_memory)
return upstream_shape_functions.arange_end(end, dtype, layout, device, pin_memory)
@check_shape_function([
Invocation(TensorOfShape(2, 3), TensorOfShape(2, 3)), # Basic case.
@ -700,58 +745,58 @@ def atenarange(end: float, dtype: Optional[int] = None, layout: Optional[int]
ErrorInvocation(TensorOfShape(2, 3), TensorOfShape(4, 3)), # Non-size-1 dimension size mismatch.
])
def atenaddTensor(self: List[int], other: List[int], alpha: float = 1) -> List[int]:
return upstream_shape_helpers.broadcast(self, other)
return upstream_shape_functions.broadcast(self, other)
def atensubTensor(self: List[int], other: List[int], alpha: float = 1) -> List[int]:
return upstream_shape_helpers.broadcast(self, other)
return upstream_shape_functions.broadcast(self, other)
def atenmulTensor(self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.broadcast(self, other)
return upstream_shape_functions.broadcast(self, other)
def atendivTensor(self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.broadcast(self, other)
return upstream_shape_functions.broadcast(self, other)
def atendivTensor_mode(self: List[int], other: List[int], rounding_mode: Optional[str]) -> List[int]:
return upstream_shape_helpers.broadcast(self, other)
return upstream_shape_functions.broadcast(self, other)
def aten__and__Tensor(self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.broadcast(self, other)
return upstream_shape_functions.broadcast(self, other)
def atenminimum(self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.broadcast(self, other)
return upstream_shape_functions.broadcast(self, other)
def atenmaximum(self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.broadcast(self, other)
return upstream_shape_functions.broadcast(self, other)
def atenbitwise_andTensor(self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.broadcast(self, other)
return upstream_shape_functions.broadcast(self, other)
def atenlogical_or(self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.broadcast(self, other)
return upstream_shape_functions.broadcast(self, other)
def atenthreshold(self: List[int], threshold: float, value: float) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenthreshold_backward(grad_output: List[int], self: List[int], threshold: float) -> List[int]:
return upstream_shape_helpers.broadcast(grad_output, self)
return upstream_shape_functions.broadcast(grad_output, self)
def ateneqTensor(self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.broadcast(self, other)
return upstream_shape_functions.broadcast(self, other)
def atengtTensor(self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.broadcast(self, other)
return upstream_shape_functions.broadcast(self, other)
def atenltTensor(self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.broadcast(self, other)
return upstream_shape_functions.broadcast(self, other)
def atenunsqueeze(self: List[int], dim: int) -> List[int]:
return upstream_shape_helpers.unsqueeze(self, dim)
return upstream_shape_functions.unsqueeze(self, dim)
def atensqueeze(self: List[int]) -> List[int]:
return upstream_shape_helpers.squeeze_nodim(self)
return upstream_shape_functions.squeeze_nodim(self)
def atensqueezedim(self: List[int], dim: int) -> List[int]:
return upstream_shape_helpers.squeeze(self, dim)
return upstream_shape_functions.squeeze(self, dim)
def primNumToTensorScalar(a: float) -> List[int]:
return []
@ -773,25 +818,25 @@ def aten_shape_as_tensor(self: List[int]) -> List[int]:
return [len(self)]
def atenwhereself(condition: List[int], self: List[int], other: List[int]) -> List[int]:
return upstream_shape_helpers.broadcast(condition, upstream_shape_helpers.broadcast(self, other))
return upstream_shape_functions.broadcast(condition, upstream_shape_functions.broadcast(self, other))
def atenwhereScalar(condition: List[int], self: float, other: float) -> List[int]:
return upstream_shape_helpers.unary(condition)
return upstream_shape_functions.unary(condition)
def atenwhereScalarOther(condition: List[int], self: List[int], other: float) -> List[int]:
return upstream_shape_helpers.broadcast(condition, self)
return upstream_shape_functions.broadcast(condition, self)
def atenwhereScalarSelf(condition: List[int], self: float, other: List[int]) -> List[int]:
return upstream_shape_helpers.broadcast(condition, other)
return upstream_shape_functions.broadcast(condition, other)
def atenlerpTensor(self: List[int], end: List[int], weight: List[int]) -> List[int]:
return upstream_shape_helpers.broadcast(self, upstream_shape_helpers.broadcast(end, weight))
return upstream_shape_functions.broadcast(self, upstream_shape_functions.broadcast(end, weight))
def atenaddcmul(self: List[int], tensor1: List[int], tensor2: List[int], value: float = 1) -> List[int]:
return upstream_shape_helpers.broadcast(self, upstream_shape_helpers.broadcast(tensor1, tensor2))
return upstream_shape_functions.broadcast(self, upstream_shape_functions.broadcast(tensor1, tensor2))
def atenaddcdiv(self: List[int], tensor1: List[int], tensor2: List[int], value: float = 1) -> List[int]:
return upstream_shape_helpers.broadcast(self, upstream_shape_helpers.broadcast(tensor1, tensor2))
return upstream_shape_functions.broadcast(self, upstream_shape_functions.broadcast(tensor1, tensor2))
@check_shape_function([
Invocation(TensorOfShape(2, 3), 1), # Basic case.
@ -808,10 +853,10 @@ def atentopk(self: List[int], k: int, dim: int = -1, largest: bool = True, so
return self, self
def atenconv2d(input: List[int], weight: List[int], bias: Optional[List[int]] = None, stride: List[int] = (1, 1), padding: List[int] = (0, 0), dilation: List[int] = (1, 1), groups: int = 1) -> List[int]:
return upstream_shape_helpers.conv2d(input, weight, bias, stride, padding, dilation, groups)
return upstream_shape_functions.conv2d(input, weight, bias, stride, padding, dilation, groups)
def atenconvolution(input: List[int], weight: List[int], bias: Optional[List[int]], stride: List[int], padding: List[int], dilation: List[int], transposed: bool, output_padding: List[int], groups: int) -> List[int]:
return upstream_shape_helpers.conv_output_size(input, weight, bias, stride, padding, dilation, groups)
return upstream_shape_functions.conv_output_size(input, weight, bias, stride, padding, dilation, groups)
def atenflip(self: List[int], dims: List[int]) -> List[int]:
return self
@ -822,26 +867,26 @@ def atenbatch_norm(input: List[int], weight: Optional[List[int]], bias: Optio
# even though the `weight` is not `Optional`.
# Upstream is working to make this more consistent.
# For now, since this function is so trivial, just write it ourselves.
#return upstream_shape_helpers.batch_norm(input, weight, bias, running_mean, running_var, training, momentum, eps, cudnn_enabled)
#return upstream_shape_functions.batch_norm(input, weight, bias, running_mean, running_var, training, momentum, eps, cudnn_enabled)
return input
def atensliceTensor(self: List[int], dim: int = 0, start: Optional[int] = None, end: Optional[int] = None, step: int = 1) -> List[int]:
return upstream_shape_helpers.slice(self, dim, start, end, step)
return upstream_shape_functions.slice(self, dim, start, end, step)
def atenselectint(self: List[int], dim: int, index: int) -> List[int]:
return upstream_shape_helpers.select(self, dim, index)
return upstream_shape_functions.select(self, dim, index)
def atenindex_select(self: List[int], dim: int, index: List[int]) -> List[int]:
return upstream_shape_helpers.index_select(self, dim, index)
return upstream_shape_functions.index_select(self, dim, index)
def atenindex_put(self: List[int], indices: List[Optional[List[int]]], values: List[int], accumulate: bool = False) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenindex_puthacked_twin(self: List[int], indices: List[List[int]], values: List[int], accumulate: bool = False) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
def atenembedding(weight: List[int], indices: List[int], padding_idx: int = -1, scale_grad_by_freq: bool = False, sparse: bool = False) -> List[int]:
return upstream_shape_helpers.embedding(weight, indices, padding_idx, scale_grad_by_freq, sparse)
return upstream_shape_functions.embedding(weight, indices, padding_idx, scale_grad_by_freq, sparse)
@check_shape_function([
Invocation(TensorOfShape(2, 3), LongTensorOfShape(2), None, 1, -100), # Basic case.
@ -866,7 +911,7 @@ def atennll_loss_forward(self: List[int], target: List[int], weight: Optional
return scalar_shape, scalar_shape
def atennll_loss_backward(grad_output: List[int], self: List[int], target: List[int], weight: Optional[List[int]], reduction: int, ignore_index: int, total_weight: List[int]) -> List[int]:
return upstream_shape_helpers.unary(self)
return upstream_shape_functions.unary(self)
@check_shape_function([
Invocation(TensorOfShape(2, 5, 2, 2, 3), [2, 2, 3], None, None, 1e-6), # Basic case.
@ -893,6 +938,17 @@ def atennative_batch_norm(input: List[int], weight: Optional[List[int]], bias
return input, [input[1]], [input[1]]
return input, [0], [0]
# TODO: This should be upstreamed.
# See https://github.com/pytorch/pytorch/pull/76889 for an example.
def pad_shape_fn(input: List[int], pad: List[int]):
assert len(pad) % 2 == 0, "Must have paired low-high pad amount values"
assert len(pad) // 2 <= len(input), "Number of padded dimensions must be less than or equal to the input dimension"
# The `pad` list takes the form of Low-high pairs starting at the
# *rightmost* dimension of `self`.
for i in range(len(pad) // 2):
input[-(i + 1)] += pad[2 * i] + pad[2 * i + 1]
return input
@check_shape_function([
Invocation(TensorOfShape(2), [1, 2]), # Basic case.
Invocation(TensorOfShape(2, 3), [1, 2, 3, 4]), # More dimensions.
@ -901,10 +957,10 @@ def atennative_batch_norm(input: List[int], weight: Optional[List[int]], bias
ErrorInvocation(TensorOfShape(2), [1]), # Unpaired pad value.
])
def atenconstant_pad_nd(self: List[int], pad: List[int], value: float = 0) -> List[int]:
return upstream_shape_helpers.pad(self, pad)
return pad_shape_fn(self, pad)
def atenpad(self: List[int], pad: List[int], mode: str = "constant", value: Optional[float] = None) -> List[int]:
return upstream_shape_helpers.pad(self, pad)
return pad_shape_fn(self, pad)
@check_shape_function([
Invocation(TensorOfShape(2), [LongTensorOfShape(4)]), # Basic case.
@ -920,11 +976,11 @@ def atenindexTensor(self: List[int], indices: List[Optional[List[int]]]) -
broadcasted_shape: List[int] = []
for index_tensor_shape in indices:
if index_tensor_shape is not None:
broadcasted_shape = upstream_shape_helpers.broadcast(broadcasted_shape, index_tensor_shape)
broadcasted_shape = upstream_shape_functions.broadcast(broadcasted_shape, index_tensor_shape)
return broadcasted_shape
def atencat(tensors: List[List[int]], dim: int = 0) -> List[int]:
return upstream_shape_helpers.cat(tensors, dim)
return upstream_shape_functions.cat(tensors, dim)
class DummyClassType:
def __init__(self):
@ -971,7 +1027,7 @@ def atenbincount(self: List[int], weights: Optional[List[int]] = None, minlen
def atenlinalg_vector_norm(self: List[int], ord: float = 2, dim: Optional[List[int]] = None, keepdim: bool = False, dtype: Optional[int] = None) -> List[int]:
if dim is None:
dim = list(range(len(self)))
return upstream_shape_helpers.mean_dim(self, dim, keepdim, dtype)
return upstream_shape_functions.mean_dim(self, dim, keepdim, dtype)
# ==============================================================================
# Shape library generator main().