Skip to content

Commit

Permalink
use apply rather than recursion
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
  • Loading branch information
kylesayrs committed Dec 19, 2024
1 parent 38d7dbf commit df3e186
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/compressed_tensors/utils/offload.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def delete_offload_parameter(module: torch.nn.Module, name: str):

@check_accelerate(fallback=contextlib.nullcontext())
@contextlib.contextmanager
def disable_hf_hook(module: torch.nn.Module, recurse: bool = False):
def disable_hf_hook(module: torch.nn.Module):
hooks = {}

def collect_hooks(module):
Expand All @@ -244,10 +244,7 @@ def collect_hooks(module):
hooks[module] = module._hf_hook
remove_hook_from_module(module)

for submodule in module.children():
collect_hooks(submodule)

collect_hooks(module)
module.apply(collect_hooks)

yield

Expand Down

0 comments on commit df3e186

Please sign in to comment.