You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On feature/togsim-cpp-trace, a bilinear F.interpolate emits invalid MLIR: a value defined
inside one gather's affine.for body is referenced from a later, sibling affine.for body.
Codegen aborts while the Python passes re-parse the kernel:
mlir._mlir_libs._site_initialize.<locals>.MLIRError: Unable to parse module assembly:
error: "-":186:42: use of undeclared SSA value name
Minimal repro
importtorchimporttorch.nn.functionalasFx=torch.randn(1, 8, 8, 8).to("npu:0")
f=torch.compile(dynamic=False)(
lambdat: F.interpolate(t, scale_factor=2, mode="bilinear", align_corners=False)
)
f(x) # -> MLIRError: use of undeclared SSA value name
What does and does not trigger it
case
result
x[i] (single gather)
OK
x[i0] - x[i1] (two gathers + sub)
OK
x[i0] + x[i1]
OK
F.interpolate(..., mode="nearest")
OK
F.interpolate(..., mode="bilinear")
FAIL
So two indirect gathers alone are fine. It needs the bilinear pattern, where several gathers of the same tensor are blended and one gather's loaded value is consumed after a later gather has run.
Mechanism
Two things are broken at once. From the generated kernel:
SSA scope violation.%tmp57 is defined in the first loop's region and used in a sibling
region, so the module does not parse.
Even with scoping fixed, the data would be wrong. Both indirect MVINs target the same %spad4 (only the index buffer differs: %spad3 vs %spad7), so value A has already been
overwritten by gather Scalar #2 by the time arith.subf runs.
A correct lowering has to either give each gather its own scratchpad buffer (and hoist the loaded
value so it stays live), or fuse the gather loops so both loads happen in one region.
Impact
Blocks HuggingFace SegFormer (issue #254). Running SegFormer on this branch, 10 of 1170 generated
kernels fail to parse; every one of them has >= 2 indirect MVINs writing the same scratchpad. The
decode head's bilinear upsample is the source.
Note this is not the error originally reported in #254 (NotImplementedError: Not supporting format),
which no longer reproduces. SegFormer now clears codegen for 145 kernels and all their gem5 runs
(~197 s with the functional Spike pass off), then dies here.
Related but distinct: #284 (the trace path does not model indirect access). This issue is about the
frontend emitting unparseable MLIR in the first place.
Environment
branch feature/togsim-cpp-trace
fails at PyTorchSimFrontend/mlir/passes/__init__.py:78 (Module.parse) via extension_codecache.load -> run_python_passes, i.e. before gem5/Spike, so it is pure frontend
codegen and independent of the simulator binaries.
Summary
On
feature/togsim-cpp-trace, a bilinearF.interpolateemits invalid MLIR: a value definedinside one gather's
affine.forbody is referenced from a later, siblingaffine.forbody.Codegen aborts while the Python passes re-parse the kernel:
Minimal repro
What does and does not trigger it
x[i](single gather)x[i0] - x[i1](two gathers + sub)x[i0] + x[i1]F.interpolate(..., mode="nearest")F.interpolate(..., mode="bilinear")So two indirect gathers alone are fine. It needs the bilinear pattern, where several gathers of the
same tensor are blended and one gather's loaded value is consumed after a later gather has run.
Mechanism
Two things are broken at once. From the generated kernel:
%tmp57is defined in the first loop's region and used in a siblingregion, so the module does not parse.
%spad4(only the index buffer differs:%spad3vs%spad7), so value A has already beenoverwritten by gather Scalar #2 by the time
arith.subfruns.A correct lowering has to either give each gather its own scratchpad buffer (and hoist the loaded
value so it stays live), or fuse the gather loops so both loads happen in one region.
Impact
Blocks HuggingFace SegFormer (issue #254). Running SegFormer on this branch, 10 of 1170 generated
kernels fail to parse; every one of them has >= 2 indirect MVINs writing the same scratchpad. The
decode head's bilinear upsample is the source.
Note this is not the error originally reported in #254 (
NotImplementedError: Not supporting format),which no longer reproduces. SegFormer now clears codegen for 145 kernels and all their gem5 runs
(~197 s with the functional Spike pass off), then dies here.
Related but distinct: #284 (the trace path does not model indirect access). This issue is about the
frontend emitting unparseable MLIR in the first place.
Environment
feature/togsim-cpp-tracePyTorchSimFrontend/mlir/passes/__init__.py:78(Module.parse) viaextension_codecache.load -> run_python_passes, i.e. before gem5/Spike, so it is pure frontendcodegen and independent of the simulator binaries.