How to get number of MAC counts from IRModule

Hi All, I know there is a function (get_total_mac_number), but my model is in IRModule type.
This function (get_total_mac_number) accepts input as Relay Expr. So how can I get the number of macs in IRModule? Or how can I convert IRModule back to Relay Expr so that I can use get_total_mac_number function?

compute_count = analysis.get_total_mac_number(func)

Thanks.

@jmatai1

Assuming mod is of type IRModule. mod[“main”] extracts RelayExpr from IRModule. You can use following expression to get the compute.

compute_count = analysis.get_total_mac_number(mod["main"])

Thanks @mak

Here is how I get the MAC counts.

func = run_opt_pass(mod["main"], relay.transform.InferType())
compute_count = relay.analysis.get_total_mac_number(func)

However, it is Warning me that it counts MACs in only certain operations. Is there a way to calculate MAC for the whole IRModule?

 This pass only counts MACs in direct conv2d, conv2d_transpose, dense, and batch_matmul ops
compute_count

This is two separate questions.

If you want to make sure the calculation covers the whole IRModule, you can just run this pass to each function in the module.

The warning you got indicates that this pass only cares those ops when calculating the MACs. This is because only those ops have MAC computation. In case you find any uncover op that includes MAC, you are welcome to file a PR to improve the get_total_mac_number.