MCPcopy Create free account
hub / github.com/MuLabPKU/TransArch / make_hook

Function make_hook

GQLA_preprint/src/compression.py:126–132  ·  view source on GitHub ↗
(li)

Source from the content-addressed store, hash-verified

124 final_hiddens: list[torch.Tensor] | None = [] if capture_final else None
125
126 def make_hook(li):
127 def _hook(_m, args, kwargs):
128 x = kwargs.get("hidden_states") if kwargs else None
129 if x is None and args:
130 x = args[0]
131 captured[li].append(x.detach().to("cpu"))
132 return _hook
133
134 def _final_hook(_m, args, kwargs):
135 x = kwargs.get("hidden_states") if kwargs else None

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected