Skip to content

[ONNX] dynamic_axes incorrect validation #25681

@rbrigden

Description

@rbrigden

🐛 Bug

Exporting ONNX model with dynamic axes complains on validation that the input/output names are not specified when they currently are.

To Reproduce

Steps to reproduce the behavior:

Attempt to export any model with dynamic axes feature.

    input_names = ["input"]
    output_names = ["output"]
    dynamic_axes = {"input": {2: "h", 3: "w"}}

    torch.onnx.export(
        model,
        dummy_input,
        "test.onnx",
        verbose=True,
        input_names=input_names,
        output_names=output_names,
        dynamic_axes=dynamic_axes,
    )

Output: Provided key input for dynamic axes is not a valid input/output name

Expected behavior

The specified parameters are expected to be valid and the model should export correctly given that the model contains supported ops.

Environment

PyTorch version: 1.2.0
Is debug build: No
CUDA used to build PyTorch: 10.0.130

OS: Ubuntu 18.04.3 LTS
GCC version: (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
CMake version: version 3.13.2

Python version: 3.7
Is CUDA available: Yes
CUDA runtime version: 10.0.130
GPU models and configuration:
GPU 0: TITAN RTX
GPU 1: TITAN RTX
GPU 2: TITAN RTX

Nvidia driver version: 430.34
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.0

Versions of relevant libraries:
[pip3] numpy==1.16.2
[pip3] pytorch-ignite==0.2.0
[pip3] torch==1.2.0
[pip3] torchvision==0.4.0+cu92

Additional context

For set[T], set.addexpects an object of typeT. In the function, _validate_dynamic_axes (/home/ryan/.local/share/virtualenvs/inokyo-OUoFAKa9/lib/python3.7/site-packages/torch/onnx/utils.py:695), the set.addshould be changed toset.update`

Activity

added
triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
on Sep 5, 2019
leimao

leimao commented on Oct 3, 2019

@leimao
Contributor

I strongly believe this is a bug. Before setting dynamic axes, the name of the input/output tensors were not assigned. Therefore, it does not even know which tensor(s) should have dynamic axes.
Running the official code gets the following warnings (these should be errors!).

/opt/conda/lib/python3.6/site-packages/torch/onnx/utils.py:718: UserWarning: Provided key input for dynamic axes is not a valid input/output name
  warnings.warn("Provided key {} for dynamic axes is not a valid input/output name".format(key))
/opt/conda/lib/python3.6/site-packages/torch/onnx/utils.py:718: UserWarning: Provided key output for dynamic axes is not a valid input/output name
  warnings.warn("Provided key {} for dynamic axes is not a valid input/output name".format(key))
leimao

leimao commented on Oct 3, 2019

@leimao
Contributor

image
Looks like this is a false warning/error. This should definitely be fixed because it is so confusing.

lzxzy

lzxzy commented on Nov 7, 2019

@lzxzy

Hi, I've met the warning too. So, have you found the solution for this? Thx.

kit1980

kit1980 commented on Nov 7, 2019

@kit1980
Contributor

Hi, I've met the warning too. So, have you found the solution for this? Thx.

I think the "solution" now is just to ignore the warning if you know that the name is correct.

leimao

leimao commented on Nov 7, 2019

@leimao
Contributor

Hi, I've met the warning too. So, have you found the solution for this? Thx.

The latest PyTorch 1.3.0 fixed this false warning if I recall it correctly.

lzxzy

lzxzy commented on Nov 10, 2019

@lzxzy

Hi, I've met the warning too. So, have you found the solution for this? Thx.

The latest PyTorch 1.3.0 fixed this false warning if I recall it correctly.

Hi, I've met the warning too. So, have you found the solution for this? Thx.

I think the "solution" now is just to ignore the warning if you know that the name is correct.

Thanks for your guys' reply. I found the problem may be caused by this

onnx.checker.check_model(onnx_model)

When I commented the code, it worked.

leimao

leimao commented on Nov 12, 2019

@leimao
Contributor

Hi, I've met the warning too. So, have you found the solution for this? Thx.

The latest PyTorch 1.3.0 fixed this false warning if I recall it correctly.

Hi, I've met the warning too. So, have you found the solution for this? Thx.

I think the "solution" now is just to ignore the warning if you know that the name is correct.

Thanks for your guys' reply. I found the problem may be caused by this

onnx.checker.check_model(onnx_model)

When I commented the code, it worked.

onnx.checker.check_model sometimes does not recognize the model exported from PyTorch, and I suggest don't be too serious about it.

garymm

garymm commented on Dec 23, 2021

@garymm
Collaborator

According to comments from @leimao this is fixed. If not please add details about what's left to do, with full repro code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: onnxRelated to torch.onnxtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kit1980@garymm@ailzhang@rbrigden@lzxzy

        Issue actions

          [ONNX] dynamic_axes incorrect validation · Issue #25681 · pytorch/pytorch