Skip to content

[torchlib] aten::copy to support inputs w/ different dtype #1162

@BowenBao

Description

@BowenBao

Repro:

import torch

def func(x, y):
    x[..., 0] = y
    return x

x = torch.randn(2, 3, 4, dtype=torch.float32)
y = torch.randn(2, 3, dtype=torch.float64)

torch.onnx.dynamo_export(func, x, y).save("repro_copy_diff_dtype.onnx")

import onnxruntime
onnxruntime.InferenceSession("repro_copy_diff_dtype.onnx", providers=["CPUExecutionProvider"])

onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model from repro_copy_diff_dtype.onnx failed:Type Error: Type (tensor(float)) of output arg (copy) of node (aten_copy_1) does not match expected type (tensor(double)).

- func: copy(Tensor self, Tensor src, bool non_blocking=False) -> Tensor

I'm leaning more towards handling it inside aten::copy than in type promotion, since this isn't really type promotion.

From pyhpc_turbulent_kinetic_energy cuda amp https://github.com/microsoft/onnx-converters-private/issues/196

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmodule: torchlibRelated to the torch/aten function lib in development

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions