# SageMaker Model | How to set Truncation within Config?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsagemaker-model-how-to-set-truncation-within-config%2F56163%3E%5C
**Category:** Amazon SageMaker\
**Created:** [September 24, 2023, 2:16pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsagemaker-model-how-to-set-truncation-within-config%2F56163 "2023-09-24T14:16:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbb](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/dbb/32/19757_2.png) [@dbb](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdbb)%5C
**Post date:** [September 24, 2023, 2:16pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsagemaker-model-how-to-set-truncation-within-config%2F56163%2F1 "2023-09-24T14:16:07Z")

</div>

Hi 🤗!

I created a sagemaker serverless endpoint that serves a fine-tuned text classification model… Now, when I try to invoke it with a sequence length longer than the maximum input length (514) it correctly returns the following error:

```auto
ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation: Received client error (400) from model with message "{
  "code": 400,
  "type": "InternalServerException",
  "message": "The expanded size of the tensor (997) must match the existing size (514) at non-singleton dimension 1. Target sizes: [1, 997]. Tensor sizes: [1, 514]"
}

```

To make sure that the model can handle any input length through truncation, I updated the models `tokenizer_config.json` with an additional argument `"model_max_length": 514` but unfortunately the error remains the same.

Am I working on the wrong part of the model? Do I have to set it in `tokenizer.json`?

Looking forward to your expertise!

Regards,  
David

---

<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:** [September 25, 2023, 7:45am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsagemaker-model-how-to-set-truncation-within-config%2F56163%2F2 "2023-09-25T07:45:33Z")

</div>

Are you passing `truncation` ? as parameter. The pipeline is not by default truncating the inputs.

---

<div class="post-metadata">

**Author:** ![dbb](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/dbb/32/19757_2.png) [@dbb](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdbb)%5C
**Post date:** [September 25, 2023, 7:59am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsagemaker-model-how-to-set-truncation-within-config%2F56163%2F3 "2023-09-25T07:59:27Z")

</div>

Hi @philschmid! No, currently I don’t.  
I know that this solution exists but I’m wondering whether there is a way to configure the model itself to apply truncation by default.  
The intuition behind it is to make the model available in the most simple way. So, my users should not worry about adding “nlp specific” parameters to their requests.

I’ll give `truncation` a try, just to see if that would be a workaround. Could I also pass `max_length` in the request?

---

<div class="post-metadata">

**Author:** ![dbb](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/dbb/32/19757_2.png) [@dbb](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdbb)%5C
**Post date:** [September 25, 2023, 8:43am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsagemaker-model-how-to-set-truncation-within-config%2F56163%2F4 "2023-09-25T08:43:05Z")

</div>

I tried it with `truncation` in the request:

```auto
data = {
  "parameters": {"truncation": true},
  "inputs": "Text longer than 514 Tokens"
  }

res = predictor.predict(data=data)
print(res)

```

and it works as expected 👍

Is there a way to make this the default behavior through the tokenizer config files?

I’d like to make my model available via an AWS API Gateway and to keep things separated my users should not worry about NLP specific topics like truncation and so on.
