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
{{ message }}
Repository navigation
Numerical issues in integration tests in Linalg on tensors #5313
Describe the bug
There are some integration tests failed in Linalg on tensors because of numerical issue. This happens on both CPU and GPU backends.
Unfortunately, we can not debug it as before because VMLA does not work with -iree-flow-dispatch-linalg-on-tensors. And it fails on both backends. Luckily, the model file can be much smaller because we can use -iree-flow-strip-and-splat-constant-variables to strip the flow variables, and the issue can be reproduced with the faked weight model.
Generate the module in Linalg on buffers: iree-translate --iree-mlir-to-vm-bytecode-module --iree-hal-target-backends=vulkan-spirv ~/keyword_spotting_tests_mobilenet-v2.mlir -o a.vmfb
Generate the module in Linalg on tensors: iree-translate --iree-mlir-to-vm-bytecode-module --iree-hal-target-backends=vulkan-spirv ~/keyword_spotting_tests_mobilenet-v2.mlir -o b.vmfb -iree-flow-dispatch-linalg-on-tensors=true -iree-codegen-spirv-experimental-linalg-on-tensors=true
Run the first module: iree-run-module --module_file=a.vmfb --driver=vulkan --entry_function=call --function_inputs=1x16000xf32=0 and you will see twelve 0.0431243.
Run the second module: iree-run-module --module_file=b.vmfb --driver=vulkan --entry_function=call --function_inputs=1x16000xf32=0 and you will see twelve 0.0787472.
One reduction loop in the second generic op should be removed because:
In the beginning d0 -> 1, d1 -> 4, d2 -> 24, d3 -> 1, which means reduction loops are d2 and d3. Now there is no unit dim, so there should be one reduction loop.
There are two unit-extent dims d0 and d2. It is fine to drop d0, but dropping d2 is legal only if there is another reduction loop after the current reduction loop. I think we just got lucky with our e2e tests.
If you can integrate this into your patch, that would be great. If not, I will fix that upstream after your patch.
It shouldnt be too hard to fix that though. When you drop unit-dims need to check the iterator type as an extra check. You said you have a fix in progress. If you can adapt it, then thats good. If not I can fix it upstream.
If there are any failing tests now, then we need to see if those can be disabled temporarily.
Oh, did I opened the pandora box? Sorry I wasn't super clear about the full logic there; just throwed in my case as a test to the modified code and it works fine. :D
Activity
hanhanW commentedon Apr 7, 2021
I feel that this is reduction fusion issue in generic op. Narrow down the test case to
Run
build-tracy/iree/tools/iree-run-mlir b.mlir --iree-hal-target-backends=vulkan-spirv --function-input=1x24x1x4xf32=0You will get
[72 72 72 72]Run
iree-run-mlir b.mlir --iree-hal-target-backends=vulkan-spirv --function-input=1x24x1x4xf32=0 -iree-flow-dispatch-linalg-on-tensors=true -iree-codegen-spirv-experimental-linalg-on-tensors=trueYou will get
[288 288 288 288].keep looking...
hanhanW commentedon Apr 7, 2021
I probably was wrong on using generic ops that have reduction loop. Let me rethink a bit on it... #4219
hanhanW commentedon Apr 7, 2021
The issue is in
LinalgFoldUnitExtentDims.The below snippet is a bit messy, but I couldn't have a better example now.
Input:
After
-linalg-fold-unit-extent-dimsOne reduction loop in the second generic op should be removed because:
In the beginning
d0 -> 1,d1 -> 4,d2 -> 24,d3 -> 1, which means reduction loops ared2andd3. Now there is no unit dim, so there should be one reduction loop.Actually if you change the input to
You will get the right IR:
One of the unit dim is not deleted, so the iterator_types and indexing maps match the behavior.
hanhanW commentedon Apr 7, 2021
cc @MaheshRavishankar
hanhanW commentedon Apr 7, 2021
I have a quick fix for small test case, let me check if it applies to all cases.
hanhanW commentedon Apr 7, 2021
It fixes all the numerical issues under integrations/tensorflow/e2e/
Let me clean it up, add some tests and send out for review...
MaheshRavishankar commentedon Apr 7, 2021
Awesome! Thanks for looking into this. Havent studied your IR example, but will do so in a bit.
MaheshRavishankar commentedon Apr 7, 2021
I think there is a subtle issue here (and I see why your fix works). Take this reduction op
There are two unit-extent dims
d0andd2. It is fine to dropd0, but droppingd2is legal only if there is anotherreductionloop after the currentreductionloop. I think we just got lucky with our e2e tests.If you can integrate this into your patch, that would be great. If not, I will fix that upstream after your patch.
hanhanW commentedon Apr 7, 2021
No, we are not lucky, it's broken in unidirectional_lstm model in element-wise fusion (and only on dbg mode...) I feel we probably want to revert https://reviews.llvm.org/D99115 from @antiagainst ...
MaheshRavishankar commentedon Apr 7, 2021
I wonder why only debug mode. Thats weird.
It shouldnt be too hard to fix that though. When you drop unit-dims need to check the iterator type as an extra check. You said you have a fix in progress. If you can adapt it, then thats good. If not I can fix it upstream.
If there are any failing tests now, then we need to see if those can be disabled temporarily.
antiagainst commentedon Apr 7, 2021
Oh, did I opened the pandora box? Sorry I wasn't super clear about the full logic there; just throwed in my case as a test to the modified code and it works fine. :D
Reverting https://reviews.llvm.org/D99115 will cause a series of fallouts. It is used by the consumer elementwise op fusion in MobileNet. Better to fix it properly, given that Mahesh said it shouldn't be hard. We need to pay the waiting time of llvm integration anyway.
MaheshRavishankar commentedon Apr 8, 2021
Patch https://reviews.llvm.org/D100145 fixes the issue.
hanhanW commentedon Apr 9, 2021
Verified that this is fixed in llvm/llvm-project@f4eb681
It is passing on both CPU and GPU. (seems that there is an issue on SwiftShader, but it could be another issue)