From 576755e6006108aa6a3d90f0cd228f314d6d52e1 Mon Sep 17 00:00:00 2001 From: Arthur <48595927+ArthurZucker@users.noreply.github.com> Date: Tue, 30 May 2023 17:12:14 +0200 Subject: [PATCH] [from_pretrained] imporve the error message when `_no_split_modules` is not defined (#23861) * Better warning * Update src/transformers/modeling_utils.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * format line --------- Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> --- src/transformers/modeling_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/transformers/modeling_utils.py b/src/transformers/modeling_utils.py index 38be4e736a7a09..2dbe5d43829b99 100644 --- a/src/transformers/modeling_utils.py +++ b/src/transformers/modeling_utils.py @@ -2734,7 +2734,10 @@ def from_pretrained(cls, pretrained_model_name_or_path: Optional[Union[str, os.P target_dtype = torch.int8 if model._no_split_modules is None: - raise ValueError(f"{model.__class__.__name__} does not support `device_map='{device_map}'` yet.") + raise ValueError( + f"{model.__class__.__name__} does not support `device_map='{device_map}'`. To implement support, the model" + "class needs to implement the `_no_split_modules` attribute." + ) no_split_modules = model._no_split_modules if device_map not in ["auto", "balanced", "balanced_low_0", "sequential"]: raise ValueError(