MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / add_hooks

Function add_hooks

PATH/helper/flops_helper.py:53–70  ·  view source on GitHub ↗
(m)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected