Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add save and export to training servicer #228

Merged
merged 4 commits into from
Jan 20, 2025

Conversation

thodkatz
Copy link
Collaborator

@thodkatz thodkatz commented Dec 12, 2024

It builds upon #227 .

Adding the options to save and export a model for the training service.

  • Save: pytorch state dict, including the optimizer
  • Export: save it as a bioimageio package (.zip)

When we save, the training is paused, and then we resume. For the export, we just pause.

TODO:

@thodkatz thodkatz force-pushed the add-save-export-to-training-servicer branch 3 times, most recently from 0e7735a to b303405 Compare December 19, 2024 10:58
@thodkatz thodkatz force-pushed the add-save-export-to-training-servicer branch from b303405 to fc70f78 Compare December 20, 2024 21:54
Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 28.98551% with 98 lines in your changes missing coverage. Please review.

Project coverage is 62.57%. Comparing base (90b4ce0) to head (6e4ec16).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
tiktorch/trainer.py 21.73% 54 Missing ⚠️
tiktorch/proto/training_pb2.py 5.88% 16 Missing ⚠️
tiktorch/server/session/backend/supervisor.py 23.07% 10 Missing ⚠️
tiktorch/server/session/backend/base.py 33.33% 6 Missing ⚠️
tiktorch/server/session/backend/commands.py 53.84% 6 Missing ⚠️
tiktorch/proto/training_pb2_grpc.py 50.00% 4 Missing ⚠️
tiktorch/server/session/process.py 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #228      +/-   ##
==========================================
- Coverage   63.63%   62.57%   -1.07%     
==========================================
  Files          47       47              
  Lines        2742     2840      +98     
==========================================
+ Hits         1745     1777      +32     
- Misses        997     1063      +66     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@thodkatz thodkatz force-pushed the add-save-export-to-training-servicer branch 3 times, most recently from 5d7f533 to e4bc4d6 Compare December 21, 2024 11:11
@thodkatz thodkatz force-pushed the add-save-export-to-training-servicer branch from e4bc4d6 to 9264874 Compare January 20, 2025 11:34
@thodkatz thodkatz force-pushed the add-save-export-to-training-servicer branch from 9264874 to 02de953 Compare January 20, 2025 11:43
- If the model was initial paused or running, save after completion
  retain the state, while temporarily pausing to perform the save.
- The export will pause the training if not paused before.
@thodkatz thodkatz force-pushed the add-save-export-to-training-servicer branch from 02de953 to 597cfe8 Compare January 20, 2025 11:48
file_path = file_path.with_suffix(".pth")

state = {
"num_epochs": self.num_epochs + 1,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason for the +1? Maybe it deserves a comment. Pytorch themselves seem to save just the epoch: https://pytorch.org/tutorials/beginner/saving_loading_models.html#saving-loading-a-general-checkpoint-for-inference-and-or-resuming-training

"""
On demand save of the training progress including the optimizer state.

Note: pytorch-3dunet automatically saves the checkpoints in intervals defined by the `validation_after_iters`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording to me here is a bit unclear. As far as I remember pytorch-3dunet will keep "latest" and "best" checkpoints. This sounds a bit as if a history were retained (or is this actually the case)?

@thodkatz thodkatz merged commit 5f5fbd1 into ilastik:main Jan 20, 2025
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants