Skip to content

[Bugfix][Relax] Fix IOHW batch norm folding - #20535

Open
Nanmur wants to merge 1 commit into
apache:mainfrom
Nanmur:codex/fix-fold-batchnorm-iohw
Open

Nanmur wants to merge 1 commit into
apache:mainfrom
Nanmur:codex/fix-fold-batchnorm-iohw

Conversation

@Nanmur

@Nanmur Nanmur commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #20534.

FoldBatchnormToConv2D already builds the OIHW broadcast reshape with relax.op.reshape, but the IOHW branch calls .reshape() directly on a Relax Call. This changes the IOHW branch to use the Relax reshape operator as well, preserving its (1, O, 1, 1) broadcast shape.

The regression test uses a valid IOHW Conv2D followed by BatchNorm and verifies that the pass completes, returns a well-formed module, and removes the BatchNorm call.

Testing

  • python -m pytest tests/python/relax/test_transform_fold_batch_norm_to_conv2d.py::test_fold_batchnorm_iohw_kernel_layout -q
  • pre-commit run --files python/tvm/relax/transform/fold_batch_norm_to_conv2d_for_inference.py tests/python/relax/test_transform_fold_batch_norm_to_conv2d.py

@Nanmur

Nanmur commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

The CPU failure is unrelated to this PR. The BatchNorm tests, including the IOHW regression case, passed in Jenkins; the only failure is the same WebGPU test failure present on the tested main commit (main CPU build #4125). I opened #20538 with the isolated upstream TIRx test fix. I will rerun this PR after that fix lands on main.

tqchen pushed a commit that referenced this pull request Oct 3, 2026
## Description

The grid-pack guard regression test added in #20424 uses TIRx syntax
that had already been replaced on `main`:

- #20437 removed the `s_tir=True` arguments from TIRx decorators.
- #20519 renamed the TIRx parameter annotation from `T.Buffer` to
`T.Tensor`.

As a result, the current CPU CI fails during test collection with:

```text
AttributeError: No script namespace 'Buffer'
```

This test-only change updates the new test to the current TIRx syntax.
The WebGPU test body and generated-code assertion are unchanged.

The same upstream failure is currently blocking unrelated PRs #20529 and
#20535.

## Testing

- `python -m py_compile
tests/python/codegen/test_target_codegen_webgpu.py`
- `python -m pre_commit run --files
tests/python/codegen/test_target_codegen_webgpu.py`

A matching current-`main` native library was not available locally, so
the targeted WebGPU runtime test is left to CI.
@Nanmur

Nanmur commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@tvm-bot rerun

1 similar comment
@Nanmur

Nanmur commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@tvm-bot rerun

This branch has not been deployed

No deployments
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.

[Bug][Relax] FoldBatchnormToConv2D crashes for the documented IOHW kernel layout

1 participant