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

Allow definition of Loss and Optimizer in config file. #132

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

drewoldag
Copy link
Collaborator

@drewoldag drewoldag commented Dec 7, 2024

This is an initial implementation that allows defining PyTorch Loss (Criterion) and Optimizers from within the config file.

Two new tables are introduced, [criterion] and [optimizer] and we currently use the relatively familiar libpath approach to avoid having to create a registry of pytorch criterion and optimizer functions which would need to be loaded at run time (kind of heavy and slow)

The keys in the tables need to share the same names as the parameters that would be passed to the loss or optimizer functions. (we just use **config to pass the params in).

Within the __init__ function of either the built in models or in an external class the user will still need to call:

self.optimizer = self._optimizer()
self.criterion = self._criterion()

(I would like to fix that in a followup PR - Issue #134)

Additionally, if the user has a special def _optimizer() or def _criterion() function that is defined in the model class, we will not over write that.

One final followup would be to allow a Learning Rate scheduler (described here) to be defined in the config as well. That won't happen in this PR though.

@drewoldag drewoldag requested a review from mtauraso December 7, 2024 00:37
@drewoldag drewoldag self-assigned this Dec 7, 2024
@drewoldag drewoldag linked an issue Dec 7, 2024 that may be closed by this pull request
Copy link

codecov bot commented Dec 7, 2024

Codecov Report

Attention: Patch coverage is 42.85714% with 8 lines in your changes missing coverage. Please review.

Project coverage is 39.87%. Comparing base (0467d4a) to head (4d6e778).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/fibad/models/model_registry.py 33.33% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #132      +/-   ##
==========================================
- Coverage   39.97%   39.87%   -0.10%     
==========================================
  Files          22       22              
  Lines        1801     1808       +7     
==========================================
+ Hits          720      721       +1     
- Misses       1081     1087       +6     

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

Copy link

github-actions bot commented Dec 7, 2024

Before [0467d4a] After [9f48f67] Ratio Benchmark (Parameter)
1.14±0.8s 2.86±1s ~2.52 benchmarks.time_computation
752 1.03k 1.37 benchmarks.mem_list

Click here to view all benchmarks.

Copy link
Collaborator

@aritraghsh09 aritraghsh09 left a comment

Choose a reason for hiding this comment

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

This implementation looks perfectly in line with what I had requested!

No comments. Looks ready to merge to me!

@drewoldag drewoldag merged commit 2fa8aa3 into main Dec 10, 2024
8 checks passed
@drewoldag drewoldag deleted the issue/131/specify-loss-and-optimizer-in-config branch December 10, 2024 00:02
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.

Allow specifying loss and optimizer functions in config
2 participants