diff --git a/src/transformers/modeling_utils.py b/src/transformers/modeling_utils.py index 697b3deb14d7ec..901677a604ddcc 100644 --- a/src/transformers/modeling_utils.py +++ b/src/transformers/modeling_utils.py @@ -2563,7 +2563,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P elif device_map in ["balanced", "balanced_low_0"] and get_balanced_memory is None: raise ValueError(f"`device_map={device_map}` requires a source install of Accelerate.") - kwargs = {"no_split_module_classes": no_split_modules, "max_memory": max_memory} + kwargs = {"no_split_module_classes": no_split_modules} if "special_dtypes" in inspect.signature(infer_auto_device_map).parameters: kwargs["special_dtypes"] = special_dtypes elif len(special_dtypes) > 0: @@ -2578,6 +2578,7 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P low_zero=(device_map == "balanced_low_0"), **kwargs, ) + kwargs["max_memory"] = max_memory # Make sure tied weights are tied before creating the device map. model.tie_weights() device_map = infer_auto_device_map(model, dtype=torch_dtype if not load_in_8bit else torch.int8, **kwargs)