The GitHub Actions job "Lint" on tvm.git/main has failed.
Run started by GitHub user tlopex (triggered by tlopex).

Head commit for run:
d5c6f2d484264fed2ba172693a39f1b144243be6 / Ronald Nap <[email protected]>
[Relax][Frontend][ONNX] Add support for Pad mode="wrap" for opset 19 (#19827)

## Summary
The ONNX Pad operator introduced `mode="wrap"` (circular padding) in
opset 19. Currently, the Relax ONNX frontend has no support for opset
19, which raises

```text
OpAttributeInvalid(tvm.error.OpAttributeInvalid: Value wrap in attribute "mode" 
is invalid for operator Pad.
```
## Changes
Add opset 19 handling to the Pad converter that dispatches `mode="wrap"`
to topi.nn.circular_pad, which already implements circular padding but
was never wired up to the ONNX frontend. Existing behavior for earlier
Pad opsets is unchanged.

## Reproduce
```python
import numpy as np
import onnx
from onnx import TensorProto, helper, numpy_helper

import tvm
from tvm import relax
from tvm.relax.frontend.onnx import from_onnx

def make_model():
    x = helper.make_tensor_value_info("input", TensorProto.FLOAT, [1, 3, 4])
    y = helper.make_tensor_value_info("output", TensorProto.FLOAT, [1, 3, 8])

    pads = numpy_helper.from_array(
        np.array([0, 0, 2, 0, 0, 2], dtype=np.int64),
        name="pads",
    )

    node = helper.make_node(
        "Pad",
        inputs=["input", "pads"],
        outputs=["output"],
        mode="wrap",
    )

    graph = helper.make_graph([node], "pad_wrap_graph", [x], [y], 
initializer=[pads])
    model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 
19)])
    onnx.checker.check_model(model)
    return model

def run_tvm(model, x_np):
    mod = from_onnx(model, shape_dict={"input": list(x_np.shape)})

    target = tvm.target.Target("llvm")
    dev = tvm.cpu(0)

    with tvm.transform.PassContext(opt_level=3):
        ex = relax.build(mod, target)

    vm = relax.VirtualMachine(ex, dev)
    out = vm["main"](tvm.runtime.tensor(x_np, dev))
    return out.numpy() if hasattr(out, "numpy") else out.asnumpy()

x_np = np.array(
    [[[1, 2, 3, 4],
      [5, 6, 7, 8],
      [9, 10, 11, 12]]],
    dtype=np.float32,
)

expected = np.pad(x_np, [[0, 0], [0, 0], [2, 2]], mode="wrap")
actual = run_tvm(make_model(), x_np)

print("Expected:")
print(expected[0])
print("Actual:")
print(actual[0])
print("Matches expected:", np.allclose(actual, expected))
```

Report URL: https://github.com/apache/tvm/actions/runs/29054374974

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to