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

Fix nn.Module type hints #2400

Merged
merged 2 commits into from
Jan 14, 2025
Merged

Conversation

adamjstewart
Copy link
Contributor

All of these inputs are classes, not instances.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@rwightman
Copy link
Collaborator

rwightman commented Jan 11, 2025

@adamjstewart started fixing some of those but never finished... I have a LayerType .... LayerType = Union[str, Callable, Type[torch.nn.Module]] that is meant to cover layer types, usually at the main model level, or major block level that is intended to pass through a module type, creation fn, or string to pass to a factory. Should any of the ones changed in this PR be a LayerType or are they appropriately scoped as Type[nn.Module] ?

Comment on lines +41 to +42
act_layer: Optional[Type[nn.Module]] = None,
conv_layer: Optional[Type[nn.Module]] = 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.

There is an existing bug here. act_layer and conv_layer both default to None, but None is an invalid input and will cause the code to crash. Should we change the default and make it non-optional?

@adamjstewart
Copy link
Contributor Author

None of these are valid LayerTypes because they don't support strings, they must be callables.

Note that I found one typing bug that could have been caught by mypy if you were using it.

@rwightman rwightman merged commit ff77dfa into huggingface:main Jan 14, 2025
22 checks passed
@adamjstewart adamjstewart deleted the types/nn-module branch January 14, 2025 17:55
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.

None yet

3 participants