LiRunGuo opened a new pull request, #20404: URL: https://github.com/apache/tvm/pull/20404
The ONNX pool converter converted every input dimension to a Python `int` in order to resolve `auto_pad=SAME_UPPER/SAME_LOWER`, so `MaxPool`, `AveragePool` and `LpPool` failed with `TypeError: int() argument must be ... not 'Var'` whenever a spatial extent was symbolic. #20398 reports this for a dynamic-width `MaxPool` taken from PP-OCR. The input extent is not actually needed in the reported case. Both SAME modes produce `ceil(input / stride)` outputs, so the total padding is `(ceil(in / s) - 1) * s + dilated_kernel - in`, which reduces to `dilated_kernel - 1` when the stride is 1. This PR computes the padding from that formula in a single helper, `Pool.get_same_pads`, which only reads an extent when the stride is greater than 1. A symbolic extent combined with a non-unit stride still cannot be expressed as a static padding attribute, so it now raises `OpAttributeUnImplemented` with a message naming the dimension, instead of the `TypeError`. Replacing the separate max-pool and avg-pool code paths with one spec-following helper also corrects two silent issues. `MaxPool` with `SAME_LOWER` derived the output extent with `floor(in / stride)` where the spec requires `ceil`, which gave wrong padding whenever the extent was not divisible by the stride. `AveragePool` ignored `dilations` when resolving `auto_pad`. Tests compare against onnxruntime for extents that are not divisible by the stride, and cover symbolic batch and width dimensions for all three ops (structurally, and numerically with a concrete input). The dilated case is checked structurally against the output shape given by ONNX shape inference, because onnxruntime ignores dilation when resolving `auto_pad` and returns a smaller output than the model's inferred shape. When the kernel is smaller than the stride the spec formula yields negative padding; the helper clamps it to zero, and this path has no onnxruntime comparison because onnxruntime rejects such models. Fixes #20398 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
