Skip to content

fix(export): onnx export issue#3554

Open
ashwinvaidya17 wants to merge 2 commits intoopen-edge-platform:mainfrom
ashwinvaidya17:ashwin/fix/anomalib_studio_setup
Open

fix(export): onnx export issue#3554
ashwinvaidya17 wants to merge 2 commits intoopen-edge-platform:mainfrom
ashwinvaidya17:ashwin/fix/anomalib_studio_setup

Conversation

@ashwinvaidya17
Copy link
Copy Markdown
Contributor

📝 Description

✨ Changes

Select what type of change your PR is:

  • 🚀 New feature (non-breaking change which adds functionality)
  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🔄 Refactor (non-breaking change which refactors the code base)
  • ⚡ Performance improvements
  • 🎨 Style changes (code style/formatting)
  • 🧪 Tests (adding/modifying tests)
  • 📚 Documentation update
  • 📦 Build system changes
  • 🚧 CI/CD configuration
  • 🔧 Chore (general maintenance)
  • 🔒 Security update
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)

✅ Checklist

Before you submit your pull request, please make sure you have completed the following steps:

  • 📚 I have made the necessary updates to the documentation (if applicable).
  • 🧪 I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).
  • 🏷️ My PR title follows conventional commit format.

For more information about code review checklists, see the Code Review Checklist.

Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>
Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>
Copilot AI review requested due to automatic review settings April 21, 2026 13:19
@ashwinvaidya17 ashwinvaidya17 changed the title fix onnx export issue fix(export): onnx export issue Apr 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates anomalib’s ONNX/OpenVINO export path to better handle PyTorch 2.9+ behavior (notably the torch.onnx.export dynamo exporter), adds targeted regression tests, and relaxes PyTorch version constraints to unblock newer Python/PyTorch combinations.

Changes:

  • Add export utility helpers to resolve dynamo defaults, translate dynamic_axesdynamic_shapes, and raise an actionable error when onnxscript is missing.
  • Update ExportMixin.to_onnx to support dynamo export while keeping the legacy exporter as default (with deprecation warning).
  • Relax PyTorch upper bounds in optional dependency groups and add unit tests covering the new export behavior.

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/anomalib/models/components/base/export_mixin/mixin.py Switch ONNX export logic to explicitly control dynamo, handle dynamic_shapes, and centralize helpers.
src/anomalib/models/components/base/export_mixin/utils.py New helper functions for export flag resolution, validation, dynamic-shape translation, and export-root creation.
src/anomalib/models/components/base/export_mixin/__init__.py Adds package export for ExportMixin.
tests/unit/deploy/test_export_mixin.py New unit tests asserting default legacy behavior, dynamo behavior, translation logic, and actionable onnxscript errors.
pyproject.toml Remove torch<=2.8.0 caps for several extras to allow newer torch versions.
CHANGELOG.md Document legacy exporter deprecation and dynamo-related export fixes under Unreleased.
Comments suppressed due to low confidence (2)

src/anomalib/models/components/base/export_mixin/mixin.py:1

  • The copyright header was changed from a prior year to a single "2026" year. For modified files, the repo commonly uses a year range (e.g., src/anomalib/engine/engine.py:1 uses 2024-2026). Please update this header to reflect the original + current year range (e.g., 2024-2026) instead of only 2026.
    src/anomalib/models/components/base/export_mixin/mixin.py:131
  • **kwargs: dict[str, Any] is not the correct typing for **kwargs. This annotation means each individual kwarg value must be a dict[str, Any], which is not what torch.onnx.export accepts and will confuse type-checkers. Please change this to **kwargs: Any (or a more specific set of explicit keyword parameters if you want stronger typing).

Comment on lines +69 to +84
def validate_input_names(input_names: object) -> list[str]:
"""Validate ONNX input names.

Args:
input_names (object): Candidate input names value.

Returns:
list[str]: Validated input names.

Raises:
TypeError: If input names are not a list of strings.
"""
if isinstance(input_names, list) and all(isinstance(name, str) for name in input_names):
return input_names
msg = "input_names must be a list of strings"
raise TypeError(msg)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate_input_names only accepts list[str], but torch.onnx.export accepts any Sequence[str] for input_names. This is a breaking behavior change for callers that previously passed a tuple (or other sequence). Consider accepting Sequence[str] (and converting to list[str] internally) to keep the public API flexible while still validating element types.

Copilot uses AI. Check for mistakes.
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.

❓ <title>Anomalib Studio setup

2 participants