# Training model file too large and fail to deploy

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftraining-model-file-too-large-and-fail-to-deploy%2F10676%3E%5C
**Category:** Amazon SageMaker\
**Created:** [October 11, 2021, 6:50am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftraining-model-file-too-large-and-fail-to-deploy%2F10676 "2021-10-11T06:50:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackieliu930](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@jackieliu930](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjackieliu930)%5C
**Post date:** [October 11, 2021, 6:50am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftraining-model-file-too-large-and-fail-to-deploy%2F10676%2F1 "2021-10-11T06:50:12Z")

</div>

hi, community!

I have trained a Bert classification model with below config on sagemaker:

```auto
from sagemaker.huggingface import HuggingFace

# hyperparameters, which are passed into the training job
hyperparameters={'epochs': 5,
                 'train_batch_size': 4,
                 'model_name':'bert-base-uncased',
                 'num_labels':31,
                 }

huggingface_estimator = HuggingFace(entry_point='train.py',
                            source_dir='./scripts',
                            instance_type='ml.p3.16xlarge',
                            instance_count=1,
                            role=role,
                            # add volume size set up
                            volume_size=200,
                            transformers_version='4.6',
                            pytorch_version='1.7',
                            py_version='py36',
                            hyperparameters = hyperparameters)
# starting the train job with our uploaded datasets as input
huggingface_estimator.fit({'train': training_input_path, 'test': test_input_path})

```

this works perfectly. however, I have two problems:

1. the generated model file is huge: 64gb. why is that?
2. I can’t deploy endpoint successfully, I am guessing due to the model size too big, any idea on how to solve?

---

<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:** [October 11, 2021, 11:39am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftraining-model-file-too-large-and-fail-to-deploy%2F10676%2F2 "2021-10-11T11:39:02Z")

</div>

Hey @jackieliu930,

Yes, I guess your artifact is so big because all saved `checkpoints` during training are included. You can either change your checkpoint saving strategy in your train.py or the location where the checkpoints are saved.  
Or you could load your `model.tar.gz` and remove all checkpoints from it and then upload it so s3 again. Documentation here: [Deploy models to Amazon SageMaker](https://huggingface.co/docs/sagemaker/inference#creating-a-model-artifact-modeltargz-for-deployment)  
Another solution would be to upload your model to [Models - Hugging Face](http://hf.co/models) and then deploy using `HF_MODE_ID` and `HF_TASK`.

---

<div class="post-metadata">

**Author:** ![kanandk](https://avatars.discourse-cdn.com/v4/letter/k/eb8c5e/32.png) [@kanandk](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fkanandk)%5C
**Post date:** [July 2, 2023, 11:04am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftraining-model-file-too-large-and-fail-to-deploy%2F10676%2F3 "2023-07-02T11:04:32Z")

</div>

Hey @philschmid, I am using run\_glue.py to fine tune a model and it generates a 150+gb model.tar.gz.  
How do I change the the location where the checkpoints are saved.?

---

<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:** [July 3, 2023, 7:05am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftraining-model-file-too-large-and-fail-to-deploy%2F10676%2F4 "2023-07-03T07:05:32Z")

</div>

You can adjust the save directory for you checkpoints by setting `output_dir` to a different path and then only save the last checkpoint into `/opt/ml/model`.
