"...git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "4c729bf3c668ad88b2a8ecc9dd77680962e3a41a"
Unverified Commit f0dde601 authored by Stas Bekman's avatar Stas Bekman Committed by GitHub
Browse files

[model.from_pretrained] raise exception early on failed load (#12574)




* [model.from_pretrained] raise exception early on failed load

Currently if `load` pretrained weights fails in `from_pretrained`, we first print a whole bunch of successful messages and then fail - this PR puts the exception first to avoid all the misleading messages.

* style
Co-authored-by: default avatarSuraj Patil <surajp815@gmail.com>
parent 75e63dbf
......@@ -1431,6 +1431,10 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix
load(model_to_load, prefix=start_prefix)
if len(error_msgs) > 0:
error_msg = "\n\t".join(error_msgs)
raise RuntimeError(f"Error(s) in loading state_dict for {model.__class__.__name__}:\n\t{error_msg}")
if len(unexpected_keys) > 0:
logger.warning(
f"Some weights of the model checkpoint at {pretrained_model_name_or_path} were not used when "
......@@ -1454,9 +1458,6 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin, PushToHubMix
f"If your task is similar to the task the model of the checkpoint was trained on, "
f"you can already use {model.__class__.__name__} for predictions without further training."
)
if len(error_msgs) > 0:
error_msg = "\n\t".join(error_msgs)
raise RuntimeError(f"Error(s) in loading state_dict for {model.__class__.__name__}:\n\t{error_msg}")
return model, missing_keys, unexpected_keys, error_msgs
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment