# Deploying HG Pipelines on AWS Sagemaker

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdeploying-hg-pipelines-on-aws-sagemaker%2F13735%3E%5C
**Category:** Amazon SageMaker\
**Created:** [January 15, 2022, 5:03pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdeploying-hg-pipelines-on-aws-sagemaker%2F13735 "2022-01-15T17:03:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomKc](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@TomKc](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FTomKc)%5C
**Post date:** [January 15, 2022, 5:03pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdeploying-hg-pipelines-on-aws-sagemaker%2F13735%2F1 "2022-01-15T17:03:00Z")

</div>

I need some help with deploying HG Pipelines on AWS Sagemaker

This is how I deploy a pre-trained model in a pipeline in my local environment and get a prediction.

```auto
local_model = BertForSequenceClassification.from_pretrained(“local_model_path”)
tokenizer = BertTokenizer.from_pretrained(“"bert-base-uncased", padding=True, truncation=True)
pipe = pipeline("text-classification", model= local_model, tokenizer=.tokenizer)
output = pipe(input)

```

I could not find a way to deploy this HG Pipeline on Sagemaker. I followed the following documentation [Deploy models to Amazon SageMaker](https://huggingface.co/docs/sagemaker/inference#user-defined-code-and-modules) and tried to use HuggingFaceModel. However, I am not sure how I can provide the other pipeline parameters.

```auto
huggingface_model = HuggingFaceModel(
   model_data="s3://model.tar.gz",
   role=role,
   transformers_version="4.12",
   pytorch_version="1.9",
   py_version='py38'
)

```

Where and how can I provide the task (text-classification) and tokenizer information? If this is not possible, should I first tokenize my data and give that as an input to predictor? predictor.predict(data\_tokenized)?

Any other suggestions? Thanks so much!!! 🙏

---

<div class="post-metadata">

**Author:** ![marshmellow77](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/marshmellow77/32/3279_2.png) [@marshmellow77](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmarshmellow77)%5C
**Post date:** [January 15, 2022, 5:40pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdeploying-hg-pipelines-on-aws-sagemaker%2F13735%2F2 "2022-01-15T17:40:18Z")

</div>

Hi Tom, I think you are on the right path. Provided your model is already on S3 and packaged as tar.gz file you can just use the deploy() method to deploy the model. To get predictions you can use predictor.predict, as you have already pointed out.

This notebook by @philschmid should be useful: [notebooks/deploy\_transformer\_model\_from\_s3.ipynb at master · huggingface/notebooks · GitHub](https://github.com/huggingface/notebooks/blob/master/sagemaker/10_deploy_model_from_s3/deploy_transformer_model_from_s3.ipynb)

Hope that helps, let me know if there are any questions.

Cheers  
Heiko

---

<div class="post-metadata">

**Author:** ![TomKc](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@TomKc](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FTomKc)%5C
**Post date:** [January 16, 2022, 3:15pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdeploying-hg-pipelines-on-aws-sagemaker%2F13735%2F3 "2022-01-16T15:15:33Z")

</div>

Thanks for the note. I followed @philschmid’s notebook. However, I am still wondering where and how I should be providing the tokenizer parameter that I usually provide in a HG pipeline. Please see below:  
pipe = pipeline(“text-classification”, model= local\_model, tokenizer=.tokenizer)

any ideas?

---

<div class="post-metadata">

**Author:** ![marshmellow77](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/marshmellow77/32/3279_2.png) [@marshmellow77](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmarshmellow77)%5C
**Post date:** [January 16, 2022, 4:22pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdeploying-hg-pipelines-on-aws-sagemaker%2F13735%2F4 "2022-01-16T16:22:21Z")

</div>

The tokenizer goes into the model.tar.gz file, together with the model and all other required files for your model to run.

---

<div class="post-metadata">

**Author:** ![philschmid](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/philschmid/32/38022_2.png) [@philschmid](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fphilschmid)%5C
**Post date:** [January 17, 2022, 7:38am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdeploying-hg-pipelines-on-aws-sagemaker%2F13735%2F5 "2022-01-17T07:38:52Z")

</div>

Hello @TomKc,

You need to create a `model.tar.gz` including your tokenizer and model files. Instructions can be found here: [Deploy models to Amazon SageMaker](https://huggingface.co/docs/sagemaker/inference#create-a-model-artifact-for-deployment) or below.  
`{repository}` must include those files.

```bash
cd {repository}
tar zcvf model.tar.gz *
aws s3 cp model.tar.gz <s3://{my-s3-path}>

```

and then you can use the `env` parameter to provide your task.

```python
huggingface_model = HuggingFaceModel(
   model_data="s3://{my-s3-path}/model.tar.gz",
   role=role,
   transformers_version="4.12",
   pytorch_version="1.9",
   py_version='py38', 
   env = {"HF_TASK":"text-classification"}
)

```
