36871622f1
[2/N] Mark unused parameters in C++ code ( #165121 )
...
This is follow-up of #164912 to mark unused C++ parameters to improve code readability.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/165121
Approved by: https://github.com/Skylion007
2025-10-15 03:04:39 +00:00
b67785d9eb
Revert "C++ API handle optimizer defaults ( #161825 )"
...
This reverts commit f33201729416ed17467228e80b04d01d4d02b5f3.
Reverted https://github.com/pytorch/pytorch/pull/161825 on behalf of https://github.com/facebook-github-bot due to Diff reverted internally ([comment](https://github.com/pytorch/pytorch/pull/161825#issuecomment-3391506427 ))
2025-10-10 17:56:11 +00:00
f332017294
C++ API handle optimizer defaults ( #161825 )
...
Fixes #141884
This fixes the issue for all optimizers and parameter options.
A member function `overwrite_from` is added to the optimizer base class. Each optimizer then implements this function for comparing their accepted parameters to defaults. A SFINAE approach to handle the different optimizer parameters generically (in optimizer.h only) was evaluated, but I think this is easier to review and maintain.
This mirrors the Python API up to one edge case. An example of the edge case is provided below.
Python can distinguish between 1) Key not present in dict = "not specified" and 2) Key present in dict = "explicitly set". The C++ implementation cannot.
The issue hinges on whether or not to track if a particular parameter was set by the user explicitly or not (discrepancy in the case when the constructor default is explicitly passed in).
To track this seems like it will take more intervention than would be worth it (modify TORCH_ARG to keep track, use std::optional for the parameter types, use bitset tracking) and was not pursued in the current PR. I'm happy to alter the design if appropriate.
### Example of edge case hinging on CONSTRUCTOR DEFAULTS vs OPTIMIZER DEFAULTS
1. CONSTRUCTOR DEFAULTS:
These are the values you get when calling AdamOptions()
AdamOptions().lr() = 0.001
AdamOptions().weight_decay() = 0
AdamOptions().eps() = 1e-08
2. OPTIMIZER DEFAULTS:
These are the values the user chose when creating the optimizer
User's optimizer defaults:
optimizer.lr() = 0.005
optimizer.weight_decay() = 0.1
optimizer.eps() = 1e-07
3. THE PROBLEM SCENARIO:
User wants to add a parameter group with explicit weight_decay=0.0
User sets: weight_decay(0)
4. THE CONFUSION:
Constructor default weight_decay: 0
User's explicit weight_decay: 0
Are they equal? YES
Since they're equal, our overwrite_from() logic thinks:
"User didn't set weight_decay explicitly, use optimizer default"
5. CURRENT BEHAVIOR:
Final weight_decay: 0.1
User expected: 0
Match? ❌ NO
=== KEY INSIGHT ===
Constructor defaults are built into the C++ class definition.
Optimizer defaults are chosen by the user at runtime. We want to respect the user intention.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/161825
Approved by: https://github.com/janeyx99
2025-10-08 16:40:45 +00:00
f37a6523ef
Move version.h to torch/headeronly ( #164381 )
...
Differential Revision: [D83685392](https://our.internmc.facebook.com/intern/diff/D83685392 )
Pull Request resolved: https://github.com/pytorch/pytorch/pull/164381
Approved by: https://github.com/janeyx99
2025-10-07 17:47:30 +00:00
9fff8155c3
[2/N] Fix clang-tidy readability checks ( #164652 )
...
This PR applies clang-tidy readability checks to jit sources and all headers in the code base.
`readability-redundant-inline-specifier` is suppressed because it incurs too many changes. `readability-redundant-inline-specifier` is used to detect redundant inline specifiers on function and variable declarations. There are many in-class method definitions that are marked inline.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/164652
Approved by: https://github.com/Skylion007
2025-10-06 01:06:01 +00:00
2c5ed6e7c0
Revert "[2/N] Fix clang-tidy readability checks ( #164652 )"
...
This reverts commit 3c5ca685d6f5b6f3971c0cd20a054aa355610419.
Reverted https://github.com/pytorch/pytorch/pull/164652 on behalf of https://github.com/izaitsevfb due to need to revert due to a conflict with revert of https://github.com/pytorch/pytorch/pull/162659 ([comment](https://github.com/pytorch/pytorch/pull/164652#issuecomment-3369346707 ))
2025-10-05 21:36:57 +00:00
3c5ca685d6
[2/N] Fix clang-tidy readability checks ( #164652 )
...
This PR applies clang-tidy readability checks to jit sources and all headers in the code base.
`readability-redundant-inline-specifier` is suppressed because it incurs too many changes. `readability-redundant-inline-specifier` is used to detect redundant inline specifiers on function and variable declarations. There are many in-class method definitions that are marked inline.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/164652
Approved by: https://github.com/Skylion007
2025-10-05 07:05:11 +00:00
5103ecc5d8
[1/N] Fix clang-tidy readability checks ( #164561 )
...
Check all `.cpp` files except `jit` files for readability thoroughly.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/164561
Approved by: https://github.com/Skylion007
2025-10-04 09:40:38 +00:00
559e8d1c20
[doc]: Small typos ( #162982 )
...
Small typo fixes
Pull Request resolved: https://github.com/pytorch/pytorch/pull/162982
Approved by: https://github.com/ezyang , https://github.com/zou3519
2025-09-16 17:42:19 +00:00
83875cdb55
[nativert] Expose ModelRunner to public through pmpl type ModelRunnerHandle. ( #159989 )
...
Summary:
Today users outside of pytorch core cannot `#include <torch/nativert/ModelRunner.h>`.
It turns out that we should place a header inside `torch/csrc/api/include/`. Placing every single nativert header here would pollute the namespace a lot and that's not what we want in general. Therefore here we just create a Handle type which hold a pointer to decouple the actual type from header definition.
Test Plan:
CI
Rollback Plan:
Differential Revision: D79751098
Pull Request resolved: https://github.com/pytorch/pytorch/pull/159989
Approved by: https://github.com/dolpm
2025-08-07 14:23:21 +00:00
f6c89c1ef3
Detach tensor before clone in SGD optimiser and other code ( #159204 )
...
Reverse the pattern of tensor clone followed by detach in SGD and other code.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/159204
Approved by: https://github.com/Skylion007
2025-07-27 03:31:12 +00:00
b0556110e5
Remove unsafe PyTorchError constructor ( #154961 )
...
Use libfmt in call sites of PyTorchError.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/154961
Approved by: https://github.com/albanD
2025-07-11 18:22:53 +00:00
e8cf5ff564
Fix the Problems About Defining Static Variable in Inline Function ( #147095 )
...
Refer to https://github.com/pytorch/pytorch/issues/125465 for more informations
- Remove unused header files
- Move common functionality to separate files to reduce dependencies between picklers and unpicklers
- Move the inline function that defines the static variable to .cc
Differential Revision: [D76266755](https://our.internmc.facebook.com/intern/diff/D76266755 )
Pull Request resolved: https://github.com/pytorch/pytorch/pull/147095
Approved by: https://github.com/cyyever , https://github.com/albanD
Co-authored-by: Edward Yang <ezyang@meta.com >
2025-06-25 01:59:10 +00:00
5b210bb3a6
[BE][9/16] fix typos in torch/ (torch/csrc/) ( #156319 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/156319
Approved by: https://github.com/albanD
ghstack dependencies: #156313 , #156314 , #156315 , #156316 , #156317
2025-06-23 02:57:50 +00:00
1d3bca40ed
Revert "[BE][9/16] fix typos in torch/ (torch/csrc/) ( #156319 )"
...
This reverts commit a23ccaa8479e038e79532759a64e9947c0fac43d.
Reverted https://github.com/pytorch/pytorch/pull/156319 on behalf of https://github.com/atalman due to export/test_torchbind.py::TestCompileTorchbind::test_compile_error_on_input_aliasing_contents_backend_aot_eager [GH job link](https://github.com/pytorch/pytorch/actions/runs/15804799771/job/44548489912 ) [HUD commit link](c95f7fa874
) ([comment](https://github.com/pytorch/pytorch/pull/156313#issuecomment-2994171213 ))
2025-06-22 12:31:56 +00:00
a23ccaa847
[BE][9/16] fix typos in torch/ (torch/csrc/) ( #156319 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/156319
Approved by: https://github.com/albanD
ghstack dependencies: #156313 , #156314 , #156315 , #156316 , #156317
2025-06-22 08:43:49 +00:00
d4ab8e74f3
Revert "Fix the Problems About Defining Static Variable in Inline Function ( #147095 )"
...
This reverts commit c6fc11af760d4ad1f01cc699a3c6488ab5f41770.
Reverted https://github.com/pytorch/pytorch/pull/147095 on behalf of https://github.com/izaitsevfb due to still fails to link internally at meta ([comment](https://github.com/pytorch/pytorch/pull/147095#issuecomment-2917221575 ))
2025-05-28 18:22:39 +00:00
c6fc11af76
Fix the Problems About Defining Static Variable in Inline Function ( #147095 )
...
Refer to https://github.com/pytorch/pytorch/issues/125465 for more informations
- Remove unused header files
- Move the inline function that defines the static variable to .cc
Pull Request resolved: https://github.com/pytorch/pytorch/pull/147095
Approved by: https://github.com/cyyever , https://github.com/albanD
2025-05-28 02:47:16 +00:00
c4d1ff02f8
[Lint] Update clang-format to 19.1.4 ( #153889 )
...
All changes other than the one to `tools/linter/adapters/s3_init_config.json` are generated by newer clang-format
Pull Request resolved: https://github.com/pytorch/pytorch/pull/153889
Approved by: https://github.com/cyyever , https://github.com/atalman
2025-05-20 14:12:46 +00:00
41bd0c900a
[1/N] Deprecate c10::string_view and at::string ( #151972 )
...
The calls of `c10::string_view` in the code base are replaced by `std::string_view`. The calls of `at::string` are replaced by `std::string`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/151972
Approved by: https://github.com/malfet
2025-04-29 07:23:52 +00:00
e2f9759bd0
Fix broken URLs ( #152237 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/152237
Approved by: https://github.com/huydhn , https://github.com/malfet
2025-04-27 09:56:42 +00:00
bf28d1cafc
Expose bicubic mode for torch::nn::functional::grid_sample in LibTorch ( #150817 )
...
When bicubic interpolation was added to grid_sampler in #44780 , `GridSampleFuncOptions` was not updated to allow a user to use bicubic mode in LibTorch, even though the function could handle it. This PR fixes the parity such that LibTorch's `torch::nn::functional::grid_sample` behaves the same as PyTorch's `torch.nn.functional.grid_sample`.
Existing users can directly use `torch::grid_sampler` but must know what int to pass for the interpolation (2 for bicubic) and padding mode parameters, which is not ideal.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/150817
Approved by: https://github.com/Skylion007
2025-04-21 08:55:27 +00:00
4926bd6004
Revert "Fix the Problems About Defining Static Variable in Inline Function ( #147095 )"
...
This reverts commit 3da14d38bd396f5bbe8494872d1509efa1a6f048.
Reverted https://github.com/pytorch/pytorch/pull/147095 on behalf of https://github.com/atalman due to breaks internally ([comment](https://github.com/pytorch/pytorch/pull/147095#issuecomment-2787129770 ))
2025-04-08 17:10:36 +00:00
3da14d38bd
Fix the Problems About Defining Static Variable in Inline Function ( #147095 )
...
Refer to https://github.com/pytorch/pytorch/issues/125465 for more informations
- Remove unused header files
- Move the inline function that defines the static variable to .cc
Pull Request resolved: https://github.com/pytorch/pytorch/pull/147095
Approved by: https://github.com/cyyever , https://github.com/albanD
2025-04-08 10:23:02 +00:00
8bece88655
[BE] Eliminate TODO for 2022 ( #149557 )
...
Need to think a bit more about what types.h includes
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/149557
Approved by: https://github.com/albanD
2025-03-23 05:35:54 +00:00
fcb633fafa
Introduce TORCH_ABI_VERSION and a runtime aoti_torch_abi_version C shim ABI ( #148892 )
...
Importable https://github.com/pytorch/pytorch/pull/148836
Pull Request resolved: https://github.com/pytorch/pytorch/pull/148892
Approved by: https://github.com/albanD
2025-03-10 22:22:10 +00:00
9aa897b992
Remove unnecessary tensor clone ( #148159 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/148159
Approved by: https://github.com/Skylion007
2025-03-02 16:21:39 +00:00
6293d1446b
[2/N] Remove NOLINT suppressions ( #146402 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/146402
Approved by: https://github.com/soulitzer
2025-02-05 08:38:52 +00:00
9a841f9321
Enable bugprone-unchecked-optional-access ( #144226 )
...
We can actually enable bugprone-unchecked-optional-access without the risk of hang.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/144226
Approved by: https://github.com/albanD
2025-01-10 03:16:56 +00:00
b0be30dd79
[19/N] Fix extra warnings brought by clang-tidy-17 ( #144448 )
...
Apply more clang-tidy fixes. There was a bug introduced by #144014 due to incorrect namespace concatenation which is reverted here.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/144448
Approved by: https://github.com/albanD
2025-01-09 15:58:05 +00:00
d0070ca07e
[18/N] Fix extra warnings brought by clang-tidy-17 ( #144014 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/144014
Approved by: https://github.com/Skylion007 , https://github.com/albanD
2025-01-08 17:21:55 +00:00
3beb7006dd
c10::optional -> std::optional in a few places ( #144340 )
...
Test Plan: Sandcastle
Pull Request resolved: https://github.com/pytorch/pytorch/pull/144340
Approved by: https://github.com/malfet
2025-01-07 21:09:39 +00:00
dca443835e
Enable more readability-redundant checks ( #143963 )
...
They are helpful to simplifying code.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/143963
Approved by: https://github.com/albanD
2024-12-30 14:49:33 +00:00
1feae27ed6
[16/N] Fix extra warnings brought by clang-tidy-17 ( #143714 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/143714
Approved by: https://github.com/Skylion007 , https://github.com/albanD
2024-12-24 03:29:38 +00:00
e2d47a133b
Disable c10::optional macros ( #138912 )
...
Test Plan: Sandcastle
Pull Request resolved: https://github.com/pytorch/pytorch/pull/138912
Approved by: https://github.com/Skylion007 , https://github.com/malfet
2024-12-17 09:22:47 +00:00
4273e1a059
[5/N] Apply bugprone-unchecked-optional-access ( #143111 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/143111
Approved by: https://github.com/Skylion007
2024-12-15 01:07:28 +00:00
075905b7bd
[14/N] Fix extra warnings brought by clang-tidy-17 ( #141644 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/141644
Approved by: https://github.com/ezyang
Co-authored-by: Eli Uriegas <1700823+seemethere@users.noreply.github.com >
2024-12-13 06:22:13 +00:00
82ce888273
c10::string_view -> std::string_view in more places ( #142517 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/142517
Approved by: https://github.com/malfet
2024-12-12 19:45:59 +00:00
2f0fe82f6d
Revert "[14/N] Fix extra warnings brought by clang-tidy-17 ( #141644 )"
...
This reverts commit 24a5a2ef258d2b482ded674cdb9555afaf081402.
Reverted https://github.com/pytorch/pytorch/pull/141644 on behalf of https://github.com/clee2000 due to failing internally D67112938 ([comment](https://github.com/pytorch/pytorch/pull/141644#issuecomment-2539602023 ))
2024-12-12 17:43:36 +00:00
f7b9533c3f
[4/N] Apply bugprone-unchecked-optional-access ( #142832 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/142832
Approved by: https://github.com/albanD
2024-12-12 04:33:32 +00:00
24a5a2ef25
[14/N] Fix extra warnings brought by clang-tidy-17 ( #141644 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/141644
Approved by: https://github.com/ezyang
2024-12-11 18:40:42 +00:00
b4c0973b59
[2/N] Apply bugprone-unchecked-optional-access ( #141091 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/141091
Approved by: https://github.com/Skylion007 , https://github.com/albanD
Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com >
2024-12-09 19:30:19 +00:00
96be048f06
[1/N] Avoid copy in std::get ( #141812 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/141812
Approved by: https://github.com/Skylion007
2024-12-01 03:53:35 +00:00
0f1a88cfba
Make Context to be Device-agnostic Step by Step (2/N) ( #136526 )
...
----
- add new method(getDefaultGenerator, getNewGenerator) into AcceleratorHooksInterface
Pull Request resolved: https://github.com/pytorch/pytorch/pull/136526
Approved by: https://github.com/ezyang , https://github.com/EikanWang
2024-11-18 18:21:17 +00:00
80d0356b11
Revert "Make Context to be Device-agnostic Step by Step (2/N) ( #136526 )"
...
This reverts commit c03324de2dfbbf0006818c86b88c92a3378f46b7.
Reverted https://github.com/pytorch/pytorch/pull/136526 on behalf of https://github.com/ZainRizvi due to This fails to build internally. See D65604944 for more details ([comment](https://github.com/pytorch/pytorch/pull/136526#issuecomment-2465790157 ))
2024-11-08 21:40:10 +00:00
c03324de2d
Make Context to be Device-agnostic Step by Step (2/N) ( #136526 )
...
----
- add new method(getDefaultGenerator, getNewGenerator) into AcceleratorHooksInterface
Pull Request resolved: https://github.com/pytorch/pytorch/pull/136526
Approved by: https://github.com/ezyang , https://github.com/EikanWang
2024-11-07 06:28:47 +00:00
6b8e3022f2
Remove c10::optional usages in PyTorch ( #139525 )
...
Test Plan: Sandcastle
Reviewed By: swolchok
Pull Request resolved: https://github.com/pytorch/pytorch/pull/139525
Approved by: https://github.com/malfet , https://github.com/Skylion007
2024-11-04 15:35:23 +00:00
419a7e197d
[6/N] Fix Wextra-semi warning ( #139605 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/139605
Approved by: https://github.com/ezyang
2024-11-04 13:43:16 +00:00
f95c71867e
[9/N] Fix extra warnings brought by clang-tidy-17 ( #139286 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/139286
Approved by: https://github.com/ezyang
2024-10-31 05:20:31 +00:00
456c87c8a2
[8/N] Fix extra warnings brought by clang-tidy-17 ( #139151 )
...
Fixes #ISSUE_NUMBER
Pull Request resolved: https://github.com/pytorch/pytorch/pull/139151
Approved by: https://github.com/ezyang
Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com >
2024-10-30 14:20:08 +00:00