(module, inputs, outputs, name="")
| 481 | recorded_parameters = set() |
| 482 | |
| 483 | def module_stats_hook(module, inputs, outputs, name=""): |
| 484 | class_name = str(module.__class__).split(".")[-1].split("'")[0] |
| 485 | if cal_flops: |
| 486 | flops_stats = get_op_stats(module, inputs, outputs) |
| 487 | if flops_stats is not None: |
| 488 | flops_stats["name"] = name |
| 489 | flops_stats["class_name"] = class_name |
| 490 | flops.append(flops_stats) |
| 491 | |
| 492 | if cal_params: |
| 493 | if ( |
| 494 | hasattr(module, "weight") |
| 495 | and (module.weight is not None) |
| 496 | and module.weight not in recorded_parameters |
| 497 | ): |
| 498 | w = module.weight |
| 499 | param_stats = get_param_stats(w) |
| 500 | param_stats["name"] = name + "-w" |
| 501 | params.append(param_stats) |
| 502 | recorded_parameters.add(w) |
| 503 | |
| 504 | if ( |
| 505 | hasattr(module, "bias") |
| 506 | and module.bias is not None |
| 507 | and module.bias not in recorded_parameters |
| 508 | ): |
| 509 | b = module.bias |
| 510 | param_stats = get_param_stats(b) |
| 511 | param_stats["name"] = name + "-b" |
| 512 | params.append(param_stats) |
| 513 | recorded_parameters.add(b) |
| 514 | |
| 515 | if cal_activations: |
| 516 | if not isinstance(outputs, (tuple, list)): |
| 517 | output = outputs |
| 518 | else: |
| 519 | output = outputs[0] |
| 520 | activation_stats = get_activation_stats(output, has_inputs) |
| 521 | activation_stats["name"] = name |
| 522 | activation_stats["class_name"] = class_name |
| 523 | activations.append(activation_stats) |
| 524 | |
| 525 | params = [] |
| 526 | flops = [] |
nothing calls this directly
no test coverage detected