I am trying to download the Hugging Face distilbert model, trying to save to S3. The model itself does not have a deploy method. So I am saving to S3, instantiating it and trying to deploy. May I know if this will work with Sagemaker. What I am doing wrong. Here are the steps:
model_name = âdistilbert-base-uncased-distilled-squadâ model = DistilBertForQuestionAnswering.from_pretrained(model_name) tokenizer = DistilBertTokenizerFast.from_pretrained(model_name)
the below works and gives output context = âxxxxâ question = âyyy?â
nlp = pipeline(âquestion-answeringâ, model=model, tokenizer=tokenizer)
nlp({ âquestionâ: âWhat organization is the IPCC a part of?â, âcontextâ: context })
save the model to local folder model.save_pretrained(â./scripts/mymodelâ)
zip the model file. with tarfile.open("./scripts/mymodel/model.tar.gz", âw:gzâ) as tar: tar.add("./scripts/mymodel/pytorch_model.bin") tar.add("./scripts/mymodel/config.json")
upload the zipped file to S3 sagemaker.Session().upload_data(bucket=sagemaker_session_bucket, path=â./scripts/mymodel/model.tar.gzâ, key_prefix=âmodelâ)
instantiating the saved model
bertmodel = PyTorchModel(entry_point=âinference.pyâ, source_dir=âscriptsâ, model_data=âs3://â+sagemaker_session_bucket+â/model/model.tar.gzâ, role=sagemaker.get_execution_role(), framework_version=â1.5â, py_version=âpy3â)
the below does not work nlp = pipeline(âquestion-answeringâ, model=bertmodel, tokenizer=tokenizer)
nlp({ âquestionâ: âWhat organization is the IPCC a part of?â, âcontextâ: context })
error recd - AttributeError: âPyTorchModelâ object has no attribute âconfigâ
I am able to deploy the predictor predictor = bertmodel.deploy(initial_instance_count=1, instance_type=âml.m5.xlargeâ)