Skip to content

bitwise_and cannot have int argument #2617

@wodesuck

Description

@wodesuck
import torch
import torch.nn as nn


class Model(nn.Module):
    def forward(self, x):
        return x & 1


def main():
    model = Model()
    args = (torch.tensor([1, 2, 3]),)
    torch.onnx.export(
        model,
        args,
        "model_test.onnx",
        dynamo=True,
    )


if __name__ == '__main__':
    main()
[torch.onnx] Obtain model graph for `Model()` with `torch.export.export(..., strict=False)`...
[torch.onnx] Obtain model graph for `Model()` with `torch.export.export(..., strict=False)`... ✅
[torch.onnx] Run decomposition...
[torch.onnx] Run decomposition... ✅
[torch.onnx] Translate the graph into ONNX...
[torch.onnx] Translate the graph into ONNX... ❌
Traceback (most recent call last):
  File ".venv/lib/python3.13/site-packages/torch/onnx/_internal/exporter/_core.py", line 519, in _handle_call_function_node_with_lowering
    outputs = onnx_function(*onnx_args, **onnx_kwargs)
  File ".venv/lib/python3.13/site-packages/onnxscript/values.py", line 625, in __call__
    return self.func(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.13/site-packages/onnxscript/function_libs/torch_lib/ops/core.py", line 1249, in aten_bitwise_and
    assert self.dtype == other.dtype
                         ^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'dtype'

Cause by #2582 , we should check inputs are int or not before checking dtype.

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions