While working on an integration, I found a lot of inconsistencies on IR printing and verification. It turns out that we were:
- Only doing "soft fail" verification on IR printing of Operation, not of a Module.
- Failed verification was interacting badly with binary=True IR printing (causing a TypeError trying to pass an str to a bytes based handle).
- For systematic integrations, it is often desirable to control verification yourself so that you can explicitly handle errors.
This patch:
- Trues up the "soft fail" semantics by having Module.__str__ delegate to Operation.__str__ vs having a shortcut implementation.
- Fixes soft fail in the presence of binary=True (and adds an additional happy path test case to make sure the binary functionality works).
- Adds an assume_verified boolean flag to the print/get_asm methods which disables internal verification, presupposing that the caller has taken care of it.
It turns out that we had a number of tests which were generating illegal IR but it wasn't being caught because they were doing a print on the Module vs operation. All except two were trivially fixed:
- linalg/ops.py : Had two tests for direct constructing a Matmul incorrectly. Fixing them made them just like the next two tests so just deleted (no need to test the verifier only at this level).
- linalg/opdsl/emit_structured_generic.py : Hand coded conv and pooling tests appear to be using illegal shaped inputs/outputs, causing a verification failure. I just used the assume_verified= flag to restore the original behavior and left a TODO. Will get someone who owns that to fix it properly in a followup (would also be nice to break this file up into multiple test modules as it is hard to tell exactly what is failing).
Notes to downstreams:
- If, like some of our tests, you get verification failures after this patch, it is likely that your IR was always invalid and you will need to fix the root cause. To temporarily revert to prior (broken) behavior, replace calls like print(module) with print(module.operation.get_asm(assume_verified=True)).