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
Tensors being hoisted to device 0 regardless of original affinity #20427
Compiling the attached MLIR (or a 2 layer toy llama) to FLOW dialect causes most (but not all) of the weights to be hoisted. However, they all appear to be hoisted by default onto device 0, even if they already had a different affinity explicitly marks.
The value of dialectAttrs is stream.affinity.default = #hal.device.affinity<@__device_0> from the enclosing module. I'm not sure if this is expected. Should util.initializers be running on the default device?
When that pass runs changes in affinity are ok - analysis should always get back to a similar result. That is to say, if you're having issues it's probably something further on and not something that needs fixing in HoistIntoGlobals. I'll see if I can take a look and identify what's going on, but if you had some IR to point me at where you're seeing what you don't expect that'll help.
AFAICT this is functioning correctly. stream.affinity.default is only used to resolve affinities when they cannot otherwise be assigned via analysis. When hoisting the new initializers capture the default that was used by the origin of the slice being hoisted so they can preserve the behavior and in this case that happens to be device 0: if no hoisting was performed from the origin function and analysis failed device 0 would be used in the same way. Once affinities are assigned all parameters seem to end up in the right place for me. If you think they aren't, please post full compile output.
(note that in the second initializer all the ops are explicitly on device 1 as intended, as analysis was able to fully resolve their affinities based on usage)
Activity
IanWood1 commentedon Jul 7, 2025
It looks like when values are hoisted they are assigned the default affinity. The new global with device 0 affinity is being created here:
iree/compiler/src/iree/compiler/Dialect/Util/Transforms/HoistIntoGlobals.cpp
Lines 290 to 295 in 3e99b2b
The value of
dialectAttrsisstream.affinity.default = #hal.device.affinity<@__device_0>from the enclosing module. I'm not sure if this is expected. Shouldutil.initializersbe running on the default device?benvanik commentedon Jul 14, 2025
When that pass runs changes in affinity are ok - analysis should always get back to a similar result. That is to say, if you're having issues it's probably something further on and not something that needs fixing in HoistIntoGlobals. I'll see if I can take a look and identify what's going on, but if you had some IR to point me at where you're seeing what you don't expect that'll help.
benvanik commentedon Jul 16, 2025
AFAICT this is functioning correctly.
stream.affinity.defaultis only used to resolve affinities when they cannot otherwise be assigned via analysis. When hoisting the new initializers capture the default that was used by the origin of the slice being hoisted so they can preserve the behavior and in this case that happens to be device 0: if no hoisting was performed from the origin function and analysis failed device 0 would be used in the same way. Once affinities are assigned all parameters seem to end up in the right place for me. If you think they aren't, please post full compile output.e.g.
(note that in the second initializer all the ops are explicitly on device 1 as intended, as analysis was able to fully resolve their affinities based on usage)