MCPcopy Create free account
hub / github.com/CERT-Lab/lora-sb / hook

Method hook

utils/offload_utils_for_quant/forward_hook.py:14–23  ·  view source on GitHub ↗
(module: torch.nn.Module, args)

Source from the content-addressed store, hash-verified

12 """
13
14 def hook(module: torch.nn.Module, args):
15 if device is not None:
16 align_device = device
17 elif len(list(module.parameters())) > 0:
18 align_device = next(module.parameters()).device
19 else:
20 align_device = "cuda"
21 module.to(align_device)
22 args = tuple(arg.to(align_device) if isinstance(arg, torch.Tensor) else arg for arg in args)
23 return args
24
25 def hook_with_kwargs(module: torch.nn.Module, args, kwargs):
26 if device is not None:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected