Load estimator from model artifact in s3 bucket aws
I have used estimator for a pytorch model and have saved the artifacts in s3 bucket. using below code
estimator = PyTorch(
    entry_point=&quot;train_deploy.py&quot;,
    source_dir=&quot;code&quot;,
    role=role,
    framework_version=&quot;1.3.1&quot;,
    py_version=&quot;py3&quot;,
    instance_count=1,  # this script only support distributed training for GPU instances.
    instance_type=&quot;ml.m5.12xlarge&quot;,
    output_path=output_path,
    hyperparameters={
        &quot;epochs&quot;: 1,
        &quot;num_labels&quot;: 7,
        &quot;backend&quot;: &quot;gloo&quot;,
    },
    disable_profiler=False, # disable debugger
)
estimator.fit({&quot;training&quot;: inputs_train, &quot;testing&quot;: inputs_test})

The model works well and there are no issues with it. However i would like to re use this model later for inference, how do i do that. i am looking for something like below
estimator = PyTorch.load(input_path = &quot;&lt;xyz&gt;&quot;)


I was able to solve this by the following steps
model_data=output_path
from sagemaker.pytorch.model import PyTorchModel 

pytorch_model = PyTorchModel(model_data=model_data,
                             role=role,
                             framework_version=&quot;1.3.1&quot;,
                             source_dir=&quot;code&quot;,
                             py_version=&quot;py3&quot;,
                             entry_point=&quot;train_deploy.py&quot;)

predictor = pytorch_model.deploy(initial_instance_count=1, instance_type=&quot;ml.m4.2xlarge&quot;)
predictor.serializer = sagemaker.serializers.JSONSerializer()
predictor.deserializer = sagemaker.deserializers.JSONDeserializer()
result = predictor.predict(&quot;&lt;text that needs to be predicted&gt;&quot;)
print(&quot;predicted class: &quot;, np.argmax(result, axis=1))

