When attempting to convert a GPT-2 model through StableHLO, I hit an issue with the fuse optimization for the power operation.
In the current form, it attempts to check if the exponent is 2, and if so, applies some optimizations. However, the check assumes the provided array is a scalar, which may not be the case.
I have added two tests illustrating the problem, and proposed a fix.
Without the fix, the new tests fail with the following errors:
FAILED coremltools/converters/mil/backend/mil/passes/test_passes.py::TestPassFusePow2Sqrt::test_fuse_multiple_exponents - ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
FAILED coremltools/converters/mil/backend/mil/passes/test_passes.py::TestPassFusePow2Sqrt::test_no_fuse_multiple_exponents - ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
When attempting to convert a GPT-2 model through StableHLO, I hit an issue with the fuse optimization for the power operation.
In the current form, it attempts to check if the exponent is 2, and if so, applies some optimizations. However, the check assumes the provided array is a scalar, which may not be the case.
I have added two tests illustrating the problem, and proposed a fix.
Without the fix, the new tests fail with the following errors: