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: Resolve #3060, preload_module_classes is lost for nested modules #3248

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

wejoncy
Copy link

@wejoncy wejoncy commented Nov 22, 2024

What does this PR do?

We ran into this issue when try to load VPTQ models by multiple devices, the VQLinear layer has embending as its sub-module. This function should move all constant buffers/parameters to the corresponding devices from Meta device.
So add_hook_to_module should pass preload_module_classes to the next recursive calling for the nested modules.

https://github.com/microsoft/VPTQ/blob/ac7258f461e214ca705f5895513f314576750528/vptq/layers/vqlinear.py#L160C18-L160C18

This PR is to fix #3060

@wejoncy wejoncy changed the title resolve 3060 Fix: Resolve #3060 Nov 22, 2024
Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

LGTM ! Thanks for fixing ! Could you share which specific issue you where having ? Also if you can implement a test, it would be nice but not needed to merged this PR. You can fix the CI with make style

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

agreed with Marc, some more details to this issue and adding a test is needed.

@wejoncy wejoncy changed the title Fix: Resolve #3060 Fix: Resolve #3060, pre is lost for nested modules Nov 26, 2024
@wejoncy wejoncy changed the title Fix: Resolve #3060, pre is lost for nested modules Fix: Resolve #3060, preload_module_classes is lost for nested modules Nov 26, 2024
@wejoncy wejoncy changed the title Fix: Resolve #3060, preload_module_classes is lost for nested modules Fix: Resolve #3060, preload_module_classes is lost for nested modules Nov 26, 2024
@wejoncy
Copy link
Author

wejoncy commented Nov 26, 2024

Hi @muellerzr and @SunMarc Thanks for your review. I have briefly described the issue in overview of this PR.
And I will try to construct such a test case.

tests/test_accelerator.py Outdated Show resolved Hide resolved
@@ -762,3 +762,64 @@ def test_save_model_with_stateful_dataloader(self, use_safetensors, tied_weights
assert torch.allclose(original_linear1, new_linear1)
assert torch.allclose(original_batchnorm, new_batchnorm)
assert torch.allclose(original_linear2, new_linear2)

@require_cuda
Copy link
Member

@SunMarc SunMarc Nov 26, 2024

Choose a reason for hiding this comment

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

we need a require_transformers decorator if you are going to import transformers here. Otherwise, we can try to not use it and just save the model with

checkpoint = os.path.join(tmp_dir, "pt_model.bin")
torch.save(model.state_dict(), checkpoint)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

preload_module_classes is lost in attach_execution_device_hook.
4 participants