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

Introducing list of tags to Keras model card #806

Merged
merged 17 commits into from
Apr 22, 2022
Merged

Conversation

merveenoyan
Copy link
Contributor

@merveenoyan merveenoyan commented Mar 29, 2022

This PR closes #800
Resulting model card looks like this when given the tags list ["audio", "speech"].

@merveenoyan merveenoyan requested a review from osanseviero March 29, 2022 11:26
@julien-c
Copy link
Member

BTW (commenting here because i just glanced at the code): maybe more future proof to create the yaml part of the model card using pyyaml (which is already a dependency of this lib anyways)

I remember that's what we did in transformers

@osanseviero
Copy link
Contributor

Actually we already have repocard.py which could make things easier for this

https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/repocard.py

@merveenoyan
Copy link
Contributor Author

@julien-c thanks for the tip, it looks much cleaner!

@merveenoyan
Copy link
Contributor Author

@osanseviero I didn't see your comment and added with yaml.dump(), it was two lines of code, do you want me to change it?

@osanseviero
Copy link
Contributor

I think using pyyaml like this works, I will add some additional suggestions to this PR a bit later

@merveenoyan
Copy link
Contributor Author

tags can be passed as string or a list, brought back task_name after tags, added warning only for save_pretrained_keras since it's already called from push_to_hub_keras and others.

@merveenoyan merveenoyan requested a review from osanseviero March 31, 2022 11:31
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Mar 31, 2022

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

@merveenoyan
Copy link
Contributor Author

Merged main into this branch for other docs related changes and aligned docstring with main.

@merveenoyan
Copy link
Contributor Author

is there any formatter or style checker that can indicate if a docstring is fit? @osanseviero

@osanseviero
Copy link
Contributor

osanseviero commented Mar 31, 2022

is there any formatter or style checker that can indicate if a docstring is fit? @osanseviero

Not sure, but as you can see at #806 (comment), the docs are actually built for you 🔥

Maybe @LysandreJik knows

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!

src/huggingface_hub/keras_mixin.py Outdated Show resolved Hide resolved
src/huggingface_hub/keras_mixin.py Outdated Show resolved Hide resolved
src/huggingface_hub/keras_mixin.py Show resolved Hide resolved
src/huggingface_hub/keras_mixin.py Outdated Show resolved Hide resolved
src/huggingface_hub/keras_mixin.py Outdated Show resolved Hide resolved
src/huggingface_hub/keras_mixin.py Show resolved Hide resolved
tests/test_keras_integration.py Show resolved Hide resolved
@merveenoyan
Copy link
Contributor Author

Sorry I kinda rushed it, missed the nits. I added a test. @osanseviero I'll be waiting for @adrinjalali's comment on deprecation.

@merveenoyan
Copy link
Contributor Author

I left metadata part as dictionary for convenience.
So if the task_name is seen, user receives warning, it's popped from kwargs and passed to metadata. I've also put a test to see if the warning is raised.

save_pretrained_keras(
                model,
                f"{WORKING_REPO_DIR}/{REPO_NAME}",
                tags=["test"],
                task_name="test",
                save_traces=True,
            )

@merveenoyan merveenoyan requested a review from osanseviero April 14, 2022 13:33
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.

Cool! This is looking safer and very nice! I left a couple of cleanup nits but almost ready to go 🚀

src/huggingface_hub/keras_mixin.py Outdated Show resolved Hide resolved
metadata["tags"] = tags
elif isinstance(tags, str):
metadata["tags"] = [tags]
if "task_name" in locals():
Copy link
Contributor

Choose a reason for hiding this comment

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

In lines 194 to 199 you can maybe do

task_name = model_save_kwargs.pop("task_name", None) # This means the default will be None
if task_name is not None:
   warnings.warn(
            "`task_name` input argument is removed. Pass `tags` instead.",
            FutureWarning,
        )

and similarly, here you won't need to check locals(), which seems a bit hacky, and you can just do
if task_name is not None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it doesn't work, it says "task_name local variable mentioned before assignment" that's why I had to do it. I'll check if I mention it anywhere else.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you get the error because task_name is created within an if. My suggestion is to have this outside all the ifs.

os.makedirs(save_directory, exist_ok=True)

task_name = model_save_kwargs.pop("task_name", None) # This means the default will be None
if task_name is not None:
   warnings.warn(
            "`task_name` input argument is removed. Pass `tags` instead.",
            FutureWarning,
        )
...

Copy link
Contributor Author

@merveenoyan merveenoyan Apr 20, 2022

Choose a reason for hiding this comment

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

I thought it wouldn't be able to pop or return KeyError. thanks!

src/huggingface_hub/keras_mixin.py Show resolved Hide resolved
tests/test_keras_integration.py Show resolved Hide resolved
@merveenoyan merveenoyan requested a review from osanseviero April 20, 2022 11:36
@merveenoyan
Copy link
Contributor Author

@osanseviero my stupidity, I did fix them after I did a git add and I didn't add changes again apparently 😅😂 I was like "I could swear I changed them previously!!! am I hallucinating? 🥲" very sorry, I do listen to your comments before I resolve them, just saying.

@merveenoyan merveenoyan requested a review from osanseviero April 20, 2022 15:54
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.

Very nice! Thank you so much for this PR and iterating on it! 🚀

src/huggingface_hub/keras_mixin.py Outdated Show resolved Hide resolved
Co-authored-by: Omar Sanseviero <osanseviero@gmail.com>
@merveenoyan merveenoyan merged commit b1cf2d8 into main Apr 22, 2022
@merveenoyan merveenoyan deleted the keras_model_tags branch April 22, 2022 12:49
@osanseviero
Copy link
Contributor

Please don't merge PRs that are in red like this one, all tests from last 4 days show in red https://github.com/huggingface/huggingface_hub/actions/workflows/python-tests.yml due to a (very minor though) mismatch in a test warning. I sent #855 to fix this

@adrinjalali
Copy link
Contributor

Also, note that we're trying to merge other people's PRs instead of our own on this repo :)

(I should get on writing our policies and their variations for our repos)

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 multiple tags with the Keras mixin
5 participants