File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
sdks/python/apache_beam/ml/inference Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 5959from apache_beam .utils import multi_process_shared
6060from apache_beam .utils import retry
6161from apache_beam .utils import shared
62- from apache_beam .ml .inference .model_manager import ModelManager
6362
6463try :
6564 # pylint: disable=wrong-import-order, wrong-import-position
6665 import resource
66+ from apache_beam .ml .inference .model_manager import ModelManager
6767except ImportError :
6868 resource = None # type: ignore[assignment]
69+ ModelManager = None # type: ignore[assignment]
6970
7071_NANOSECOND_TO_MILLISECOND = 1_000_000
7172_NANOSECOND_TO_MICROSECOND = 1_000
Original file line number Diff line number Diff line change @@ -317,6 +317,15 @@ def validate_inference_args(self, inference_args):
317317 pass
318318
319319
320+ def try_import_model_manager ():
321+ try :
322+ # pylint: disable=unused-import
323+ from apache_beam .ml .inference .model_manager import ModelManager
324+ return True
325+ except ImportError :
326+ return False
327+
328+
320329class RunInferenceBaseTest (unittest .TestCase ):
321330 def test_run_inference_impl_simple_examples (self ):
322331 with TestPipeline () as pipeline :
@@ -1894,6 +1903,7 @@ def test_model_status_provides_valid_garbage_collection(self):
18941903
18951904 self .assertEqual (0 , len (tags ))
18961905
1906+ @skipIf (try_import_model_manager () is False , 'Model Manager not available' )
18971907 def test_run_inference_impl_with_model_manager (self ):
18981908 with TestPipeline () as pipeline :
18991909 examples = [1 , 5 , 3 , 10 ]
@@ -1903,6 +1913,7 @@ def test_run_inference_impl_with_model_manager(self):
19031913 SimpleFakeModelHanlder (), use_model_manager = True )
19041914 assert_that (actual , equal_to (expected ), label = 'assert:inferences' )
19051915
1916+ @skipIf (try_import_model_manager () is False , 'Model Manager not available' )
19061917 def test_run_inference_impl_with_model_manager_args (self ):
19071918 with TestPipeline () as pipeline :
19081919 examples = [1 , 5 , 3 , 10 ]
You can’t perform that action at this time.
0 commit comments