Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update torch/nn/modules/conv.py to use Literal for support padding modes #152280

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

Open
Skylion007 opened this issue Apr 27, 2025 · 7 comments Β· May be fixed by #152458, #152590 or #152610
Open

Update torch/nn/modules/conv.py to use Literal for support padding modes #152280

Skylion007 opened this issue Apr 27, 2025 · 7 comments Β· May be fixed by #152458, #152590 or #152610
Labels
actionable good first issue module: typing Related to mypy type annotations triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@Skylion007
Copy link
Collaborator

Skylion007 commented Apr 27, 2025

πŸš€ The feature, motivation and pitch

It would be great to update torch/nn/modules/conv.py to use typing.Literal instead of just str to denote with padding modes are actually supported by various operations.

for example instead of
padding_mode : str

do
padding_mode: Literal["valid", "same"] etc to the type checker can catch bugs for the code is actually ran.

Alternatives

No response

Additional context

No response

cc @ezyang @malfet @xuzhao9 @gramster

@Skylion007 Skylion007 added good first issue module: typing Related to mypy type annotations actionable labels Apr 27, 2025
@sudiptap
Copy link

sudiptap commented Apr 27, 2025

can I work on this one? @Skylion007

@Skylion007
Copy link
Collaborator Author

Sure

@soulitzer soulitzer added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Apr 28, 2025
@sudiptap
Copy link

Hi! I had asked to work on this issue earlier (see above), and received approval. Would it be possible to coordinate next time to avoid duplication?

@sudiptap
Copy link

Hi @Skylion007,
Just a quick note to clarify that I had asked to work on issue #152280 and had received approval before starting the work and submitting this PR. I went ahead with the implementation based on that.

I understand someone else submitted a PR earlier, but since my implementation includes test verification and follows the suggested corrections, I hope it can still be considered.

Appreciate your time reviewing this, and happy to make any changes needed. Thanks!

@AnandVishesh1301
Copy link

Hi @Skylion007 , I'd be happy to take a look at the current mypy type error and help resolve the linting failure related to Literal[...] usage in conv.py. Let me know if it's alright for me to jump in and contribute a patch on top of the current implementation. Thanks!

AnandVishesh1301 added a commit to AnandVishesh1301/pytorch that referenced this issue May 1, 2025
* Defines PaddingMode alias
* Annotates Conv{1,2,3}d constructors
* Fixes pytorch#152280
@Muwinuddin
Copy link

"HI i'd like to work on this.Can I take it?

@sudiptap
Copy link

sudiptap commented May 1, 2025

The following files also have similar type annotation issues , torch/ao/nn/qat/modules/conv.py and torch/ao/nn/quantized/modules/conv.py . The QAT version has different padding mode support. The quantized version has a restricted set of supported padding modes (_SUPPORTED_PADDING = {"zeros", "reflect"}) should we file issues to fix those too ? @Skylion007

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment