4141from accelforge .model ._looptree .types import Buffet , Compute , Network
4242from accelforge .model ._looptree .reuse .symbolic .mapping_utils import (
4343 DataMovementConnections ,
44- get_tensor_to_backer_id
44+ get_tensor_to_backer_id ,
4545)
4646
4747from accelforge .mapper .FFM ._make_pmappings .pmapper_job import Job
@@ -251,7 +251,7 @@ def net_max_per_unit_write_actions(self) -> Any:
251251 @classmethod
252252 def blank (cls ):
253253 stats = cls ()
254- stats .n_loops_above = None # Inherit from whoever is added to this
254+ stats .n_loops_above = None # Inherit from whoever is added to this
255255 return stats
256256
257257
@@ -573,7 +573,9 @@ def analyze_reuse_and_add_reservations_to_mapping(
573573 tensor_to_backer_id = tensor_to_backer_id ,
574574 is_copy_operation = is_copy_operation ,
575575 job = job ,
576- data_movement_connections = DataMovementConnections .from_pmapping (cur_mapping .nodes ),
576+ data_movement_connections = DataMovementConnections .from_pmapping (
577+ cur_mapping .nodes
578+ ),
577579 )
578580 cur_result = analyze_node (0 , job .rank_variable_bounds , info )
579581 if result is None :
@@ -826,7 +828,9 @@ def handle_repeated_value(repeated_shape):
826828 accumulated_stats .n_loops_above = stats .n_loops_above + 1
827829
828830 for network , network_stats in child_result .network_stats .items ():
829- result_accumulator .network_stats [network ] = network_stats .repeat (shape_repeats )
831+ result_accumulator .network_stats [network ] = network_stats .repeat (
832+ shape_repeats
833+ )
830834
831835 for einsum , child_steps in child_result .temporal_steps .items ():
832836 if einsum not in result_accumulator .temporal_steps :
@@ -925,29 +929,31 @@ def handle_repeated_value(repeated_shape):
925929 result_accumulator .network_stats [network ] = NetworkStats ()
926930 accumulated_network_stats = result_accumulator .network_stats [network ]
927931
928- accumulated_network_stats .total_hops += \
929- child_network_stats .total_hops * shape_repeats
932+ accumulated_network_stats .total_hops += (
933+ child_network_stats .total_hops * shape_repeats
934+ )
930935 accumulated_network_stats .max_hops = max (
931936 accumulated_network_stats .max_hops ,
932937 child_network_stats .max_hops ,
933938 )
934939 projection = info .einsum_tensor_to_projection [(einsum_name , network .tensor )]
935940 component_object = find_component_object (
936- network .component ,
937- info .job .flattened_arch
941+ network .component , info .job .flattened_arch
938942 )
939943 bits_per_value_scale = component_object .bits_per_value_scale [network .tensor ]
940944 bits_per_value = (
941945 bits_per_value_scale
942- *
943- info .job .einsum .tensor_accesses [network .tensor ].bits_per_value
946+ * info .job .einsum .tensor_accesses [network .tensor ].bits_per_value
944947 )
945948 bits_per_action = component_object .bits_per_action
946949 if bits_per_action is not None :
947- actions_per_value = bits_per_value / bits_per_action
950+ actions_per_value = bits_per_value / bits_per_action
948951 else :
949952 actions_per_value = bits_per_value
950- volume = compute_dense_tile_occupancy (projection , child_shape ) * actions_per_value
953+ volume = (
954+ compute_dense_tile_occupancy (projection , child_shape )
955+ * actions_per_value
956+ )
951957
952958 if info .job .spec .arch .is_above (node .component , network .component ):
953959 continue
@@ -956,27 +962,29 @@ def handle_repeated_value(repeated_shape):
956962 last_fanout = last_fanout .get (node .name , 1 )
957963 if isinstance (relevancy , Irrelevant ):
958964 # Cost of multicasting is the cost of delivering along the dimension
959- multicast_hops = (shape_repeats - 1 ) * last_fanout
965+ multicast_hops = (shape_repeats - 1 ) * last_fanout
960966 multicast_cost = multicast_hops * volume
961967 overall_max_hops += multicast_hops
962968
963969 accumulated_network_stats .total_hops += multicast_cost
964970 accumulated_network_stats .max_hops = max (
965971 accumulated_network_stats .max_hops ,
966- overall_max_hops + child_network_stats .max_hops
972+ overall_max_hops + child_network_stats .max_hops ,
967973 )
968974 elif isinstance (relevancy , Relevant ):
969975 # Cost of unicast is the cost of delivering to each point in
970976 # the dimension with shape as stride
971977 # TODO: we should use the actual stride
972- total_unicast_cost = 0.5 * (shape_repeats - 1 )* shape_repeats * last_fanout * volume
973- max_unicast_hops = (shape_repeats - 1 )* last_fanout
978+ total_unicast_cost = (
979+ 0.5 * (shape_repeats - 1 ) * shape_repeats * last_fanout * volume
980+ )
981+ max_unicast_hops = (shape_repeats - 1 ) * last_fanout
974982 overall_max_hops += max_unicast_hops
975983
976984 accumulated_network_stats .total_hops += total_unicast_cost
977985 accumulated_network_stats .max_hops = max (
978986 accumulated_network_stats .max_hops ,
979- overall_max_hops + child_network_stats .max_hops
987+ overall_max_hops + child_network_stats .max_hops ,
980988 )
981989 elif isinstance (relevancy , PartiallyRelevant ):
982990 raise NotImplementedError ()
@@ -1256,17 +1264,15 @@ def analyze_reservation(node_idx, current_shape, info: AnalysisInfo):
12561264
12571265 # Reservation nodes are the first to produce stats for a network
12581266 network_node = info .job .spec .arch .find_first_of_type_above (
1259- NetworkSpec ,
1260- buffet .level ,
1261- default = None
1267+ NetworkSpec , buffet .level , default = None
12621268 )
12631269 if network_node is not None :
12641270 network = Network (
12651271 tensor ,
12661272 einsum_name ,
12671273 info .data_movement_connections .get_src (buffet ),
12681274 buffet ,
1269- component = network_node .name if network_node else network_node
1275+ component = network_node .name if network_node else network_node ,
12701276 )
12711277 assert network not in child_result .network_stats
12721278 child_result .network_stats [network ] = NetworkStats ()
@@ -1313,17 +1319,15 @@ def analyze_compute(
13131319 result_accumulator .buffet_stats [buffet ] = stats
13141320
13151321 network_node = info .job .spec .arch .find_first_of_type_above (
1316- NetworkSpec ,
1317- node .component ,
1318- default = None
1322+ NetworkSpec , node .component , default = None
13191323 )
13201324 if network_node is not None :
13211325 network = Network (
13221326 tensor ,
13231327 info .job .einsum_name ,
13241328 info .data_movement_connections .get_src (buffet ),
13251329 buffet ,
1326- component = network_node .name if network_node else network_node
1330+ component = network_node .name if network_node else network_node ,
13271331 )
13281332 result_accumulator .network_stats [network ] = NetworkStats ()
13291333
0 commit comments