MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / sum_op_stats

Function sum_op_stats

imperative/python/megengine/utils/module_stats.py:257–279  ·  view source on GitHub ↗
(flops, bar_length_max=20)

Source from the content-addressed store, hash-verified

255
256
257def 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
282def print_op_stats(flops):

Callers 2

visualizeFunction · 0.90
module_statsFunction · 0.85

Calls 5

maxFunction · 0.85
sizeof_fmtFunction · 0.85
sumFunction · 0.85
formatMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected