Hooks logic

returnn.frontend.hooks.setup_post_hook_on_method(obj: Any, attr: str, hook: Callable[[T, Tuple[Any, ...], Dict[str, Any], Any], Any | None], *, prepend: bool = False) RemovableHandle[source]
  • obj – e.g. module

  • attr – attribute name to get the method, via getattr(obj, attr)

  • hook

  • prepend – if there are multiple hooks, this will be registered in front of all, otherwise at the end

class returnn.frontend.hooks.RemovableHandle(method: MethodWithHooks, hooks_dict: Dict[int, Any])[source]

A handle which provides the capability to remove a hook.

Code partly copied from PyTorch.

next_id: int = 0[source]
id: int[source]
remove() None[source]

remove hook