3131from pydantic import ConfigDict , Discriminator , Tag , computed_field
3232import sympy
3333
34- from accelforge .frontend .renames import EinsumName
34+ from accelforge .frontend .renames import EinsumName , TensorName
3535from accelforge .util ._basetypes import (
3636 # Parsing helpers for the input files.
3737 EvalableModel ,
@@ -758,6 +758,14 @@ def _consolidate_tensor_holders(self) -> None:
758758 break
759759 if isinstance (n , Loop ):
760760 break
761+ # Don't lift a storage above a storage for the same tensor
762+ if isinstance (n , TensorHolder ) and set [TensorName ](n .tensors ) & set (
763+ node .tensors
764+ ):
765+ break
766+ # Don't lift a storage above a reservation for the same tensor
767+ if isinstance (n , Reservation ) and n .purpose in node .tensors :
768+ break
761769 if not found :
762770 new_nodes .append (node )
763771 else :
@@ -781,6 +789,14 @@ def _consolidate_reservations(self) -> None:
781789 break
782790 if isinstance (n , Loop ):
783791 break
792+ # Don't lift a reservation above a reservation for the same tensor
793+ if isinstance (n , TensorHolder ) and set [TensorName ](n .tensors ) & set (
794+ node .tensors
795+ ):
796+ break
797+ # Don't lift a reservation above a storage for the same tensor
798+ if isinstance (n , Reservation ) and n .purpose in node .tensors :
799+ break
784800 if not found :
785801 new_nodes .append (node )
786802 else :
@@ -1746,8 +1762,8 @@ def einsum_names(pmapping: Nested) -> str:
17461762 mapping ._elevate_persistent_nodes_above_splits ()
17471763 mapping ._elevate_tensor_holders_above_splits ()
17481764 mapping ._propagate_backing_reservations_between_splits ()
1749- mapping ._consolidate_tensor_holders ()
1750- mapping ._consolidate_reservations ()
1765+ # mapping._consolidate_tensor_holders()
1766+ # mapping._consolidate_reservations()
17511767 mapping ._move_tensor_holders_above_reservations ()
17521768 # mapping._remove_reservations_for_tolls()
17531769 return mapping
0 commit comments