190 Commits
Author SHA1 Message Date
Adrian Abeyta 9978001139 [Stable-ABI] Add STABLE_TORCH_WARN and STABLE_TORCH_WARN_ONCE macros (#200065)
Adds `STABLE_TORCH_WARN` and `STABLE_TORCH_WARN_ONCE` to stable ABI. Needed for torchvision's [decode_webp](https://github.com/pytorch/vision/blob/main/torchvision/csrc/io/image/cpu/decode_webp.cpp#L62-L63).

## Summary
- Introduces `STABLE_TORCH_WARN` and `STABLE_TORCH_WARN_ONCE` mirroring [TORCH_WARN / TORCH_WARN_ONCE](https://github.com/pytorch/pytorch/blob/b50a07471edbdf47bdd042a13b774d3a7a1664d2/c10/util/Exception.h#L713-L747). The difference in behavior is such that messages go through `std::ostringstream` instead of `c10::str` and are always a `UserWarning`.
- `STABLE_TORCH_WARN` only needs `aoti_torch_warn` so it works at any target version. `STABLE_TORCH_WARN_ONCE` needs the new `torch_is_warn_always_enabled` shim to respect `set_warn_always`, so it's gated to 2.16+.
- Adds a `libtorch_agn_2_16_extension`.  `STABLE_TORCH_WARN` is tested from the 2_9 extension and `STABLE_TORCH_WARN_ONCE` from 2_16.

Supported by @janeyx99
Pull Request resolved: https://github.com/pytorch/pytorch/pull/200065
Approved by: https://github.com/janeyx99
2026-10-21 01:06:27 +00:00
Adrian Abeyta 25b62c91c9 [Stable-ABI] Add torch::stable::add. (#196762)
Adds `torch::stable::add` to the stable ABI, gated on a new `TORCH_VERSION_2_16_0`. This is needed for the torchvision stable-ABI port, which currently works around the missing op with [subtract(self, other, -1.0)](https://github.com/pytorch/vision/blob/ac8d215f7d45d6601451b62e9f81622dac8aa0b4/torchvision/csrc/ops/cpu/deform_conv2d_kernel.cpp#L90-L93).

## Summary
- Introduces `torch::stable::add(self, other, double alpha = 1.0)` via the aten C shim (`aoti_torch_aten_add_Tensor`), mirroring [torch::stable::subtract](https://github.com/pytorch/pytorch/blob/879f5e08bd32c01bf8374d7e9cf1c2f5f61468cb/torch/csrc/stable/ops.h#L1065-L1087).
- Adds `TORCH_VERSION_2_16_0`, registers the shim in `shim_function_versions.txt`, and documents the new API in the stable operators docs.
- Adds a `libtorch_agn_2_16` extension and a `test_my_add` test covering an integer `alpha` and aten error for two integral tensors.

Note `alpha` is a `double` instead of a `Scalar` since the C shim lowers Scalar to double, so adding two integral or boolean tensors is rejected by aten (same limitation as `torch::stable::subtract`). Mixed integral/floating inputs still work via type promotion.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/196762
Approved by: https://github.com/janeyx99
2026-10-19 17:38:12 +00:00
PyTorch MergeBot 7c4ecedcf3 Revert "[Stable-ABI] Add torch::stable::add. (#196762)"
This reverts commit 755182b4f3.

Reverted https://github.com/pytorch/pytorch/pull/196762 on behalf of https://github.com/izaitsevfb due to Conflicts with pytorch/pytorch#199089, which landed internally first (D121335193); safe to rebase and re-merge after it lands ([comment](https://github.com/pytorch/pytorch/pull/196762#issuecomment-6220260591))
2026-10-16 16:46:07 +00:00
Adrian Abeyta 755182b4f3 [Stable-ABI] Add torch::stable::add. (#196762)
Adds `torch::stable::add` to the stable ABI, gated on a new `TORCH_VERSION_2_16_0`. This is needed for the torchvision stable-ABI port, which currently works around the missing op with [subtract(self, other, -1.0)](https://github.com/pytorch/vision/blob/ac8d215f7d45d6601451b62e9f81622dac8aa0b4/torchvision/csrc/ops/cpu/deform_conv2d_kernel.cpp#L90-L93).

## Summary
- Introduces `torch::stable::add(self, other, double alpha = 1.0)` via the aten C shim (`aoti_torch_aten_add_Tensor`), mirroring [torch::stable::subtract](https://github.com/pytorch/pytorch/blob/879f5e08bd32c01bf8374d7e9cf1c2f5f61468cb/torch/csrc/stable/ops.h#L1065-L1087).
- Adds `TORCH_VERSION_2_16_0`, registers the shim in `shim_function_versions.txt`, and documents the new API in the stable operators docs.
- Adds a `libtorch_agn_2_16` extension and a `test_my_add` test covering an integer `alpha` and aten error for two integral tensors.

Note `alpha` is a `double` instead of a `Scalar` since the C shim lowers Scalar to double, so adding two integral or boolean tensors is rejected by aten (same limitation as `torch::stable::subtract`). Mixed integral/floating inputs still work via type promotion.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/196762
Approved by: https://github.com/cleonard530, https://github.com/janeyx99
2026-10-16 13:49:08 +00:00
Adrian Abeyta 903d704d38 [Stable-ABI] Add torch::stable::from_file. (#198263)
Adds `torch::stable::from_file` to the stable ABI. Needed for torchvision stable-ABI, which currently carries a local [stable_from_file helper](https://github.com/pytorch/vision/blob/7b0e250acf82aac5a2389f54c6855da17bfeace9/torchvision/csrc/io/image/cpu/read_write_file.cpp#L21-L40) for image decoding.

## Summary
- Introduces `torch::stable::from_file` and it returns a 1-D tensor backed by a memory-map of the file.
- Functional differences between the ATen and stable signatures include `filename` being `const std::string&` rather than `std::string_view`.
- Adds my_from_file to the libtorch_agn_2_10 extension and tests mapping the entire file with shared=False and dtype as well as checking the returned bytes against the original data.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/198263
Approved by: https://github.com/janeyx99
2026-10-15 02:50:24 +00:00
Adrian Abeyta f5be7f9ac6 [Stable-ABI] Add torch::stable::flip. (#197594)
Adds `torch::stable::flip` to the stable ABI via the dispatcher path. Needed for torchvision stable-ABI, which currently carries a local [stable_flip helper](https://github.com/pytorch/vision/blob/7b0e250acf82aac5a2389f54c6855da17bfeace9/torchvision/csrc/io/image/common_stable.h#L18-L28).

## Summary
- Introduces `torch::stable::flip(self, dims)` in the existing 2.10 block of `ops.h`, mirroring [torch::stable::permute](https://github.com/pytorch/pytorch/blob/main/torch/csrc/stable/ops.h#L1255-L1264).
- Adds `my_flip` to the libtorch_agn_2_10 extension and a `test_my_flip` over float32/int32/bool, covering negative, multiple and empty dims on contiguous and non-contiguous inputs, the returned copy, zero-element and 0-dim tensors, and duplicate/out-of-range dim errors.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/197594
Approved by: https://github.com/cleonard530, https://github.com/janeyx99
2026-10-14 15:06:53 +00:00
Adrian Abeyta 2d30e76662 [Stable-ABI] Add torch::stable::mm_out and bmm_out. (#197441)
Adds `torch::stable::mm_out` and `torch::stable::bmm_out` to the stable ABI via the dispatcher path. Fixes #196927 and needed for torchvision stable-ABI, which currently carries a local [mm_out helper](https://github.com/pytorch/vision/blob/6436a89646d0c4f07154209781298b35ffb0e584/torchvision/csrc/ops/StableABICompat.h#L82-L91).

## Summary
- Introduces `torch::stable::mm_out(out, self, mat2)` and `torch::stable::bmm_out(out, self, mat2)` in the existing 2.10 block of `ops.h`, mirroring [torch::stable::sum_out](https://github.com/pytorch/pytorch/blob/main/torch/csrc/stable/ops.h#L1045-L1062).
- Adds my_mm_out /my_bmm_out and my_mm_out_dtype/my_bmm_out_dtype to the libtorch_agn_2_10 extension, with test_my_mm_out_ops and test_my_mm_out_dtype_ops both parametrized over mm/bmm.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/197441
Approved by: https://github.com/cleonard530, https://github.com/janeyx99
2026-10-14 01:40:43 +00:00
Adrian Abeyta 9760bfac5d [Stable-ABI] Move acc_type into torch::headeronly. (#199203)
Moves the accumulate-type traits into `torch::headeronly`. Needed for torchvision stable-ABI, which currently carries a local [AccType helper](https://github.com/pytorch/vision/blob/9769007f09193b307a90d2b833aac31d364f03e3/torchvision/csrc/ops/cuda/nms_kernel.cu#L27-L38) that only covers the types it dispatches.

## Summary
- Introduces `acc_type`, `acc_type_device`, `AccumulateType` and `AccumulateTypeDevice` in the `torch::headeronly` namespace.

## BC-breaking note

### `at::AccumulateTypeDevice` can no longer be specialized inside namespace `at`

Moves the trait definition to `torch::headeronly` so `at::AccumulateTypeDevice` is now a using declaration.  Code that specializes it inside `namespace at` no longer compiles.

Previously a specialization compiled and `at::acc_type` returned the type it named. To get the previous behavior, specialize in `torch::headeronly` instead.

Example (the same applies to `at::AccumulateType`) :

Version 2.14.0:

```cpp
namespace at {
template <>
struct AccumulateTypeDevice<MyType, c10::DeviceType::CPU> {
  using type = double;
};
}
```

Version 2.15.0:

```cpp
// The code above fails with:
// error: specialization of 'template<class T, c10::DeviceType D> struct torch::headeronly::AccumulateTypeDevice' in different namespace

// Specialize it by its torch::headeronly name:
template <>
struct torch::headeronly::AccumulateTypeDevice<MyType, c10::DeviceType::CPU> {
  using type = double;
};
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/199203
Approved by: https://github.com/janeyx99
2026-10-13 16:35:29 +00:00
Adrian Abeyta 52976db7b6 [Stable-ABI] Add torch::stable::masked_select. (#198048)
Exposes `masked_select` through the stable ABI as `torch::stable::masked_select`. torchvision's stable-ABI currently utilizes a local [masked_select helper](https://github.com/pytorch/vision/blob/7b0e250acf82aac5a2389f54c6855da17bfeace9/torchvision/csrc/ops/StableABICompat.h#L59-L66).

## Summary
- Adds `torch::stable::masked_select`, which calls `aten::masked_select` through the dispatcher and returns a 1-D tensor of the elements of self where mask is true. The wrapper has the same shape as [torch::stable::index_select](https://github.com/pytorch/pytorch/blob/main/torch/csrc/stable/ops.h#L1266-L1290).
- Adds a `my_masked_select` op to the libtorch_agn_2_10 extension and a `test_my_masked_select ` test covering a non-contiguous view, a broadcast mask, an all-false mask, and a non-boolean mask error.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/198048
Approved by: https://github.com/janeyx99
2026-10-13 14:34:07 +00:00
Adrian Abeyta 49827038dc [Stable-ABI] Add torch::stable::sort. (#198038)
Adds `torch::stable::sort` to stable ABI. Needed for torchvision stable-ABI, which currently carries a local [sort helper](https://github.com/pytorch/vision/blob/7b0e250acf82aac5a2389f54c6855da17bfeace9/torchvision/csrc/ops/StableABICompat.h#L39-L57).

## Summary
- Adds `torch::stable::sort`, backed by `aten::sort` and `aten::sort.stable`, which returns a `std::tuple` of sorted values and their indices. It follows the same dispatcher pattern as [torch::stable::index_select](https://github.com/pytorch/pytorch/blob/main/torch/csrc/stable/ops.h#L1266-L1290).
- Adds `my_sort` and `my_sort_stable` ops to the libtorch_agn_2_10 extension, along with `test_my_sort` and `test_my_sort_stable`.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/198038
Approved by: https://github.com/cleonard530, https://github.com/janeyx99
2026-09-23 20:33:49 +00:00
Eddie Yan a2bf3a697d [cuBLAS] Always eagerly allocate cuBLAS(Lt) workspaces (#194311)
authored with codex
as discussed w/ @eellison , @ngimel ,~~~ just stashing this prototype here as performance doesn't look great on the hot path:~~~

```

  Latest benchmark results:

   Backend        Shape (M,N,K)       Cached        Eager                 Delta
  ━━━━━━━━━━  ━━━━━━━━━━━━━━━━━━  ━━━━━━━━━━━  ━━━━━━━━━━━  ━━━━━━━━━━━━━━━━━━━━
   cuBLAS            (64,64,64)    14.807 µs    15.092 µs    +0.284 µs / +1.92%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLAS         (256,256,256)    14.904 µs    15.301 µs    +0.397 µs / +2.66%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLAS      (1024,1024,1024)    14.850 µs    15.363 µs    +0.513 µs / +3.46%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLAS       (32,2048,10944)    16.777 µs    17.626 µs    +0.849 µs / +5.06%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLASLt          (64,64,64)    14.781 µs    15.181 µs    +0.399 µs / +2.70%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLASLt       (256,256,256)    14.850 µs    15.099 µs    +0.249 µs / +1.68%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLASLt    (1024,1024,1024)    14.718 µs    14.792 µs    +0.074 µs / +0.50%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLASLt     (32,2048,10944)    16.715 µs    17.247 µs    +0.532 µs / +3.18%

  Paste-ready discussion summary—if this goes on GitHub, please add your own commentary around the quoted AI-generated material:

  > AI-generated benchmark summary, provided for human review
  >
  > Benchmarked cached versus operation-scoped eager cuBLAS workspaces on an NVIDIA GB300, CC 10.3, CUDA 13.4. PyTorch was built for CC 10.0. Measurements are medians across five alternating cached/eager process trials using synchronized
  > torch.utils.benchmark.Timer measurements of BF16 torch.mm.
  >
  > Eager workspace allocation added approximately 0.07–0.85 µs per operation. Relative overhead ranged from 0.5% to 5.1%, with the largest measured overhead on the legacy cuBLAS (M,N,K)=(32,2048,10944) regression shape.
  >
  > The cached implementation reproduced CUDA_ERROR_ILLEGAL_ADDRESS when separately captured graphs reused a workspace on the same stream. The eager implementation passed that reproducer.
  >
  > Given that most of the eager overhead appears to come from caching-allocator allocation/free bookkeeping, a simpler alternative under consideration is to retain the existing workspace cache but explicitly clear or isolate cached workspaces at
  > graph-capture boundaries.

```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/194311
Approved by: https://github.com/ngimel, https://github.com/eellison
2026-09-05 05:35:27 +00:00
PyTorch MergeBot 4900b347cf Revert "[cuBLAS] Always eagerly allocate cuBLAS(Lt) workspaces (#194311)"
This reverts commit 4202fb82cb.

Reverted https://github.com/pytorch/pytorch/pull/194311 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](https://github.com/pytorch/pytorch/pull/194311#issuecomment-5536352297))
2026-09-04 05:57:50 +00:00
eqy 4202fb82cb [cuBLAS] Always eagerly allocate cuBLAS(Lt) workspaces (#194311)
authored with codex
as discussed w/ @eellison , @ngimel ,~~~ just stashing this prototype here as performance doesn't look great on the hot path:~~~

```

  Latest benchmark results:

   Backend        Shape (M,N,K)       Cached        Eager                 Delta
  ━━━━━━━━━━  ━━━━━━━━━━━━━━━━━━  ━━━━━━━━━━━  ━━━━━━━━━━━  ━━━━━━━━━━━━━━━━━━━━
   cuBLAS            (64,64,64)    14.807 µs    15.092 µs    +0.284 µs / +1.92%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLAS         (256,256,256)    14.904 µs    15.301 µs    +0.397 µs / +2.66%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLAS      (1024,1024,1024)    14.850 µs    15.363 µs    +0.513 µs / +3.46%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLAS       (32,2048,10944)    16.777 µs    17.626 µs    +0.849 µs / +5.06%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLASLt          (64,64,64)    14.781 µs    15.181 µs    +0.399 µs / +2.70%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLASLt       (256,256,256)    14.850 µs    15.099 µs    +0.249 µs / +1.68%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLASLt    (1024,1024,1024)    14.718 µs    14.792 µs    +0.074 µs / +0.50%
  ──────────  ──────────────────  ───────────  ───────────  ────────────────────
   cuBLASLt     (32,2048,10944)    16.715 µs    17.247 µs    +0.532 µs / +3.18%

  Paste-ready discussion summary—if this goes on GitHub, please add your own commentary around the quoted AI-generated material:

  > AI-generated benchmark summary, provided for human review
  >
  > Benchmarked cached versus operation-scoped eager cuBLAS workspaces on an NVIDIA GB300, CC 10.3, CUDA 13.4. PyTorch was built for CC 10.0. Measurements are medians across five alternating cached/eager process trials using synchronized
  > torch.utils.benchmark.Timer measurements of BF16 torch.mm.
  >
  > Eager workspace allocation added approximately 0.07–0.85 µs per operation. Relative overhead ranged from 0.5% to 5.1%, with the largest measured overhead on the legacy cuBLAS (M,N,K)=(32,2048,10944) regression shape.
  >
  > The cached implementation reproduced CUDA_ERROR_ILLEGAL_ADDRESS when separately captured graphs reused a workspace on the same stream. The eager implementation passed that reproducer.
  >
  > Given that most of the eager overhead appears to come from caching-allocator allocation/free bookkeeping, a simpler alternative under consideration is to retain the existing workspace cache but explicitly clear or isolate cached workspaces at
  > graph-capture boundaries.

```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/194311
Approved by: https://github.com/ngimel, https://github.com/eellison
2026-09-04 04:34:40 +00:00
Anthony Barbier d543b1af61 Set the C++ standard on the exported CMake target. (#190784)
This is needed so that downstream targets inherits the c++20 requirement.

This change propagates the required standard only to CXX translation units; downstream consumers compiling CUDA sources must explicitly set CMAKE_CUDA_STANDARD (for example, to 20), because the Torch target does not propagate a CUDA standard.

Without it, downstream C++ code fails with for example:

```
pytorch/torch/include/ATen/core/TensorBase.h:1041:5: note: ‘requires’ only available with ‘-std=c++20’ or ‘-fconcepts’ pytorch/torch/include/ATen/core/TensorBase.h:1044:5: error: ‘requires’ does not name a type
1044 |     requires std::is_same_v<T, int64_t>
     |     ^~~~~~~~
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/190784
Approved by: https://github.com/Skylion007
2026-09-02 08:08:02 +00:00
Chris Leonard dcf02e5137 Add stable Tensor overloads for index_select, floor_divide, and is_pinned (2.14+) (#192097)
## Summary
- Add `torch::stable::{index_select,floor_divide,is_pinned}` Tensor–Tensor wrappers (gated at 2.14) via `torch_call_dispatcher`
- Document the new APIs in the stable operators docs
- Cover them in the 2.14 libtorch-agnostic extension tests

'stacked' on top of:
https://github.com/pytorch/pytorch/pull/192083
https://github.com/pytorch/pytorch/pull/191973
Will need to rebase once those are merged.

see commits https://github.com/pytorch/pytorch/pull/192097/changes/c4e0c5c1ef85bb93cd0d6e3cc46cff6446222db7..cb760bb831420502c80f49fa7881c6050a029807 for new edits in this PR

## Test plan
- [x] `python -m pytest test/cpp_extensions/test_libtorch_agnostic.py -k 'test_my_index_select or test_my_floor_divide or test_my_is_pinned' -v`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/192097
Approved by: https://github.com/janeyx99
2026-08-07 20:14:20 +00:00
Chris Leonard b1f35045bb Add stable permute and view_dtype (2.14+) (#192083)
## Summary
- Add `torch::stable::{permute,view_dtype}` wrappers (gated at 2.14) via `torch_call_dispatcher`
- Document the new APIs in the stable operators docs
- Cover them in the 2.14 libtorch-agnostic extension tests

~~Stacked on #191973. (testing new gh stack)~~
stack seemed to be disabled. Will rebase this when #191973 lands

## Test plan
- [x] `python -m pytest test/cpp_extensions/test_libtorch_agnostic.py -k 'test_my_permute or test_my_view_dtype'`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/192083
Approved by: https://github.com/janeyx99
2026-08-07 15:49:48 +00:00
Chris LeonardandJane Xu 420de487c9 Add stable Tensor overloads for bitwise_and/or/left_shift/right_shift (2.14+) (#191973)
## Summary
- Add `torch::stable::{bitwise_and,bitwise_or,bitwise_left_shift,bitwise_right_shift}` Tensor–Tensor wrappers (gated at 2.14) via `torch_call_dispatcher`
- Document the new APIs in the stable operators docs
- Cover them in the 2.14 libtorch-agnostic extension tests (same-shape + broadcasting)

## Test plan
- [x] `python -m pytest test/cpp_extensions/test_libtorch_agnostic.py -k test_my_bitwise_ops`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/191973
Approved by: https://github.com/janeyx99

Co-authored-by: Jane (Yuan) Xu <31798555+janeyx99@users.noreply.github.com>
2026-08-07 03:49:18 +00:00
Akshay Madavalappil Ramesh deafcda021 Fix stale 404 links caught by URL lint (#189619)
Addresses the 404 link-rot portion of [#189557](https://github.com/pytorch/pytorch/issues/189557).

This PR updates or removes stale URLs reported by the nightly lint-urls job:

- Updates moved PyTorch documentation links to current working pages.
- Removes hyperlinks where the referenced page no longer has a reliable replacement.
- Updates the ROCm PR reference from `ROCm/clr` to `ROCm/rocm-systems`.
- Leaves reachable links unchanged, including the `pytorch/data` issue link and the `hud.pytorch.org` URLs.

The `hud.pytorch.org` 000 failures are left unchanged because the issue notes they may be transient/rate-limit related rather than dead links. I did not add `@lint-ignore` for those URLs in this PR; if maintainers prefer suppressing those flaky checks, I can follow up separately.

Validation:

- Manually rechecked the originally reported URLs.
- Verified the stale 404 URLs are present on `upstream/main`.
- Verified the same stale URL patterns are absent on `fix-stale-doc-links`.
- Ran `git diff --check upstream/main...HEAD`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/189619
Approved by: https://github.com/albanD
2026-07-24 17:56:32 +00:00
Chris Leonard 1267c8437b Add stable AOTI stream native-handle shim and Stream::nativeHandle() (#183930)
Adds aoti_torch_stream_native_handle and torch::stable::accelerator::Stream::nativeHandle() behind TORCH_FEATURE_VERSION >= 2.13, wires stable/version.h into the AOTI shim header for correct guards, and covers the behavior with a libtorch_agn_2_13 extension test plus a CUDA test_libtorch_agnostic case.

@janeyx99
Pull Request resolved: https://github.com/pytorch/pytorch/pull/183930
Approved by: https://github.com/janeyx99
2026-06-05 19:29:42 +00:00
Evan Alferez 64ab523462 [Docs][C++] Use kFloat64 in TensorOptions example to illustrate dtype override (#167467) (#184457)
## Summary

Fixes #167467.

The C++ `TensorOptions` example in `docs/cpp/source/api/aten/creation.md` explicitly sets `.dtype(torch::kFloat32)`, which is exactly the documented default listed in the immediately-following **Defaults** section of the same page. As a result the example doesn't actually demonstrate the point of `TensorOptions` — overriding the defaults — for the `dtype` axis.

This PR switches the example (and its matching assertion) to `kFloat64` so it shows a real override of the `kFloat32` default, while leaving `layout` / `device` / `requires_grad` overrides untouched.

## Problem

`docs/cpp/source/api/aten/creation.md` currently has:

```cpp
auto options =
  torch::TensorOptions()
    .dtype(torch::kFloat32)      // <- same as the documented default
    .layout(torch::kStrided)
    .device(torch::kCUDA, 1)
    .requires_grad(true);

torch::Tensor tensor = torch::full({3, 4}, /*value=*/123, options);

assert(tensor.dtype() == torch::kFloat32);
```

…and 7 lines later the same page says:

> **Defaults:** Any axis you omit takes its default value: `kFloat32` for dtype, `kStrided` for layout, `kCPU` for device, and `false` for `requires_grad`.

So the only axes the example actually *overrides* are `device` and `requires_grad`; the `.dtype(...)` call is a no-op vs. the documented default.

## Solution

Change both the example call and the assertion from `kFloat32` to `kFloat64`. That makes `.dtype(...)` an actual override, matching the spirit of the surrounding prose ("creating a `TensorOptions` object" by configuring its axes). `kFloat64` is the same dtype suggested in @malfet's review of PR #167474 ("better example would be to change value of `dtype` to `kFloat64`") and is what PR #171406 implemented before going stale.

## Prior art

Two earlier attempts on this issue were approved on substance but couldn't merge:

- #167474 — first attempt, flipped the surrounding prose ("64-bit float" → "32-bit float") instead of the code. Approved by @malfet who suggested the inverse: change the example dtype to `kFloat64`. Went stale.
- #171406 — implemented exactly the `kFloat32` → `kFloat64` change here. Approved by @jbschlosser, who tried to merge it (`@pytorchbot merge`), but the merge failed on EasyCLA: `The commit ... is not authorized under a signed CLA`. PR then went stale.

The original prose "64-bit float, strided tensor that requires a gradient, and lives on CUDA device 1" that #167467 originally cited was rewritten by the C++ docs restructure (#174096), so the wording mismatch is already gone — but the example still uses the default `dtype`, which is the substantive thing the issue and the maintainer feedback were after.

## Out of scope

- The **Defaults** section a few lines below still correctly documents `kFloat32` as the dtype default — left untouched.
- The "shorthand" examples further down the page (`torch::ones(10, torch::kFloat32)`, etc.) intentionally use `kFloat32` to show the shorthand syntax against the default and are unrelated to the "override the default" point. Left untouched.

## Test plan

- [ ] Docs-only change to a single Markdown code block — no Python/C++ behavior changes, no test changes needed.
- [ ] CI docs build / link-check to confirm the C++ docs page still renders.

## Related

- #167467 — original issue (still open)
- #167474 — prior attempt, approved by @malfet with the kFloat64 suggestion
- #171406 — prior attempt, approved by @jbschlosser, merge blocked on EasyCLA, went stale
- #174096 — C++ docs restructure that moved this content into `docs/cpp/source/api/aten/creation.md` and rewrote the surrounding prose

Pull Request resolved: https://github.com/pytorch/pytorch/pull/184457
Approved by: https://github.com/malfet
2026-05-21 23:48:28 +00:00
zxuhan7 98a0359064 Docs: recommend stable ABI umbrella headers instead of *_struct.h (#181393)
Fixes #180492.

The stable ABI docs pointed users at `torch/csrc/stable/tensor_struct.h` and `device_struct.h`, which only contain forward declarations for constructors that are defined `inline` in the matching `*_inl.h` files. Following the docs led to a linker error such as:

```
undefined reference to `torch::stable::Device::Device(std::string const&)'
```

Update the docs to point at the umbrella headers `tensor.h` and `device.h`, which include both the struct and the inl headers and match what `test/cpp_extensions` already uses. Also add an entry for `device.h` in the header list in `libtorch_stable_abi.md`, which was previously missing.

## Test plan

Pure docs change; relying on the docs-preview build in CI to confirm rendering.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/181393
Approved by: https://github.com/janeyx99
2026-04-27 18:26:22 +00:00
Svetlana Karslioglu 19da3da3d3 Restructure C++ docs (#174096)
The fix-cpp-build branch is a major restructuring that:

- Drops Exhale (which auto-generated API docs but caused OOM in CI) in favor of hand-written RST pages using Breathe directives
- Reorganizes notes into a hierarchical API reference with proper categories
- Adds new content: XPU docs, stable ABI docs, DeviceGuard/Stream docs
- Always runs Doxygen instead of gating on an env var

Pull Request resolved: https://github.com/pytorch/pytorch/pull/174096
Approved by: https://github.com/janeyx99, https://github.com/seemethere, https://github.com/albanD
2026-04-07 17:24:38 +00:00
Nikita Shulga df87ffc950 [Build] Update CXX_STANDARD to 20 (#178343)
It's set to that in top-level projects, but not propagated to some of the build targets

Pull Request resolved: https://github.com/pytorch/pytorch/pull/178343
Approved by: https://github.com/ngimel, https://github.com/Skylion007
ghstack dependencies: #178389
2026-03-25 23:50:34 +00:00
Jane Xu 7daf9eb4ce More improvements on docs, e.g., on STD_TORCH_CHECK (#177997)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/177997
Approved by: https://github.com/mikaylagawarecki
ghstack dependencies: #177996
2026-03-23 21:00:51 +00:00
Jane Xu e07fa41a2c Improve docs on headeronly DISPATCH macros for our stable ABI (#177996)
Existing doc referenced a nonexistent macro.
This PR takes the opportunity to make it better.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/177996
Approved by: https://github.com/mikaylagawarecki
2026-03-23 21:00:51 +00:00
Mikayla Gawarecki 830aba823c Fix stable cpp docs rendering (#171957)
https://docs-preview.pytorch.org/pytorch/pytorch/nightly-560ad42dc4f1bbed96eb0f9ac1cccc9aa32ddd48/cppdocs/stable.html

Pull Request resolved: https://github.com/pytorch/pytorch/pull/171957
Approved by: https://github.com/svekars, https://github.com/janeyx99
ghstack dependencies: #172120
2026-01-13 19:13:06 +00:00
Mikayla Gawarecki 5f3f1a50de Add cpp docs for torch::stable (#170912)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/170912
Approved by: https://github.com/janeyx99
2026-01-05 21:40:30 +00:00
Ryan Zhou 79d2397b6b Fix grammar issues in C++ frontend documentation (#167702)
Corrected minor grammatical errors in the documentation.

Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/167702
Approved by: https://github.com/jerryzh168
2025-11-15 05:55:08 +00:00
linhaifeng 1764f3a9c8 [Fix] fix gramma error in PyTorch docs (#166158)
Fix several gramma errors in PyTorch docs.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/166158
Approved by: https://github.com/yewentao256, https://github.com/cyyever, https://github.com/ezyang
2025-10-29 03:01:07 +00:00
Svetlana Karslioglu b61bdc7cc4 Fix cpp build (#162774)
Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/162774
Approved by: https://github.com/malfet, https://github.com/atalman
2025-09-25 18:21:45 +00:00
Svetlana Karslioglu e6a9db58d7 Add analytics ID to cpp docs (#163370)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/163370
Approved by: https://github.com/albanD
2025-09-19 21:45:19 +00:00
Anita Katahoire 996c4d803d Removing conda references from PyTorch Docs (#152702)
Addresses #148339

Pull Request resolved: https://github.com/pytorch/pytorch/pull/152702
Approved by: https://github.com/svekars, https://github.com/albanD, https://github.com/atalman
2025-05-20 20:33:28 +00:00
Anthony Shoumikhin 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
Svetlana Karslioglu cd7bc60e11 Migrate to new theme (#149331)
- Migrate pytorch docs, cpp docs and functorch docs to the pytorch_sphinx_theme2
- Migrate index.rst to markdown and restructure to use high-level horizontal bar sections Python API, Developer Notes
- Added python-api.md which becomes the main container for the API docs. This file will be used to add all api references in the toctree. It would be great to have lint for this file: https://github.com/pytorch/pytorch/issues/150718
- Enabled mermaid sphinx extension and opengraph sphinx extension

Pull Request resolved: https://github.com/pytorch/pytorch/pull/149331
Approved by: https://github.com/malfet, https://github.com/atalman, https://github.com/albanD
2025-04-16 21:35:19 +00:00
Alanna Burke 43ee67e8dc Removing doc references to PRE_CXX11_ABI. (#149756)
Fixes #149550

Pull Request resolved: https://github.com/pytorch/pytorch/pull/149756
Approved by: https://github.com/svekars, https://github.com/atalman
2025-03-25 16:01:59 +00:00
Dmitry Nikolayev db92d0f388 A bunch of typos (#149404)
Improves readability.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/149404
Approved by: https://github.com/soulitzer
2025-03-24 16:16:04 +00:00
Jane Xu 971606befa Add a stable TORCH_LIBRARY to C shim (#148124)
This PR adds two main parts:
- shim.h stable C APIs into torch::Library APIs
- a higher level API in torch/csrc/stable/library.h that calls into this shim.h + otherwise is self contained

Goal: custom kernel writers should be able to call the apis in the directories above in order to register their library in a way that allows their custom extension to run with a different libtorch version than it was built with.

Subplots resolved:

- Do we want a whole separate StableLibrary or do we want to freeze torch::Library and add `m.stable_impl(cstring, void (*fn)(void **, int64_t, int64_t)` into it
    - Yes, we want a separate StableLibrary. We cannot freeze Library and it is NOT header only.
- Should I use unint64_t as the common denominator instead of void* to support 32bit architectures better?
    -  Yes, and done
- Should I add a stable `def` and `fragment` when those can be done in python?
    - I think we do want these --- and now they're done
- Where should library_stable_impl.cpp live? -- no longer relevant
- I need some solid test cases to make sure everything's going ok. I've intentionally thrown in a bunch of random dtypes into the signature, but I still haven't tested returning multiple things, returning nothing, complex dtypes, etc.
    - Have since tested all the torch library endpoints. the others can be tested in a followup to separate components that need to be in shim.h vs can be added later

Pull Request resolved: https://github.com/pytorch/pytorch/pull/148124
Approved by: https://github.com/albanD, https://github.com/zou3519, https://github.com/atalman
2025-03-11 19:12:46 +00:00
PyTorch MergeBot 275a7c5dbb Revert "Add a stable TORCH_LIBRARY to C shim (#148124)"
This reverts commit 327e07ac1d.

Reverted https://github.com/pytorch/pytorch/pull/148124 on behalf of https://github.com/malfet due to Sorry for reverting your PR, but somehow it caused test failures in newly introduced tests, see https://hud.pytorch.org/hud/pytorch/pytorch/main/1?per_page=50&name_filter=pull%20%2F%20linux-focal-cuda12.6-py3.10-gcc11-sm89%20%2F%20test%20(default%2C%201&mergeLF=true ([comment](https://github.com/pytorch/pytorch/pull/148124#issuecomment-2709057833))
2025-03-09 20:44:56 +00:00
Jane Xu 327e07ac1d Add a stable TORCH_LIBRARY to C shim (#148124)
This PR adds two main parts:
- shim.h stable C APIs into torch::Library APIs
- a higher level API in torch/csrc/stable/library.h that calls into this shim.h + otherwise is self contained

Goal: custom kernel writers should be able to call the apis in the directories above in order to register their library in a way that allows their custom extension to run with a different libtorch version than it was built with.

Subplots resolved:

- Do we want a whole separate StableLibrary or do we want to freeze torch::Library and add `m.stable_impl(cstring, void (*fn)(void **, int64_t, int64_t)` into it
    - Yes, we want a separate StableLibrary. We cannot freeze Library and it is NOT header only.
- Should I use unint64_t as the common denominator instead of void* to support 32bit architectures better?
    -  Yes, and done
- Should I add a stable `def` and `fragment` when those can be done in python?
    - I think we do want these --- and now they're done
- Where should library_stable_impl.cpp live? -- no longer relevant
- I need some solid test cases to make sure everything's going ok. I've intentionally thrown in a bunch of random dtypes into the signature, but I still haven't tested returning multiple things, returning nothing, complex dtypes, etc.
    - Have since tested all the torch library endpoints. the others can be tested in a followup to separate components that need to be in shim.h vs can be added later

Pull Request resolved: https://github.com/pytorch/pytorch/pull/148124
Approved by: https://github.com/albanD, https://github.com/zou3519
2025-03-09 10:07:25 +00:00
Alexander Kurakin 18c1dcb8f3 docs: get rid of copyright year (#144562)
Fixes https://github.com/pytorch/pytorch/pull/144153#pullrequestreview-2540418083
Pull Request resolved: https://github.com/pytorch/pytorch/pull/144562
Approved by: https://github.com/albanD
2025-01-10 19:57:25 +00:00
Nikita Shulga d1be61ce4e Update copyrights to 2024 (#138638)
Spiritual successor of https://github.com/pytorch/pytorch/pull/119413 + CPP docs copyright update as well
Fixes https://github.com/pytorch/pytorch/issues/138630

Pull Request resolved: https://github.com/pytorch/pytorch/pull/138638
Approved by: https://github.com/atalman
2024-10-22 21:00:58 +00:00
Nikita Shulga 4fd16dd8aa Clarify that libtorch API is C++17 compatible (#136471)
As it relies on some common C++17 primitives, such as `std::optional`
Replace all docs references from C++14 to C++17

Fixes https://github.com/pytorch/pytorch/issues/133205

Pull Request resolved: https://github.com/pytorch/pytorch/pull/136471
Approved by: https://github.com/kit1980, https://github.com/atalman
2024-09-24 02:03:33 +00:00
Wouter Devriendt e8645fa2b9 [Doc] fix some typos (found by codespell and typos) (#132544)
Applying doc fixes from PR https://github.com/pytorch/pytorch/pull/127267 - with CLA
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132544
Approved by: https://github.com/kit1980
2024-08-05 17:21:56 +00:00
Xuehai Pan a3abfa5cb5 [BE][Easy][1/19] enforce style for empty lines in import segments (#129752)
See https://github.com/pytorch/pytorch/pull/129751#issue-2380881501. Most changes are auto-generated by linter.

You can review these PRs via:

```bash
git diff --ignore-all-space --ignore-blank-lines HEAD~1
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/129752
Approved by: https://github.com/ezyang, https://github.com/malfet
2024-07-16 00:42:56 +00:00
ibartol 65d3ddcb8b Add GLIBC requirements for libtorch to solve #113124 (#128135)
Fixes #113124.

## Description

I modified the installing.rst file to address the system requirements and troubleshooting steps for using LibTorch with different GLIBC versions.

### Summary of Changes

- Added system requirements specifying the GLIBC version needed for both the cxx11 ABI version and the pre-cxx11 ABI version of LibTorch.
- Included a troubleshooting section with instructions on how to check the dependencies of the LibTorch libraries and identify the required GLIBC version using the `ldd lib/libtorch.so` command.

## Checklist
- [X] The issue that is being fixed is referred in the description
- [X] Only one issue is addressed in this pull request
- [X] Labels from the issue that this PR is fixing are added to this pull request
- [X] No unnecesary issues are included into this pull request

Pull Request resolved: https://github.com/pytorch/pytorch/pull/128135
Approved by: https://github.com/jbschlosser
2024-06-14 21:24:53 +00:00
Nikita Shulga f9a611a3ce Update Jinja to 3.1.3 (#124976)
To fix CVE-2024-22195

Also, delete unused docs/cpp/requirements.txt and functorch/docs/requirements.txt

Pull Request resolved: https://github.com/pytorch/pytorch/pull/124976
Approved by: https://github.com/kit1980
2024-04-26 02:57:55 +00:00
Yu, Guangye 3d3d4e1cd5 export XPUStream to doc (#121398)
# Motivation
We would like to export XPUStream to public [doc](https://pytorch.org/cppdocs/api/library_root.html). The detailed documentation can help users understand and utilize XPU more effectively.

# Additional Context
A detailed XPUStream API and usage should be documented to public doc, like cuda's [doc](https://github.com/pytorch/pytorch/blob/main/docs/cpp/source/notes/tensor_cuda_stream.rst).

Pull Request resolved: https://github.com/pytorch/pytorch/pull/121398
Approved by: https://github.com/gujinghui, https://github.com/jgong5, https://github.com/EikanWang, https://github.com/albanD
2024-03-30 00:36:26 +00:00
Nikita Shulga d84dcfb3e0 [Doc] Fix typo in cpp/installing when wheel is used (#111143)
<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 34a15a6</samp>

Updated the cmake command in `docs/cpp/source/installing.rst` to use python3 and fix a documentation error.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/111143
Approved by: https://github.com/clee2000, https://github.com/kit1980
2023-10-13 18:56:27 +00:00
Edward Z. Yang f70844bec7 Enable UFMT on a bunch of low traffic Python files outside of main files (#106052)
Signed-off-by: Edward Z. Yang <ezyang@meta.com>

Pull Request resolved: https://github.com/pytorch/pytorch/pull/106052
Approved by: https://github.com/albanD, https://github.com/Skylion007
2023-07-27 01:01:17 +00:00
Justin Chu 14d87bb5ff [BE] Enable ruff's UP rules and autoformat tools and scripts (#105428)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/105428
Approved by: https://github.com/albanD, https://github.com/soulitzer, https://github.com/malfet
2023-07-19 01:24:44 +00:00