Skip to content

Materialize the DFT axis default when converting opset 19 to 20 - #3023

Merged
Justin Chu (justinchuby) merged 2 commits into
microsoft:mainfrom
MohammedAlkindi:fix/dft-axis-default
Sep 1, 2026
Merged

Materialize the DFT axis default when converting opset 19 to 20#3023
Justin Chu (justinchuby) merged 2 commits into
microsoft:mainfrom
MohammedAlkindi:fix/dft-axis-default

Conversation

@MohammedAlkindi

Copy link
Copy Markdown
Contributor

Opset 19 defines DFT axis as an attribute defaulting to 1. Opset 20 moved it to an input defaulting to -2. dft_19_20 read the attribute with a None default and returned early when it was absent, so the node was left untouched while the model opset was bumped. For any input of rank greater than 3 the converted model silently computes a different transform.

Measured on a rank-4 input with no axis attribute, numpy as ground truth, at the parent commit:

converted DFT inputs: ['input_x']
opset-19 result == numpy fft(axis=1): True
opset-20 result == numpy fft(axis=2): True
max abs diff: 4.825716018676758

onnx 1.22.0's own converter emits an axis Constant of 1 for this model, so the fix makes onnxscript agree with it.

The existing DFT tests all set axis explicitly, so the default path was never exercised. The added test omits it and fails on the unpatched source with 1 != 3.

version_converter, optimizer and rewriter: 573 passed, 2 skipped, 6 xfailed.

The None guard stays: _get_int_attribute also returns None for a wrongly-typed attribute. Open PR #2941 changes only the @register decorator on this function, so the two do not overlap.

Opset 19 defines DFT axis as an attribute defaulting to 1. Opset 20 moved it to an input defaulting to -2. dft_19_20 read the attribute with a None default and returned early when it was absent, so the node was left untouched while the model opset was bumped, silently retargeting the transform from axis 1 to axis -2 for any input of rank greater than 3.

The None guard is kept because _get_int_attribute also returns None for an attribute of unexpected type.

@justinchuby Justin Chu (justinchuby) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@justinchuby

Copy link
Copy Markdown
Collaborator

Mohammed Alkindi (@MohammedAlkindi) could you please fix lint

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.65%. Comparing base (3ba2bf7) to head (a33e8bf).

Files with missing lines Patch % Lines
onnxscript/version_converter/_version_converter.py 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3023   +/-   ##
=======================================
  Coverage   72.64%   72.65%           
=======================================
  Files         265      265           
  Lines       32251    32260    +9     
  Branches     3050     3050           
=======================================
+ Hits        23429    23438    +9     
  Misses       7786     7786           
  Partials     1036     1036           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@MohammedAlkindi

Copy link
Copy Markdown
Contributor Author

Lint is fixed and pushed as a33e8bf. It was one duplicate blank line in _version_converter_test.py. With the repo's pinned ruff 0.15.1, ruff format --check . now reports 378 files already formatted and ruff check onnxscript/version_converter/ passes.

On the red that remains: the three py311-torch-nightly jobs are failing on main too. Run 33344827505 on main fails exactly those three (ubuntu, macos, windows), so they look unrelated to this change. Happy to dig into them if you want.

@justinchuby
Justin Chu (justinchuby) enabled auto-merge (squash) August 31, 2026 21:29
@justinchuby Justin Chu (justinchuby) added the module: torchlib Related to the torch/aten function lib in development label Aug 31, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a semantic mismatch in the opset 19 → 20 version conversion for DFT by materializing opset-19’s default axis=1 as an explicit opset-20 axis input, preventing silent behavior changes when the axis attribute is omitted.

Changes:

  • Update dft_19_20 to treat a missing axis attribute as 1 (while still returning None for invalid/wrongly-typed attributes).
  • Always emit an explicit axis Constant input when conversion applies.
  • Add a regression test that omits the axis attribute and validates the converted node has a third input with value 1.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
onnxscript/version_converter/_version_converter.py Materializes opset-19 DFT.axis default (1) as an opset-20 axis input Constant to preserve semantics during conversion.
onnxscript/version_converter/_version_converter_test.py Adds regression coverage for converting DFT without an axis attribute and asserting the axis input is explicitly set to 1.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@MohammedAlkindi

Copy link
Copy Markdown
Contributor Author

The test (windows-latest, py311) red looks like a flake rather than the change.

It passed on 00f94a2 and fails on a33e8bf, and the only difference between those two commits is one removed blank line in _version_converter_test.py. The failures are conv2d_cpu_float16 tolerance assertions in tests/function_libs/torch_lib/ops_test.py, which whitespace in a version-converter test cannot reach.

I do not have rights to re-run the job, so it needs a nudge from your side. The three py311-torch-nightly failures are the pre-existing ones on main from earlier.

@justinchuby
Justin Chu (justinchuby) merged commit c927620 into microsoft:main Sep 1, 2026
28 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: torchlib Related to the torch/aten function lib in development

Projects

Development

Successfully merging this pull request may close these issues.

3 participants