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_nested_hook #3289

Merged
merged 1 commit into from
Dec 11, 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
12 changes: 6 additions & 6 deletions tests/test_accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,15 @@ def test_save_model_with_stateful_dataloader(self, use_safetensors, tied_weights

@require_cuda
@require_huggingface_suite
def test_nested_hook(self, use_safetensors):
def test_nested_hook(self):
from transformers.modeling_utils import PretrainedConfig, PreTrainedModel

class MyLinear(torch.nn.Module):
def __init__(self, device=None, dtype=None):
factory_kwargs = {"device": device, "dtype": dtype}
super().__init__()
self.centroid = torch.nn.Embedding(1, 2)
self.indices = torch.nn.parameter(torch.empty((1, 2, 2), **factory_kwargs))
self.indices = torch.nn.Parameter(torch.empty((1, 2, 2), **factory_kwargs))

def forward(self, x):
orig_shape = x.shape
Expand Down Expand Up @@ -821,7 +821,7 @@ def forward(self, x):
offload_folder=offload_folder,
preload_module_classes=["MyLinear"],
)
# before fix, this would raise an error
# weight is on the meta device, we need a `value` to put in on 0
x = torch.randn(1, 2)
my_model(x)
# before fix, this would raise an error
# weight is on the meta device, we need a `value` to put in on 0
x = torch.randn(1, 2)
my_model(x)
Loading