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

Add support for ONNX type and tag broadcasting #2919

Merged
merged 4 commits into from
May 31, 2024

Conversation

RunDevelopment
Copy link
Member

@RunDevelopment RunDevelopment commented May 29, 2024

Closes #1370

This adds support for type and tag broadcasting for all ONNX models. While we did have type broadcasting for ONNX models before, those broadcasts did not contain much information. Now they contain the model's input/output channels and scale, just like for PyTorch and NCNN models. This finally allows us to compute output types for ONNX's Upscale Image node.

A model's input/output channels and scale(s) are detected using onnx.shape_inference [1] [2]. This allows us to statically determine the shape of the output tensor for a given input tensor shape without actually running the model (=no inference session). While this is roughly 10-100x faster than creating an ort.InferenceSession, it's still not free. Loading generic ONNX models will now take roughly 3-4x longer. This might sound bad, but it's not. E.g. an ESRGAN ONNX model previously took 0.11s and now it takes 0.38s. A lot slower, but not a problem.

image
image


Changes:

  • Extract out loading ONNX models into its own file. This ensures that the type definitions for ONNX models don't depend on the ONNX package.
  • Store ONNX model information in new OnnxInfo class.
  • Removed is_rembg_model function, because it wasn't necessary.
  • Refactored create_inference_session.

@joeyballentine joeyballentine merged commit 842fa93 into chaiNNer-org:main May 31, 2024
17 checks passed
@RunDevelopment RunDevelopment deleted the onnx-broadcasting branch May 31, 2024 10:58
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

Successfully merging this pull request may close these issues.

Add broadcasting to ONNX models
2 participants