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

[design] adding a validation decorator #6814

Open
yiyixuxu opened this issue Feb 1, 2024 · 6 comments
Open

[design] adding a validation decorator #6814

yiyixuxu opened this issue Feb 1, 2024 · 6 comments
Labels
stale Issues that haven't received updates

Comments

@yiyixuxu
Copy link
Collaborator

yiyixuxu commented Feb 1, 2024

We try to avoid using the kwargs argument at diffusers because it's error prone and makes our code less readable. However, there are some instances where a fixed signature might not be practical. For example, our default attention processor class AttnProcessor/AttnProcessor2.0 can now be used in conjunction with other attention processors such as IPAdapterProcessor. If we need to pass a new argument to IPAdapterProcessor, we will need to add it to the AttnProcessor's signature as well. It may be worthwhile to consider adding a validation decorator https://github.com/huggingface/huggingface_hub/blob/c528f78fa7404869f32a2b04eac0f9964a5c6f9e/src/huggingface_hub/utils/_validators.py#L46 for this use case

(Original discussion can be found here: #6573 (comment).)

@spezialspezial
Copy link
Contributor

You are the second person saying that and it confuses me. Could someone explain? If I grep across the diffusers codebase there is a gazillion occurrences of kwargs usage, function signatures included. Why is that a precedent now?

Other than that, most languages not supporting variadic functions is another thing I don't get. If not one of these outsider dialects https://en.wikipedia.org/wiki/Variadic_function, what's in your list? Even if it's not supported in some language it's not clear, to me at least, whether this is an pedagogical move. If you are held hostage by big Visual Basic or the Rust user group enforcing their definition of "most languages" blink twice.

@Wauplin
Copy link
Collaborator

Wauplin commented Feb 9, 2024

Hi @yiyixuxu, I just came across this post and I've read this thread as well. I agree with @patrickvonplaten that in general the **kwargs syntax makes it more difficult and error-prone to use an API.

About using a decorator to handle extra parameters I think it's fine (I'm the one that introduced validate_hf_hub_args in the first place in huggingface_hub) but should be thought thoroughly before implementing it. The risks with this hack are about the same as with kwargs: users can't know about the extra params, no early error if typo correction, etc. In the huggingface_hub example I think it's fine because it handles use_auth_token, a parameter that we want to definitely remove/un-document => the validator ensures backward compatibility while not promoting the legacy parameter in the methods signatures.

That being said, I don't exactly know what is the use case here. IMO obfuscation of legacy parameters is a legit use case but **kwargs can have other purposes. So just a warning here, no strong opinion on the specific use case discussed here :)

@spezialspezial
Copy link
Contributor

Maybe we're just talking about different things. Like you said, you don't know what it's about but you agree. How would you support processors with varying, unknown arguments? How do you validate if you don't know ahead of time what to validate for? In this case kwargs.get already validates what is of interest, throws a well known and easily recognizable error, does the minimal amount of work necessary and is likely highly optimized across interpreters. This function is literally called a 1000 times per generation. Not too bad, not nothing either.

Everyone likes readability but does it really trump capabilities? Almost every main() in the world disagrees. It's somewhat getting into "But would you think of the children" territory. Why would you hate children, err, readability?

This issue seems to have a surprising huge push back. In the end I already worked around the issue and I don't know why I'm still invested. Sorry for that.

Copy link

github-actions bot commented Mar 4, 2024

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@sayakpaul
Copy link
Member

@yiyixuxu is this relevant?

@github-actions github-actions bot removed the stale Issues that haven't received updates label Nov 28, 2024
Copy link

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@github-actions github-actions bot added the stale Issues that haven't received updates label Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issues that haven't received updates
Projects
None yet
Development

No branches or pull requests

4 participants