Skip to content
New issue

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

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

Already on GitHub? # to your account

Keras: Saving history in a JSON file #861

Merged
merged 2 commits into from
May 9, 2022
Merged

Keras: Saving history in a JSON file #861

merged 2 commits into from
May 9, 2022

Conversation

merveenoyan
Copy link
Contributor

@merveenoyan merveenoyan commented May 5, 2022

This is a minor change that saves history as a JSON file, if history exists.
We check if history exists or not during parsing it to a markdown in _parse_model_history() so I handled it there not to write repetitive checks. It can be further improved inside, just wanted to keep them separately for the sake of readability. (will later refactor the whole mixin and card creation after sprint is done) This might not be the best choice ever so feel free to criticize.
Wrote a test to check if the file is there.

@merveenoyan merveenoyan requested a review from osanseviero May 5, 2022 12:21
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented May 5, 2022

The documentation is not available anymore as the PR was closed or merged.

@merveenoyan
Copy link
Contributor Author

Also @osanseviero do you think it makes sense to get rid of history in model card?
It logs every single epoch to card, which will be long once people train models with 100 epochs. Or we can at least toggle.

Copy link
Contributor

@osanseviero osanseviero left a comment

Choose a reason for hiding this comment

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

The PR Looks fine to me, thanks Merve for this PR!! @nateraw could you take a second look please?

(will later refactor the whole mixin and card creation after sprint is done)

Note from internal discussions, #847 and other things going on that refactoring the mixin and card creation is overlapping with other efforts (but also totally unrelated to this PR I think 😄 )

@osanseviero osanseviero requested a review from nateraw May 5, 2022 13:38
@merveenoyan
Copy link
Contributor Author

@osanseviero I find model card code not readable, and I feel like functions can be tweaked for better readability that's what the refactor I'm planning is about. But it's not prioritized anyway 🤗

Copy link
Contributor

@nateraw nateraw left a comment

Choose a reason for hiding this comment

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

LGTM 🤗. In future PRs, let's try to simplify here, as this keras mixin file is getting a little hard to read haha.

Thanks for this one @merveenoyan! ❤️

@@ -39,10 +39,13 @@ def _extract_hyperparameters_from_keras(model):
return hyperparameters


def _parse_model_history(model):
def _parse_model_history(model, save_directory):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not in love with the fact this history writing is happening so deep in the logic here. save_pretrained_keras -> _create_model_card -> _write_metrics -> _parse_model_history is so deep in the code to just save model.history.history as a json file.

I don't want to block on this, but just wanted to point that out so we remember to put this in a nicer spot in future refactors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's what I wanted to refactor as well (it disturbed me too!). I'm planning to do that after next Keras sprint.

@julien-c julien-c changed the title Saving history in a JSON file Keras: Saving history in a JSON file May 6, 2022
Co-authored-by: Nathan Raw <nxr9266@g.rit.edu>
@merveenoyan merveenoyan requested a review from osanseviero May 9, 2022 12:24
@LysandreJik LysandreJik added this to the v0.6 milestone May 9, 2022
Copy link
Contributor

@osanseviero osanseviero left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! 🚀

@osanseviero osanseviero merged commit a7eecef into huggingface:main May 9, 2022
@merveenoyan merveenoyan deleted the keras_mixin_history branch May 10, 2022 11:11
LysandreJik pushed a commit that referenced this pull request May 24, 2022
* added test and history saving

* Update src/huggingface_hub/keras_mixin.py

Co-authored-by: Nathan Raw <nxr9266@g.rit.edu>

Co-authored-by: Nathan Raw <nxr9266@g.rit.edu>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants