We train our sklearn model locally and then upload it as *.tar.gz file to S3 in order to deploy it via Sagemaker. There we use Sagemaker's own SKLearnModel docker image and aim to deploy our model to a Sagemaker endpoint. Our approach is similar to what is described in this thread or over here.
This is basically, what the code in our Sagemaker jupyter notebook looks like:
from sagemaker.sklearn.model import SKLearnModel
sagemaker_model = SKLearnModel(model_data='s3://ourModelS3Bucket/ourModelTarball.tar.gz',
role='arn:aws:iam::someNumber:role/OurPredefinedRole',
entry_point='our_entry_point.py')
predictor = sagemaker_model.deploy(initial_instance_count=1,
instance_type='ml.t2.large') #be careful which instance you choose!
What we want to know is, how do we have to write the entry point code (here called 'our_entry_point.py') for our model, so that Sagemaker can deploy it successfully?
Does it have to contain a predict() function, is it executed like a script from top to bottom or do we have to define a if __name__ == "__main__":
block? This is especially relevant, since we probably want to add some additional feature generation/selection here, before we execute the prediction itself.
Any help would be very welcome, either a direct answer or a link to a documentation/tutorial which might provide the answer. So far, the Sagemaker docs and some of the Github examples were quite helpful...