# Save custom objects in the state for each process

**URL:** <https://discuss.huggingface.co/t/save-custom-objects-in-the-state-for-each-process/23361>\
**Category:** 🤗Accelerate\
**Created:** [September 20, 2022, 12:52am UTC](https://discuss.huggingface.co/t/save-custom-objects-in-the-state-for-each-process/23361 "2022-09-20T00:52:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aps](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/aps/32/6128_2.png) [@aps](https://discuss.huggingface.co/u/aps)\
**Post date:** [September 20, 2022, 12:52am UTC](https://discuss.huggingface.co/t/save-custom-objects-in-the-state-for-each-process/23361/1 "2022-09-20T00:52:19Z")

</div>

As of now custom registered objects are not saved per process as seen [here](https://github.com/huggingface/accelerate/blob/6dc429f6f748600c4319e438f6bdaa22261c4f6a/src/accelerate/accelerator.py#L1271). Is there a way to save a separate checkpoint and load for each of the register custom objects per process/rank in a distributed setting?

Alternatively, do you suggest that we should gather everything before saving and then distribute during loading?

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [October 3, 2022, 3:30pm UTC](https://discuss.huggingface.co/t/save-custom-objects-in-the-state-for-each-process/23361/2 "2022-10-03T15:30:44Z")

</div>

I’m not fully understanding how it’s not supported by just saving what you want to save outside of Accelerate right now (so each process will save its own version). Could you tell us more about your use case?

---

<div class="post-metadata">

**Author:** ![SaulLu](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/saullu/32/2637_2.png) [@SaulLu](https://discuss.huggingface.co/u/SaulLu)\
**Post date:** [October 4, 2022, 12:51pm UTC](https://discuss.huggingface.co/t/save-custom-objects-in-the-state-for-each-process/23361/3 "2022-10-04T12:51:38Z")

</div>

Thanks for the answer!

> I’m not fully understanding how it’s not supported by just saving what you want to save outside of Accelerate right now (so each process will save its own version).

Yes, I think it should work. We did not take this strategy and chose to `register_for_checkpointing` the object with `accelerate`.

> Could you tell us more about your use case?

Sure, in our case, we have a custom object that we use to follow the progress of the dataloader on each rank and each worker id so that we can resume the training where it was stopped the previous time.

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [October 4, 2022, 1:28pm UTC](https://discuss.huggingface.co/t/save-custom-objects-in-the-state-for-each-process/23361/4 "2022-10-04T13:28:50Z")

</div>

Ok, so in this case it does seem easier to not register the object for checkpointing and save/load it manually (using the process index in the name of the save somehow, so you know which saved file to pick when reloading).

---

<div class="post-metadata">

**Author:** ![SaulLu](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/saullu/32/2637_2.png) [@SaulLu](https://discuss.huggingface.co/u/SaulLu)\
**Post date:** [October 4, 2022, 1:50pm UTC](https://discuss.huggingface.co/t/save-custom-objects-in-the-state-for-each-process/23361/5 "2022-10-04T13:50:32Z")

</div>

Thanks a lot for your feedback!
