(m)
| 51 | handler_collection = [] |
| 52 | |
| 53 | def add_hooks(m): |
| 54 | if len(list(m.children())) > 0: |
| 55 | return |
| 56 | |
| 57 | m.register_buffer('total_ops', torch.zeros(1)) |
| 58 | m.register_buffer('total_params', torch.zeros(1)) |
| 59 | |
| 60 | m_type = type(m) |
| 61 | fn = None |
| 62 | if m_type in register_hooks: |
| 63 | fn = register_hooks[m_type] |
| 64 | |
| 65 | if fn is None: |
| 66 | if verbose: |
| 67 | print("No implemented counting method for {} in flops_helper".format(m)) |
| 68 | else: |
| 69 | handler = m.register_forward_hook(fn) |
| 70 | handler_collection.append(handler) |
| 71 | |
| 72 | # original_device = model.parameters().__next__().device |
| 73 | training = model.training |
nothing calls this directly
no outgoing calls
no test coverage detected