|
|
@ -14,6 +14,7 @@ __all__ = ["avgpool_meta_info", "maxpool_meta_info"]
|
|
|
|
@meta_register.register(torch.nn.AdaptiveAvgPool1d)
|
|
|
|
@meta_register.register(torch.nn.AdaptiveAvgPool1d)
|
|
|
|
@meta_register.register(torch.nn.AdaptiveAvgPool2d)
|
|
|
|
@meta_register.register(torch.nn.AdaptiveAvgPool2d)
|
|
|
|
@meta_register.register(torch.nn.AdaptiveAvgPool3d)
|
|
|
|
@meta_register.register(torch.nn.AdaptiveAvgPool3d)
|
|
|
|
|
|
|
|
@meta_register.register(torch.flatten)
|
|
|
|
def avgpool_meta_info(*args, **kwargs) -> Tuple[TrainCycleItem, TrainCycleItem, List[torch.Tensor]]:
|
|
|
|
def avgpool_meta_info(*args, **kwargs) -> Tuple[TrainCycleItem, TrainCycleItem, List[torch.Tensor]]:
|
|
|
|
"""Meta info for AdaptiveAvgPool
|
|
|
|
"""Meta info for AdaptiveAvgPool
|
|
|
|
The aten graph of AdaptiveAvgPool is
|
|
|
|
The aten graph of AdaptiveAvgPool is
|
|
|
@ -32,6 +33,7 @@ def avgpool_meta_info(*args, **kwargs) -> Tuple[TrainCycleItem, TrainCycleItem,
|
|
|
|
|
|
|
|
|
|
|
|
input_tensor = args[0].data
|
|
|
|
input_tensor = args[0].data
|
|
|
|
output_tensor = next(filter(lambda x: x.type == OperationDataType.OUTPUT, args)).data
|
|
|
|
output_tensor = next(filter(lambda x: x.type == OperationDataType.OUTPUT, args)).data
|
|
|
|
|
|
|
|
is_inplace = kwargs.get("inplace", False)
|
|
|
|
|
|
|
|
|
|
|
|
# construct forward args for flop mapping
|
|
|
|
# construct forward args for flop mapping
|
|
|
|
fwd_in_args = [input_tensor]
|
|
|
|
fwd_in_args = [input_tensor]
|
|
|
@ -51,8 +53,8 @@ def avgpool_meta_info(*args, **kwargs) -> Tuple[TrainCycleItem, TrainCycleItem,
|
|
|
|
compute_cost = TrainCycleItem(fwd=fwd_compute_cost, bwd=bwd_compute_cost, total=fwd_compute_cost + bwd_compute_cost)
|
|
|
|
compute_cost = TrainCycleItem(fwd=fwd_compute_cost, bwd=bwd_compute_cost, total=fwd_compute_cost + bwd_compute_cost)
|
|
|
|
|
|
|
|
|
|
|
|
# calculate memory cost
|
|
|
|
# calculate memory cost
|
|
|
|
fwd_mem_cost = MemoryCost(activation=activation_size(output_tensor))
|
|
|
|
fwd_mem_cost = MemoryCost() if is_inplace else MemoryCost(activation=activation_size(output_tensor))
|
|
|
|
bwd_mem_cost = MemoryCost(activation=activation_size(input_tensor))
|
|
|
|
bwd_mem_cost = MemoryCost() if is_inplace else MemoryCost(activation=activation_size(input_tensor))
|
|
|
|
|
|
|
|
|
|
|
|
# total cost
|
|
|
|
# total cost
|
|
|
|
total_mem_cost = MemoryCost(activation=fwd_mem_cost.activation + bwd_mem_cost.activation)
|
|
|
|
total_mem_cost = MemoryCost(activation=fwd_mem_cost.activation + bwd_mem_cost.activation)
|
|
|
|