File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,12 @@ def create_model_instance(self, load_model=True):
104104 model .load_model ()
105105 return model
106106
107+ def create_error_model_instance (self , exception : Exception ):
108+ """
109+ Create an instance of the model class that just raises the given exception.
110+ """
111+ return ErrorModel (exception )
112+
107113 def _validate_folder (self , folder ):
108114 if folder == "." :
109115 folder = "" # will getcwd() next which ends with /
@@ -641,6 +647,24 @@ def monitor_model_build(self):
641647 return False
642648
643649
650+ class ErrorModel (ModelClass ):
651+
652+ def __init__ (self , exception ):
653+ self .exception = exception
654+
655+ def load_model (self ):
656+ pass
657+
658+ def predict (self , * args , ** kwargs ):
659+ raise self .exception from self .exception
660+
661+ def generate (self , * args , ** kwargs ):
662+ raise self .exception from self .exception
663+
664+ def stream (self , * args , ** kwargs ):
665+ raise self .exception from self .exception
666+
667+
644668def upload_model (folder , download_checkpoints , skip_dockerfile ):
645669 builder = ModelBuilder (folder )
646670 if download_checkpoints :
Original file line number Diff line number Diff line change @@ -70,7 +70,11 @@ def main():
7070
7171 builder = ModelBuilder (parsed_args .model_path )
7272
73- model = builder .create_model_instance ()
73+ try :
74+ model = builder .create_model_instance ()
75+ except Exception as e :
76+ logger .exception ("Error creating model instance" )
77+ model = builder .create_error_model_instance (e )
7478
7579 # Setup the grpc server for local development.
7680 if parsed_args .grpc :
You can’t perform that action at this time.
0 commit comments