Unverified Commit 16d6e308 authored by Yih-Dar's avatar Yih-Dar Committed by GitHub
Browse files

Better error message for pipeline loading (#25912)



* update

* update

* update

* update

---------
Co-authored-by: default avatarydshieh <ydshieh@users.noreply.github.com>
parent 53e2fd78
...@@ -19,6 +19,7 @@ import json ...@@ -19,6 +19,7 @@ import json
import os import os
import pickle import pickle
import sys import sys
import traceback
import types import types
import warnings import warnings
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
...@@ -248,6 +249,7 @@ def infer_framework_load_model( ...@@ -248,6 +249,7 @@ def infer_framework_load_model(
if len(class_tuple) == 0: if len(class_tuple) == 0:
raise ValueError(f"Pipeline cannot infer suitable model classes from {model}") raise ValueError(f"Pipeline cannot infer suitable model classes from {model}")
all_traceback = {}
for model_class in class_tuple: for model_class in class_tuple:
kwargs = model_kwargs.copy() kwargs = model_kwargs.copy()
if framework == "pt" and model.endswith(".h5"): if framework == "pt" and model.endswith(".h5"):
...@@ -270,10 +272,16 @@ def infer_framework_load_model( ...@@ -270,10 +272,16 @@ def infer_framework_load_model(
# Stop loading on the first successful load. # Stop loading on the first successful load.
break break
except (OSError, ValueError): except (OSError, ValueError):
all_traceback[model_class.__name__] = traceback.format_exc()
continue continue
if isinstance(model, str): 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: if framework is None:
framework = infer_framework(model.__class__) framework = infer_framework(model.__class__)
......
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