def dynamic_server( train_env: TrainEnv, ) -> ContextManager["testutil.ServerFacade"]: serve_env = ServeEnv(train_env.path.base) settings = Settings(sagemaker_server_port=testutil.free_port()) with testutil.temporary_server(serve_env, MeanPredictor, settings) as server: yield server
def static_server( train_env: TrainEnv, ) -> ContextManager["testutil.ServerFacade"]: predictor = MeanPredictor.from_hyperparameters(**train_env.hyperparameters) predictor.serialize(train_env.path.model) serve_env = ServeEnv(train_env.path.base) settings = Settings(sagemaker_server_port=testutil.free_port()) with testutil.temporary_server(serve_env, None, settings) as server: yield server
def temporary_serve_env(predictor: Predictor) -> ContextManager[ServeEnv]: """ A context manager that instantiates a serve environment for a given `Predictor` in a temporary directory and removes the directory on exit. Parameters ---------- predictor A predictor to serialize in `ServeEnv` `model` folder. Returns ------- ContextManager[gluonts.shell.env.ServeEnv] A context manager that yields the `ServeEnv` instance. """ with tempfile.TemporaryDirectory(prefix="gluonts-serve-env") as base: paths = ServePaths(base=Path(base)) # serialize model predictor.serialize(paths.model) yield ServeEnv(path=paths.base)