# Saving checkpoints in drive

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsaving-checkpoints-in-drive%2F8865%3E%5C
**Category:** 🤗Transformers\
**Created:** [July 31, 2021, 4:00am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsaving-checkpoints-in-drive%2F8865 "2021-07-31T04:00:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![imshmen](https://avatars.discourse-cdn.com/v4/letter/i/a9adbd/32.png) [@imshmen](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fimshmen)%5C
**Post date:** [July 31, 2021, 4:00am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsaving-checkpoints-in-drive%2F8865%2F1 "2021-07-31T04:00:18Z")

</div>

```auto
from transformers import Trainer, TrainingArguments

training_args = TrainingArguments(
    output_dir="/gdrive/MyDrive/Thesis/GPT2/checkpoints",
    overwrite_output_dir=False,
    num_train_epochs=5,
    per_device_train_batch_size=6, #previous was 6
    save_steps=100,
    save_total_limit=5,
    fp16 = True,
    dataloader_drop_last=True,
    #evaluate_during_training=True,
    warmup_steps=200
)

trainer = Trainer(
    model=model,
    args=training_args,
    data_collator=data_collator,
    train_dataset=dataset,
    # prediction_loss_only = True
) 

trainer.train()

```

I want to save the checkpoints directly to my google drive. The problem is the code above saves my checkpoints upto to save limit all well. But after the limit it can’t delete or save any new checkpoints. Although it says checkpoints saved/deleted in the console. Any help?

---

<div class="post-metadata">

**Author:** ![ahmedlone123](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ahmedlone123](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fahmedlone123)%5C
**Post date:** [July 31, 2021, 8:44am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsaving-checkpoints-in-drive%2F8865%2F2 "2021-07-31T08:44:12Z")

</div>

I think just wait a bit and they appear up in drive , that’s what happened with me

---

<div class="post-metadata">

**Author:** ![imshmen](https://avatars.discourse-cdn.com/v4/letter/i/a9adbd/32.png) [@imshmen](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fimshmen)%5C
**Post date:** [July 31, 2021, 10:39am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsaving-checkpoints-in-drive%2F8865%2F3 "2021-07-31T10:39:35Z")

</div>

I waited around 20-30 mins. Didn’t notice anything.  
It works fine when I remove the save\_limits arg though.

---

<div class="post-metadata">

**Author:** ![ahmedlone123](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ahmedlone123](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fahmedlone123)%5C
**Post date:** [July 31, 2021, 6:05pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsaving-checkpoints-in-drive%2F8865%2F4 "2021-07-31T18:05:09Z")

</div>

i figured out a soloution

```auto
from google.colab import drive
drive.flush_and_unmount()

```

use this code after the training in done and it will update everything to drive

---

<div class="post-metadata">

**Author:** ![imshmen](https://avatars.discourse-cdn.com/v4/letter/i/a9adbd/32.png) [@imshmen](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fimshmen)%5C
**Post date:** [July 31, 2021, 6:27pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsaving-checkpoints-in-drive%2F8865%2F5 "2021-07-31T18:27:54Z")

</div>

This could be a solution. But what if my runtime gets disconnected while training. My checkpoints will be lost then. So I actually need to have the checkpoints in my drive after the save steps.

---

<div class="post-metadata">

**Author:** ![ahmedlone123](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@ahmedlone123](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fahmedlone123)%5C
**Post date:** [August 1, 2021, 7:13am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsaving-checkpoints-in-drive%2F8865%2F6 "2021-08-01T07:13:08Z")

</div>

Try this , after every save step use interrupt execution in collab and save the checkpoint using this , then restart training from the saved checkpoint

---

<div class="post-metadata">

**Author:** ![Swiee](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@Swiee](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FSwiee)%5C
**Post date:** [July 19, 2022, 7:52pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsaving-checkpoints-in-drive%2F8865%2F7 "2022-07-19T19:52:57Z")

</div>

Can anyone please tell me on how to start the training of transformer from where it had left by loading the previously saved checkpoints. It would be really appreciated. Also thanks in advance.
