Skip to content

[torchlib] Current mypy errors (sampled) #788

Open

Description

>>> Lint for onnxscript/autocast.py:

  Error (MYPY) arg-type
    Argument 3 to "cast_inputs" has incompatible type "Optional[OpSchema]";
    expected "OpSchema"
    
    To disable, use `  # type: ignore[arg-type]`

        110  |            return tmp
        111  |        return x.name
        112  |
    >>> 113  |    return cast_inputs(get_type_info, cast, op_schema, args)



>>> Lint for onnxscript/function_libs/torch_lib/ops/core.py:

  Error (MYPY) type-var
    Value of type variable "Tind_Gather" of "Gather" of "Opset13" cannot be
    "int"
    
    To disable, use `  # type: ignore[type-var]`

          48  |def aten_abs_complex(self: TrealOrUInt8) -> TrealOrUInt8:
          49  |    """abs(Tensor self) -> Tensor"""
          50  |    # self_real = self[..., 0]
    >>>   51  |    self_real = op.Gather(self, 0, axis=-1)
          52  |    # self_imag = self[..., 1]
          53  |    self_imag = op.Gather(self, 1, axis=-1)
          54  |    real_pow = op.Pow(self_real, 2)

  Error (MYPY) type-var
    Value of type variable "Tind_Gather" of "Gather" of "Opset13" cannot be
    "int"
    
    To disable, use `  # type: ignore[type-var]`

          50  |    # self_real = self[..., 0]
          51  |    self_real = op.Gather(self, 0, axis=-1)
          52  |    # self_imag = self[..., 1]
    >>>   53  |    self_imag = op.Gather(self, 1, axis=-1)
          54  |    real_pow = op.Pow(self_real, 2)
          55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)

  Error (MYPY) type-var
    Value of type variable "T1_Pow" of "Pow" of "Opset15" cannot be "int"
    
    To disable, use `  # type: ignore[type-var]`

          51  |    self_real = op.Gather(self, 0, axis=-1)
          52  |    # self_imag = self[..., 1]
          53  |    self_imag = op.Gather(self, 1, axis=-1)
    >>>   54  |    real_pow = op.Pow(self_real, 2)
          55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)
          57  |    return op.Sqrt(real_plus_imag)

  Error (MYPY) type-var
    Value of type variable "T_Pow" of "Pow" of "Opset15" cannot be "INT8"
    
    To disable, use `  # type: ignore[type-var]`

          51  |    self_real = op.Gather(self, 0, axis=-1)
          52  |    # self_imag = self[..., 1]
          53  |    self_imag = op.Gather(self, 1, axis=-1)
    >>>   54  |    real_pow = op.Pow(self_real, 2)
          55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)
          57  |    return op.Sqrt(real_plus_imag)

  Error (MYPY) type-var
    Value of type variable "T_Pow" of "Pow" of "Opset15" cannot be "INT16"
    
    To disable, use `  # type: ignore[type-var]`

          51  |    self_real = op.Gather(self, 0, axis=-1)
          52  |    # self_imag = self[..., 1]
          53  |    self_imag = op.Gather(self, 1, axis=-1)
    >>>   54  |    real_pow = op.Pow(self_real, 2)
          55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)
          57  |    return op.Sqrt(real_plus_imag)

  Error (MYPY) type-var
    Value of type variable "T_Pow" of "Pow" of "Opset15" cannot be "UINT8"
    
    To disable, use `  # type: ignore[type-var]`

          51  |    self_real = op.Gather(self, 0, axis=-1)
          52  |    # self_imag = self[..., 1]
          53  |    self_imag = op.Gather(self, 1, axis=-1)
    >>>   54  |    real_pow = op.Pow(self_real, 2)
          55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)
          57  |    return op.Sqrt(real_plus_imag)

  Error (MYPY) type-var
    Value of type variable "T1_Pow" of "Pow" of "Opset15" cannot be "int"
    
    To disable, use `  # type: ignore[type-var]`

          52  |    # self_imag = self[..., 1]
          53  |    self_imag = op.Gather(self, 1, axis=-1)
          54  |    real_pow = op.Pow(self_real, 2)
    >>>   55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)
          57  |    return op.Sqrt(real_plus_imag)
          58  |

  Error (MYPY) type-var
    Value of type variable "T_Pow" of "Pow" of "Opset15" cannot be "INT8"
    
    To disable, use `  # type: ignore[type-var]`

          52  |    # self_imag = self[..., 1]
          53  |    self_imag = op.Gather(self, 1, axis=-1)
          54  |    real_pow = op.Pow(self_real, 2)
    >>>   55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)
          57  |    return op.Sqrt(real_plus_imag)
          58  |

  Error (MYPY) type-var
    Value of type variable "T_Pow" of "Pow" of "Opset15" cannot be "INT16"
    
    To disable, use `  # type: ignore[type-var]`

          52  |    # self_imag = self[..., 1]
          53  |    self_imag = op.Gather(self, 1, axis=-1)
          54  |    real_pow = op.Pow(self_real, 2)
    >>>   55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)
          57  |    return op.Sqrt(real_plus_imag)
          58  |

  Error (MYPY) type-var
    Value of type variable "T_Pow" of "Pow" of "Opset15" cannot be "UINT8"
    
    To disable, use `  # type: ignore[type-var]`

          52  |    # self_imag = self[..., 1]
          53  |    self_imag = op.Gather(self, 1, axis=-1)
          54  |    real_pow = op.Pow(self_real, 2)
    >>>   55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)
          57  |    return op.Sqrt(real_plus_imag)
          58  |

  Error (MYPY) type-var
    Value of type variable "T_Sqrt" of "Sqrt" of "Opset13" cannot be "INT8"
    
    To disable, use `  # type: ignore[type-var]`

          54  |    real_pow = op.Pow(self_real, 2)
          55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)
    >>>   57  |    return op.Sqrt(real_plus_imag)
          58  |
          59  |
          60  |@torch_op("aten::acos")

  Error (MYPY) type-var
    Value of type variable "T_Sqrt" of "Sqrt" of "Opset13" cannot be "INT16"
    
    To disable, use `  # type: ignore[type-var]`

          54  |    real_pow = op.Pow(self_real, 2)
          55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)
    >>>   57  |    return op.Sqrt(real_plus_imag)
          58  |
          59  |
          60  |@torch_op("aten::acos")

  Error (MYPY) type-var
    Value of type variable "T_Sqrt" of "Sqrt" of "Opset13" cannot be "INT32"
    
    To disable, use `  # type: ignore[type-var]`

          54  |    real_pow = op.Pow(self_real, 2)
          55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)
    >>>   57  |    return op.Sqrt(real_plus_imag)
          58  |
          59  |
          60  |@torch_op("aten::acos")

  Error (MYPY) type-var
    Value of type variable "T_Sqrt" of "Sqrt" of "Opset13" cannot be "INT64"
    
    To disable, use `  # type: ignore[type-var]`

          54  |    real_pow = op.Pow(self_real, 2)
          55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)
    >>>   57  |    return op.Sqrt(real_plus_imag)
          58  |
          59  |
          60  |@torch_op("aten::acos")

  Error (MYPY) type-var
    Value of type variable "T_Sqrt" of "Sqrt" of "Opset13" cannot be "UINT8"
    
    To disable, use `  # type: ignore[type-var]`

          54  |    real_pow = op.Pow(self_real, 2)
          55  |    imag_pow = op.Pow(self_imag, 2)
          56  |    real_plus_imag = op.Add(real_pow, imag_pow)
    >>>   57  |    return op.Sqrt(real_plus_imag)
          58  |
          59  |
          60  |@torch_op("aten::acos")

  Error (MYPY) type-var
    Value of type variable "T1_CastLike" of "CastLike" of "Opset15" cannot
    be "float"
    
    To disable, use `  # type: ignore[type-var]`

          76  |    """add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor"""
          77  |    # FIXME(titaiwang): get rid of this when we have type_promotion
          78  |    other = op.CastLike(other, self)
    >>>   79  |    alpha = op.CastLike(alpha, other)
          80  |    other = op.Mul(other, alpha)
          81  |    return op.Add(self, other)
          82  |

  Error (MYPY) type-var
    Value of type variable "T_Mul" of "Mul" of "Opset14" cannot be "object"
    
    To disable, use `  # type: ignore[type-var]`

          77  |    # FIXME(titaiwang): get rid of this when we have type_promotion
          78  |    other = op.CastLike(other, self)
          79  |    alpha = op.CastLike(alpha, other)
    >>>   80  |    other = op.Mul(other, alpha)
          81  |    return op.Add(self, other)
          82  |
          83  |

  Error (MYPY) type-var
    Value of type variable "T_Mul" of "Mul" of "Opset14" cannot be "object"
    
    To disable, use `  # type: ignore[type-var]`

         116  |    """addmm(Tensor self, Tensor mat1, Tensor mat2, *, Scalar beta=1, Scalar alpha=1) -> Tensor"""
         117  |
         118  |    mat1_mat2 = op.MatMul(mat1, mat2)
    >>>  119  |    scaled_mat1_mat2 = op.Mul(mat1_mat2, alpha)
         120  |    scaled_self = op.Mul(self, beta)
         121  |    return op.Add(scaled_self, scaled_mat1_mat2)
         122  |

  Error (MYPY) type-var
    Value of type variable "T_Mul" of "Mul" of "Opset14" cannot be "object"
    
    To disable, use `  # type: ignore[type-var]`

         117  |
         118  |    mat1_mat2 = op.MatMul(mat1, mat2)
         119  |    scaled_mat1_mat2 = op.Mul(mat1_mat2, alpha)
    >>>  120  |    scaled_self = op.Mul(self, beta)
         121  |    return op.Add(scaled_self, scaled_mat1_mat2)
         122  |
         123  |

  Error (MYPY) type-var
    Value of type variable "T_Add" of "Add" of "Opset14" cannot be "object"
    
    To disable, use `  # type: ignore[type-var]`

         118  |    mat1_mat2 = op.MatMul(mat1, mat2)
         119  |    scaled_mat1_mat2 = op.Mul(mat1_mat2, alpha)
         120  |    scaled_self = op.Mul(self, beta)
    >>>  121  |    return op.Add(scaled_self, scaled_mat1_mat2)
         122  |
         123  |
         124  |def aten_addmv(

  Error (MYPY) type-var
    Value of type variable "T1_Cast" of "Cast" of "Opset13" cannot be
    "COMPLEX64"
    
    To disable, use `  # type: ignore[type-var]`

         195  |    """all(Tensor self) -> Tensor"""
         196  |
         197  |    if op.Size(op.Shape(self)) == 0:
    >>>  198  |        result = op.Cast(self, to=BOOL.dtype)
         199  |    else:
         200  |        self_bool = op.Cast(self, to=BOOL.dtype)
         201  |        self_int = op.Cast(self_bool, to=INT64.dtype)

  Error (MYPY) type-var
    Value of type variable "T1_Cast" of "Cast" of "Opset13" cannot be
    "COMPLEX128"
    
    To disable, use `  # type: ignore[type-var]`

         195  |    """all(Tensor self) -> Tensor"""
         196  |
         197  |    if op.Size(op.Shape(self)) == 0:
    >>>  198  |        result = op.Cast(self, to=BOOL.dtype)
         199  |    else:
         200  |        self_bool = op.Cast(self, to=BOOL.dtype)
         201  |        self_int = op.Cast(self_bool, to=INT64.dtype)

  Error (MYPY) type-var
    Value of type variable "T1_Cast" of "Cast" of "Opset13" cannot be
    "COMPLEX64"
    
    To disable, use `  # type: ignore[type-var]`

         197  |    if op.Size(op.Shape(self)) == 0:
         198  |        result = op.Cast(self, to=BOOL.dtype)
         199  |    else:
    >>>  200  |        self_bool = op.Cast(self, to=BOOL.dtype)
         201  |        self_int = op.Cast(self_bool, to=INT64.dtype)
         202  |        result_int = op.ReduceMin(self_int, keepdims=0)
         203  |        result = op.Cast(result_int, to=BOOL.dtype)

  Error (MYPY) type-var
    Value of type variable "T1_Cast" of "Cast" of "Opset13" cannot be
    "COMPLEX128"
    
    To disable, use `  # type: ignore[type-var]`

         197  |    if op.Size(op.Shape(self)) == 0:
         198  |        result = op.Cast(self, to=BOOL.dtype)
         199  |    else:
    >>>  200  |        self_bool = op.Cast(self, to=BOOL.dtype)
         201  |        self_int = op.Cast(self_bool, to=INT64.dtype)
         202  |        result_int = op.ReduceMin(self_int, keepdims=0)
         203  |        result = op.Cast(result_int, to=BOOL.dtype)

  Error (MYPY) type-var
    Value of type variable "T1_Cast" of "Cast" of "Opset13" cannot be
    "Union[BFLOAT16, BOOL, DOUBLE, FLOAT, FLOAT16, INT16, INT32, INT64, INT8,
    STRING, UINT16, UINT32, UINT64, UINT8]"
    
    To disable, use `  # type: ignore[type-var]`

         198  |        result = op.Cast(self, to=BOOL.dtype)
         199  |    else:
         200  |        self_bool = op.Cast(self, to=BOOL.dtype)
    >>>  201  |        self_int = op.Cast(self_bool, to=INT64.dtype)
         202  |        result_int = op.ReduceMin(self_int, keepdims=0)
         203  |        result = op.Cast(result_int, to=BOOL.dtype)
         204  |

  Error (MYPY) type-var
    Value of type variable "T_ReduceMin" of "ReduceMin" of "Opset18" cannot be
    "Union[BFLOAT16, BOOL, DOUBLE, FLOAT, FLOAT16, INT16, INT32, INT64, INT8,
    STRING, UINT16, UINT32, UINT64, UINT8]"
    
    To disable, use `  # type: ignore[type-var]`

         199  |    else:
         200  |        self_bool = op.Cast(self, to=BOOL.dtype)
         201  |        self_int = op.Cast(self_bool, to=INT64.dtype)
    >>>  202  |        result_int = op.ReduceMin(self_int, keepdims=0)
         203  |        result = op.Cast(result_int, to=BOOL.dtype)
         204  |
         205  |    return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    topic: torch_libRelated to the torch/aten function lib in developmenttopic: typingTyping related issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions