Skip to content
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

Fix test_model_reload test #1005

Merged
merged 1 commit into from
Dec 20, 2024
Merged
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 @@ -11,7 +11,7 @@
ModelCompressor,
SparsityCompressionConfig,
is_module_offloaded,
update_parameter_data,
update_offload_parameter,
)
from loguru import logger
from safetensors.torch import storage_ptr
Expand Down Expand Up @@ -238,14 +238,15 @@ def patch_tied_tensors_bug(model: torch.nn.Module):

if storage_ptr(input_embed.weight) == storage_ptr(output_embed.weight):
for module in (input_embed, output_embed):
offloaded = is_module_offloaded(module)
if offloaded:
module._hf_hook.pre_forward(module)

update_parameter_data(module, module.weight.data.clone(), "weight")

if offloaded:
module._hf_hook.post_forward(module, None)
if not is_module_offloaded(module):
# create new storage ptr for onloaded weight
untied_data = module.weight.data.clone()
module.weight.data = untied_data
else:
# create new storage ptr for offloaded weight
# note `update_offload_parameter` does not create a new storage ptr
untied_data = module._hf_hook.weights_map["weight"].clone()
update_offload_parameter(module, "weight", untied_data)


def get_model_compressor(
Expand Down
Loading