Skip to content

Commit

Permalink
Better error message for pipeline loading (huggingface#25912)
Browse files Browse the repository at this point in the history
* update

* update

* update

* update

---------

Co-authored-by: ydshieh <[email protected]>
  • Loading branch information
2 people authored and parambharat committed Sep 26, 2023
1 parent 5ae5e90 commit 292a6ad
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/transformers/pipelines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os
import pickle
import sys
import traceback
import types
import warnings
from abc import ABC, abstractmethod
Expand Down Expand Up @@ -248,6 +249,7 @@ def infer_framework_load_model(
if len(class_tuple) == 0:
raise ValueError(f"Pipeline cannot infer suitable model classes from {model}")

all_traceback = {}
for model_class in class_tuple:
kwargs = model_kwargs.copy()
if framework == "pt" and model.endswith(".h5"):
Expand All @@ -270,10 +272,16 @@ def infer_framework_load_model(
# Stop loading on the first successful load.
break
except (OSError, ValueError):
all_traceback[model_class.__name__] = traceback.format_exc()
continue

if isinstance(model, str):
raise ValueError(f"Could not load model {model} with any of the following classes: {class_tuple}.")
error = ""
for class_name, trace in all_traceback.items():
error += f"while loading with {class_name}, an error is thrown:\n{trace}\n"
raise ValueError(
f"Could not load model {model} with any of the following classes: {class_tuple}. See the original errors:\n\n{error}\n"
)

if framework is None:
framework = infer_framework(model.__class__)
Expand Down

0 comments on commit 292a6ad

Please sign in to comment.