Conversation
…c sizes Two input-unpacking paths in the Resize converter rejected graphs that PyTorch emits for `F.interpolate(size=...)`: - At opset <= 12 the exporter passes `roi` and `scales` as empty constant tensors rather than omitting them, so the "only one of scales and sizes" assertion fired even though scales was effectively absent. Treat a zero-element constant as a missing input. - With a dynamic batch dimension the `sizes` input is built as Concat(Shape(x)[:2], spatial) and reaches the converter as a ShapeExpr whose leading entries are symbolic, so `int(val.value)` raised AttributeError on a tir.Var. Only the spatial entries are used, and the relax resize ops accept symbolic extents there, so keep non-constant entries as PrimExprs instead of forcing them to int. Add tests for both patterns, including spatial sizes taken from another input's symbolic shape.
Member
|
@tvm-bot rerun |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Models exported from PyTorch with
F.interpolate(x, size=...)currently fail to import throughfrom_onnx, and the failure comes from how the Resize converter unpacks its optional inputs rather than from the resize itself. There are two separate triggers.At opset 12 and below, the PyTorch exporter does not omit
roiandscaleswhensizesis used; it passes them as empty constant tensors. The converter only treated a missing input as "not provided", so it saw bothscalesandsizesand failed theOnly one of scales and sizes can be provided in Resizeassertion. The ONNX spec treats an empty tensor here the same as an omitted input, so this PR maps zero-element constants toNonebefore the check.At opset 13 and above, when the model has a dynamic batch dimension, the exporter builds
sizesasConcat(Shape(x)[:2], [H_out, W_out]). That reaches the converter as aShapeExprwhose leading entries are symbolic, andint(val.value)raisedAttributeError: 'Var' object has no attribute 'value'. Only the spatial entries are used, andrelax.op.image.resize2d/resize3dalready accept symbolic output extents, so the converter now keeps non-constant entries asPrimExprs instead of forcing them to Python ints. As a side effect, resizing to another tensor's runtime height and width (sizes taken from a symbolicShape) also imports.A minimal reproduction:
The new tests cover the empty-
scalespattern with static and symbolic batch,sizescomputed fromShape(x)with a symbolic batch, and spatial sizes taken from a second input with symbolic height and width. Each checks the imported output shape and compares against onnxruntime; all four fail without this change. I also checked PyTorch exports of nearest and bilinearF.interpolateat opsets 11, 13 and 17 with batch sizes 1 and 3, which match onnxruntime to within 2.4e-7.