Skip to content

Commit 9d6c227

Browse files
committed
remove hooks
Signed-off-by: Kyle Sayers <[email protected]>
1 parent a275f53 commit 9d6c227

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/llmcompressor/entrypoints/oneshot.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from llmcompressor.entrypoints.utils import post_process, pre_process
1515
from llmcompressor.pipelines import CalibrationPipeline
1616

17+
from accelerate.hooks import remove_hook_from_module
18+
1719
__all__ = ["Oneshot", "oneshot"]
1820

1921

@@ -130,6 +132,8 @@ def __init__(
130132
# TODO: consider renaming function similar to "offload_dispatch_model"
131133
# TODO: modify function to remove any hooks if they already exist (making
132134
# sure to move to cpu when removing hook
135+
# TODO: remove hook in util
136+
remove_hook_from_module(model_args.model, recurse=True)
133137
force_cpu_offload(model_args.model, model_args.oneshot_device)
134138
else:
135139
logger.warning("CUDA is not available! Compressing model on CPU instead")

src/llmcompressor/entrypoints/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
)
2828
from llmcompressor.typing import Processor
2929
from llmcompressor.utils.fsdp.helpers import is_fsdp_model
30+
from accelerate.hooks import remove_hook_from_module
3031

3132

3233
def pre_process(model_args: "ModelArguments"):
@@ -105,6 +106,9 @@ def post_process(
105106
"Ex. `oneshot(..., output_dir=...)`"
106107
)
107108

109+
# Remove any existing hooks (maybe added by oneshot sequential onloading)
110+
remove_hook_from_module(model_args.model, recurse=True)
111+
108112
# Reset the one-time-use session upon completion
109113
if recipe_args is not None and recipe_args.clear_sparse_session:
110114
reset_session()

0 commit comments

Comments
 (0)