Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing model with dynamic batch size fails #47

Open
mortont opened this issue Dec 2, 2022 · 2 comments
Open

Importing model with dynamic batch size fails #47

mortont opened this issue Dec 2, 2022 · 2 comments

Comments

@mortont
Copy link
Owner

mortont commented Dec 2, 2022

I'm attempting to import a model with a dynamic batch size (modified export of a Whisper encoder) and I'm getting the following error

12:08:45.008 [warning] mel_spectrogram_dynamic_axes_1 has no specified dimension, assuming nil
** (ArgumentError) invalid dimension in axis 0 found in shape. Each dimension must be a positive integer, got nil in shape {nil, 80, 3000}
    (nx 0.4.0) lib/nx/shape.ex:60: Nx.Shape.validate!/3
    (nx 0.4.0) lib/nx.ex:2819: Nx.broadcast/3
    (axon_onnx 0.3.0) lib/axon_onnx/deserialize.ex:1402: anonymous fn/1 in AxonOnnx.Deserialize.recur_nodes/2
    (elixir 1.14.0) lib/map.ex:258: Map.do_map/2
    (elixir 1.14.0) lib/map.ex:252: Map.new_from_map/2
    (axon_onnx 0.3.0) lib/axon_onnx/deserialize.ex:1402: AxonOnnx.Deserialize.recur_nodes/2
    (elixir 1.14.0) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    iex:5: (file)

I've been able to run it in onnxruntime and it validates correctly with onnx.checker.check_model in python, is there something I'm missing? The input signature of the model is

onnx.load('./tiny.en/encoder.onnx').graph.input
[name: "mel_spectrogram"
type {
  tensor_type {
    elem_type: 1
    shape {
      dim {
        dim_param: "mel_spectrogram_dynamic_axes_1"
      }
      dim {
        dim_value: 80
      }
      dim {
        dim_value: 3000
      }
    }
  }
}
]
@seanmor5
Copy link
Contributor

seanmor5 commented Dec 7, 2022

If you try importing but specifying mel_spectrogram_dynamic_axes_1: 1, does the import work:

AxonOnnx.import("model.onnx", mel_spectrogram_dynamic_axes_1: 1)

For some deserializations to work we need to know shapes up front. If this does not work, can you tell me where to get the model so I can debug?

@mortont
Copy link
Owner Author

mortont commented Dec 8, 2022

If I specify the axis dimension or re-export the onnx model without a dynamic dimension it won't fail in that way, but it does fail on another op (I have re-parametrized the axis labels, but it's the same model from before):

iex(1)> {model, params} = AxonOnnx.import("whisper-onnx/model.onnx", batch: 1, feature_size: 1, encoder_sequence: 1, decoder_sequence: 1)
** (ArgumentError) unable to build model from ONNX graph, expected value /model/encoder/layers.0/self_attn/Concat_output_0 to be constant value, but was :concatenate
    (axon_onnx 0.3.0) lib/axon_onnx/deserialize.ex:2286: AxonOnnx.Deserialize.constant!/4
    (axon_onnx 0.3.0) lib/axon_onnx/deserialize.ex:1201: AxonOnnx.Deserialize.recur_nodes/2
    (elixir 1.14.0) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    (axon_onnx 0.3.0) lib/axon_onnx/deserialize.ex:44: AxonOnnx.Deserialize.graph_to_axon/2
    (axon_onnx 0.3.0) lib/axon_onnx/deserialize.ex:27: AxonOnnx.Deserialize.to_axon/2
    iex:1: (file)

The model is an encoder-decoder transformer (whisper tiny.en). The onnx model is generated with:

python -m transformers.onnx --model=openai/whisper-tiny.en --feature=speech2seq-lm whisper-onnx/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants