-
Notifications
You must be signed in to change notification settings - Fork 632
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
ENH remove history writing into model card, convert hyperparameters from a dict into table in model card, removed a header #872
Conversation
The documentation is not available anymore as the PR was closed or merged. |
@merveenoyan could you write a test for this so that we could see how it affects the results? |
@adrinjalali This changes output in the model card (basically the hyperparameters were printed as dictionary and now they're a table) and I removed the part that wrote history inside the card, and I feel like testing it is too overkill, if you insist I will write the test but I wouldn't like to do it for the time being 😅 |
src/huggingface_hub/keras_mixin.py
Outdated
if model.history.history != {}: | ||
path = os.path.join(save_directory, "history.json") | ||
with open(path, "w") as f: | ||
json.dump(model.history.history, f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a test that checks that this file is created and contains the history?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already added that test previously, see
self.assertIn("history.json", files) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you want I can create a test for the case where there's no history (can make a prediction and make history go away) and assert that the file doesn't exist but I feel like that's also overkill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually confused by this part as I thought this was added in #861. Also, you're not keeping the original format
path = os.path.join(save_directory, "history.json")
with open(path, "w", encoding="utf-8") as f:
json.dump(model.history.history, f, indent=2, sort_keys=True)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's already a test then it's good, but let's keep the json format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR name says "ENH remove history writing into model card and convert hyperparameters into table in model card for Keras #872", but i feel there are more things going around. Improving a bit the PR description and name would be very useful here.
Some general thoughts/questions though:
- Creating a markdown table in a function called
_extract_hyperparameters_from_keras
seems misleading, should this be renamed? - Why was "training procedure" h2 removed?
- Why were the metric writing removed entirely?
src/huggingface_hub/keras_mixin.py
Outdated
if model.history.history != {}: | ||
path = os.path.join(save_directory, "history.json") | ||
with open(path, "w") as f: | ||
json.dump(model.history.history, f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's already a test then it's good, but let's keep the json format
@osanseviero I will check and address your comments :) |
It's just that as it is, it's not easy for me to review the PR since I don't know what the effect of this PR is. It would make it easier to review if I could see an example before and after this PR, and then we can decide if a test makes sense. Like, a standalone example to use this change, and generate the modelcard locally and see the difference. |
@osanseviero I updated the description and name. I also changed the function name for table creation and brought back the JSON format. |
I removed metric writing in the card only, previously we put it inside a JSON file so it's redundant to have it in the card and looks bad when user trains a model with 100 epochs (in the card). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok so I see a few things going on here, not just hparams related stuff.
- I see training metrics being removed entirely? (Maybe I looked too quickly?)
- I don't see tensorboard in your second model repo you posted above that is the result of this PR. Is this intentional?
- I would really like to see some comments/docstrings added so folks who want to contribute can have better understanding of what's going on
- The code has changed quite a bit but the tests haven't. Should we be adding in tests for this? (I think probably yes?)
Also, if we're going to add hparams to a file, might I suggest we do so with hparams.yaml
so we can get the added benefit of seeing hparams in tensorboard if the user pushes tensorboard? This would take some additional logic + testing I'm sure, but I'm pretty sure if you put hparams.yaml in the same dir as your tensorboard logs, they should surface up in the hparams
tab in TensorBoard, which can be really helpful. Not a dealbreaker, but an idea that could be fruitful to some.
if model.history.history != {}: | ||
path = os.path.join(save_directory, "history.json") | ||
with open(path, "w") as f: | ||
json.dump(model.history.history, f, indent=2, sort_keys=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making sure the format is in line with HF stuff.
@@ -27,45 +27,27 @@ | |||
import tensorflow as tf | |||
|
|||
|
|||
def _extract_hyperparameters_from_keras(model): | |||
def _create_hyperparameters_table(model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A docstring here would be helpful to explain what's going on.
@@ -123,15 +85,11 @@ def _create_model_card( | |||
model_card += "\n## Intended uses & limitations\n\nMore information needed\n" | |||
model_card += "\n## Training and evaluation data\n\nMore information needed\n" | |||
if hyperparameters is not None: | |||
model_card += "\n## Training procedure\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this removed? I don't know if it needs to be there or not, but just curious as to why its gone now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was redundant. We're putting training related stuff only if hyperparams are there so it doesn't make any sense to keep it since metrics are gone.
with open(path, "w", encoding="utf-8") as f: | ||
json.dump(model.history.history, f, indent=2, sort_keys=True) | ||
lines = [] | ||
logs = model.history.history |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait so here the training metrics section is gone too? No TensorBoard logs either?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TensorBoard logs don't leverage this anyway. They're still here.
see
if log_dir is not None: |
Multiple small PRs, each one with individual changes, tends to be better than a larger PR with multiple changes impacting different completely unrelated things, it's making it a bit harder for 3 people to go through the PR, understand what is being changed, and clearly is creating a bit of confusion 😅 |
I didn't remove tensorboard, it's just in the model I pushed I didn't log them to be quick. See
|
I will break this PR up. |
Closing this as it's now split. |
This PR removes the history part in model card and turns hyperparameters dictionary into table in the model card like below.
It was previously looking like this:

I removed the metrics (aka history) from the card itself, and turned hyperparameters into a table. History is already kept in a json file and when people train a model with 1000 epochs it will not look good on the card that's why I did it.
I also removed the header "Training Procedure" because I felt like it looked redundant.
this solves #869