Skip to content

Instantly share code, notes, and snippets.

@brifordwylie
Created June 3, 2022 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brifordwylie/6386b49c78847b757e2649a2d039eeb6 to your computer and use it in GitHub Desktop.
Save brifordwylie/6386b49c78847b757e2649a2d039eeb6 to your computer and use it in GitHub Desktop.
Grabbing a 'model' from an existing endpoint

Grabbing a 'model' from an existing endpoint

Should be easy, but....

Context

I'm trying to create a simple inference pipeline (see Inference Pipeline Example. )

In my case I have two ^existing^ endpoints and I'm trying to 'get' the model from those endpoints for the pipeline creation.

sm_model = PipelineModel( name=model_name, role=role, models=[model_1, model_2] )

I do not have the Estimator object (so can't call create_model())... I'm looking at the docs/google.. and I can't see how to do the equivalent of 'get_model()' from an endpoint.

Long Path

Here's my current 'long way around' path, this seems silly.. the endpoint obviously knows it's model(s) so having to do a this lengthy process must not be the right way...

  • Get the model name from endpoint
sm_client.describe_endpoint_config(EndpointConfigName=<endpoint_config_name>)
...'ProductionVariants': [{'VariantName': 'AllTraffic', 'ModelName': <model_name_is_here>
  • Get the model data url by using the model name
sm_client.describe_model(ModelName=<model_name>)
...PrimaryContainer': {'Image': '683313688378.dkr.ecr.us-east-1.amazonaws.com/sagemaker-scikit-learn:0.23-1-cpu-py3',
 'Mode': 'SingleModel',
 'ModelDataUrl': <here... blah/blah/model.tar.gz>
  • Get the image from the endpoint
sm_client.describe_endpoint(EndpointName=<endpoint name>)
'ProductionVariants': [{'VariantName': 'AllTraffic', 'DeployedImages': <image_is_here>
  • Create a new model
model = Model(model_data=model_data, image_uri=endpoint_iimage, role=role)

And ^finally^ do that twice (for each endpoint) and use those models as my arguments to PipelineModel

PipelineModel(name=model_name, role=role, models=[model_1, model_2])

There has to be a better/easier way :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment