diff --git a/python/paddle/hapi/dynamic_flops.py b/python/paddle/hapi/dynamic_flops.py index 63de7f971afe8a4c30922e1a84bfe4726858f175..35819d6b7bb555aade60c7114f0ea28c67631ac6 100644 --- a/python/paddle/hapi/dynamic_flops.py +++ b/python/paddle/hapi/dynamic_flops.py @@ -121,7 +121,7 @@ def count_convNd(m, x, y): bias_ops = 1 if m.bias is not None else 0 total_ops = int(y.numel()) * ( x.shape[1] / m._groups * kernel_ops + bias_ops) - m.total_ops += total_ops + m.total_ops += abs(int(total_ops)) def count_leaky_relu(m, x, y): @@ -135,15 +135,14 @@ def count_bn(m, x, y): nelements = x.numel() if not m.training: total_ops = 2 * nelements - - m.total_ops += int(total_ops) + m.total_ops += abs(int(total_ops)) def count_linear(m, x, y): total_mul = m.weight.shape[0] num_elements = y.numel() total_ops = total_mul * num_elements - m.total_ops += int(total_ops) + m.total_ops += abs(int(total_ops)) def count_avgpool(m, x, y): @@ -161,8 +160,7 @@ def count_adap_avgpool(m, x, y): kernel_ops = total_add + total_div num_elements = y.numel() total_ops = kernel_ops * num_elements - - m.total_ops += int(total_ops) + m.total_ops += abs(int(total_ops)) def count_zero_ops(m, x, y): @@ -173,7 +171,7 @@ def count_parameters(m, x, y): total_params = 0 for p in m.parameters(): total_params += p.numel() - m.total_params[0] = int(total_params) + m.total_params[0] = abs(int(total_params)) def count_io_info(m, x, y): diff --git a/python/paddle/hapi/static_flops.py b/python/paddle/hapi/static_flops.py index 4314633603130e44f9ad2a34181639e28448488f..3656e0c18945a6665292ceeb3f167d79505b523e 100644 --- a/python/paddle/hapi/static_flops.py +++ b/python/paddle/hapi/static_flops.py @@ -127,6 +127,7 @@ def count_convNd(op): bias_ops = 1 if len(op.inputs("Bias")) > 0 else 0 output_numel = np.product(op.outputs("Output")[0].shape()[1:]) total_ops = output_numel * (filter_ops + bias_ops) + total_ops = abs(total_ops) return total_ops @@ -138,6 +139,7 @@ def count_leaky_relu(op): def count_bn(op): output_numel = np.product(op.outputs("Y")[0].shape()[1:]) total_ops = 2 * output_numel + total_ops = abs(total_ops) return total_ops @@ -145,6 +147,7 @@ def count_linear(op): total_mul = op.inputs("Y")[0].shape()[0] numel = np.product(op.outputs("Out")[0].shape()[1:]) total_ops = total_mul * numel + total_ops = abs(total_ops) return total_ops @@ -157,12 +160,14 @@ def count_pool2d(op): kernel_ops = total_add + total_div num_elements = np.product(output_shape[1:]) total_ops = kernel_ops * num_elements + total_ops = abs(total_ops) return total_ops def count_element_op(op): input_shape = op.inputs("X")[0].shape() total_ops = np.product(input_shape[1:]) + total_ops = abs(total_ops) return total_ops