# Incrementally finetuning a HF model in SageMaker

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fincrementally-finetuning-a-hf-model-in-sagemaker%2F17443%3E%5C
**Category:** Amazon SageMaker\
**Created:** [May 2, 2022, 7:46pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fincrementally-finetuning-a-hf-model-in-sagemaker%2F17443 "2022-05-02T19:46:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaximusDecimusMeridi](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/maximusdecimusmeridi/32/3390_2.png) [@MaximusDecimusMeridi](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FMaximusDecimusMeridi)%5C
**Post date:** [May 2, 2022, 7:46pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fincrementally-finetuning-a-hf-model-in-sagemaker%2F17443%2F1 "2022-05-02T19:46:31Z")

</div>

If I have an already pretrained model, and want to train it on some additional data, how do I go about that in SageMaker?

In this case I’ve trained a model loaded with AutoModelForSequenceClassification using “distilbert-base-uncased”.

---

<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:** [May 3, 2022, 6:19am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fincrementally-finetuning-a-hf-model-in-sagemaker%2F17443%2F2 "2022-05-03T06:19:15Z")

</div>

You can provide your trained model as model\_id instead of the base model this would further train it. But you need to make sure that you have the same labels etc.

---

<div class="post-metadata">

**Author:** ![petarulev](https://avatars.discourse-cdn.com/v4/letter/p/c5a1d2/32.png) [@petarulev](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpetarulev)%5C
**Post date:** [May 3, 2022, 8:24am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fincrementally-finetuning-a-hf-model-in-sagemaker%2F17443%2F3 "2022-05-03T08:24:00Z")

</div>

> [@MaximusDecimusMeridi](#):
>
> In this case I’ve trained a model loaded with AutoModelForSequenceClassification using “distilbert-base-uncased”.

Hello!  
Consider using huggingface’s Trainer and TrainingArguments. Please check this page: [Trainer](https://huggingface.co/docs/transformers/main_classes/trainer) .  
If you have any questions on how to do it, let me know and I will forward some other links or help you do it. 🙂

---

<div class="post-metadata">

**Author:** ![MaximusDecimusMeridi](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/maximusdecimusmeridi/32/3390_2.png) [@MaximusDecimusMeridi](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FMaximusDecimusMeridi)%5C
**Post date:** [May 3, 2022, 3:39pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fincrementally-finetuning-a-hf-model-in-sagemaker%2F17443%2F4 "2022-05-03T15:39:35Z")

</div>

> [@petarulev](#):
>
> If you have any questions on how to do it, let me know and I will forward some other links or help you do it.

Thank you. Yes if you can please share any other links with additional context/backgrouynd that would be great 🙏

---

<div class="post-metadata">

**Author:** ![MaximusDecimusMeridi](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/maximusdecimusmeridi/32/3390_2.png) [@MaximusDecimusMeridi](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FMaximusDecimusMeridi)%5C
**Post date:** [May 3, 2022, 8:45pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fincrementally-finetuning-a-hf-model-in-sagemaker%2F17443%2F5 "2022-05-03T20:45:10Z")

</div>

> [@philschmid](#):
>
> You can provide your trained model as model\_id

Can I do this without using the hub? Would I just unzip the model into a local directory and load this and train with data and use same labels?

Thanks

---

<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:** [May 4, 2022, 2:30am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fincrementally-finetuning-a-hf-model-in-sagemaker%2F17443%2F6 "2022-05-04T02:30:14Z")

</div>

@MaximusDecimusMeridi - if you want to do this without using the model hub then, yes, downloading the model from S3, unzipping it into a local folder, and using `model = AutoModelForSequenceClassification.from_pretrained('path/to/model/folder')` should work!

Cheers  
Heiko

---

<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:** [May 4, 2022, 6:05am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fincrementally-finetuning-a-hf-model-in-sagemaker%2F17443%2F7 "2022-05-04T06:05:45Z")

</div>

You can also provide the model in a similar fashion you do with your training in the estimator, e.g. `huggingface_estimator.fit({"train":s3_train_uri,"model":s3_model_uri})` which should download the s3\_model\_uri into /opt/ml/input/model or rather speaking stores the path in the env var `SM_CHANNEL_MODEL`
