Skip to content

[Bugfix] Safeguard against submodule parameter deletion in decompress_model #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,10 @@ def compress_model(self, model: Module):

# in the future, support compression on same device
with align_module_device(module, execution_device=exec_device):
state_dict = module.state_dict(prefix=f"{prefix}.")
state_dict = {
f"{prefix}.{name}": param
for name, param in module.named_parameters(recurse=False)
}

# quantization first
if prefix in module_to_scheme:
Expand All @@ -421,7 +424,7 @@ def compress_model(self, model: Module):

# remove any existing parameters
offload_device = get_offloaded_device(module)
for name, _ in list(module.named_parameters()):
for name, _ in list(module.named_parameters(recurse=False)):
delete_offload_parameter(module, name)

# replace with compressed parameters
Expand Down Expand Up @@ -458,7 +461,10 @@ def decompress_model(self, model: Module):
if prefix in module_to_scheme or prefix in sparse_compression_targets:
# in the future, support decompression on same device
with align_module_device(module, execution_device="cpu"):
state_dict = module.state_dict(prefix=f"{prefix}.")
state_dict = {
f"{prefix}.{name}": param
for name, param in module.named_parameters(recurse=False)
}

# sparsity first
if prefix in sparse_compression_targets:
Expand All @@ -483,7 +489,7 @@ def decompress_model(self, model: Module):
# remove any existing parameters
exec_device = get_execution_device(module)
offload_device = get_offloaded_device(module)
for name, _ in list(module.named_parameters()):
for name, _ in list(module.named_parameters(recurse=False)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like we want to recurse in this case, to get all nested named parameters, but i must be missing something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of technically. A lot of this code already makes assumptions that the module being compressed is already a child module, so you're right that this probably doesn't guard against anything that wouldn't error somewhere else in this function

delete_offload_parameter(module, name)

# replace with decompressed parameters
Expand Down