c855f8632e
Pyrefly suppressions 7/n ( #164913 )
...
Adds suppressions to pyrefly will typecheck clean: https://github.com/pytorch/pytorch/issues/163283
Almost there!
Test plan:
dmypy restart && python3 scripts/lintrunner.py -a
pyrefly check
step 1: delete lines in the pyrefly.toml file from the project-excludes field
step 2: run pyrefly check
step 3: add suppressions, clean up unused suppressions
before: https://gist.github.com/maggiemoss/4b3bf2037014e116bc00706a16aef199
after:
INFO 0 errors (6,884 ignored)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/164913
Approved by: https://github.com/oulgen
2025-10-08 07:27:17 +00:00
468c1f9e9d
Revert "[nn] Assert parsed iterable arguments are an appropriate length ( #162340 )"
...
This reverts commit b5e6e58050bd2a15f4173cfffa00c7e32e382b49.
Reverted https://github.com/pytorch/pytorch/pull/162340 on behalf of https://github.com/huydhn due to Sorry for reverting your change but it seems to break an MPS tests on ExecuTorch ([comment](https://github.com/pytorch/pytorch/pull/162340#issuecomment-3282676242 ))
2025-09-11 21:22:57 +00:00
b5e6e58050
[nn] Assert parsed iterable arguments are an appropriate length ( #162340 )
...
Fixes #162327
Pull Request resolved: https://github.com/pytorch/pytorch/pull/162340
Approved by: https://github.com/Skylion007
2025-09-10 15:15:49 +00:00
69cc99525c
[nn]: updated type alias for padddingmode in module/conv.py ( #158843 )
...
Fixes #152280
Changed type of `padding_mode` from `str` to `Literal["zeros", "reflect", "replicate", "circular"]`
**cc** @Skylion007
Pull Request resolved: https://github.com/pytorch/pytorch/pull/158843
Approved by: https://github.com/mikaylagawarecki
2025-07-25 23:05:02 +00:00
163f0d8f2a
[BE][Ez]: Auto add return type annotations for methods in torch/nn/module ( #157925 )
...
Automatically type a bunch of methods in nn.Module using ruff's type inference rules
Pull Request resolved: https://github.com/pytorch/pytorch/pull/157925
Approved by: https://github.com/albanD
2025-07-09 21:12:25 +00:00
596b418391
[BE][PYFMT] migrate PYFMT for {torch,test}/{nn,optim}/**
to ruff format
( #144548 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/144548
Approved by: https://github.com/ezyang
2025-06-14 11:27:04 +00:00
5a64476ed6
[Easy] Add output_size
in forward method of ConvTranspose2d ( #150609 )
...
Fixes #74593
Add description for `forward` in [ConvTranspose2d](https://pytorch.org/docs/stable/generated/torch.nn.ConvTranspose2d.html ) doc
## Test Result

Pull Request resolved: https://github.com/pytorch/pytorch/pull/150609
Approved by: https://github.com/mikaylagawarecki
Co-authored-by: mikaylagawarecki <mikaylagawarecki@gmail.com >
2025-04-14 09:53:22 +00:00
d94cc0e994
Optimize ConvTranspose2d
stride description ( #150819 )
...
Fixes #150775
## Test Result
### Before

### After

Pull Request resolved: https://github.com/pytorch/pytorch/pull/150819
Approved by: https://github.com/jbschlosser
2025-04-11 09:37:56 +00:00
7178b827d7
PEP585: Missed conversions ( #145342 )
...
Differential Revision: [D68785969](https://our.internmc.facebook.com/intern/diff/D68785969 )
Pull Request resolved: https://github.com/pytorch/pytorch/pull/145342
Approved by: https://github.com/bobrenjc93
2025-01-29 05:24:36 +00:00
5fd881a5b6
Revert "PEP585 update - torch/nn torch/optim torch/package torch/profiler torch/serialization torch/sparse torch/xpu ( #145175 )"
...
This reverts commit 54a00af2c6026a830f40d9e6a659ff81d51f9bc6.
Reverted https://github.com/pytorch/pytorch/pull/145175 on behalf of https://github.com/huydhn due to Sorry for reverting your change but it seems to break some trunk tests ([comment](https://github.com/pytorch/pytorch/pull/145175#issuecomment-2603418267 ))
2025-01-21 00:49:55 +00:00
54a00af2c6
PEP585 update - torch/nn torch/optim torch/package torch/profiler torch/serialization torch/sparse torch/xpu ( #145175 )
...
See #145101 for details.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/145175
Approved by: https://github.com/bobrenjc93
2025-01-20 22:32:59 +00:00
d87aad6877
[5/N] Apply Ruff fixes and pyupgrade to Python 3.9 ( #144205 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/144205
Approved by: https://github.com/albanD
2025-01-15 04:00:47 +00:00
08db735629
[BE]: Update mypy to 1.13.0 ( #140808 )
...
Update mypy to 1.13.0 . Should hopefully reduce linting time. Has support for orjson cache serialization which should improve mypy cache perf if orjson is installed.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/140808
Approved by: https://github.com/ezyang , https://github.com/malfet
2024-12-03 02:50:10 +00:00
daa77f3d9f
Revert "[BE]: Update mypy to 1.13.0 ( #140808 )"
...
This reverts commit 00134d68af2ce50560fa5a74473665ea229e6c9d.
Reverted https://github.com/pytorch/pytorch/pull/140808 on behalf of https://github.com/huydhn due to This is failing a distributed test in trunk, target determination missed this test and did not run it on PR ([comment](https://github.com/pytorch/pytorch/pull/140808#issuecomment-2512788426 ))
2024-12-02 20:47:43 +00:00
00134d68af
[BE]: Update mypy to 1.13.0 ( #140808 )
...
Update mypy to 1.13.0 . Should hopefully reduce linting time. Has support for orjson cache serialization which should improve mypy cache perf if orjson is installed.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/140808
Approved by: https://github.com/ezyang , https://github.com/malfet
2024-12-02 18:47:54 +00:00
c9de2efde6
[Docs] fix inconsistent docs in conv1d, conv2d, and conv3d ( #135894 )
...
Addresses https://github.com/pytorch/pytorch/issues/135880
Pull Request resolved: https://github.com/pytorch/pytorch/pull/135894
Approved by: https://github.com/mikaylagawarecki , https://github.com/malfet
2024-09-13 00:19:42 +00:00
534f43ddce
[Doc] Fix rendering of the unicode characters ( #134597 )
...
https://github.com/pytorch/pytorch/pull/124771 introduced unicode escape sequences inside raw strings, which were not rendered correctly. Also fix typo in `\uue0 ` escape sequence (should have been `\u00e0`)
Fix it by relying on [string literal concatenation](https://docs.python.org/3/reference/lexical_analysis.html#string-literal-concatenation ) to join raw and regular strings together during lexical analysis stage
Fixes https://github.com/pytorch/pytorch/issues/134422
Pull Request resolved: https://github.com/pytorch/pytorch/pull/134597
Approved by: https://github.com/aorenste , https://github.com/Skylion007
2024-08-27 19:52:46 +00:00
62ccf6d7cd
[BE] enable UFMT for torch/nn/modules
( #128594 )
...
Part of #123062
- #123062
Pull Request resolved: https://github.com/pytorch/pytorch/pull/128594
Approved by: https://github.com/mikaylagawarecki
2024-06-23 05:37:57 +00:00
d4022b4658
Revert "[BE] enable UFMT for torch/nn/modules
( #128594 )"
...
This reverts commit 95ac2d648279ebc73feccf6d8eccafa4b2759de8.
Reverted https://github.com/pytorch/pytorch/pull/128594 on behalf of https://github.com/fbgheith due to breaking internal builds ([comment](https://github.com/pytorch/pytorch/pull/128594#issuecomment-2181788935 ))
2024-06-21 00:50:08 +00:00
95ac2d6482
[BE] enable UFMT for torch/nn/modules
( #128594 )
...
Part of #123062
- #123062
Pull Request resolved: https://github.com/pytorch/pytorch/pull/128594
Approved by: https://github.com/mikaylagawarecki
ghstack dependencies: #128596
2024-06-17 16:29:25 +00:00
27f9d3b0a1
Flip default value for mypy disallow_untyped_defs [8/11] ( #127845 )
...
See #127836 for details.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/127845
Approved by: https://github.com/oulgen
ghstack dependencies: #127842 , #127843 , #127844
2024-06-08 18:49:56 +00:00
67ef2683d9
[BE] wrap deprecated function/class with typing_extensions.deprecated
( #127689 )
...
Use `typing_extensions.deprecated` for deprecation annotation if possible. Otherwise, add `category=FutureWarning` to `warnings.warn("message")` if the category is missing.
Note that only warnings that their messages contain `[Dd]eprecat(ed|ion)` are updated in this PR.
Resolves #126888
- #126888
This PR is split from PR #126898 .
- #126898
------
Pull Request resolved: https://github.com/pytorch/pytorch/pull/127689
Approved by: https://github.com/Skylion007
2024-06-02 12:30:43 +00:00
033e733021
Revert "[BE] wrap deprecated function/class with typing_extensions.deprecated
( #126898 )"
...
This reverts commit 749a132fb0a8325cbad4734a563aa459ca611991.
Reverted https://github.com/pytorch/pytorch/pull/126898 on behalf of https://github.com/fbgheith due to switching typing-extensions=4.3.0 to 4.9.0 causes internal failure ([comment](https://github.com/pytorch/pytorch/pull/126898#issuecomment-2142884456 ))
2024-05-31 19:47:24 +00:00
749a132fb0
[BE] wrap deprecated function/class with typing_extensions.deprecated
( #126898 )
...
Use `typing_extensions.deprecated` for deprecation annotation if possible. Otherwise, add `category=FutureWarning` to `warnings.warn("message")` if the category is missing.
Note that only warnings that their messages contain `[Dd]eprecat(ed|ion)` are updated in this PR.
UPDATE: Use `FutureWarning` instead of `DeprecationWarning`.
Resolves #126888
- #126888
Pull Request resolved: https://github.com/pytorch/pytorch/pull/126898
Approved by: https://github.com/albanD
2024-05-29 12:09:27 +00:00
a8574a9719
Fix global flake8 issues ( #124771 )
...
Prior to this `lintrunner --all-files --take FLAKE8` failed.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/124771
Approved by: https://github.com/Skylion007
ghstack dependencies: #124428
2024-04-26 15:35:53 +00:00
1ac60484c1
Revert "Fix global flake8 issues ( #124771 )"
...
This reverts commit f01275934bfa1ff358b1c01d3754f2807cd04ee2.
Reverted https://github.com/pytorch/pytorch/pull/124771 on behalf of https://github.com/jeanschmidt due to Unfortunately, I needed to revert #123735 and this one depends on it. So please check if there are no merge conflicts or breakages and feel free to merge this PR again ([comment](https://github.com/pytorch/pytorch/pull/124428#issuecomment-2078699836 ))
2024-04-26 06:15:17 +00:00
f01275934b
Fix global flake8 issues ( #124771 )
...
Prior to this `lintrunner --all-files --take FLAKE8` failed.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/124771
Approved by: https://github.com/Skylion007
ghstack dependencies: #124428
2024-04-25 14:25:00 +00:00
5a1216bb2e
[BE]: Update ruff to 0.4.1 ( #124549 )
...
Update ruff to 0.4.1 .
This version fixes a lot false negatives/false positives, is 20-40% faster, and has various other bug fixes.
Below is a before and after table showing the execution time of ruff lint and ruff format in milliseconds courtesy of https://astral.sh/blog/ruff-v0.4.0
| Repository | Linter (v0.3) | Linter (v0.4) | Formatter (v0.3) | Formatter (v0.4) |
|----------------------------------------------------|---------------|---------------|------------------|------------------|
| [pytorch/pytorch](https://github.com/pytorch/pytorch ) | 328.7 | 251.8 | 351.1 | 274.9 |
Pull Request resolved: https://github.com/pytorch/pytorch/pull/124549
Approved by: https://github.com/ezyang
2024-04-21 14:06:23 +00:00
93e249969b
[BE] enable ruff
rule RSE
and remove useless parentheses in raise
statements ( #124261 )
...
Remove useless parentheses in `raise` statements if the exception type is raised with no argument.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/124261
Approved by: https://github.com/albanD
2024-04-17 19:29:34 +00:00
eeea3b12aa
Fix _LazyConvXdMixin.initialize_parameters and add related tests ( #123756 )
...
Fixes #123257
_LazyConvXdMixin.initialize_parameters did not handle positional args (other than input) and kwargs to be passed on to the corresponding non-lazy class' .forward() method.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/123756
Approved by: https://github.com/mikaylagawarecki
2024-04-13 03:58:37 +00:00
cb233dada4
Fix docstrings on torch/nn/modules ( #113260 )
...
Fixes #112598
## Description
Fixes the docstrings on following files.
```bash
pydocstyle path-to-file --count
```
| File | Count |
| ------------------------------------- | ------- |
| torch/nn/modules/adaptive.py | 20 -> 4 |
| torch/nn/modules/channelshuffle.py | 7 -> 4 |
| torch/nn/modules/conv.py | 37 -> 25 |
| torch/nn/modules/distance.py | 7 -> 5 |
| torch/nn/modules/dropout.py | 17 -> 7 |
| torch/nn/modules/flatten.py | 10 -> 7 |
| torch/nn/modules/fold.py | 11 -> 7 |
| torch/nn/modules/instancenorm.py | 13 -> 1 |
| torch/nn/modules/lazy.py | 11 -> 2 |
| torch/nn/modules/linear.py | 20 -> 14 |
| torch/nn/modules/normalization.py | 25 -> 16 |
| torch/nn/modules/padding.py | 33 -> 19 |
Pull Request resolved: https://github.com/pytorch/pytorch/pull/113260
Approved by: https://github.com/mikaylagawarecki
2023-11-10 18:22:48 +00:00
660e8060ad
[BE]: Update ruff to 0.285 ( #107519 )
...
This updates ruff to 0.285 which is faster, better, and have fixes a bunch of false negatives with regards to fstrings.
I also enabled RUF017 which looks for accidental quadratic list summation. Luckily, seems like there are no instances of it in our codebase, so enabling it so that it stays like that. :)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/107519
Approved by: https://github.com/ezyang
2023-08-22 23:16:38 +00:00
d59a6864fb
Revert "[BE]: Update ruff to 0.285 ( #107519 )"
...
This reverts commit 88ab3e43228b7440a33bf534cde493446a31538c.
Reverted https://github.com/pytorch/pytorch/pull/107519 on behalf of https://github.com/ZainRizvi due to Sorry, but this PR breaks internal tests. @ezyang, can you please hep them get unblocked? It seems like one of the strings was prob accidentally modified ([comment](https://github.com/pytorch/pytorch/pull/107519#issuecomment-1688833480 ))
2023-08-22 19:53:32 +00:00
88ab3e4322
[BE]: Update ruff to 0.285 ( #107519 )
...
This updates ruff to 0.285 which is faster, better, and have fixes a bunch of false negatives with regards to fstrings.
I also enabled RUF017 which looks for accidental quadratic list summation. Luckily, seems like there are no instances of it in our codebase, so enabling it so that it stays like that. :)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/107519
Approved by: https://github.com/ezyang
2023-08-20 01:36:18 +00:00
4cc1745b13
[BE] f-stringify torch/ and scripts ( #105538 )
...
This PR is a follow up on the pyupgrade series to convert more strings to use f-strings using `flynt`.
- https://docs.python.org/3/reference/lexical_analysis.html#f-strings
- https://pypi.org/project/flynt/
Command used:
```
flynt torch/ -ll 120
flynt scripts/ -ll 120
flynt tools/ -ll 120
```
and excluded `collect_env.py`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/105538
Approved by: https://github.com/ezyang , https://github.com/malfet
2023-07-21 19:35:24 +00:00
79c5e33349
[BE] Enable ruff's UP rules and autoformat nn/ mps/ and torch/ ( #105436 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/105436
Approved by: https://github.com/malfet , https://github.com/albanD
2023-07-21 07:38:46 +00:00
5837e95d30
[Reland] Update mypy to 1.4.1 ( #105227 )
...
This PR re-lands
- [Typing] Fix PEP 484 Violation (#105022 )
- Update mypy to 1.4.1 (#91983 )
That were reverted due to the conflict with internal source repo.
Mostly fixes for PEP-484 violation (i.e. when default arg is set to None, but type is not annotated as optional)
Plus few real fixes:
- Add missing `_get_upgraders_entry_map` to `torch/_C/__init__.pyi`
- Add missing return statement to `torch._export. deserialize_graph`
- Fix error message in `torch.ao.ns.fx.weight_utils.get_lstm_mod_weights`
- Add assert it `torch/optim/optimizer.py` that Optional list is not None
TODO (in followup PR):
- Fix erroneous `isinstance` check in `torch/ao/quantization/_pt2e/qat_utils.py`
Unrelated, to bypass CI failures due to the gcc9 dependency update in Ubuntu-18.04:
- Add hack to squash older libstdc++ from conda environment in favor one from OS to `.ci/docker/install_conda.sh`
- Update bazel cuda builds to focal, as with libstdc++-6.0.32 bazel builds loose the ability to catch exceptions (probably because they link with cupti statically, but I could not found where it is done)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/105227
Approved by: https://github.com/atalman , https://github.com/albanD , https://github.com/Skylion007
2023-07-15 20:30:20 +00:00
15fd1ea118
Revert "[Reland] Update mypy to 1.4.1 ( #105227 )"
...
This reverts commit c9c4f8efc3dd4e66059522bf5f5c1ba0431e2069.
Reverted https://github.com/pytorch/pytorch/pull/105227 on behalf of https://github.com/atalman due to trying to mitigate ci sev #105248 ([comment](https://github.com/pytorch/pytorch/pull/105227#issuecomment-1636510935 ))
2023-07-14 22:28:35 +00:00
c9c4f8efc3
[Reland] Update mypy to 1.4.1 ( #105227 )
...
This PR re-lands
- [Typing] Fix PEP 484 Violation (#105022 )
- Update mypy to 1.4.1 (#91983 )
That were reverted due to the conflict with internal source repo.
Mostly fixes for PEP-484 violation (i.e. when default arg is set to None, but type is not annotated as optional)
Plus few real fixes:
- Add missing `_get_upgraders_entry_map` to `torch/_C/__init__.pyi`
- Add missing return statement to `torch._export. deserialize_graph`
- Fix error message in `torch.ao.ns.fx.weight_utils.get_lstm_mod_weights`
- Add assert it `torch/optim/optimizer.py` that Optional list is not None
TODO (in followup PR):
- Fix erroneous `isinstance` check in `torch/ao/quantization/_pt2e/qat_utils.py`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/105227
Approved by: https://github.com/atalman , https://github.com/albanD , https://github.com/Skylion007
2023-07-14 20:45:12 +00:00
3c5a494d7a
Revert "Update mypy to 1.4.1 ( #91983 )"
...
This reverts commit 634659e262f82bbc76aa776119c9fea079fbffe3.
Reverted https://github.com/pytorch/pytorch/pull/91983 on behalf of https://github.com/malfet due to It's dependent change was reverted, so reverting this one as well, to keep CI clean ([comment](https://github.com/pytorch/pytorch/pull/91983#issuecomment-1636059709 ))
2023-07-14 15:59:16 +00:00
634659e262
Update mypy to 1.4.1 ( #91983 )
...
Mostly fixes for PEP-484 violation (i.e. when default arg is set to None, but type is not annotated as optional)
Plus few real fixes:
- Add missing `_get_upgraders_entry_map` to `torch/_C/__init__.pyi`
- Add missing return statement to `torch._export. deserialize_graph`
- Fix error message in `torch.ao.ns.fx.weight_utils.get_lstm_mod_weights`
-
TODO (in followup PR):
- Fix erroneous `isinstance` check in `torch/ao/quantization/_pt2e/qat_utils.py`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/91983
Approved by: https://github.com/kit1980 , https://github.com/ZainRizvi , https://github.com/huydhn , https://github.com/thiagocrepaldi , https://github.com/aaronenyeshi
2023-07-13 16:30:36 +00:00
5b1cedacde
[BE] [2/3] Rewrite super()
calls in functorch and torch ( #94588 )
...
Rewrite Python built-in class `super()` calls. Only non-semantic changes should be applied.
- #94587
- #94588
- #94592
Also, methods with only a `super()` call are removed:
```diff
class MyModule(nn.Module):
- def __init__(self):
- super().__init__()
-
def forward(self, ...):
...
```
Some cases that change the semantics should be kept unchanged. E.g.:
f152a79be9/caffe2/python/net_printer.py (L184-L190)
f152a79be9/test/test_jit_fuser_te.py (L2628-L2635)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/94588
Approved by: https://github.com/ezyang , https://github.com/albanD
2023-02-10 21:16:33 +00:00
6f609dd0e0
docs: conv2d padding
attribute- add int
option ( #85004 )
...
`padding: int` already exists but isn't mentioned in the genereted docs
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85004
Approved by: https://github.com/albanD , https://github.com/kit1980
2022-11-18 04:29:02 +00:00
ae67099e88
Fix type annotation in _ConvNd
for in_channels ( #84302 )
...
`_ConvNd` has an attribute `in_channels` that was mistakenly annotated as `_in_channels`.
This fixes https://github.com/pytorch/pytorch/issues/84223
Pull Request resolved: https://github.com/pytorch/pytorch/pull/84302
Approved by: https://github.com/albanD
2022-09-02 15:15:30 +00:00
357b7d589c
Fix docstring inconsistencies: string -> str, boolean -> bool ( #82410 )
...
### Description
Throughout the PyTorch docs and codebase, the `string` type in docstrings is referred to by two separate names. This leads to inconsistent docs, like you can see here: https://pytorch.org/docs/stable/generated/torch.nn.Conv3d.html#torch.nn.Conv3d
This PR fixes this issue by ensuring that all mentions of the string type in docstrings, are using the same format that Sphinx generates hyperlinks for.
### Testing
No testing should be required for this change
Pull Request resolved: https://github.com/pytorch/pytorch/pull/82410
Approved by: https://github.com/jbschlosser
2022-07-28 21:29:57 +00:00
9db3c517de
Add __all__ for torch.nn.modules, torch.distributed.elastic, torch.nn.utils submodules ( #80240 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/80240
Approved by: https://github.com/rohan-varma
2022-06-27 17:11:12 +00:00
4e1f41f66a
[docs][nn] conv: complex support note ( #78351 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/78351
Approved by: https://github.com/anjali411 , https://github.com/jbschlosser
2022-05-26 20:33:36 +00:00
c186250d95
raise error when groups is not positive in Conv modules
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/77919
Approved by: https://github.com/jbschlosser
2022-05-23 20:35:00 +00:00
de86146c61
rocblas alt impl during backward pass only ( #71881 )
...
In preparation of adopting future rocblas library options, it is necessary to track when the backward pass of training is executing. The scope-based helper class `BackwardPassGuard` is provided to toggle state.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/71881
Approved by: https://github.com/albanD
2022-05-18 19:42:58 +00:00
041e6e750a
Fix to support no-batch-dim inputs in ConvTransposeNd._output_padding
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76151
Approved by: https://github.com/albanD
2022-04-22 19:25:09 +00:00