# Serverless deploy troubles

**URL:** <https://discuss.huggingface.co/t/serverless-deploy-troubles/17972>\
**Category:** Amazon SageMaker\
**Created:** [May 15, 2022, 9:28am UTC](https://discuss.huggingface.co/t/serverless-deploy-troubles/17972 "2022-05-15T09:28:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexG](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@AlexG](https://discuss.huggingface.co/u/AlexG)\
**Post date:** [May 15, 2022, 9:28am UTC](https://discuss.huggingface.co/t/serverless-deploy-troubles/17972/1 "2022-05-15T09:28:57Z")

</div>

Hi, I’m trying to deploy a serverless endpoint from model\_data. Trying to do it in the same manner I deployed a similar model to an EC2 instance, but it seems to fail.

I do  
huggingface\_model = HuggingFaceModel(\*\*model\_params)  
where  
model\_params = {‘role’: \<exec\_role\>, ‘transformers\_version’: ‘4.6’, ‘sagemaker\_session’: \<sagemaker.session.Session object at 0x158528e50\>, ‘pytorch\_version’: ‘1.7’, ‘py\_version’: ‘py36’, ‘model\_data’: \<path\_to\_S3\>}

then  
serverless\_config = ServerlessInferenceConfig(  
memory\_size\_in\_mb=memory\_size\_in\_mb, max\_concurrency=max\_concurrency  
)  
huggingface\_model.deploy(  
serverless\_inference\_config=serverless\_config, endpoint\_name=model\_name, wait=wait)

All seems to deploy well, then when I run, i’m getting:  
“(“You need to define one of the following [\u0027feature-extraction\u0027, \u0027text-classification\u0027, \u0027token-classification\u0027, \u0027question-answering\u0027, \u0027table-question-answering\u0027, \u0027fill-mask\u0027, \u0027summarization\u0027, \u0027translation\u0027, \u0027text2text-generation\u0027, \u0027text-generation\u0027, \u0027zero-shot-classification\u0027, \u0027conversational\u0027, \u0027image-classification\u0027] as env \u0027TASK\u0027.”, 403)”

I tried adding env={“HF\_TASK”: “feature-extraction”} to the model creation, but i then get an error (which makes sense, since i’m not really specifying a model from the hub)  
“Can\u0027t load config for \u0027/.sagemaker/mms/models/model\u0027. Make sure that:\n\n- \u0027/.sagemaker/mms/models/model\u0027 is a correct model identifier listed on \u0027https://huggingface.co/models\u0027\n\n- or \u0027/.sagemaker/mms/models/model\u0027 is the correct path to a directory containing a config.json file\n\n”  
}

Anyone has some idea that can help?

Thank you,  
Alex

---

<div class="post-metadata">

**Author:** ![marshmellow77](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/marshmellow77/32/3279_2.png) [@marshmellow77](https://discuss.huggingface.co/u/marshmellow77)\
**Post date:** [May 15, 2022, 7:08pm UTC](https://discuss.huggingface.co/t/serverless-deploy-troubles/17972/2 "2022-05-15T19:08:56Z")

</div>

Hi Alex

The way you instantiate the `HuggingFaceModel` class looks a bit unusual to me. I usually go about it this way:

```auto
huggingface_model = HuggingFaceModel(
   model_data="s3://hf-sagemaker-inference/model.tar.gz", # path to your trained sagemaker model
   role=role, # iam role with permissions to create an Endpoint
   transformers_version="4.17", # transformers version used
   pytorch_version="1.10", # pytorch version used
   py_version="py38", # python version of the DLC
)

```

In terms of serverless deployment, you seem to do everything right, as far as I can tell. Just make sure you use the latest DLC (i.e. specify the latest supported Transformers and Pytorch versions, 4.17 and 1.10 respectively, in this case). You can find the latest versions here: [Reference](https://huggingface.co/docs/sagemaker/reference#inference-dlc-overview)

You can also check out these two sample notebooks and mix and match to fit your use case:

- [Deploying from S3](https://github.com/huggingface/notebooks/blob/main/sagemaker/10_deploy_model_from_s3/deploy_transformer_model_from_s3.ipynb)
- [Deploying Serverless](https://github.com/huggingface/notebooks/blob/main/sagemaker/19_serverless_inference/sagemaker-notebook.ipynb)

Hope that helps!

Cheers  
Heiko

---

<div class="post-metadata">

**Author:** ![AlexG](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@AlexG](https://discuss.huggingface.co/u/AlexG)\
**Post date:** [May 16, 2022, 6:28am UTC](https://discuss.huggingface.co/t/serverless-deploy-troubles/17972/3 "2022-05-16T06:28:52Z")

</div>

Thank you Heiko for the response and references. It’s really helpful. I tried the examples you shared, and what actually worked was both updating the library versions, and specifying the TASK in environment:

```auto
huggingface_model = HuggingFaceModel(
   model_data="s3://smbdata-development/models/MiniLM-L6-H384-uncased/model.tar.gz", # path to your trained sagemaker model
   role=get_role(), # iam role with permissions to create an Endpoint
   sagemaker_session=session,
   transformers_version="4.17.0", # transformers version used
   pytorch_version="1.10.2", # pytorch version used
   env={"HF_TASK": "feature-extraction"},
   py_version="py38" # python version of the DLC
)

```

However, when I try doing the same for another model, where i’ve overridden the some functions, it doesn’t work:

```auto
huggingface_model = HuggingFaceModel(
   model_data="s3://smbdata-development/models/all-MiniLM-L6-v2/model.tar.gz", # path to your trained sagemaker model
   role=get_role(), # iam role with permissions to create an Endpoint
   sagemaker_session=session,
   transformers_version="4.17.0", # transformers version used
   pytorch_version="1.10.2", # pytorch version used
   env={"HF_TASK": "feature-extraction"},
   py_version="py38" # python version of the DLC
)

```

gives me :message": “Can\u0027t load config for \u0027/.sagemaker/mms/models/model\u0027. If you were trying to load it from \u0027https://huggingface.co/models\u0027, make sure you don\u0027t have a local directory with the same name. Otherwise, make sure \u0027/.sagemaker/mms/models/model\u0027 is the correct path to a directory containing a config.json file”  
}

---

<div class="post-metadata">

**Author:** ![philschmid](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/philschmid/32/38022_2.png) [@philschmid](https://discuss.huggingface.co/u/philschmid)\
**Post date:** [May 16, 2022, 8:33am UTC](https://discuss.huggingface.co/t/serverless-deploy-troubles/17972/4 "2022-05-16T08:33:37Z")

</div>

Hey @AlexG,

You most likely have some small issue in your `model.tar.gz`. You can follow this example on how to create a custom `inference.py`: [notebooks/sagemaker-notebook.ipynb at main · huggingface/notebooks · GitHub](https://github.com/huggingface/notebooks/blob/main/sagemaker/17_custom_inference_script/sagemaker-notebook.ipynb)

---

<div class="post-metadata">

**Author:** ![AlexG](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@AlexG](https://discuss.huggingface.co/u/AlexG)\
**Post date:** [May 16, 2022, 8:49am UTC](https://discuss.huggingface.co/t/serverless-deploy-troubles/17972/5 "2022-05-16T08:49:57Z")

</div>

@philschmid Thanks! I actually copied the exact implementation from your notebook for this test. Then placed it under “code” directory as you show…

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/2X/f/fc2e8da68ac6cd5fa06fc2554bb6e7f504cafb40.png)

---

<div class="post-metadata">

**Author:** ![AlexG](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@AlexG](https://discuss.huggingface.co/u/AlexG)\
**Post date:** [May 16, 2022, 11:49am UTC](https://discuss.huggingface.co/t/serverless-deploy-troubles/17972/6 "2022-05-16T11:49:15Z")

</div>

Got suspicious following @philschmid 's comment, so I ran his deployment code as is, and got the same error. Then changed the model to msmarco-distilbert-dot-v5 and used the same inference.py file to override the functions.  
All deployed now and no errors. Possibly some issue with MiniLM configuraiton.

Thanks for the help everyone! The references were extremely helpful
