(flops, bar_length_max=20)
| 255 | |
| 256 | |
| 257 | def sum_op_stats(flops, bar_length_max=20): |
| 258 | max_flops_num = max([i["flops_num"] for i in flops] + [0]) |
| 259 | total_flops_num = 0 |
| 260 | for d in flops: |
| 261 | total_flops_num += int(d["flops_num"]) |
| 262 | d["flops_cum"] = sizeof_fmt(total_flops_num, suffix="OPs") |
| 263 | |
| 264 | for d in flops: |
| 265 | ratio = d["ratio"] = d["flops_num"] / total_flops_num |
| 266 | d["percentage"] = "{:.2f}%".format(ratio * 100) |
| 267 | bar_length = int(d["flops_num"] / max_flops_num * bar_length_max) |
| 268 | d["bar"] = "#" * bar_length |
| 269 | d["flops"] = sizeof_fmt(d["flops_num"], suffix="OPs") |
| 270 | |
| 271 | total_flops_str = sizeof_fmt(total_flops_num, suffix="OPs") |
| 272 | total_var_size = sum( |
| 273 | sum(s[1] if len(s) > 1 else 0 for s in d["output_shapes"]) for d in flops |
| 274 | ) |
| 275 | flops.append( |
| 276 | dict(name="total", flops=total_flops_str, output_shapes=total_var_size) |
| 277 | ) |
| 278 | |
| 279 | return total_flops_num, flops |
| 280 | |
| 281 | |
| 282 | def print_op_stats(flops): |
no test coverage detected