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
MLIR introduced signedness for integer types in the past year. Some passes and checks were added before it, so we actually did not handle it correctly.
E.g.,
In flow type converter, it does not handle ui64 types.
IIRC, the isSignlessIntOrFloat stuff were added by integration fixes. Now it causes issues to compile ASR models, and it's a good time to clean these up.
Yes that's because MHLO incorrectly uses signless to mean signed because integer signedness was not originally present in MLIR. So for legacy reasons signless integers in MHLO should be interpreted as signed, but that's something that really needs to be fixed.
MHLO -> linalg now handles unsigned types at a basic level. IREE itself uses signless ints, but this new conversion of ui64->i32 is happening before dispatch region formation (which is why we're still seeing unsigned). Once we switch entirely to linalg-on-tensors this should be easier to cleanup. For now though, this is doing more than just silently truncating (which is already not great). It's also silently converting unsigned to signed, effectively, because this is still happening on MHLO where signless means signed. This means that the op created would be an signed instead of an unsigned variant. Stuff gets weird and this is likely going to result in some confusing bug.
I don't think that's right though. At least, it's not enforced by the verifier. My understanding is that std.constant is supposed to support any type, which I assume would include [un]signed integers. You hit an assert printing such a constant though.
Ok my take on std.constant was wrong. It does indeed require signless integers. This is just a bug in the lowering of mhlo.dynamic-slice to std.subtensor though, I think. It's assuming signed (aka signless)
/tmp/repro.mlir:428:12: error: expected result element type to be 'i64'
%388 = "mhlo.dynamic-slice"(%364, %387) {slice_sizes = dense<1> : tensor<1xi64>} : (tensor<3xui64>, tensor) -> tensor
^
/tmp/repro.mlir:428:12: note: see current operation: %639 = "std.subtensor"(%632, %638) {operand_segment_sizes = dense<[1, 1, 0, 0]> : vector<4xi32>, static_offsets = [-9223372036854775808], static_sizes = [1], static_strides = [1]} : (tensor<3xi64>, index) -> tensor
I think we still use our own lowering for concatenate op. I did not know that there is a version in MHLO repo. I suspect that MHLO's one has some issues that I hit before. I will take a look and raise the issue to MHLO folks if that is the case. Everything looks good in IREE now. :)
I think we still use our own lowering for concatenate op. I did not know that there is a version in MHLO repo. I suspect that MHLO's one has some issues that I hit before. I will take a look and raise the issue to MHLO folks if that is the case. Everything looks good in IREE now. :)
Yeah I think I looked at using it briefly and there was some issue I hit (should've written it down). Should be easy to repro though by just removing our pattern
Activity
Legalize ui64 to i32 in Flow type converter (#5384)
GMNGeoffrey commentedon Apr 9, 2021
I think we're trying to lower some very similar models here :-P I just hit the same issue of unhandled unsigned types in linalg. See some discussion in https://discord.com/channels/689900678990135345/689932666505920596/830177574096207892
hanhanW commentedon Apr 12, 2021
After talking to @antiagainst , we found that there are unsigned integers and signless integers in the model. I don't see
si[0-9]in the MLIR files.GMNGeoffrey commentedon Apr 12, 2021
Yes that's because MHLO incorrectly uses signless to mean signed because integer signedness was not originally present in MLIR. So for legacy reasons signless integers in MHLO should be interpreted as signed, but that's something that really needs to be fixed.
GMNGeoffrey commentedon May 4, 2021
MHLO -> linalg now handles unsigned types at a basic level. IREE itself uses signless ints, but this new conversion of ui64->i32 is happening before dispatch region formation (which is why we're still seeing unsigned). Once we switch entirely to linalg-on-tensors this should be easier to cleanup. For now though, this is doing more than just silently truncating (which is already not great). It's also silently converting unsigned to signed, effectively, because this is still happening on MHLO where signless means signed. This means that the op created would be an signed instead of an unsigned variant. Stuff gets weird and this is likely going to result in some confusing bug.
GMNGeoffrey commentedon May 4, 2021
The rationale for converting unsigned to signless is that std.constant doesn't support unsigned.
https://github.com/google/iree/blob/0b3289aea9fcea8d0e00117045a1256fdddb93f7/iree/compiler/Dialect/Flow/Conversion/TypeConverter.cpp#L41-L51
I don't think that's right though. At least, it's not enforced by the verifier. My understanding is that std.constant is supposed to support any type, which I assume would include [un]signed integers. You hit an assert printing such a constant though.
Sent https://reviews.llvm.org/D101810 to clean that up
GMNGeoffrey commentedon May 4, 2021
Ok my take on std.constant was wrong. It does indeed require signless integers. This is just a bug in the lowering of mhlo.dynamic-slice to std.subtensor though, I think. It's assuming signed (aka signless)
GMNGeoffrey commentedon May 4, 2021
Sent a patch to fix the lowering. Now hitting the same issue with mhlo.concatenate. I'm just going to fix these and we can hopefully remove this hack
GMNGeoffrey commentedon May 4, 2021
Fixing in upstream MHLO is not hard. For some reason IREE has its own pattern for concat as well though
GMNGeoffrey commentedon May 4, 2021
tensorflow/tensorflow@55338bb for dynamic-slice
GMNGeoffrey commentedon May 4, 2021
tensorflow/tensorflow@6adc0d0 for concatenate (except apparently we actually use our own concatenate lowering)
Add unsigned support for lowering mhlo concatenate and constant (#5736)
Don't drop signedness semantics when narrowing 64-bit ints (#5738)
hanhanW commentedon May 11, 2021
Thanks for working on this!
I think we still use our own lowering for concatenate op. I did not know that there is a version in MHLO repo. I suspect that MHLO's one has some issues that I hit before. I will take a look and raise the issue to MHLO folks if that is the case. Everything looks good in IREE now. :)
GMNGeoffrey commentedon May 11, 2021
Yeah I think I looked at using it briefly and there was some issue I hit (should've written it down). Should be easy to repro though by just removing our pattern