简报·YT
← 返回 GitHub 动态
pytorch/pytorch · 📌 手动指定 已完成

pytorch/pytorch v2.14.0

2026-09-02 17:40 · ⭐ 10.3万 · GitHub Release 原文 ↗
#版本更新 #编译优化 #分布式

pytorch/pytorch v2.14.0

PyTorch 2.14.0 是一次大规模版本更新,重点引入 NVGEMM、torch.switch、声明式动态形状、分布式 nccl2 后端以及 Apple Silicon 原生线性代数支持,同时移除并废弃了一批旧 API,并包含大量分布式、编译、MPS/ROCm/XPU 的修复与性能优化。

Highlights

Breaking Changes

New Features

Improvements & Bug Fixes

Performance

其他

▸ Release Notes 英文原文(112747 字符)
# PyTorch 2.14.0 Release Notes - [Highlights](#highlights) - [Backwards Incompatible Changes](#backwards-incompatible-changes) - [Deprecations](#deprecations) - [New Features](#new-features) - [Improvements](#improvements) - [Bug fixes](#bug-fixes) - [Performance](#performance) - [Documentation](#documentation) - [Security](#security) - [Developers](#developers) # Highlights <table> <tr><td><strong>NVGEMM</strong> brings CuTeDSL-generated CUTLASS kernels to Inductor, with epilogue fusion, scaled and NVFP4 GEMM, and grouped-reduction epilogues autotuned alongside Triton and ATen</td></tr> <tr><td><strong><code>torch.switch</code></strong> generalizes <code>torch.cond</code> to multi-way branching, and <code>torch.while_loop</code> can now be captured in a CUDA graph</td></tr> <tr><td><strong>Declarative dynamic shapes via <code>@dynamic_spec</code></strong>, shared across <code>torch.compile</code>, <code>torch.export</code> and <code>make_fx</code></td></tr> <tr><td><strong>Experimental <code>torch.compile</code> support for complex-valued tensors</strong>: Opt-in support decomposes supported complex operations into real and imaginary computations, enabling compiler backends to optimize more complex-number workloads.</td></tr> <tr><td><strong>A new <code>nccl2</code> backend for PyTorch Distributed</strong>, ported from torchcomms, implementing the full collective contract with nonblocking communicators and eager communicator splitting</td></tr> <tr><td><strong>Fault tolerance becomes a first-class <code>c10d</code> concept</strong>, with in-place process-group reconfiguration, one-sided RMA windows, and a Flight Recorder that works for any backend rather than only NCCL</td></tr> <tr><td><strong>Apple Silicon gains native linear algebra</strong>, including Jacobi-kernel SVD, <code>eigh</code>, QR and Cholesky, alongside a five-part reduction rewrite and a further MPSGraph to Metal kernel migration</td></tr> <tr><td><strong>Broader platform support</strong>: ROCm 7.14 wheels are produced from the TheRock pip SDK, Intel XPU adds native graph capture, and Inductor targets Rubin (<code>sm_107</code>)</td></tr> </table> For more details about these highlighted features, you can look at the release blogpost. Below are the full release notes for this release. # Backwards Incompatible Changes ## torch.nn - `torch.nn.LinearCrossEntropyOptions` no longer accepts `acc_policy="balanced"`; use `"compact"` instead (#188283) The `"balanced"` policy was removed because `"compact"` provides the same weight-gradient accumulation precision with lower memory use on CUDA, already uses the equivalent scratch layout for mixed-precision inputs on other devices, and was never selected by `"auto"`. Constructing the options with `acc_policy="balanced"` now raises `ValueError: invalid acc_policy: 'balanced'; expected one of 'auto', 'accurate', 'compact'`. Before: ```python options = torch.nn.LinearCrossEntropyOptions(acc_policy="balanced") loss = torch.nn.functional.linear_cross_entropy( input, linear_weight, target, options=options ) ``` After: ```python options = torch.nn.LinearCrossEntropyOptions(acc_policy="compact") loss = torch.nn.functional.linear_cross_entropy( input, linear_weight, target, options=options ) ``` ## Autograd - Clamp and min/max boundary subgradients now follow the selected dispatcher schema's input space (#191142) This affects gradients exactly at nondifferentiable bounds or ties. A scalar clamp bound is a fixed parameter, so the input gradient at equality changes from `1` to the minimum-norm subgradient `0`. A Tensor bound is part of the differentiable input space, so `clamp`, `clamp_min`, and `clamp_max` now split the gradient evenly between the input and bound at an ordinary tie instead of assigning it entirely to the input. `fmin` and `fmax` use the same even tie split, and forward-mode AD for the min/max family is aligned with these rules. Code that intentionally depends on the old tie-breaking behavior can express it explicitly with `torch.where`, such as `torch.where(value >= bound, value, bound)`. Version 2.13: ```python import torch x = torch.tensor(0.0, requires_grad=True) torch.clamp_min(x, 0.0).backward() print(x.grad) # tensor(1.) value = torch.tensor(0.0, requires_grad=True) bound = torch.tensor(0.0, requires_grad=True) torch.clamp_min(value, bound).backward() print(value.grad, bound.grad) # tensor(1.) tensor(0.) ``` Version 2.14: ```python import torch x = torch.tensor(0.0, requires_grad=True) torch.clamp_min(x, 0.0).backward() print(x.grad) # tensor(0.) value = torch.tensor(0.0, requires_grad=True) bound = torch.tensor(0.0, requires_grad=True) torch.clamp_min(value, bound).backward() print(value.grad, bound.grad) # tensor(0.5000) tensor(0.5000) ``` ## Distributed - Custom Python process groups that implement `new_group()` must now accept a `backend` keyword argument (#188489) This applies when the default process group supplies its own `new_group()` method and `torch.distributed.new_group()` delegates subgroup creation to it. PyTorch now forwards the resolved backend so custom implementations can construct the requested subgroup correctly. Existing implementations without this parameter will raise `TypeError: ... got an unexpected keyword argument 'backend'`. Accept and use the argument, or accept and ignore it when the implementation has only one backend. Before: ```python class MyProcessGroup(...): def new_group( self, ranks, *, timeout=None, pg_options=None, group_name=None, group_desc=None ): ... ``` After: ```python class MyProcessGroup(...): def new_group( self, ranks, *, timeout=None, backend=None, pg_options=None, group_name=None, group_desc=None ): ... ``` - NCCL symmetric-memory pools no longer automatically upgrade segments allocated after `register_mem_pool(..., symm=True)` to symmetric windows (#192112) Registering those late segments from the CUDA allocator callback could invoke a collective NCCL operation on only some ranks while holding the allocator lock, causing an unrecoverable hang. Late segments now remain ordinary registered NCCL buffers. Applications that need newly allocated segments to use symmetric-window algorithms must collectively deregister and register the pool again after those allocations are created. Before: ```python backend.register_mem_pool(pool, symm=True) with torch.cuda.use_mem_pool(pool): tensor = torch.empty(size, device="cuda") # Newly allocated segments were automatically upgraded, but this could hang. ``` After: ```python backend.register_mem_pool(pool, symm=True) with torch.cuda.use_mem_pool(pool): tensor = torch.empty(size, device="cuda") # Collectively refresh registration after the pool grows. backend.deregister_mem_pool(pool) backend.register_mem_pool(pool, symm=True) ``` - Nonmember ranks now receive `GroupMember.NON_GROUP_MEMBER` instead of `None` from experimental `torch.distributed.split_group()` (#190725) When the calling rank is absent from every requested split, `split_group()` now returns the same nonmember sentinel as `new_group()`. Code that identifies nonmembers with `is None` must compare against `torch.distributed.GroupMember.NON_GROUP_MEMBER` instead. Before: ```python group = torch.distributed.split_group( split_ranks=[[0, 1], [2, 3]] ) if group is None: return ``` After: ```python group = torch.distributed.split_group( split_ranks=[[0, 1], [2, 3]] ) if group == torch.distributed.GroupMember.NON_GROUP_MEMBER: return ``` ## Linear Algebra Frontend - Remove the deprecated `torch.cholesky()` and `Tensor.cholesky()` APIs (#186817) Calls now raise a `RuntimeError` directing users to `torch.linalg.cholesky()`. The replacement returns a lower-triangular factor; callers that previously requested `upper=True` should take the conjugate transpose with `.mH`. Version 2.13: ```python lower = torch.cholesky(a) upper = torch.cholesky(a, upper=True) ``` Version 2.14: ```python lower = torch.linalg.cholesky(a) upper = torch.linalg.cholesky(a).mH ``` - Remove the deprecated `torch.qr()` and `Tensor.qr()` APIs (#186815) Calls now raise a `RuntimeError` directing users to `torch.linalg.qr()`. Replace the Boolean `some` argument with `mode="reduced"` or `mode="complete"`. Version 2.13: ```python q, r = torch.qr(a) q_full, r_full = torch.qr(a, some=False) ``` Version 2.14: ```python q, r = torch.linalg.qr(a, mode="reduced") q_full, r_full = torch.linalg.qr(a, mode="complete") ``` ## Profiler - The deprecated `use_cuda` argument has been removed from `torch.profiler.profile` and `torch.autograd.profiler.profile` (#192543) Passing `use_cuda` to either profiler now raises `TypeError: profile.__init__() got an unexpected keyword argument 'use_cuda'`. Select CUDA explicitly through `activities` when using `torch.profiler.profile`, or use `use_device="cuda"` with `torch.autograd.profiler.profile`. Version 2.13: ```python with torch.profiler.profile(use_cuda=True) as prof: run_workload() with torch.autograd.profiler.profile(use_cuda=True) as prof: run_workload() ``` Version 2.14: ```python with torch.profiler.profile( activities=[ torch.profiler.ProfilerActivity.CPU, torch.profiler.ProfilerActivity.CUDA, ] ) as prof: run_workload() with torch.autograd.profiler.profile(use_device="cuda") as prof: run_workload() ``` ## Dynamo - The `tvm` backend now uses TVM's relax frontend exclusively; the relay path has been removed (#190766, #189639) Relay was removed in TVM 0.20, so the backend now requires a TVM providing `tvm.relax.frontend.torch`. Two things are gone with it: the relay-only `scheduler` / `trials` options, replaced by a TVM pipeline passed as `options={"pipeline": ...}`; and the `tvm_meta_schedule` / `tvm_auto_scheduler` backend entry points, which no longer exist in `torch._dynamo.backends.tvm`. With an older TVM installed, `torch.compile(..., backend="tvm")` now raises `ImportError: Please install apache-tvm to use the tvm backend.` Version 2.13: ```python opt = torch.compile(model, backend="tvm", options={"scheduler": "meta_schedule", "trials": 20000}) # or through the relay-only entry points from torch._dynamo.backends.tvm import tvm_meta_schedule, tvm_auto_scheduler ``` Version 2.14: ```python import tvm pipeline = tvm.relax.get_pipeline("static_shape_tuning", target="llvm", total_trials=2000) opt = torch.compile(model, backend="tvm", options={"pipeline": pipeline}) # tvm_meta_schedule / tvm_auto_scheduler no longer exist: # ImportError: cannot import name 'tvm_meta_schedule' ``` ## C++ Frontend - Remove the deprecated zero-argument C++ overloads `c10::Scalar::isIntegral()` and `c10::isIntegralType(ScalarType)` (#187115) Code that calls either overload without specifying whether Boolean values count as integral will no longer compile. Pass `includeBool` explicitly; use `false` to preserve the removed overloads' behavior. Version 2.13: ```cpp bool scalar_is_integer = scalar.isIntegral(); bool dtype_is_integer = c10::isIntegralType(dtype); ``` Version 2.14: ```cpp bool scalar_is_integer = scalar.isIntegral(/*includeBool=*/false); bool dtype_is_integer = c10::isIntegralType(dtype, /*includeBool=*/false); ``` ## Release Engineering - `setup.py` is now a deprecation shim; build PyTorch through pip or `python -m build` (#180248) `setup.py` is now a thin shim. `install` and `develop` still forward to pip, but `build`, `bdist_wheel`, `clean`, `sdist` and the rest print the replacement command instead of falling through to setuptools. Builds that already go through a PEP 517 frontend are unaffected, since pip and `python -m build` never ran `setup.py`. The shim prints the schedule: `install`/`develop` keep forwarding through 2.15, every command stops working in 2.16, and `setup.py` is removed in 2.18. Version 2.13: ```bash python setup.py bdist_wheel ``` Version 2.14: ```bash python -m build --wheel --no-isolation ``` ## MPS - The C++ MPS macOS-version helper and its enum members have been renamed (#188645) Downstream C++ code that includes `<ATen/mps/MPSDevice.h>` must replace the exported `at::mps::is_macos_13_or_newer()` function with `at::mps::is_macos_at_least()`. The associated `MacOSVersion` members also drop the `VER` and `PLUS` portions of their names. No compatibility aliases are provided, so code using the old names will no longer compile. Version 2.13: ```cpp const bool supported = at::mps::is_macos_13_or_newer( at::mps::MacOSVersion::MACOS_VER_15_0_PLUS); ``` Version 2.14: ```cpp const bool supported = at::mps::is_macos_at_least( at::mps::MacOSVersion::MACOS_15_0); ``` ## Complex Frontend - Complex type promotion for `bfloat16` now uses the new `torch.bcomplex32` shell dtype instead of `torch.complex64` (#186928) `torch.bcomplex32` stores real and imaginary components as `bfloat16`. Operations that combine a `bfloat16` tensor with a complex scalar or otherwise request its corresponding complex type can therefore produce `bcomplex32` instead of `complex64`. Because `bcomplex32` is a shell dtype with limited operator support, an operation that previously ran in `complex64` may now raise a not-implemented error. Explicitly cast to `complex64` when the previous precision or operator coverage is required. Version 2.13: ```python x = torch.ones(4, dtype=torch.bfloat16) assert torch.result_type(x, 1j) == torch.complex64 ``` Version 2.14: ```python x = torch.ones(4, dtype=torch.bfloat16) assert torch.result_type(x, 1j) == torch.bcomplex32 # Preserve the previous complex64 behavior explicitly. y = x.to(torch.complex64) + 1j ``` # Deprecations ## Autograd - Selective activation checkpointing will change to honor surrounding `saved_tensors_hooks` by default; use the new `respect_saved_tensors_hooks` argument to choose the behavior explicitly (#190581) The current default, `None`, preserves the legacy behavior in which tensors retained by selective activation checkpointing bypass user hooks, but now emits a `FutureWarning` when hooks are active. Pass `True` to opt into the future behavior or `False` to preserve the legacy behavior without a warning. This option requires `use_reentrant=False`. Before: ```python with torch.autograd.graph.saved_tensors_hooks(pack, unpack): output = torch.utils.checkpoint.checkpoint( function, input, use_reentrant=False, context_fn=sac_context_fn, ) ``` After: ```python with torch.autograd.graph.saved_tensors_hooks(pack, unpack): output = torch.utils.checkpoint.checkpoint( function, input, use_reentrant=False, context_fn=sac_context_fn, respect_saved_tensors_hooks=True, ) ``` ## Distributed - Use `torch.compiler.config.compile_on_one_rank` instead of `torch.distributed.config.compile_on_one_rank` (#187869) The distributed spelling remains as a forwarding alias but now emits a `FutureWarning`. The preferred environment variable is also `TORCH_COMPILE_ON_ONE_RANK`; the older `TORCH_DISTRIBUTED_COMPILE_ON_ONE_RANK` remains supported for compatibility. Before: ```python import torch.distributed.config torch.distributed.config.compile_on_one_rank = True ``` After: ```python import torch.compiler.config torch.compiler.config.compile_on_one_rank = True ``` ## Profiler - The experimental `profiler_metrics` and `profiler_measure_per_kernel` options no longer enable CUPTI range profiling and now emit a `FutureWarning` when set to a non-default value (#187204) Kineto no longer supports this range-profiler path on PyTorch's supported CUDA versions. The arguments remain accepted temporarily for compatibility, but they are ignored and have no direct replacement. Before: ```python config = torch.profiler._ExperimentalConfig( profiler_metrics=["sm__cycles_elapsed.avg"], profiler_measure_per_kernel=True, ) ``` After: ```python config = torch.profiler._ExperimentalConfig() ``` - The `with_modules` profiler option is deprecated and now emits a `FutureWarning` (#192808) `with_modules=True` only collected module hierarchy for TorchScript models and did nothing in eager mode. For eager models, use `with_stack=True` to record `nn.Module` events. Before: ```python with torch.profiler.profile(with_modules=True) as prof: run_workload() ``` After: ```python with torch.profiler.profile(with_stack=True) as prof: run_workload() ``` ## Dynamo - `torch._dynamo.config.enable_faithful_generator_behavior` is deprecated and is now a no-op (#189894) Faithful (lazy) generator tracing has been the default and is the only supported behavior, so the dead eager-exhaustion path was removed. The config is kept as a deprecated setting that always behaves as `True`, so setting it does not error but no longer changes anything. Version 2.13: ```python # generators were eagerly exhausted on first execution with torch._dynamo.config.patch(enable_faithful_generator_behavior=False): torch.compile(fn)(x) ``` Version 2.14: ```python # the flag is ignored; generators are always traced lazily torch.compile(fn)(x) ``` ## CUDA - Deprecate `CUDAGraph.register_generator_state()`; CUDA graphs now register generator state lazily on first RNG use during capture (#176753) The method is now a no-op and emits a deprecation warning. Remove explicit registration calls; the graph automatically retains the required state when the generator is used during capture. Before: ```python graph = torch.cuda.CUDAGraph() state = generator.graphsafe_get_state() graph.register_generator_state(state) with torch.cuda.graph(graph): generator.graphsafe_set_state(state) output = torch.rand(16, device="cuda", generator=generator) ``` After: ```python graph = torch.cuda.CUDAGraph() state = generator.graphsafe_get_state() with torch.cuda.graph(graph): generator.graphsafe_set_state(state) output = torch.rand(16, device="cuda", generator=generator) ``` - Deprecate `GreenContext.set_context()` and `GreenContext.pop_context()`; use custom streams to activate a green context instead (#188419) These methods now emit a `FutureWarning`. Create a stream from the green context and use it with `torch.cuda.stream()` instead. Synchronization with streams outside the green context remains the caller's responsibility and should use CUDA events when needed. Before: ```python ctx = torch.cuda.green_contexts.GreenContext(num_sms=1) ctx.set_context() try: output = model(input) finally: ctx.pop_context() ``` After: ```python ctx = torch.cuda.green_contexts.GreenContext(num_sms=1) stream = ctx.Stream() with torch.cuda.stream(stream): output = model(input) ``` ## JIT - TorchScript APIs now emit visible `FutureWarning`s instead of normally hidden `DeprecationWarning`s (#189914) Calls such as `torch.jit.script`, `torch.jit.trace`, `torch.jit.save`, and `torch.jit.load` now visibly direct users toward `torch.compile` or `torch.export`. Imports of `torch.utils.mkldnn`, `torch.fx.experimental.optimization`, and `torch.distributed.optim` also avoid eagerly compiling TorchScript when those modules are merely imported. Before: ```python scripted = torch.jit.script(model) torch.jit.save(scripted, "model.pt") ``` After: ```python exported = torch.export.export(model, example_inputs) torch.export.save(exported, "model.pt2") ``` # New Features ## Python Frontend - Add `torch.accelerator.initial_seed()`, `torch.accelerator.get_rng_state()`, and `torch.accelerator.get_rng_state_all()` for backend-agnostic accelerator RNG inspection (#186597) - Add read-only DLPack export through `Tensor.__dlpack__(read_only=True)` and `torch.utils.dlpack.ReadOnlyTensorWrapper`, including copy-on-write-preserving exchange with compatible consumers (#188554) - Add `torch.Generator.philox_state()` so Python-authored kernels can reserve Philox counter ranges that remain correct across CUDA Graph capture and replay (#191019) ## Autograd - `torch.utils.checkpoint.checkpoint()` can now be called without a function to create an eager-mode decorator with checkpoint configuration separated from the wrapped function's arguments (#189411) ```python checkpointed_function = torch.utils.checkpoint.checkpoint( use_reentrant=False )(function) output = checkpointed_function(*args, **kwargs) ``` The curried form is initially supported in eager mode; existing direct calls remain the compatible form under `torch.compile`. - Add `torch.autograd.graph.node_creation_hook`, a thread-local context manager whose callback receives every fully populated autograd graph node created within its scope. The callback can inspect nodes, store metadata, or register backward pre-hooks and post-hooks, including for nodes created during higher-order differentiation and checkpoint recomputation (#189284) - Add `ctx.set_output_grad_dtype(*dtypes)` for custom `torch.autograd.Function` implementations. Called once from `forward` or `setup_context`, it declares the gradient dtype expected for each output independently of the output's storage dtype; a concrete dtype converts incoming gradients, while `None` leaves their dtype unchanged (#189634) - Add second-order gradient support for `torch.cdist` and `torch.nn.functional.pdist`, so grad-grad computations no longer fail because `_cdist_backward` or `_pdist_backward` lacks a derivative (#188901) ## Distributed - Add portable JSON serialization through `DebugMode.save_logs()` and `DebugMode.load_logs()` so distributed execution logs can be compared across separate processes or model configurations (#185010) - Add the public `torch.distributed.set_timeout()` API; the private `_set_pg_timeout()` alias remains available with a deprecation warning (#187387) - Add `torch.distributed.tensor.logspace` for constructing distributed logarithmically spaced tensors (#186398) - Add experimental `torch.distributed.get_backend_impl()` and `ProcessGroup.get_backend()` accessors for custom backend development (#187494) - Add `torch.distributed.tensor.linspace` for constructing distributed linearly spaced tensors (#187933) - Add fault-tolerant reconfiguration and one-sided window operations to the experimental `nccl2` backend (#189359, #189360) - Add the experimental `nccl-lazy` backend, which creates per-peer NCCL point-to-point communicators on demand (#189362) - Add the `CheckpointableTensor` protocol so distributed checkpointing can save and load `torch.Tensor` objects exposing `global_shape`, `global_offsets`, `local_offsets`, and `local_sizes` metadata (#189492) - Add an explicit `nccl-legacy` backend and the `TORCH_DIST_USE_NCCL2=1` opt-in for selecting the experimental replacement behind the `nccl` name (#191272) - Allow `ProcessGroupNCCL.Options.config.comm_name` to assign readable communicator names for NCCL logs and profiler tools (#191001) - Add `torchrun --log-line-prefix-template` and a `${hostname}` template variable for identifying the host that emitted each worker log line (#191265) - Allow pipeline schedules to consume explicitly pre-split positional inputs, keyword inputs, and targets through `arg_mbs`, `kwarg_mbs`, and `target_mbs` (#188500) - Add optional shell-completion generation to `torchrun` through `--print-completion` and the `shtab` package (#191289) ## Symmetric Memory - Add XPU support for symmetric-memory operations used by asynchronous tensor parallelism, enabling communication/computation overlap on Intel GPUs (#185102) ## Linear Algebra Frontend - Add `torch.linalg.polar()` for computing `A = U @ H` for matrices with at least as many rows as columns, using a portable SVD implementation and cuSOLVER QDWH acceleration for eligible CUDA inputs (#185837) - Add `torch.linalg.matrix_sqrth` for computing the principal square root of symmetric or Hermitian positive-definite matrices, with support for batched inputs, autograd, `vmap`, and `torch.compile` (#187987) - Add CUDA cuBLASLt support to TunableOp, including controls for the number of heuristic candidates through `torch.cuda.tunable.set_cublaslt_requested_algo_count()` and `PYTORCH_TUNABLEOP_CUBLASLT_REQUESTED_ALGO_COUNT` (#186270) ## Profiler - Memory snapshots can now include CPU pinned-memory allocations by passing `record_pinned_host_memory=True` to `torch.cuda.memory._record_memory_history()` (#182407) Pinned-memory allocator state and history are available in the snapshot's `host_segments` and `host_traces` fields. Pass `record_cuda=False` to record only pinned host memory; the web memory visualizer does not yet display host-memory data. - Profiler events now expose Kineto metadata as typed values through `FunctionEvent.metadata` when `expose_kineto_event_metadata=True` is enabled (#191756) The new dictionary avoids reparsing JSON strings and automatically includes metadata fields supported by the active profiler backend. ## Dynamo - Add `torch.compiler.nonstrict_trace` as a public API (#187737) - Add the prototype `switch` higher-order op, which selects between N branches by index and mirrors `jax.lax.switch`. It is available as `from torch._higher_order_ops.switch import switch` and lowers to `torch.ops.higher_order.switch`; autograd is not yet supported (#182902, #188374, #189028) - Declare dynamic shapes explicitly with `ShapesSpec` / `ParamsSpec`, now accepted by strict and non-strict `torch.export.export`, `make_fx(tracing_mode="fake")`, and `torch.compile` through a shared `dynamic_shapes=` keyword (#185982, #186751, #187602, #187010) - Support Dynamo and AOTAutograd tracing of permitted input mutations in the prototype `scan`, `map`, and `switch` higher-order ops when gradients are disabled; Inductor lowering for these mutations is not yet supported (#186474, #187568, #188903) - Support `torch.cuda.use_mem_pool` inside a compiled region, so allocations in the context - including fallback and extern kernels - are routed to the pool (#185057) - Support calls to `logging.Logger` methods that are explicitly registered in `torch._dynamo.config.reorderable_logging_functions`, so supported positional-argument logging calls run after the compiled region instead of causing graph breaks (#190840) ## Inductor - Add NVGEMM epilogue fusion so supported pointwise operations and output casts can be fused into autotuned matrix multiplications (#186183) - Add NVGEMM autotuning support for `torch.addmm`, including fused bias and supported pointwise epilogues (#189774) - Support FlexAttention FLASH-backend backward graphs that differentiate through the returned log-sum-exp output (#189784) - Add an opt-in `torch._inductor.config.reorder_for_locality_in_training` setting for applying locality-based graph reordering to training graphs (#186643) - Add opt-in CUDA Graph Trees generation cloning through `torch._inductor.config.triton.cudagraph_trees_generation_cloning = "user_visible"`, preserving live user-visible outputs across generations (#188078) - Add `bfloat16` support to `torch.fft` operations and `torch.stft` on CUDA and add `float16`/`bfloat16` support on XPU. Native CUDA `bfloat16` cuFFT execution requires SM80 or newer and power-of-two transform sizes; unsupported CUDA and XPU cases promote to `float32`. CPU FFT continues to reject these low-precision dtypes (#180766) - Add the opt-in `autotuning_inputs` log artifact, enabled with `TORCH_LOGS=autotuning_inputs`, to report Triton autotuning input shapes, dtypes, strides, and scalar values (#184399) - Add Inductor support for the prototype `switch` control-flow operator on CPU and GPU, including dynamic shapes, multiple outputs, and AOTInductor; CUDA graphs remain unsupported for graphs containing `switch` (#188976) - Add dynamic-shape support to `torch.compiler.precompile` for dimensions marked with `torch._dynamo.decorators.mark_unbacked`, allowing one artifact to serve multiple runtime sizes without guarding on the marked dimension (#189165) - Add `torch.compiler.cudagraph_mark_warmup_incomplete()` so code can request another CUDA Graph Trees warmup iteration (#191386) ## Ahead-Of-Time Inductor (AOTI) - Add `AOTInductorModelContainerCreateWithExternalConstants`, allowing callers to construct an AOTInductor model container from caller-owned weight tensors for zero-copy sharing such as CUDA IPC (#188643) The new C API skips loading constants from the package and leaves ownership with the caller. Existing model-container creation and constant-loading paths are unchanged unless external constants are explicitly provided. - Support explicit user-defined streams in the AOTInductor C++ wrapper. A compiled region that selects a stream with `torch.cuda.stream(...)` now emits stream-guard code so its kernels run on the requested stream, instead of always running on the default stream (#182971) ## Export - Add the `torch.fx.experimental.dynamic_spec.dynamic_spec` decorator for attaching a dynamic-shape specification to a function or `nn.Module.forward`. `torch.compile`, `torch.export.export`, and `make_fx` automatically use the attached specification; passing a conflicting call-site specification raises an error (#187639) ## Composability - Add a `length` argument to the prototype `torch._higher_order_ops.scan`, allowing a scan to run for a fixed number of steps when `xs=None`, matching the corresponding `jax.lax.scan` usage pattern (#188349) - Add grouped-query attention to the CUDA memory-efficient backend for `torch.nn.functional.scaled_dot_product_attention`, including native grouped key/value heads, implicit multi-query attention broadcasting, and backward support under `vmap` (#191085) ## C++ Frontend - Add `torch::stable::tensor_from_pyobject` and `torch::stable::tensor_to_pyobject` for converting between Python `torch.Tensor` objects and `torch::stable::Tensor` (#183323) - Move the `c10/util/complex_utils.h` helpers and the `ATen/NumericUtils.h` `_isinf` and `_isnan` implementations into the header-only ABI (#192552, #192557) - Add stable-ABI `torch::stable::permute` and the dtype overload of `torch::stable::view` (#192083) - Add stable-ABI `torch::stable::Tensor` overloads for `bitwise_and`, `bitwise_or`, `bitwise_left_shift`, `bitwise_right_shift`, `index_select`, `floor_divide`, and `is_pinned` (#191973, #192097) - Add `torch::stable::Tensor::has_storage()` (#189877) ## Release Engineering - Expand Python 3.15 and free-threaded (no-GIL) Python 3.15t binary coverage to Windows and macOS, completing support across the PyTorch release matrix (#189722, #190360, #190361, #186033) PyTorch 2.14 publishes Python 3.15 and 3.15t wheels for Linux on x86-64 and aarch64, Windows x86-64, and macOS on Apple silicon, covering the applicable CPU, CUDA, ROCm, and XPU builds. `torchvision` 0.29.0 publishes matching Python 3.15 and 3.15t wheels for the same supported platform and accelerator combinations. This is binary and eager-runtime support; `torch.compile` remains unsupported on Python 3.15 in this release. ## CUDA - Add a cuBLASLt backend for grouped GEMM on Hopper and Blackwell GPUs with CUDA 13.3 or newer (#177037, #190372) The backend supports `float16` and `bfloat16`, works with `torch.compile` and CUDA Graphs, and is selected by default for eligible `float16` workloads. Set `torch.backends.cuda.matmul.prefer_cublaslt_grouped_gemm = True` to opt into it for `bfloat16`. Matrices and leading dimensions must be 16-byte aligned, so some shapes may require padding and slicing. - Add `torch.cuda.memory._annotate_tensor()` for attaching metadata to a live CUDA tensor allocation after it is created (#190575) Each annotation is recorded as a timestamped memory-history event, multiple annotations accumulate without replacing allocation-time metadata, and memory snapshot tools display the annotations alongside the affected allocation. Memory history must be enabled with `torch.cuda.memory._record_memory_history()` for annotations to be observable. Only the native CUDA caching allocator supports annotations. - Add the public `torch.cuda.graph_annotations` module (#189417) - Annotate backward kernels in `mark_kernels` via `node_creation_hook` (#191563) - Allow multiple memory pools in a single `CUDAGraph` (#187929) - Add CUDA graph support for `torch.while_loop` (#186055) - Add destroy callbacks and object retention to `torch.cuda.CUDAGraph` (#190582) - Add replay start/end hooks to `torch.cuda.CUDAGraph` (#190602) - Add global CUDA graph capture-start/end and replay-start/end hooks, plus `torch.cuda.CUDAGraph.register_capture_start_hook()` (#192162) ## cuDNN - Add cuDNN SDPA support for head dimension 256 on SM90 and SM10.x GPUs with cuDNN newer than 9.22 and cuDNN Frontend 1.24 or newer; backward currently supports only `(d_qk, d_v) = (256, 256)` (#185553) ## MPS - Add native MPS support for binomial sampling (#187078) - Add MPS forward and backward support for `torch.nn.functional.ctc_loss` (#187716, #188187) - Add MPS support for `torch.linalg.matrix_exp`, including complex inputs, on macOS 15 or newer (#188954) - Add native MPS Poisson sampling, eliminating its CPU fallback (#173319) - Add native `float32` and `complex64` MPS implementations of `torch.linalg.svd`, `svdvals`, `eigh`, `eigvalsh`, and `lstsq`, while retaining CPU fallbacks for small matrices and matrices that exceed threadgroup memory (#185954) ## ROCm - Add initial, technology-preview support for AMD `gfx1250`; CK SDPA/GEMM, FP8 grouped GEMM, and int4 matrix multiplication remain unsupported (#187548, #188597, #188612) - Enable hipFile on Linux with ROCm 7.14 or newer (#191069, #192803) ## XPU - Add FP8 blockwise scaling support for MXFP8/MXFP4/NVFP4 recipes to `torch._scaled_mm` and `torch._scaled_mm_v2` on XPU (#181726, #181727, #187315) - Add XPU Graph native recording mode on non-PVC devices when PyTorch is built with oneAPI 2026.1 or newer (#188874) - Add `torch.xpu.list_gpu_processes` to query per-process GPU memory usage on XPU (#185192) # Improvements ## Python Frontend - Allow `torch.quantile` and `torch.nanquantile` to process `float32` and `float64` inputs larger than `2**24` elements on devices with `float64` support by computing ranks in `float64` (#187574) ## torch.nn - Allow the chunked path of `torch.nn.functional.linear_cross_entropy` to handle probability targets for `reduction="mean"` and `reduction="sum"` when the target dtype matches the input and the target does not require gradients (#187053) - Improve static typing for `torch.nn.Sequential` indexing so integer keys resolve to `Module` and slices resolve to `Sequential` (#187758) - Add the documented `memory_format` overload to `torch.nn.Module.to()` so static type checkers accept calls such as `module.to(memory_format=torch.channels_last)` (#185117) ## Optimizer - Add the `"spectral_unclamped"` scaling option to the `adjust_lr_fn` parameter of `torch.optim.Muon` (#187402) - Add a `maximize` parameter to `torch.optim.LBFGS` (#187309) - Make `torch.optim.LBFGS.step()` a no-op for an empty parameter group (#191666) ## Distributed - Expand `DTensor` sharding strategies for matrix, attention, sorting, scanning, softmax, and related operations (#186667, #179068) - Allow custom Python `ProcessGroup` implementations to use `batch_isend_irecv` and the coalescing manager (#186964) - Improve the Flight Recorder diagnostic emitted when a `TCPStore` check fails (#187191) - Allow pipeline parallel stages to use separate forward and backward point-to-point communicators, reducing cross-batch ordering hazards (#186173) - Add fault-tolerant reconfiguration support to Gloo process groups (#187381) - Make compile-on-one-rank graphs portable across ranks by replacing baked accelerator device indices with a runtime current-device operation (#186892) - Expand active `DTensor` single-dimension strategies for tensor operations (#186754) - Auto-qualify bare backend names and pass process-group options through custom TorchComms backend creation (#187856) - Add complete collective coverage to custom Python process groups, including single-tensor gather/scatter and the remaining point-to-point and collective operations (#188548, #188570) - Make TorchElastic NUMA binding and `ShardedTensor` device transfers work with accelerator backends beyond CUDA (#185266, #187939) - Use generic collective coalescing when aborting process groups so third-party backends can avoid multi-communicator teardown deadlocks (#189770) - Mark CUDA symmetric-memory allocations as GPUDirect RDMA capable on supported systems (#189941) - Add communicator memory suspend/resume support to the experimental `nccl2` backend (#189361) - Allow unknown device-qualified TorchComms backend names to register as custom backends without requiring manual changes to internal backend maps (#191034) - Add eager `split_group` support, complete `Work` semantics, nonblocking communicators, and uneven list collectives to the experimental `nccl2` backend (#190943, #191517, #191528, #191542) - Include `nccl-lazy` pair communicators in error reporting, suspend/resume operations, and memory statistics, and expand its shared backend coverage (#191553, #191556) - Add memory-pool registration and deregistration support to the experimental `nccl2` backend (#192108) - Add per-process-group collective sequence numbers and accurate split-group membership metadata to `nccl2` profiler traces (#192114, #192115) - Support non-overlapping final-spatial-dimension `DTensor` sharding for `Conv1d`, `Conv2d`, and `Conv3d` forward and backward (#192147) - Pass process-group descriptions and names to NCCL's `commName` field while preserving user-specified communicator names (#192487) - Support `DTensor` redistribution from final-dimension sharding to `Partial("sum")` (#191828) ## Distributed (c10d) - Upgrade NCCL to 2.30.7 for CUDA 13.0 and CUDA 13.2 builds (#187528) - Enable Inductor's `simple_overlap` scheduler pass by default for compiled distributed workloads, moving collective starts earlier and waits later without reordering collectives or increasing peak memory (#184235, #184240) ## Linear Algebra Frontend - Add backward support for `torch.linalg.polar` on CPU, CUDA, and MPS (#189732) - Enable `torch.linalg.eig` on ROCm 7.14 or newer through hipSOLVER's generic `Xgeev` API, and update generated linear-algebra tests to recognize hipSOLVER implementations that do not require MAGMA (#188720) - Allow `torch.backends.cuda.preferred_blas_library("ck")` to select the CK GEMM backend on ROCm `gfx90a` devices by separating GEMM support from CK attention support (#187267) - Expand ROCm backend coverage for `torch.linalg.eig`, `torch.linalg.ldl_solve`, `torch.linalg.solve`, and `torch.linalg.solve_triangular` through hipSOLVER and hipBLAS paths (#185557) ## Profiler - Record XPU profiler overhead as `OVERHEAD` activities, making collection costs visible on a dedicated track in exported traces (#187835) ## FX - Allow `split_const_subgraphs()` callers to supply an `is_impure_node` callback so destination-passing operations and other side-effecting nodes are preserved during dead-code elimination (#190716) - Make `get_source_partitions()` return input nodes, output nodes, and parameters in deterministic graph order (#188965) ## Dynamo - Extend `torch.compiler.nested_compile_region` reuse to source-backed objects, symbolic shapes, dataclasses, and namedtuples (#192003, #191806, #191817) - Expand compilation support for `staticmethod`, built-in leaf modules, cross-device `tensor.data` swaps, raw unbacked `SymInt` inputs, zero-length scans, and methods reached through `super()` (#190673, #185722, #185980, #187273, #188348, #183850) - Trace accelerator probes, channels-last `out=` tensors, sourceless `DistributedDataParallel`, `dist.reduce_scatter`, `SDPAParams`, and `torch.linalg.polar` (#185277, #185089, #187210, #190429, #190839, #188537) - Recognize out-of-tree Triton devices and accept module functions or constants as `torch._check` messages (#190324, #188576) - Match more Python built-ins and operators, including `min`/`max`, integer bases and formatting, `range`/slice coercion, object and container subclasses, mutable string splits, rich comparisons, item mutation, and `callable()` (#191401, #191402, #191408, #187129, #186976, #189021, #187588, #185999, #188306, #191406, #190259, #186971) - Expand iterator support for `itertools`, dict/set views, and range iterators (#188080, #189022, #186937, #187080, #186240, #188081, #188221, #189575) - Improve `deque`, dict, set, dict-view, `__dict__`, and list initialization fidelity (#187128, #188220, #191403, #189052, #191405, #186759, #186760, #186669, #186761, #186763, #188908, #187586, #187587, #187583, #187584) - Improve object representation and copying, exception attributes, and subgenerator closure behavior (#187775, #188909, #189053, #189576, #188105, #189024, #188825, #188834) - Trace module-level random calls, text-file encoding operations, and additional numeric operator slots (#188235, #188083, #189984, #186296, #189585, #185641) - Improve graph-break, guard-mismatch, in-place-view, backend-name, and exception diagnostics (#185763, #185083, #185903, #189333, #182972, #185508) - Support TVM's Relax frontend and pipeline-based tuning (#189010, #189638) ## Inductor - Make missing CUDA and ROCm warp-size metadata explicit so Inductor skips heuristics that require it instead of silently assuming a warp size of 32. Raise when a code path requires a concrete warp size but the metadata is unavailable (#183014) - Make autotuning subprocesses honor `ZE_AFFINITY_MASK` on XPU while preserving `CUDA_VISIBLE_DEVICES` behavior on CUDA (#183436) - Add a dedicated `XPUCompileError` for SYCL compilation failures and clear loaded XPU libraries when the code cache is reset (#183530) - Make partitioned-scatter selection memory- and contention-aware, enable it by default on ROCm, and replace the removed `partitioned_scatter_memory_budget` setting with memory-headroom controls; set `partitioned_scatter_enabled = False` to opt out (#184365) - Support ROCm Composable Kernel GEMM templates when compiling with the JIT C++ wrapper (#185505) - Fuse decomposed SiLU activations into CUTLASS GEMM epilogues and improve XPU GEMM template compatibility (#186197, #186198) - Accept multiword compiler commands such as `CXX="zig c++"` when building Inductor-generated C++ code on POSIX systems (#186336) - Add Intel Arc B580 and Arc Pro B70 specifications to Inductor's device-performance metadata (#187308) - Lower `uniform_` and `aten.uniform` through a native decomposition instead of always falling back to eager execution (#187887) - Enable Triton indirect-indexing assertions on ROCm with Triton 3.7 or newer, improving diagnostics for out-of-bounds accesses (#188075) - Allow XPU's static launcher to accept host and shared USM pointers recognized by the driver instead of requiring device memory (#188240) - Extend manual communication-overlap scheduling to bucket and defer waits for DDP and HSDP `all_reduce` operations (#188472) - Support grouped and FP8-scaled grouped GEMM Triton lowering on compatible ROCm hardware (#188600, #188742) - Apply per-region Inductor configuration patches throughout nested-region compilation and allow separate forward and backward patches (#189320, #190068) - Decompose semi-structured sparse CUTLASS matrix multiplication so Inductor can lower and autotune the underlying operation (#189366) - Report stuck compile workers and their current phase in structured `tlparse` traces through the configurable compile-worker watchdog (#189485, #189486) - Prefer device datasheet bandwidth for Inductor's bandwidth-driven heuristics and add Intel Data Center GPU Max 1100 metadata (#189819) - Lower `torch.float8_e8m0fnu` conversions directly on CPU and CUDA instead of relying on fallback conversion code (#190593) - Expand NVGEMM epilogue fusion to pointwise operations, multiple outputs, and grouped reductions, including scaled and centered outputs (#190643, #190808, #190809, #190810, #190813, #190817, #190823) - Suppress empty generated-code dumps from `TORCH_LOGS=output_code` during autotuning (#191381) ## Ahead-Of-Time Inductor (AOTI) - Support `int[]`, `SymInt[]`, and optional integer-list arguments in AOTI eager cache keys, enabling cached compilation for operators such as `new_zeros`, `mean.dim`, and `count_nonzero.dim_IntList` (#187360) - Support lazy autotuning when compiling with the AOTInductor dual-wrapper, so Triton autotuning is deferred to a first JIT pass rather than being done during ahead-of-time compilation (#184735) - Support `torch.cond` and `torch.while_loop` when compiling with the AOTInductor dual-wrapper (#184736) - Add an `AOTI_LOG_LOADING` environment variable. When it is set, AOTInductor prints timing and diagnostic messages for each stage of constant loading, prefixed with `[AOTI_LOAD]`, without requiring a rebuild (#186309) - Check the error codes returned by the generated `scatter`, `index_put`, `clone`, and tensor-handle shim calls, so a failure inside one of these fallbacks raises an error instead of being silently ignored (#190909, #190910) ## Export - Support serializing nested integer and floating-point list arguments, including empty nested lists, for custom operators in exported programs (#189424) - Support `ObjectSpec`, `SeqSpec`, and `DictSpec` container types when using shape specifications with strict export (#186167) ## Composability - Add `torch.linalg.vector_norm` to the core ATen decomposition table used by `ExportedProgram.run_decompositions()`, including correct `dim=()` handling (#185735) - Allow out-of-tree backends to define additional `out_dtype` combinations for `torch.mm`, `torch.bmm`, and `torch.baddbmm` under fake/meta tracing; CUDA and XPU restrictions remain unchanged (#187096) - Provide a targeted dynamic-shape error when a data-dependent expression conflicts with a `dynamic_spec` constraint (#187143) ## Foreach - Use the nvmath `_foreach_mm` path only when the loaded cuBLASLt version supports grouped GEMM (#189757) ## ONNX - Preserve constants introduced during export decompositions so `ExportedProgram` remains valid when ONNX symbolic operations are inserted during retracing (#185090) ## C++ Frontend - Enable stable-ABI error-message retrieval dynamically when the required runtime shim is available (#183823) - Treat `-Wdeprecated-declarations` diagnostics as warnings rather than errors in `c10`, ATen, and LibTorch builds (#189948) - Reject negative CUDA storage-resize requests instead of wrapping them to huge `size_t` allocation requests (#190652) ## Release Engineering - Enable ROCm 7.14 nightly manywheel builds through TheRock wheels (#190276) and add `libatomic` to the manywheel builder image (#192254) - Update the bundled Triton to 3.8.0 (#188251, #190349) - Add full CUDA 13.2 CI coverage for stable-version configurations (#190641), Inductor, H100, B200, and `DTensor` (#190948), plus B200 smoke tests (#191705) - Upgrade the XPU support package to 2026.1 (#189593) - Update OpenBLAS to v0.3.34 (#190314) - Update the Arm Compute Library (ACL) version used by aarch64 builds (#191316) - Relax the `nvidia-nvjitlink-cu12` runtime dependency of CUDA 12 wheels so it no longer forces an exact version (#186958) ## CUDA - Add CUDA compute capability 10.7 (`sm_107`) awareness for NVIDIA Rubin GPUs with CUDA 13.4 or newer in extension builds and Inductor code generation (#190654) - Update CUDA compatibility checks for Jetson devices using SBSA binaries with CUDA 13.2 or newer (#186285) - Move green contexts to cuda-python bindings (#185527) - Unify the `CUDAGraph` debug flag, move `debug_dump` to Python, and add capture hooks (#187749) - Trim the `cudaMallocAsync` pool and retry once before raising an out-of-memory error (#188110) - Improve CUDA errors by including excerpts from CUDA logs (#191334) - Add `torch.float16` and `torch.bfloat16` support to `torch.angle` on CUDA (#191301) ## cuDNN - Upgrade the CUDA 12.8, 12.9, and 13.x wheels to cuDNN 9.24 and re-enable convolution engine 5 after its nondeterminism issue was fixed (#187091, #189483) ## CPU (x86) - Add `Half` support to the eager `torch.polar` kernel (#192311) - Allow `xeon/run_cpu.py` to accept multiple values for `--ncores-per-instance` (#169916) ## MPS - Support `return_aux(max_scores=True)` in MPS `flex_attention` forward (#188362) - Support `SymInt` captures in MPS `flex_attention` score and mask functions, including dynamically shaped compiled graphs (#188403) - Add MPS support for `torch.linalg.polar` (#189701) - Support MPS `torch.nonzero` on tensors containing more than `2**32` elements (#188816) - Add complex MPS support for Cholesky factorization (#191836) - Support key/value batch broadcasting and returning log-sum-exp values from MPS `flex_attention` (#187722, #187768) - Add MPS backward support for antialiased bilinear and bicubic 2D upsampling (#188819) - Add complex MPS support to `torch.nan_to_num` and correctly resize empty `out=` tensors (#189489) - Add MPS `torch.geqrf` support and align the MPS `torch.linalg.qr` implementation with other backends (#189192) ## ROCm - Add `torch.utils.hipify` mappings for the `cublasMath_t` type, its enum values, and `CUBLAS_COMPUTE_16F`, so HIP-ported extensions that call `cublasGemmEx` with `CUBLAS_COMPUTE_16F` or set a cuBLAS math mode hipify cleanly without per-project aliases (#187752) - Migrate from `rocm_smi` to `amd_smi` (#190014) - Preload TheRock ROCm dependencies so wheels are self-contained (#188454) - Enable Inductor lowering for FMA on ROCm (#187165) ## XPU - Add device-wide synchronization support on XPU (#191900) - Add IPC memory handle sharing support to `XPUCachingAllocator` on XPU (#188789) - Support head dimensions 32 and 256 for XPU FlashAttention (#180646) - Enable TF32 `fpmath` mode for XPU deconvolution, matching the existing convolution behavior (#185606) - Fix XPU graph-capture hangs by deferring memory-pool block handling until capture ends (#187931) - Refine `clock_rate` and `power_draw` device property queries through `pyzes` 0.1.2 (#188248, #188256) - Add experimental C++ XPU device properties for Xe topology, including `xe_stack_count`, `xe_regions_per_stack`, `xe_clusters_per_region`, and `xe_cores_per_cluster` (#191477) - Support BMG-G31 architecture compilation for the SYCL-TLA CUTLASS backend on XPU (#187040) - Enable the XPU scope profiler to gather hardware metrics through the Kineto plugin (#165766) - Make Inductor use XPU's device-specific TF32 setting so compiled matrix multiplication matches eager behavior (#187948) - Enable SYCL native fast-math approximations for `exp`, `log`, `log1p`, and `tan` on XPU (#176262) ## Sparse Frontend - Add CUDA `float16` and `bfloat16` support to `torch.sparse.sampled_addmm`, including supported sparse-CSR backward paths (#187681) - Add sparse COO dispatch for `torch.linalg.vector_norm`, allowing it to replace deprecated `torch.norm` calls on sparse COO tensors (#185309) ## torch.func - Allow `torch.vmap` to handle the scalar overload of `torch.searchsorted` (#188974) - Expand `torch.vmap` coverage for copy-view operations by routing them through existing batching rules (#187256) - Add a batching rule for `torch.repeat_interleave` when `repeats` is batched; callers must provide a common `output_size` because per-example output lengths are data-dependent (#187702) - Add a native batching rule for in-place `Tensor.masked_fill_()`, avoiding the slow fallback and its performance warning under `torch.vmap` (#175513) - Expand scalar fill and comparison support under `torch.vmap`, including accelerator placement for scalar operands (#189176) # Bug Fixes ## Python Frontend - Fix `torch.arange` computing the wrong length for fractional arguments with an integer output dtype because it truncates those arguments too early (#185812) - Raise a clear unsupported-operation error for dense tensor factories targeting `device="mkldnn"` instead of triggering an internal assertion (#185711) ## Dataloader Frontend - Release CUDA IPC-backed dataset storage when `DataLoader` workers exit, preventing producer-side IPC references and allocations from being retained indefinitely (#190485) ## torch.nn - Enable eligible fused scaled dot-product attention backends for dense rank-3 inputs on CPU, CUDA/ROCm, and XPU instead of always falling back to the math implementation (#192271) Rank-3 inputs are normalized to rank 4 with a singleton batch dimension before backend selection. This fixes fused execution for rank-3 and vmapped inputs, but automatic backend selection can change floating-point numerics, dropout RNG consumption, whether the result is a view, and higher-order-gradient support. Fused CUDA backends do not support the second derivatives provided by the math backend; code that depends on those semantics should explicitly select the math backend. ```python from torch.nn.attention import SDPBackend, sdpa_kernel with sdpa_kernel(backends=[SDPBackend.MATH]): output = torch.nn.functional.scaled_dot_product_attention( query, key, value ) ``` - Reject `norm_type=0` in functional and module Lp pooling APIs with a descriptive `ValueError` instead of a deferred `ZeroDivisionError` (#187861) - Fix failures in memory-efficient scaled dot-product attention backward after `torch.autograd.graph.save_on_cpu()` changes an attention mask's aligned strides (#188246) - Fix a CUDA illegal memory access in memory-efficient scaled dot-product attention backward when only the floating-point attention mask requires gradients (#188302) - Make the cuDNN CTC loss backend correctly zero infinite losses and their gradients when `zero_infinity=True` (#176911) - Validate each output dimension for `replication_pad2d` and `replication_pad3d` so excessive negative padding raises a clear error instead of attempting to create a negative-sized tensor (#184254) - Fix silently incorrect CUDA gradients from channels-last `avg_pool2d` when padding is nonzero (#188345) - Make CPU eager and decomposed `torch.nn.functional.softshrink` cast scalar `lambd` values consistently for reduced-precision inputs (#186358) - Prevent CUDA `avg_pool3d` backward from corrupting gradients when an overlapping-window input contains more than `2**31` elements (#188229) - Reject non-positive `kernel_size` values in raw `fractional_max_pool2d` and `fractional_max_pool3d` operations instead of returning `-inf` outputs with invalid indices (#190480) - Support 64-bit indexing for channels-last CUDA bilinear upsampling so outputs with at least `2**31` elements no longer fail with `CUDA error: invalid configuration argument` (#185788) - Fall back to the ATen CUDA implementation when the fused RMSNorm override's normalized dimension exceeds the device's shared-memory capacity, avoiding compiler hangs or crashes (#186941) - Reject invalid `dim` types when constructing `torch.nn.Softmax` or `torch.nn.LogSoftmax` instead of failing later during the forward pass with a confusing overload error (#185055) - Handle misaligned input and weight storage in the fused RMSNorm override instead of raising `Misaligned Tensor data on argument #0` (#186235) - Make CUDA `float16` softmax with `dtype=torch.float32` use the same persistent-kernel range as the `float16` output path, fixing rounding inconsistencies for dimensions between 1025 and 2048 (#188247) ## Optimizer - Fix skipped updates and incorrect `float16`/`bfloat16` casts in fused CPU `torch.optim.SGD` and `torch.optim.Adagrad` (#192545) ## Autograd - Reject unsupported third-order derivatives for training-mode batch normalization instead of silently returning an invalid result; second-order derivatives and evaluation mode are unchanged (#186779) - Fix `torch.pow` backward when the base is a Boolean scalar by promoting the scalar before computing its logarithm, avoiding an internal assertion failure (#182564) - Fix `torch.pow` backward under `torch.compile(dynamic=True)` when a Python integer exponent becomes symbolic, avoiding the `NYI SymInt equality` crash without specializing on the exponent (#185851) - Make `native_group_norm` and `native_group_norm_backward` safely handle non-contiguous tensors, fixing `vmap` failures and possible out-of-bounds memory accesses (#186414) - Fix the `torch.ldexp` gradient for negative integer exponents so it returns `2.0 ** exponent` instead of zero (#186566) - Fix `DeviceContext` mode leaks during checkpoint recomputation and default-device restoration (#189286) - Fix end-of-backward leaf-stream synchronization across CUDA graph capture boundaries, avoiding opaque `cudaErrorStreamCaptureIsolation` failures and providing an actionable error when the crossing cannot be safely skipped (#189591) - Fix precision errors in the CUDA `native_group_norm_backward` kernel and its decomposition by applying the missing upcasts (#190245) - Stop `register_full_backward_pre_hook`-only modules from emitting a warning intended for `register_full_backward_hook` when their forward inputs do not require gradients (#190685) - Fix max-pooling double backward under `vmap` for channels-last inputs, which previously raised `NYI: querying is_contiguous inside of vmap` (#191678) - Preserve dynamic type names and argument indices in custom `torch.autograd.Function` validation error messages (#191748) - Improve `log2` and `log10` backward accuracy by using named mathematical constants, including a correctly rounded double-precision `log(10)` constant (#192613) ## Distributed - Fix construction of Python `ProcessGroup` subclasses through the `(store, rank, size)` constructor and ensure their virtual overrides are dispatched correctly (#186853) - Select registered custom communication backends instead of incorrectly falling back to NCCL or Gloo when the backend is unspecified (#179901) - Fix compiled DTensor backward paths producing data-dependent guards for valid symbolic local layouts (#187026) - Preserve local Philox seed and offset outputs when expanding DTensor scaled dot-product attention strategies across multidimensional meshes (#187199) - Respect nonzero `root` arguments in `torch.cuda.nccl.broadcast` instead of always broadcasting from the first tensor (#187216) - Fix ring-attention backward using mismatched maximum sequence lengths when context-parallel load balancing is enabled (#185493) - Fix DTensor backward strategies emitting placements for outputs disabled by `output_mask` (#187383) - Preserve the configured FSDP2 gradient-reduction dtype when parameters are frozen during the first forward and later unfrozen (#187376) - Make `torch.distributed.set_timeout()` a no-op for fake process groups and warn rather than fail for backends that cannot configure timeouts (#187693) - Prevent `LocalDeviceMesh` from returning stale coordinates after a temporary submesh is destroyed and its object ID is reused (#187052) - Fix asynchronous coalesced collectives failing CUDA graph capture under `torch.compile(mode="reduce-overhead")` because tensors were retained by the wrong work object (#187433) - Implement `barrier()` for the NCCL symmetric-memory backend instead of raising a not-implemented error (#188051) - Flush distributed-checkpoint streams before `fsync()` so buffered writes are persisted correctly on remote filesystems such as GCS (#183877) - Fix repeated `hipMemMap` calls causing symmetric-memory failures on ROCm (#188673) - Fix custom backend registration with a string `devices` argument incorrectly registering each character as a device type (#187960) - Fix FSDP `summon_full_params(offload_to_cpu=True)` accessing freed storage when the flattened parameter is already on CPU (#188990) - Include the local device in compiled DTensor cache keys so ranks cannot reuse kernels compiled for another device (#188401) - Prevent stale symmetric-memory signal data when virtual addresses are reused by placing and clearing the signal pad at the front of each allocation (#189088) - Fix collective validation, sequence tracking, complex tensors, barriers, and work cleanup in the experimental `nccl2` backend (#190138) - Preserve container object identity when FSDP recursively moves values but their elements do not change (#171617) - Make compile-on-one-rank graphs resolve process groups from their device mesh at runtime instead of serializing rank-specific process-group objects (#188215) - Fix `torch.distributed.nn.functional.broadcast` producing a zero source gradient for subgroups whose local and global source ranks differ (#190583) - Create TorchComms subgroups on the calling rank's actual device, including under launchers that do not set TorchComms rank variables (#189072) - Fix work-object and expandable-segment allocator lifetimes in the experimental `nccl2` backend (#190370) - Return `GroupMember.NON_GROUP_MEMBER` consistently from locally synchronized `new_group` calls on nonmember ranks (#190588) - Support the linear `avg` reduction in functional `all_reduce` backward instead of rejecting it after a successful forward pass (#190224) - Prevent subgroup creation hangs and duplicate-finalization crashes by making subgroup-name salts rank-consistent and finalizing each communicator once (#189073, #189074) - Fix single-operation point-to-point completion ordering and synchronous barrier semantics in the experimental `nccl2` backend (#190622, #190682) - Allow NCCL symmetric memory to use communicators created by the experimental `nccl2` backend (#191109) - Normalize `new_group` ranks through Python's integer protocol so tensor integer ranks work and non-integral values fail clearly (#191377) - Fix simulated `all_to_all_single` with uneven split sizes in `LocalTensorMode` and raise a clear error for inconsistent splits (#190311) - Accept device-qualified Gloo backends in `monitored_barrier` when TorchComms is enabled (#189070) - Prevent `CommDebugMode` hooks from leaking or double-running when a module executes more than once (#191452) - Warn when symmetric-memory collectives are launched concurrently on multiple streams, which can otherwise deadlock (#191482) - Choose a process group's default backend only from backend types that were actually registered (#189193) - Report the correct group-local rank and process-group identifier in NCCL work timeout and error logs (#191440) - Preserve the caller's current CUDA device in the experimental `nccl2` backend and validate full device identities (#191510) - Validate all-to-all split sizes consistently across Gloo, NCCL, and `nccl2` (#191511) - Prevent destroying one TorchComms subgroup from inadvertently destroying every live group (#191637) - Propagate `device_id` through `ProcessGroupWrapper` so debug wrappers do not hang with heterogeneous rank-to-GPU mappings (#182273) - Forward group identifiers through `nccl-lazy` so NCCL symmetric-memory rendezvous can find the primary communicator (#191544) - Reject unsupported reconfigurable mode for `nccl-lazy` instead of advertising incomplete membership-change support (#191549) - Disable NCCL NVLS in `nccl2` when deterministic algorithms are enabled, matching the legacy NCCL backend (#192104) - Prevent `nccl2` watchdog errors, timeouts, explicit aborts, and normal teardown from unconditionally terminating the process (#192105) - Fix Gloo and NCCL `split_group` crashes when the world process group was not the first backend instance created in the process (#192106, #192109) - Fix device-bound `nccl2` process-group initialization failing before the CUDA caching allocator has been initialized (#192107) - Give split and merged process groups independent backend options so child creation cannot corrupt parent metadata or share mutable options (#192110) - Fix `split_group(backend=...)` filtering for parent groups created with a bare backend name (#192111) - Prevent private `TCPStore` rendezvous under `torchrun` from hanging by using the agent store only for the agent's own address (#192113) - Fix `bfloat16` NCCL `PREMUL_SUM` factors being interpreted as zero and silently producing zero gradients (#190747) - Fix a use-after-free race while concurrently dumping Flight Recorder entries (#192232) - Run symmetric-memory allocation and rendezvous device work on the caller's current CUDA stream (#192308) - Recognize libuv's lowercase `address already in use` message when TorchElastic retries `TCPStore` creation (#191561) - Add missing collective-fingerprint checks for `allgather_into_tensor_coalesced` under `ProcessGroupWrapper` (#185123) - Fix DTensor AOT compilation misclassifying overload names containing `out` as output-variant operators (#187466) - Fix compiled functional point-to-point collectives that pass global peer ranks to subgroup operations requiring group-local ranks (#187924) - Preserve pipeline-stage module buffers while dynamic metadata inference runs representative forward and backward passes (#188558) - Fix DTensor backward support for `cumprod`, `cummax`, and `cummin` (#185228) - Make pipeline schedules select static metadata locally when a fake process group cannot perform cross-rank metadata inference, and report incomplete stage metadata clearly (#191538) - Restore the caller's cyclic garbage collector state after Flight Recorder `read_dir()` calls, including when loading fails (#191607) ## Distributed (c10d) - Fix `destroy_process_group()` hanging after collectives run on partially split process groups by keeping group names consistent across ranks (#190431) ## DTensor - Fix compiled functions failing when they return DTensor permutation views such as `transpose`, `permute`, or `movedim` (#191784) - Fix deferred `local_map` export failing inside nested compile regions (#186647) ## Linear Algebra Frontend - Fix `torch.linalg.cond()` reporting a misleading overflow error for a complex norm order; invalid orders now raise `ValueError` with a clear message (#188591) - Fix `torch.lu_unpack` segfaulting when `LU_pivots` has a shape inconsistent with `LU_data`; invalid shapes now raise a clear error (#187660) - Fix `torch.linalg.lstsq(driver="gelsy")` returning an incorrect rank on CPU when stale pivot values leaked between batched LAPACK calls (#187436) - Fix `torch.compile(dynamic=True)` failing on `torch.linalg.cond` with `p="fro"` or `p="nuc"` because symbolic tensor sizes were queried as concrete values (#187614) - Fix offline `TunableOp` tuning silently using the wrong GEMM shape when a padded leading dimension matches another matrix dimension (#189355) - Fix `CUBLAS_STATUS_NOT_SUPPORTED` failures in matrix multiplication on CUDA compute capability 11.0 by increasing the default cuBLAS workspace to 32 MiB (#189312) ## Indexing - Reject nonempty `torch.unravel_index()` inputs whose `shape` contains a zero-sized dimension with a clear `ValueError` instead of an uncaught division-by-zero `RuntimeError`; empty indices remain supported (#191092) - Fix assigning Python integers greater than `INT64_MAX` into `torch.uint64` tensors, which previously raised `Overflow when unpacking long long` (#191604) - Fix an illegal CUDA memory access in `torch.nn.functional.adaptive_avg_pool2d` backward for very large contiguous tensors whose element offsets exceed 32-bit indexing limits (#189082) ## Profiler - Exclude individual Python function events from `key_averages()` by default so frames such as `threading.py: wait` do not obscure operator-level hotspots; pass `include_python_functions=True` to retain the previous view (#188631) - Clamp incomplete Python function events to their parent event's end time so exported traces retain correct nesting instead of placing overrunning events on unrelated tracks (#190950) - Avoid importing the experimental CUPTI monitor during ordinary `record_function` profiling, preventing repeated warnings and tracebacks on systems with incompatible `cupti-python` versions (#187874) - Fix reference leaks when reading the `layout` and `dtype` properties of profiler tensor metadata (#187068) ## FX - Respect deferred runtime-assert bounds when deriving optimization hints for unbacked symbolic sizes, preventing negative storage sizes and downstream CUDA indexing failures (#190589) - Make selected Dynamo, Inductor, and FX tracing state thread-local to prevent race conditions when `torch.compile` is invoked concurrently from multiple threads (#168999) - Fix FX `GraphModule` serialization when generated code contains string type annotations (#185051) - Fix scripting FX-generated modules with nested `Optional[Dict[...]]` annotations on Python 3.14 (#190580) - Skip constant folding for `get_attr` nodes whose targets cannot be resolved or refer to modules (#191939) - Preserve non-persistent buffer registration when an FX `GraphModule` copies attributes, keeping those buffers out of `state_dict()` (#191708) - Fix Z3 translation validation for graphs containing symbolic boolean negation through `torch.sym_not` (#185147) - Fix FX-generated code raising `NameError` for complex constants whose imaginary component is `nan` or `inf` (#188596) - Preserve signed zero when FX code generation emits complex constants with a zero real or imaginary component (#185550) - Apply `skip_folding_node_fn` recursively to `call_module` subgraphs so FX constant folding does not evaluate skipped or symbolic nodes inside them (#189487) - Return valid `tuple[...]` annotations from `get_signature_for_torch_op` for operators that return multiple tensors (#189142) - Avoid a `linecache` loader warning when executing generated FX `GraphModule` code on Python 3.15 (#187221) ## Dynamo - Match CPython errors for invalid `next`, `set`, and `frozenset` calls (#190624, #189051) - Fix `torch.compiler.nested_compile_region` graph reuse, eager autograd, graph capture, and transposed captured buffers (#192006, #184700, #186137, #191785) - Fix nested graph breaks involving generators, hooks, context managers, custom operators, comprehensions, f-strings, and `DeviceMesh` submeshes (#188622, #191388, #187088, #191264, #191523, #189601, #187005, #187701, #188861) - Fix `eager_then_compile` for higher-rank inputs (#184689) - Fix precompile caches, package globals, and guard serialization for tensor subclasses, `torch.func`, and autocast (#191128, #191418, #190576, #191428, #184850, #187736, #184562) - Fix tensor-subclass metadata guards, fake-mode re-entry, metadata replay, and stale metadata after in-place mutation (#184684, #176977, #185732, #187057, #187890) - Fix compiled class definitions, scalar-tensor indexing, non-module globals, and conditional hook handles (#185998, #184625, #184653, #184712) - Graph-break on forward-AD dual tensors instead of silently dropping tangents; `fullgraph=True` now errors (#189644) - Preserve `ctx.needs_input_grad`, autocast state, overlapping-view storage, `vmap` gradients, and captured FlexAttention gradients (#191492, #186530, #187111, #186362, #188869) - Fix compiled-method attribute reads, `TorchDispatchMode` skip state, symbolic lazy modules, and stale tracing weak references (#190185, #190287, #188595, #190951) - Preserve dynamic f-string formatting and Python-side mutation order across graph breaks (#189830, #182638) - Match Python semantics for `vars`, pybind enums, pytree equality, call errors, numeric conversion, descriptors, custom `isinstance`, deque reinitialization, sequence/set operators, subclass types, slice errors, and attribute probing (#185128, #188605, #190649, #190797, #190257, #190776, #186491, #188171, #189554, #189274, #189145, #187777, #190970) - Fix Python 3.12 exception tables and free-threaded/Python 3.15 list-comprehension bytecode (#185731, #187086, #187103) - Fix TorchScript backends, CUDA repro probing, and backend device/dtype classification while preserving third-party minifier configuration (#188875, #185843, #190425, #190426, #187855) - Fix self-referential backward-compiler state when AOTAutograd compiles a second graph (#189325) ## Inductor - Fix handling of `torch.combinations`, indexed `randperm`, dynamic-output custom ops, tensor-subclass standalone compilation, `torch.cond` constants, duplicate kernel registrations, generic `associative_scan`, dynamic combo reductions, empty scatters, autograd `expand`, tuple graph outputs, aliased FX outputs, and fused positional arguments (#189305, #184066, #185601, #185638, #185838, #186262, #186633, #187275, #188466, #188758, #189887, #190255, #190976) - Match eager arithmetic, validation, dtype, NaN/infinity, signed-zero, and overflow semantics across `addmm`, remainder, min/max, low-precision scalar math, unsigned `abs`, CELU, Bessel functions, multiply-by-zero folding, `signbit`, floor division, `cummax`/`cummin`, `cumsum`, adaptive pooling, index propagation, and CPU integer arithmetic (#183511, #185168, #185970, #186818, #186933, #187024, #187321, #187354, #187580, #187941, #188049, #188361, #188556, #188862, #190328, #190427, #190531, #190566, #191132) - Fix wrong or unstable results in CPU outer-loop and Halide fusion, nested/split/TMA reductions, MPS special functions, scheduler-recomputed gradients, CPU `expm1`, small transposed GEMMs, and noncontiguous `uniform_` (#185855, #186121, #188771, #189291, #189896, #185873, #190533, #191127, #191709, #192344) - Fix CPU code generation for vectorized atomics and boolean `index_put_`, including an out-of-bounds atomic that could produce wrong results; fix max-autotune failures with reused GEMM inputs or outputs and zero-hinted symbolic rows (#185325, #185767, #186523, #191502, #191861, #192553) - Fix `_scaled_mm` scale-shape compilation; fall back safely for `_scaled_mm_v2` with swizzled MXFP8/NVFP4 scales; and fix complex signatures, `float8` storage, dtype bitcasts, and CUTLASS INT8 target filtering (#183964, #185501, #186384, #188209, #189561, #189584, #192414) - Fix convolution and attention pattern selection or fallback correctness for dynamic bias, transposed or dilated convolution, CUDA convolution backward, `ConvTranspose2d`, and unsupported 3D SDPA key permutations (#184132, #186067, #187372, #189660, #191260) - Fix dynamic-shape and symbolic-expression failures in split ranges, adaptive pooling, AOTI autotuning, regional wrappers, TMA `addmm`, `torch.cond`, fused epilogues, stride guards, tiling, and FX wrappers (#184566, #185369, #185778, #185890, #187371, #189529, #189890, #190965, #191605, #191811) - Prevent index-expression overflow, unsound loop-index inversion, and negative modular-term miscompilations (#186060, #189108, #190401, #190966) - Fix FlexAttention errors and wrong results involving large or sliced buffers, invalid `score_mod`, kernel options, sparse masks, and mixed or 64-bit captured indices (#185264, #185991, #186876, #187886, #187904, #188484, #188876) - Fix ordering and races in multi-stream event/control-dependency graphs, aligned input copies, bidirectional synchronization, replacement-created intermediates, captured events, and cross-warp reductions; honor `torch.use_deterministic_algorithms()` for compiled scans (#183803, #183804, #186022, #186023, #186025, #187224, #188533, #189095, #189096, #190519, #191714) - Fix premature reuse, leaks, and races in memory planning, cached launchers, failed autotuning, dynamic reduction caching, mutation dependencies, fallback storage reuse, and saved compiler-cache loading (#187678, #188607, #188907, #189124, #189288, #189735, #192526) - Reject incompatible custom-Triton epilogue fusion, fall back when descriptor alignment or template tiling is unsupported, and serialize custom-kernel `Enum` metadata correctly (#184248, #186922, #186932, #187209, #189494) - Fix CUTLASS and NVGEMM compilation, worker initialization, XPU wrapper selection, reshaped epilogues, newer CuTeDSL compatibility, target filtering, cache reentrancy, and CUDA Graph outputs (#186385, #186791, #187404, #188865, #189775, #189780, #189781) - Gate TF32 warnings, use an NVML clock-rate fallback, report CUDA Graph skip reasons, fix CUDA Graph capture for `torch.linalg.eigh`, and suppress internal `TypedStorage` warnings (#185541, #187427, #188384, #188641, #191383) - Fix imports, compiler probes, workers, template decoding, and generated builds across vendored `typing_extensions`, localized MSVC output, initialized CUDA, Windows path limits, Python 3.11/3.12, UTF-8 templates, dead workers, and library paths containing spaces (#185708, #185972, #187408, #187641, #187700, #189196, #189290, #191010) - Fix AOTInductor floor division by captured tensor constants, CUDA architecture packaging, and constant-graph code generation with lazy autotuning (#186242, #187888, #190073) - Fix duplicate MPS Metal kernel names and XPU compiled RNG or quantized tensor-subclass handling (#187894, #189310, #189509) - Fix manual collective-bucketing graph order and register DTensor shard-all-to-all autograd while adding an opt-in functional decomposition (#187341, #188137) - Restrict ROCm Origami GEMM selection to static shapes to avoid dynamic-shape `NoValidChoicesError` (#190024) ## Ahead-Of-Time Inductor (AOTI) - Fix compilation and dispatch failures for C++ wrapper fallback operators with `Any` arguments, including distributed operators such as `all_gather_into_tensor` (#188124) - Route custom operators with `SymInt`, `SymBool`, or `SymFloat` arguments through boxed C++ wrapper dispatch, avoiding runtime `API call failed` errors (#188154) - Box `None` passed to non-optional tensor arguments as an undefined tensor in C++ wrappers, matching eager custom-operator behavior (#188485) - Prevent C++ wrappers from dereferencing a null tensor handle when a Python fallback operator returns a one-element `Tensor[]` (#190551) - Emit portable `std::array::data()` pointers in generated CPU wrappers instead of relying on iterator-to-pointer conversion (#191240) - Package AOTInductor CUDA multi-architecture kernels for the requested deployment architecture instead of the physical compilation GPU (#185328) - Fix AOTInductor C++ wrappers recovering integer symbols from composed dynamic sizes through floating-point division, which could truncate valid runtime dimensions (#185841) - Fail fast with a clear error when loading a CUDA AOTInductor package in a process without CUDA or ROCm available (#186943) - Fix C++ wrapper fallback output indexing for mutable custom operators and remove invalid 16-byte alignment assumptions for misaligned tensor views (#187331) - Preserve C++ wrapper input slots when graphs contain Python-only custom-class inputs (#188030) - Pass the device the model was actually loaded on to custom operator fallbacks, instead of the device recorded when the model was compiled. Previously a model compiled for one GPU and then loaded on another would hand the wrong device to its custom ops (#184741) - Synchronize the default stream after copying model constants on AMD GPUs, fixing a race in which inference could read constants before the copy had completed (#186963) - Fix a 32-bit integer overflow when computing the SYCL global launch range in the AOTInductor runtime, which produced incorrect launch dimensions for large grids on XPU (#187307) - Release AOTInductor input tensor handles when runtime input validation fails, preventing a GPU memory leak (#189503) - Release untransferred AOTInductor constants when runtime constant folding fails, preventing a memory leak on the error path (#189505) - Prevent an AOTInductor constant-folding segmentation fault on XPU when no stream is provided (#189517) - Make the C++ wrapper's debug synchronization device-aware, fixing a regression on ROCm (#190071) - Fix a missing CUDA header in the generated constant graph when compiling with the dual-wrapper, which made the generated code fail to compile (#191050) - Skip CUDA stream event code generation in the AOTInductor C++ wrapper on XPU, where those APIs do not apply (#190637) ## Export - Fix `torch.export` dynamic-shape specifications for functions with `**kwargs`, accepting both call-like keys and specs nested under the variadic parameter while reporting ambiguous name collisions as `UserError` (#185730) - Prevent `ExportedProgram.module()` from raising `RecursionError` while generating guard messages for deeply nested symbolic-shape expressions (#186993) - Fix `torch.export.unflatten` failing to restore parameters, buffers, and constants for non-contiguously numbered repeated module calls (#188185) - Fix strict export of parameters from modules stored in unregistered Python containers by treating the traced-only parameters as constants instead of attempting to restore them from the eager module's state (#185728) - Fix non-strict export of tensor indexing under `vmap` when the index is a batched scalar tensor (#186894) ## AOTDispatcher - Resolve nested `AsyncCollectiveTensor` inputs before AOTAutograd tracing so compiled forward execution waits for in-flight data and backward metadata expects the correct local-tensor cotangents (#186442) - Prevent activation-memory-budget partitioning from crashing with `expected all tensors_saved_with_vc_check to be Tensors, got [Tensor, tuple]` when a required multi-output node is marked `MUST_SAVE` (#188014) - Prevent AOTAutograd common-subexpression elimination from merging forward-only values with nodes required by backward, preserving correct partitioning and reduction fusion (#184044) - Fix backward graphs missing symbolic-integer bindings by preserving both raw symbols and their ShapeEnv replacement targets, preventing unbound guard expressions and `FxGraphCache` lookup failures (#185473, #189783) - Fix incorrect alias-output slicing when Inductor clones a misaligned input (#191002) - Move `invoke_subgraph` inference-mode input mutations to the AOT epilogue so they are applied correctly (#191672) - Fix `control_deps` handling in the partitioner during forward/backward extraction (#187695) - Support mutable (`Tensor!`) custom ops in input-mutating `invoke_subgraph` regions by routing them through Python functionalization (#189543) - Fix common subexpression elimination (CSE) to correctly deduplicate NaN constant tensors by normalizing float/complex hashing and comparison (#191173) ## Composability - Raise `NotImplementedError` for unsupported Boolean operations and distinguish unsupported FFT dtypes from invalid real/complex domains with `NotImplementedError` and `TypeError` (#192348, #192349) - Preserve eager identity semantics for no-op dropout decompositions, preventing `torch.compile` and `torch.export` from replacing a `Parameter` with a cloned fake tensor when dropout is disabled (#185335) - Fix compiled `torch.nn.functional.multilabel_margin_loss` values and gradients when targets use `-1` padding (#189552) - Fix `torch.nansum` meta output shapes when `dim=()` should reduce all dimensions (#191530) - Make the `constant_pad_nd` reference decomposition fully functional so `torch.onnx.export(dynamo=True)` no longer fails functionalization for models using `torch.nn.functional.pad` (#185636) - Keep `torch.istft` length clamping and padding symbolic under dynamic shapes, avoiding recompilation and data-dependent guard failures when the requested length crosses the signal length (#186490) - Make compiled and fake/meta `torch.aminmax(..., out=...)` enforce the same exact output-dtype requirements as eager execution (#186227) - Make compiled `torch.nn.functional.celu` reject `alpha=0` with the same error as eager execution (#179375) - Avoid data-dependent guard failures in fake/meta tracing of native multi-head attention with unbacked symbolic sizes (#187144) - Avoid data-dependent guards in `torch.nn.utils.rnn.pad_sequence` decompositions when sequence lengths are symbolic (#187145) - Make the CUDA `native_layer_norm` decomposition reject mixed affine-parameter dtypes in the same cases as eager execution (#185693) - Fix incorrect compiled output and gradients for overlapping-input `torch.diagonal_scatter` operations (#182292) - Match compiled `max_unpool2d` output strides and channels-last memory format to eager CPU execution (#186602, #187195) - Route meta `view` operations through the symbolic-shape-aware kernel, avoiding `SymIntArrayRef expected to contain only concrete integers` failures (#189447) - Avoid data-dependent guard failures in the transformer encoder layer meta kernel when the input size is an unbacked symbol (#187860) - Prevent fake/meta decompositions of in-place operations from silently resizing their destination when operands cannot broadcast to its shape; compiled execution now raises the same shape error as eager execution (#191373) - Preserve symbolic tensor, scalar, and unbacked-binding metadata across `ProxyTensor` and `make_fx` tracing (#187231) - Preserve loop-local value ranges and use known ranges when simplifying symbolic `Min` and `Max` expressions, avoiding `vr must not be None` and spurious data-dependent guard failures (#187350, #186248) - Fix symbolic proxy tracing and repeated lowering edge cases involving natural powers, `torch.cond` contiguous-stride expressions, and equivalent rebound unbacked symbols (#188278, #189525, #190083) - Fix silently incorrect second-order gradients from post-dispatch `make_fx` tracing by decomposing `detach` by default; callers that provide an explicit decomposition table retain the previous behavior (#186845) ## Quantization - Fix a divide-by-zero crash (`SIGFPE`) in `torch.quantize_per_channel` on the per-channel `float_qparams` path for the `qint32` dtype; whole-byte quantized types now pack correctly instead of underflowing the packing factor to zero (#186767) - Add the missing overflow check to the FBGEMM build of the ARM `quantize_val` path, fixing incorrect quantized values that showed up as quantization test failures on some hardware (#187481) - Fix a GPU memory access fault that aborted quantized `embedding_bag` byte and 4-bit rowwise lookups on ROCm, caused by a bitwise-AND typo in the bit-field extraction primitive (#192571) ## Foreach - Prevent out-of-bounds metadata writes in CUDA foreach operations with complex scalar lists by respecting their reduced per-launch tensor capacity (#189915) ## ONNX - Fix signed right-shift export in the TorchScript exporter so negative values round toward negative infinity as they do in PyTorch (#191226) - Fix quantized `gather` export by unpacking quantized tensor inputs before lowering (#188272) ## C++ Frontend - Fix a memory leak when converting `StableIValue` to `std::string` (#190493) - Remove `noexcept` from `TensorMaker::computeStorageSize()` (#188062) - Fix uninitialized return in Chebyshev polynomial helpers for NaN inputs (#187767) - Guard the `Scalar(long long)` constructor on NetBSD and other LP64 BSDs (#188941) - Replace `FileBaton` with `filelock` to prevent stale-lock deadlocks in `CppExtension` (#190543) - Fix floating-point-to-integer range checks at wide-integer boundaries in `c10/util/overflows.h` (#190651) ## Build Frontend - Fix source-build linker failures on systems where CMake reordered static and shared libraries by linking `libcpuinfo` through the `c10` shared library instead of linking it separately into both `c10` and `torch_cpu` (#167328) - Fix Windows ARM64 builds failing to register a CPU quantized backend by recognizing the uppercase `ARM64` CMake processor name and enabling oneDNN (#189346) ## Release Engineering - Fix invalid ZIP64 archives for ROCm wheels larger than 4 GB by repackaging them with `auditwheel` (#189903) - Prevent an intermittent deadlock during `import torch` with ROCm wheels by shipping a bare `.so` alias (#189114) - Fix missing CUDA dependencies when extracting LibTorch from a wheel, which previously left the extracted tree with unresolved RPATHs (#184336) ## CUDA - Fix CUDA graph kernel-annotation remapping across sequentially captured graphs and with `keep_graph=True` (#186638, #187741) - Fix a heap overflow in `CachingHostAllocator` when rounding is disabled (#192722) - Preserve signed zero in `relu` and `clamp` (#185354) - Fix `int32` overflow in `embedding_bag(mode="max")` backward (#188661) - Include CUDA graph memory pools in `memory_reserved()` (#186809) - Use 64-bit sample offsets in `NLLLoss2d` backward (#190144) - Fix remap extents, causal key bounds, and 32-bit dropout offsets in memory-efficient attention (#192138) ## cuDNN - Fix cuDNN variable-length SDPA (#172108) - Disable cuDNN convolution engines 58 and 63 on `sm120` to prevent illegal memory accesses (#190112) - Declare the attention-mask dtype to cuDNN instead of inheriting the graph I/O dtype (#191612) - Update the cuDNN errata filter for `sm120` (#191701) ## CPU (x86) - Fix incorrect results from CPU flash SDPA when the innermost dimension of the inputs is not contiguous (#187506) - Prevent the Laguerre and Legendre polynomial kernels from returning uninitialized memory (#188027) ## CPU (AArch64) - Fix an integer overflow in the `bfloat16`/`float16` GEMM staging-buffer size calculation, which could corrupt results or crash on large matrix multiplications (#191096) - Fix CPU `embedding_bag` using the wrong index count for `scale_grad_by_freq`, producing incorrect gradients (#190264) ## MPS - Fix compiled MPS operations such as `torch.eye(256)` failing with `KeyError` when Inductor generates unsigned 16-, 32-, or 64-bit index expressions (#192020) - Preserve the MPS dispatch key through `torch.func` transforms so MPS autocast and autograd work under transforms such as `vmap` and `grad` (#187282) - Reject complex MPS average-pooling inputs with `NotImplementedError` instead of an internal MPSGraph error (#187671) - Propagate NaNs correctly through MPS scaled dot-product attention kernels (#188147) - Raise a clear error when MPS batch normalization receives an unsupported dtype (#188265) - Fix corrupted MPS prefill-attention output on macOS 26 by selecting the correct Metal cooperative-tensor ABI (#191794) - Fix Metal argument alignment that could make MPS kernels fail validation or crash under the Metal debug layer (#191640) - Fix `torch.hypot` producing incorrect results for extreme values (#192541) - Handle empty indices in MPS `index_add` and empty dimensions in threshold, `baddbmm`, and `addbmm` operations (#186990, #187719, #188808, #187879) - Fix `mm` and `addmm` with strided output tensors on macOS 14 and 15 (#187255) - Respect `storage_offset` when an MPS binary operation consumes a zero-dimensional CPU tensor view (#187229) - Make MPS `baddbmm` follow its documented behavior by not propagating NaN or infinity from the input when `beta=0` (#187522) - Fix MPS linear backward for inputs with more than four dimensions and prevent complex high-rank linear operations from aborting on macOS 27 (#187379, #190352) - Prevent `BatchNorm` backward from crashing for channels-last MPS tensors (#188371) - Fix incorrect MPS Conv2d output when a kernel spatial dimension is at least 256 (#188359) - Match CPU and CUDA nonfinite-value semantics for MPS `torch.div(..., rounding_mode="floor")` (#189252) - Make MPS-backed pinned memory correctly appear as a CPU tensor while retaining its shared Metal buffer (#181720) - Prevent dtype-converting MPS-to-CPU copies from overwriting their source and correctly copy non-dense views with matching strides (#189572, #189966) - Compute integer absolute values exactly instead of rounding through `float32` (#190053) - Handle zero `in_features` in MPS linear forward and backward without aborting (#190051) - Fix `torch.nextafter` returning its input unchanged for MPS `bfloat16` tensors (#190481) - Preserve exact integer values in MPS `torch.linspace` for large ranges (#189630) - Fix `int64` minimum and maximum reductions returning zero when a partial SIMD group contains only negative or positive values (#191104) - Fix adaptive max pooling for input sizes that are not divisible by the output size (#189659) - Fix large matrix multiplications producing incorrect results on M1 and M2 GPUs (#183535) - Keep MPS exponential samples strictly positive so `torch.multinomial(..., 1)` cannot select a zero-probability entry (#192621) - Make CPU and MPS `torch.logit` agree with other backends when `eps > 0.5` (#181297) - Fix MPS FFT operations when a transformed dimension is not among the tensor's final four dimensions (#186967) - Fix `torch.nn.functional.linear` dropping its bias for vector-shaped inputs on macOS 26 (#188619) - Raise clear unsupported-dtype errors for complex MPS inputs to `cummax`, `cummin`, and `logaddexp2` (#188038, #188800) - Fix MPS ternary-kernel dispatch for large tensors and mixed-dtype `out=` tensors, including `torch.clamp` (#189624) - Apply inter-layer dropout correctly in MPS LSTM backward and avoid NaNs when `dropout=1` (#190059) - Improve MPS layer-normalization correctness for small-variance rows and add 64-bit indexing support (#190492) - Fix biased MPS linear operations corrupting rows when a batch dimension exceeds 2^16 (#189496) - Validate MPS `EmbeddingBag` offsets consistently with CPU and CUDA instead of silently returning incorrect results (#187572) - Support `float32` affine parameters with `float16` or `bfloat16` MPS layer normalization in forward and backward (#190055) - Match CPU and CUDA RMSNorm precision by performing the fused affine multiplication in float32 (#189617) - Fix Conv2d forward and backward with non-contiguous MPS weights (#192303) - Raise clear unsupported-dtype errors for complex `igamma`/`igammac` and boolean `torch.linalg.cross` inputs on MPS (#188134, #187274) - Prevent intermittent crashes when stopping a Metal capture by draining work from all active MPS streams first (#191362) ## ROCm - Fix `torch.nn.functional.interpolate` with `mode="nearest"` failing on large channels-last inputs with `torch.AcceleratorError: HIP error: invalid configuration argument`. The channels-last `upsample_nearest2d` forward kernel launched a grid whose total thread count exceeded HIP's `UINT32_MAX` limit once the output approached 2^32 elements; this was a regression from 2.9 that showed up in diffusion VAE decode at large batch sizes (#180310) - Fix incorrect `torch.nn.LayerNorm` results for tensors with a very large number of rows when the normalized size is not a multiple of 4. The non-vectorized fallback exceeded HIP's launch limit; it now uses a grid-stride loop over rows (#186956) - Fix `torch.cuda.make_graphed_callables` failing to capture, or hanging, on ROCm when the callable uses hipBLASLt. Warmup and capture now run on the same stream so the hipBLASLt handle is created and cached before capture instead of being lazily created mid-capture (#187745) - Fix graph-capture error handling on ROCm 7.14 and later by using HIP's native capture errors instead of the compatibility precheck required by older ROCm versions (#187110) - Fix transposed convolution failing with `miopenStatusBadParm` when the computed spatial output is zero-sized. MIOpen rejects zero-length tensor descriptors, so these cases now short-circuit to an empty output (and zero gradients in backward), matching cuDNN and CPU behavior (#187431) - Fix a meta-kernel shape mismatch for memory-efficient scaled dot product attention on ROCm. The meta registration padded the log-sum-exp dimension to a 32-element alignment as CUDA does, while the ROCm backends return a compact log-sum-exp, breaking nested tensor SDPA backward and `torch.compile` (#190723) - Fix the memory-wait instructions used by the atomic-store commit path on `gfx10`, `gfx11`, and `gfx12` GPUs. These architectures have separate load and store counters, and `gfx12` renames the wait instructions, so the wrong instruction was previously emitted (#188067) - Fix failures when building HIP C++ extensions on Windows with `Don't know how to compile <file>.hip`. `.hip` sources produced by hipify are now registered with the MSVC compiler so they are dispatched to `hipcc` (#187665) - Fix out-of-bounds accesses in CK SDPA for tile-unaligned shapes by padding sequence-length allocations (#187152) ## XPU - Fix compiled `torch.signbit` for `float64` inputs on XPU by avoiding an incorrect Triton XPU signature (#188818) - Fix compiled `multi_margin_loss` with weights on XPU by using one-dimensional indexing in its decomposition (#188770) - Handle empty tensor inputs correctly in XPU `addmv` (#174193) - Fix oneDNN SDPA with GQA and a broadcasted mask on XPU (#190503) - Fix `max_unpool2d` channels-last stride mismatch on XPU (#190189) - Fix `bmm_outer_product` Triton override to support XPU tensors (#188783) - Raise `RuntimeError` instead of crashing when XPU cannot allocate a pinned host-memory buffer (#189681) - Route `GPU_USER_ANNOTATION` Kineto profiler events to `DeviceType::XPU` (#191841) ## Functorch - Fix a crash in `torch.func.vmap` when `out_dims=-1` and the mapped function returns an output that is independent of its vmapped input (#178495) ## JIT - Make TorchScript reject bare `list` and `tuple` value annotations consistently with `Attempted to use list without a contained type` or the equivalent tuple error; specify an element type such as `list[int]` instead (#188779) - Fix runtime compilation of JIT fuser kernels on ROCm 7 when HIPRTC's `bfloat16` conversion symbols collide with PyTorch's embedded definitions (#185656) - Fix `torch.jit.script` failing with `Cannot re-assign modules in a ScriptModule with non-scripted module` when a wrapper contains an already-scripted child with a `__jit_ignored_attributes__` submodule (#187863) ## Sparse Frontend - Create cuSPARSELt handles per device so sparse operations remain valid when a thread switches between CUDA devices (#189048) - Make grouped-matrix, batch-normalization, and sparse-matrix operations on ROCm Windows raise clear unsupported-operation errors instead of crashing with access violation `0xC0000005` when optional libraries are unavailable (#191680) # Performance ## Python Frontend - Reduce Python custom-op dispatch overhead and speed up CPU quantiles with partial selection (#187949, #186175, #188394) ## torch.nn - Reduce `linear_cross_entropy` memory and chunking costs, and avoid materializing RMSNorm copy-on-write tensors (#187219, #187838, #189202) ## Autograd - Reduce `autograd.Function.apply` overhead and constant-fold more generated backward formulas (#189582, #189788, #189800, #189577, #192611) ## Distributed - Balance packed-document context-parallel attention across ranks (#189902) ## Symmetric Memory - Improve symmetric-memory all-gather, peer-copy overlap, and large-scale rendezvous (#185359, #192530, #192623) ## Linear Algebra Frontend - Speed up CUDA `addmm`, batched LU factorization, and viewable batched `matmul` (#191706, #181998, #186178) ## FX - Speed up unused-submodule deletion and reduce boxed-call peak memory (#178320, #187186) ## Dynamo - Reduce compiled-call and TVM overhead and speed up native `itertools` tracing (#190390, #190571, #190392, #186973, #186974, #189012) - Avoid unnecessary guards, recompiles, and FlexAttention cache misses (#187782, #189482, #185739, #188177) ## Inductor - Reduce RNG clones, tune RDNA3 FlexAttention and ROCm reductions, enable XPU linear fusion, and enable Origami for ROCm max-autotuning by default (`TORCHINDUCTOR_ORIGAMI=0` opts out) (#188495, #177840, #181854, #183364, #186644) - Reduce combo-kernel, guard, NVGEMM-cache, and CPU expression overhead (#184323, #184752, #185966, #185967, #187013, #186356) - Improve combo and persistent reductions, XPU fallbacks, and optional `cat_linear` fusion (#186668, #186957, #187147, #187880, #187940, #188179, #188180) - Improve NVGEMM isolation and decode tuning, Blackwell split reductions, and host-side TMA launches (#188303, #188579, #188646, #188822) - Optimize FlexAttention predicates, broadcast-bias `baddbmm`, small GEMMs, softmax, and Triton 3.8 defaults (#188929, #189127, #189149, #189162, #189187) - Improve NVGEMM small-M and block-scaled kernels, compilation, launching, and caching; profile ten configurations by default (`TORCHINDUCTOR_NVGEMM_MAX_PROFILING_CONFIGS=5` restores five) (#189771, #189777, #189805, #189773, #189778, #189779, #189806, #189841, #189807) - Optimize Triton min/max with relaxed signed-zero ties (`torch._inductor.config.strict_signed_zero=True` preserves eager ties), combo-kernel register use, fusion locality, FlexAttention code generation, and peak-memory scheduling (#190404, #190689, #191349, #192247, #192449) - Reduce fusion-analysis, repro-generation, and symbolic-comparison overhead (#192675, #192818, #192819) ## Ahead-Of-Time Inductor (AOTI) - Add opt-in pinned asynchronous AOTInductor constant loading through `AOTI_COPY_USE_PINNED_ASYNC=1` (#186258) ## Export - Make large-graph export decomposition scale linearly (#177927) ## AOTDispatcher - Avoid an unnecessary `Tensor.detach()` in AOTAutograd backward (#189759) ## Composability - Reduce dynamic-shape tracing and wide-symbol substitution costs (#192677, #185884) - Optimize `reciprocal(sqrt(x))` and BatchNorm inference with `rsqrt` (#190206) ## Quantization - Speed up bias addition in dynamically quantized `float16` CPU linear layers (#189943) ## CUDA - Avoid synchronization and redundant initialization in CUDA kernels, optimize FFT fill, and tune Rubin elementwise kernels (#186508, #190269, #190953, #190546) ## cuDNN - Reduce cuDNN convolution cold-start overhead (#187212) ## MPS - Move interpolation, logical, indexing, Mish, median, and range operations to faster native Metal kernels (#186989, #187324, #187109, #187906, #187060, #188905, #188921, #191060) - Speed up Cholesky, LU factorization and solves, GEMV, and sequence-length-one linear decoding (#187022, #187038, #189200, #186927, #189855) - Optimize full, strided, batched, variance, normalization, and arg/min/max reductions (#187313, #188412, #191101, #191097, #191098, #191099, #191100) - Reduce allocator fragmentation, decoding memory, and synchronization overhead (#187441, #190438, #190115) - Optimize FlexAttention, 3D convolution, GLU, sigmoid, and log-sigmoid; accelerate attention prefill on supported macOS versions and GPUs (#188663, #188802, #192229, #187833, #187151, #187228, #182256) - Speed up concatenation and sliced-view copies, including pinned transfers (#188200, #188483, #188613, #189512) - Fix incorrect large-`int64` results while optimizing flat `torch.unique`, and reduce `torch.nonzero` memory use (#184780, #191274) ## ROCm - Prefer hipBLASLt on additional ROCm architectures (#185375) ## XPU - Fuse low-precision upcasts into XPU softmax and reduction kernels (#189999) ## JIT - Reduce JIT startup and compilation overhead (#181118, #188121, #183813) # Documentation ## Python Frontend - Document all accepted device-like arguments for `torch.set_default_device`, including integer accelerator indices and `None` (#187240) - Document the tensor-factory keyword arguments accepted by the `torch.normal(mean, std, size)` overload (#187820) - Clarify that the `index` argument to `Tensor.index_reduce_()` selects positions in `self` to accumulate into, rather than positions in `source` (#189008) - Document that `torch.searchsorted` does not validate sorting and has undefined behavior for unsorted input when no `sorter` is provided (#184888) - Correct the `torch.arange` dtype-inference note to refer to the `step` argument instead of the nonexistent `stop` argument (#188943) - Add docstrings for top-level in-place functions that have out-of-place equivalents (#189571) ## torch.nn - Clarify that `torch.nn.functional.gaussian_nll_loss` uses `eps` to clamp `var` to a minimum rather than adding it to `var` (#190058) - Add deterministic example output to the `torch.nn.Tanh` documentation (#189390) - Correct the documented `mat_b` shape for `torch.nn.functional.grouped_mm` and explain how to pass grouped linear weights (#191610) - Correct the `ceil_mode=True` output-size formula in the `torch.nn.MaxPool1d` documentation (#188735) - Document that repeated calls to `torch.nn.Module.parameters()` return parameters in a deterministic order when the module is unchanged (#189990) ## Optimizer - Fix incorrect learning-rate curves in the `torch.optim.lr_scheduler.ChainedScheduler` and `torch.optim.lr_scheduler.SequentialLR` documentation (#186468) ## Distributed - Correct typos in distributed memory-analysis documentation and related distributed and utility docstrings (#187079, #189357, #190827) - Document the callback signatures, return values, keyword-argument behavior, and usage of `distribute_module` (#188071) - Correct PyTorch brand name capitalization in distributed checkpoint and other documentation (#189248) - Document the experimental process-group reconfiguration APIs and provide an end-to-end usage example (#191384) - Document how to enable and verify NCCL symmetric-memory kernels through registered memory pools or symmetric-memory rendezvous (#192515) ## Linear Algebra Frontend - Clarify `torch.linalg.norm`, `torch.linalg.matrix_norm`, and `torch.linalg.vector_norm` behavior for complex inputs, and correct the documented `ord` values accepted by `torch.linalg.vector_norm` (#190381, #188204) ## Dynamo - Link the guard-overhead page to the developer blog post and document a profiler-based way to measure guard overhead (#191387) ## ONNX - Clarify that `output_names` labels outputs but does not reorder them (#175796) ## XPU - Update the XPU documentation with newly supported operating-system versions and simplified installation instructions (#187923, #190992) # Security ## Python Frontend - Validate tensor shapes and sequence bounds in `torch.quasirandom.SobolEngine` before native kernels index direction-number tables (#191198) - Make stream comparisons with non-stream objects safe and Python-consistent: equality returns `False`, `stream != None` now returns `True` instead of `False`, and ordering comparisons raise `TypeError` instead of returning `False` (#192523) ## torch.nn - Validate `grad_output` shapes in 2D and 3D `grid_sample` backward operations before CPU, CUDA, or MPS kernels can read out of bounds (#191915) - Validate channel counts in `replication_pad1d` and `replication_pad2d` backward operations to prevent out-of-bounds reads and segmentation faults (#189463) - Validate `mean`, `invstd`, and `counts` shapes before CUDA batch-normalization statistics gathering to prevent out-of-bounds reads (#190005) ## Distributed - Add an opt-in `weights_only=True` mode to distributed object collectives for restricted deserialization; the default remains unchanged for compatibility (#189353) - Validate symmetric-memory signal channels and peer ranks to prevent out-of-bounds device-memory access and adjacent-allocation corruption (#191596, #191842) - Parse Flight Recorder rank expressions with `ast.literal_eval()` instead of executing them with `eval()` (#191490) ## Mobile - Reject malformed mobile FlatBuffer modules whose function class-type index is out of range, preventing an out-of-bounds access and crash during loading (#186672) ## Sparse Frontend - Always validate sparse-tensor invariants when loading with `torch.load(..., weights_only=True)` so malformed checkpoints cannot create tensors whose indices cause out-of-bounds reads (#184750) Validation is an O(nnz) scan and applies regardless of the global `torch.sparse.check_sparse_tensor_invariants` setting. Fix or regenerate malformed sparse checkpoints that now raise errors such as `RuntimeError: size is inconsistent with indices`. Do not use `weights_only=False` as a workaround for untrusted files. # Developers ## torch.nn - Integrate Helion with the native-DSL registry and add reusable kernel instrumentation (#190636) ## Distributed - Extend process groups for reconfiguration, one-sided windows, lifecycle hooks, backend-routed rank/size, and safe ROCm builds (#186888, #186298, #186299, #186300, #187467) - Modernize RPC and backend extension APIs with atomic shared pointers, canonical `_single` collectives, custom-op `ProcessGroup` inputs, and Python entry points (#185633, #187140, #187459, #187388) - Support optional NCCL expert parallelism and keep experimental `nccl2` builds portable (#187366, #187385, #189938, #189958) - Add TorchElastic error enrichment, update sequence-number and `FakeStore` interfaces, and expose a backend-agnostic Flight Recorder hook (#187098, #188611, #189259, #189363) ## Distributed (c10d) - Add fake-backend `split_group` support and correct c10d type stubs (#186290, #191633) ## Symmetric Memory - Add the `USE_NCCL_EP` source-build option (#177437) ## Profiler - Add CUDA graph lifecycle hooks for the experimental CUPTI monitor (#191299) ## FX - Add source-stack provenance to compiler profiler timelines and preserve device indices in minifier repros (#186230, #186547) ## Dynamo - Make generated graphs and repros deterministic and robust for higher-order operators, symbolic storage sizes, and non-UTF-8 diagnostics (#181775, #186804, #190838, #190696) ## Inductor - Improve compiler provenance, custom-pattern matching, wrapper timing, and repro serialization (#183952, #184419, #187936, #190728) - Add optional external TLX backend integration (#189094) ## Ahead-Of-Time Inductor (AOTI) - Add optional kernel-context metadata for generated C++ wrappers (#184513) ## Export - Improve raw Triton export errors and draft-export report readability (#185827, #186070) ## C++ Frontend - Add portable lifetime annotations across borrowed C++ APIs (#190076, #190077, #190075, #190074, #189912) - Enforce C++20 headers and add safer integer conversions and borrowed-range support (#178150, #190092, #186635) ## Developer Experience - Add the contributor-facing `spin docs` wrapper (#182814) ## Build Frontend - Limit concurrent FlashAttention compilation and update `clang-tidy` (#192305, #191111) ## Release Engineering - Migrate builds from `setuptools` to `scikit-build-core` (#180247) ## MPS - Regenerate bundled Metal headers when sources change and clean up newer-SDK compiler warnings (#189179, #187087, #186822, #187753, #188416, #188910, #191636, #191970) ## ROCm - Support ROCm ASAN builds and derive hipCUB's CCCL version automatically (#188242, #188072) - Update CK/AITER for `gfx1033` and residual-NaN fixes, and fix a `libdrm` installer overflow (#183965, #187799) ## XPU - Consolidate XPU operator generation and align internals with oneAPI 2026 (#181233, #191470) - Move the XPU C++ memory-pool API to ATen (#192032) ## Caffe2 - Fix source builds with `fmt` 12.2 and Windows Clang 17 (#190691, #192376, #190929) ## JIT - Restore `TensorExpr` builds with LLVM 24 (#192381)
▸ 主项目介绍 · pytorch/pytorch
▸ README 原文(同步于 2026-07-19 13:04)
<picture> <source media="(prefers-color-scheme: dark)" srcset="https://github.com/pytorch/pytorch/raw/main/docs/source/_static/img/pytorch-logo-light.png" /> <source media="(prefers-color-scheme: light)" srcset="https://github.com/pytorch/pytorch/raw/main/docs/source/_static/img/pytorch-logo-dark.png" /> <img src="https://github.com/pytorch/pytorch/raw/main/docs/source/_static/img/pytorch-logo-dark.png" alt="PyTorch logo" /> </picture> -------------------------------------------------------------------------------- PyTorch is a Python package that provides two high-level features: - Tensor computation (like NumPy) with strong GPU acceleration - Deep neural networks built on a tape-based autograd system You can reuse your favorite Python packages such as NumPy, SciPy, and Cython to extend PyTorch when needed. Our trunk health (Continuous Integration signals) can be found at [hud.pytorch.org](https://hud.pytorch.org/ci/pytorch/pytorch/main). <!-- toc --> - [More About PyTorch](#more-about-pytorch) - [A GPU-Ready Tensor Library](#a-gpu-ready-tensor-library) - [Dynamic Neural Networks: Tape-Based Autograd](#dynamic-neural-networks-tape-based-autograd) - [Python First](#python-first) - [Imperative Experiences](#imperative-experiences) - [Fast and Lean](#fast-and-lean) - [Extensions Without Pain](#extensions-without-pain) - [Installation](#installation) - [Binaries](#binaries) - [NVIDIA Jetson Platforms](#nvidia-jetson-platforms) - [From Source](#from-source) - [Prerequisites](#prerequisites) - [NVIDIA CUDA Support](#nvidia-cuda-support) - [AMD ROCm Support](#amd-rocm-support) - [Intel GPU Support](#intel-gpu-support) - [Get the PyTorch Source](#get-the-pytorch-source) - [Install Dependencies](#install-dependencies) - [Install PyTorch](#install-pytorch) - [Adjust Build Options (Optional)](#adjust-build-options-optional) - [Docker Image](#docker-image) - [Using pre-built images](#using-pre-built-images) - [Building the image yourself](#building-the-image-yourself) - [Building the Documentation](#building-the-documentation) - [Troubleshooting CI Errors](#troubleshooting-ci-errors) - [Building a PDF](#building-a-pdf) - [Previous Versions](#previous-versions) - [Getting Started](#getting-started) - [Resources](#resources) - [Communication](#communication) - [Releases and Contributing](#releases-and-contributing) - [The Team](#the-team) - [License](#license) <!-- tocstop --> ## More About PyTorch [Learn the basics of PyTorch](https://pytorch.org/tutorials/beginner/basics/intro.html) At a granular level, PyTorch is a library that consists of the following components: | Component | Description | | ---- | --- | | [**torch**](https://pytorch.org/docs/stable/torch.html) | A Tensor library like NumPy, with strong GPU support | | [**torch.autograd**](https://pytorch.org/docs/stable/autograd.html) | A tape-based automatic differentiation library that supports all differentiable Tensor operations in torch | | [**torch.jit**](https://pytorch.org/docs/stable/jit.html) | A compilation stack (TorchScript) to create serializable and optimizable models from PyTorch code | | [**torch.nn**](https://pytorch.org/docs/stable/nn.html) | A neural networks library deeply integrated with autograd designed for maximum flexibility | | [**torch.multiprocessing**](https://pytorch.org/docs/stable/multiprocessing.html) | Python multiprocessing, but with magical memory sharing of torch Tensors across processes. Useful for data loading and Hogwild training | | [**torch.utils**](https://pytorch.org/docs/stable/data.html) | DataLoader and other utility functions for convenience | Usually, PyTorch is used either as: - A replacement for NumPy to use the power of GPUs. - A deep learning research platform that provides maximum flexibility and speed. Elaborating Further: ### A GPU-Ready Tensor Library If you use NumPy, then you have used Tensors (a.k.a. ndarray). ![Tensor illustration](https://github.com/pytorch/pytorch/raw/main/docs/source/_static/img/tensor_illustration.png) PyTorch provides Tensors that can live either on the CPU or the GPU and accelerates the computation by a huge amount. We provide a wide variety of tensor routines to accelerate and fit your scientific computation needs such as slicing, indexing, mathematical operations, linear algebra, reductions. And they are fast! ### Dynamic Neural Networks: Tape-Based Autograd PyTorch has a unique way of building neural networks: using and replaying a tape recorder. Most frameworks such as TensorFlow, Theano, Caffe, and CNTK have a static view of the world. One has to build a neural network and reuse the same structure again and again. Changing the way the network behaves means that one has to start from scratch. With PyTorch, we use a technique called reverse-mode auto-differentiation, which allows you to change the way your network behaves arbitrarily with zero lag or overhead. Our inspiration comes from several research papers on this topic, as well as current and past work such as [torch-autograd](https://github.com/twitter/torch-autograd), [autograd](https://github.com/HIPS/autograd), [Chainer](https://chainer.org), etc. While this technique is not unique to PyTorch, it's one of the fastest implementations of it to date. You get the best of speed and flexibility for your crazy research. ![Dynamic graph](https://github.com/pytorch/pytorch/raw/main/docs/source/_static/img/dynamic_graph.gif) ### Python First PyTorch is not a Python binding into a monolithic C++ framework. It is built to be deeply integrated into Python. You can use it naturally like you would use [NumPy](https://www.numpy.org/) / [SciPy](https://www.scipy.org/) / [scikit-learn](https://scikit-learn.org) etc. You can write your new neural network layers in Python itself, using your favorite libraries and use packages such as [Cython](https://cython.org/) and [Numba](http://numba.pydata.org/). Our goal is to not reinvent the wheel where appropriate. ### Imperative Experiences PyTorch is designed to be intuitive, linear in thought, and easy to use. When you execute a line of code, it gets executed. There isn't an asynchronous view of the world. When you drop into a debugger or receive error messages and stack traces, understanding them is straightforward. The stack trace points to exactly where your code was defined. We hope you never spend hours debugging your code because of bad stack traces or asynchronous and opaque execution engines. ### Fast and Lean PyTorch has minimal framework overhead. We integrate acceleration libraries such as [Intel MKL](https://software.intel.com/mkl) and NVIDIA ([cuDNN](https://developer.nvidia.com/cudnn), [NCCL](https://developer.nvidia.com/nccl)) to maximize speed. At the core, its CPU and GPU Tensor and neural network backends are mature and have been tested for years. Hence, PyTorch is quite fast — whether you run small or large neural networks. The memory usage in PyTorch is extremely efficient compared to Torch or some of the alternatives. We've written custom memory allocators for the GPU to make sure that your deep learning models are maximally memory efficient. This enables you to train bigger deep learning models than before. ### Extensions Without Pain Writing new neural network modules, or interfacing with PyTorch's Tensor API, was designed to be straightforward and with minimal abstractions. You can write new neural network layers in Python using the torch API [or your favorite NumPy-based libraries such as SciPy](https://pytorch.org/tutorials/advanced/numpy_extensions_tutorial.html). If you want to write your layers in C/C++, we provide a convenient extension API that is efficient and with minimal boilerplate. No wrapper code needs to be written. You can see [a tutorial here](https://pytorch.org/tutorials/advanced/cpp_extension.html) and [an example here](https://github.com/pytorch/extension-cpp). ## Installation ### Binaries Commands to install binaries via Conda or pip wheels are on our website: [https://pytorch.org/get-started/locally/](https://pytorch.org/get-started/locally/) #### NVIDIA Jetson Platforms Python wheels for NVIDIA's Jetson Nano, Jetson TX1/TX2, Jetson Xavier NX/AGX, and Jetson AGX Orin are provided [here](https://forums.developer.nvidia.com/t/pytorch-for-jetson-version-1-10-now-available/72048) and the L4T container is published [here](https://catalog.ngc.nvidia.com/orgs/nvidia/containers/l4t-pytorch) They require JetPack 4.2 and above, and [@dusty-nv](https://github.com/dusty-nv) and [@ptrblck](https://github.com/ptrblck) are maintaining them. ### From Source #### Prerequisites If you are installing from source, you will need: - Python 3.10 or later - A compiler that fully supports C++20, such as clang or gcc (gcc 11.3.0 or newer is required, on Linux) - Visual Studio or Visual Studio Build Tool (Windows only) - At least 10 GB of free disk space - 30-60 minutes for the initial build (subsequent rebuilds are much faster) \* PyTorch CI uses Visual C++ BuildTools, which come with Visual Studio Enterprise, Professional, or Community Editions. You can also install the build tools from https://visualstudio.microsoft.com/visual-cpp-build-tools/. The build tools *do not* come with Visual Studio Code by default. An example of environment setup is shown below: * Linux: ```bash $ source <CONDA_INSTALL_DIR>/bin/activate $ conda create -y -n <CONDA_NAME> $ conda activate <CONDA_NAME> ``` * Windows: ```bash $ source <CONDA_INSTALL_DIR>\Scripts\activate.bat $ conda create -y -n <CONDA_NAME> $ conda activate <CONDA_NAME> $ call "C:\Program Files\Microsoft Visual Studio\<VERSION>\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 ``` A conda environment is not required. You can also do a PyTorch build in a standard virtual environment, e.g., created with tools like `uv`, provided your system has installed all the necessary dependencies unavailable as pip packages (e.g., CUDA, MKL.) ##### NVIDIA CUDA Support If you want to compile with CUDA support, [select a supported version of CUDA from our support matrix](https://pytorch.org/get-started/locally/), then install the following: - [NVIDIA CUDA](https://developer.nvidia.com/cuda-downloads) - [NVIDIA cuDNN](https://developer.nvidia.com/cudnn) v9.0 or above - [Compiler](https://gist.github.com/ax3l/9489132) compatible with CUDA Note: You could refer to the [cuDNN Support Matrix](https://docs.nvidia.com/deeplearning/cudnn/backend/latest/reference/support-matrix.html) for cuDNN versions with the various supported CUDA, CUDA driver, and NVIDIA hardware. If you want to disable CUDA support, export the environment variable `USE_CUDA=0`. Other potentially useful environment variables may be found in `setup.py`. If CUDA is installed in a non-standard location, set PATH so that the nvcc you want to use can be found (e.g., `export PATH=/usr/local/cuda-12.8/bin:$PATH`). If you are building for NVIDIA's Jetson platforms (Jetson Nano, TX1, TX2, AGX Xavier), Instructions to install PyTorch for Jetson Nano are [available here](https://devtalk.nvidia.com/default/topic/1049071/jetson-nano/pytorch-for-jetson-nano/) ##### AMD ROCm Support If you want to compile with ROCm support, install - [AMD ROCm](https://rocm.docs.amd.com/en/latest/deploy/linux/quick_start.html) 4.0 and above installation - ROCm is currently supported only for Linux systems. By default the build system expects ROCm to be installed in `/opt/rocm`. If ROCm is installed in a different directory, the `ROCM_PATH` environment variable must be set to the ROCm installation directory. The build system automatically detects the AMD GPU architecture. Optionally, the AMD GPU architecture can be explicitly set with the `PYTORCH_ROCM_ARCH` environment variable [AMD GPU architecture](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html#supported-gpus) If you want to disable ROCm support, export the environment variable `USE_ROCM=0`. Other potentially useful environment variables may be found in `setup.py`. ##### Intel GPU Support If you want to compile with Intel GPU support, follow these - [PyTorch Prerequisites for Intel GPUs](https://www.intel.com/content/www/us/en/developer/articles/tool/pytorch-prerequisites-for-intel-gpu.html) instructions. - Intel GPU is supported for Linux and Windows. If you want to disable Intel GPU support, export the environment variable `USE_XPU=0`. Other potentially useful environment variables may be found in `setup.py`. #### Get the PyTorch Source ```bash git clone https://github.com/pytorch/pytorch cd pytorch # if you are updating an existing checkout git submodule sync git submodule update --init --recursive ``` #### Install Dependencies **Common** ```bash # Run this command from the PyTorch directory after cloning the source code using the “Get the PyTorch Source“ section above pip install --group dev ``` **On Linux** ```bash pip install mkl-static mkl-include # CUDA only: Add LAPACK support for the GPU if needed # magma installation: run with active conda environment. specify CUDA version to install .ci/docker/common/install_magma_conda.sh 12.4 # (optional) If using torch.compile with inductor/triton, install the matching version of triton # Run from the pytorch directory after cloning # For Intel GPU support, please explicitly `export USE_XPU=1` before running command. make triton ``` **On Windows** ```bash pip install mkl-static mkl-include # Add these packages if torch.distributed is needed. # Distributed package support on Windows is a prototype feature and is subject to changes. conda install -c conda-forge libuv=1.51 ``` #### Install PyTorch **On Linux** If you're compiling for AMD ROCm then first run this command: ```bash # Only run this if you're compiling for ROCm python tools/amd_build/build_amd.py ``` Install PyTorch ```bash # the CMake prefix for conda environment export CMAKE_PREFIX_PATH="${CONDA_PREFIX:-'$(dirname $(which conda))/../'}:${CMAKE_PREFIX_PATH}" python -m pip install --no-build-isolation -v -e . # the CMake prefix for non-conda environment, e.g. Python venv # call following after activating the venv export CMAKE_PREFIX_PATH="${VIRTUAL_ENV}:${CMAKE_PREFIX_PATH}" ``` **On macOS** ```bash python -m pip install --no-build-isolation -v -e . ``` **On Windows** If you want to build legacy python code, please refer to [Building on legacy code and CUDA](https://github.com/pytorch/pytorch/blob/main/CONTRIBUTING.md#building-on-legacy-code-and-cuda) **CPU-only builds** In this mode PyTorch computations will run on your CPU, not your GPU. ```cmd python -m pip install --no-build-isolation -v -e . ``` Note on OpenMP: The desired OpenMP implementation is Intel OpenMP (iomp). In order to link against iomp, you'll need to manually download the library and set up the building environment by tweaking `CMAKE_INCLUDE_PATH` and `LIB`. The instruction [here](https://docs.pytorch.org/docs/main/notes/windows.html#building-from-source) is an example for setting up both MKL and Intel OpenMP. Without these configurations for CMake, Microsoft Visual C OpenMP runtime (vcomp) will be used. **CUDA based build** In this mode PyTorch computations will leverage your GPU via CUDA for faster number crunching [NVTX](https://docs.nvidia.com/gameworks/content/gameworkslibrary/nvtx/nvidia_tools_extension_library_nvtx.htm) is needed to build PyTorch with CUDA. NVTX is a part of CUDA distributive, where it is called "Nsight Compute". To install it onto an already installed CUDA run CUDA installation once again and check the corresponding checkbox. Make sure that CUDA with Nsight Compute is installed after Visual Studio. Currently, VS 2017 / 2019, and Ninja are supported as the generator of CMake. If `ninja.exe` is detected in `PATH`, then Ninja will be used as the default generator, otherwise, it will use VS 2017 / 2019. <br/> If Ninja is selected as the generator, the latest MSVC will get selected as the underlying toolchain. Additional libraries such as [Magma](https://developer.nvidia.com/magma), [oneDNN, a.k.a. MKLDNN or DNNL](https://github.com/oneapi-src/oneDNN), and [Sccache](https://github.com/mozilla/sccache) are often needed. Please refer to the [installation-helper](https://github.com/pytorch/pytorch/tree/main/.ci/pytorch/win-test-helpers/installation-helpers) to install them. You can refer to the [build_pytorch.bat](https://github.com/pytorch/pytorch/blob/main/.ci/pytorch/win-test-helpers/build_pytorch.bat) script for some other environment variables configurations ```cmd cmd :: Set the environment variables after you have downloaded and unzipped the mkl package, :: else CMake would throw an error as `Could NOT find OpenMP`. set CMAKE_INCLUDE_PATH={Your directory}\mkl\include set LIB={Your directory}\mkl\lib;%LIB% :: Read the content in the previous section carefully before you proceed. :: [Optional] If you want to override the underlying toolset used by Ninja and Visual Studio with CUDA, please run the following script block. :: "Visual Studio 2019 Developer Command Prompt" will be run automatically. :: Make sure you have CMake >= 3.12 before you do this when you use the Visual Studio generator. set CMAKE_GENERATOR_TOOLSET_VERSION=14.27 set DISTUTILS_USE_SDK=1 for /f "usebackq tokens=*" %i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version [15^,17^) -products * -latest -property installationPath`) do call "%i\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=%CMAKE_GENERATOR_TOOLSET_VERSION% :: [Optional] If you want to override the CUDA host compiler set CUDAHOSTCXX=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX64\x64\cl.exe python -m pip install --no-build-isolation -v -e . ``` **Intel GPU builds** In this mode PyTorch with Intel GPU support will be built. Please make sure [the common prerequisites](#prerequisites) as well as [the prerequisites for Intel GPU](#intel-gpu-support) are properly installed and the environment variables are configured prior to starting the build. For build tool support, `Visual Studio 2022` is required. Then PyTorch can be built with the command: ```cmd :: CMD Commands: :: Set the CMAKE_PREFIX_PATH to help find corresponding packages :: %CONDA_PREFIX% only works after `conda activate custom_env` if defined CMAKE_PREFIX_PATH ( set "CMAKE_PREFIX_PATH=%CONDA_PREFIX%\Library;%CMAKE_PREFIX_PATH%" ) else ( set "CMAKE_PREFIX_PATH=%CONDA_PREFIX%\Library" ) python -m pip install --no-build-isolation -v -e . ``` ##### Adjust Build Options (Optional) You can adjust the configuration of cmake variables optionally (without building first), by doing the following. For example, adjusting the pre-detected directories for CuDNN or BLAS can be done with such a step. On Linux ```bash export CMAKE_PREFIX_PATH="${CONDA_PREFIX:-'$(dirname $(which conda))/../'}:${CMAKE_PREFIX_PATH}" CMAKE_ONLY=1 python setup.py build ccmake build # or cmake-gui build ``` On macOS ```bash export CMAKE_PREFIX_PATH="${CONDA_PREFIX:-'$(dirname $(which conda))/../'}:${CMAKE_PREFIX_PATH}" MACOSX_DEPLOYMENT_TARGET=11.0 CMAKE_ONLY=1 python setup.py build ccmake build # or cmake-gui build ``` ### Docker Image #### Using pre-built images You can also pull a pre-built docker image from Docker Hub and run with docker v23.0+ ```bash docker run --gpus all --rm -ti --ipc=host pytorch/pytorch:latest ``` Please note that PyTorch uses shared memory to share data between processes, so if torch multiprocessing is used (e.g. for multithreaded data loaders) the default shared memory segment size that container runs with is not enough, and you should increase shared memory size either with `--ipc=host` or `--shm-size` command line options to `nvidia-docker run`. #### Building the image yourself **NOTE:** Must be built with a Docker version >= 23.0 The Dockerfile is supplied to build images with CUDA 12.1 support and cuDNN v9. You can pass `PYTHON_VERSION=x.y` make variable to specify which Python version is to be used by Miniconda, or leave it unset to use the default, as the Dockerfile uses system Python. ```bash make -f docker.Makefile # images are tagged as docker.io/${your_docker_username}/pytorch ``` You can also pass the `CMAKE_VARS="..."` environment variable to specify additional CMake variables to be passed to CMake during the build. See [setup.py](./setup.py) for the list of available variables. ```bash make -f docker.Makefile ``` ### Building the Documentation To build documentation in various formats, you will need [Sphinx](http://www.sphinx-doc.org) and the `pytorch_sphinx_theme2`. Before you build the documentation locally, ensure `torch` is installed in your environment. For small fixes, you can install the nightly version as described in [Getting Started](https://pytorch.org/get-started/locally/). For more complex fixes, such as adding a new module and docstrings for the new module, you might need to install torch [from source](#from-source). See [Docstring Guidelines](https://github.com/pytorch/pytorch/wiki/Docstring-Guidelines) for docstring conventions. ```bash cd docs/ pip install -r requirements.txt make html make serve ``` Run `make` to get a list of all available output formats. If you get a katex error run `npm install katex`. If it persists, try `npm install -g katex` > [!NOTE] > If you see a numpy incompatibility error, run: > ``` > pip install 'numpy<2' > ``` #### Troubleshooting CI Errors Your build may show errors you didn't have locally - here's how to find the errors relevant to the docs. If the build has any errors, you will see something like this on the PR: <img width="781" height="400" alt="Monosnap Update installation instructions for doc build · Pull Request #169534 · pytorch:pytorch 2025-12-18 18-22-53" src="https://github.com/user-attachments/assets/49a3dfe7-81c2-4246-852b-bc3f807e95af" /> Any doc-related errors will occur in jobs that include "doc" somewhere in the title. It doesn't look like any of these jobs are relevant to our docs. Let's take a look anyway. Click on the job to see the logs: <img width="1187" height="668" alt="Monosnap Update installation instructions for doc build · pytorch:pytorch@7380336 2025-12-18 18-24-15" src="https://github.com/user-attachments/assets/117df543-8356-4323-8e1c-ef02a95554ba" /> And we can be sure that this job does not involve docs. Looking at this build, we can see these jobs are relevant to our docs - and they didn't have any errors: <img width="777" height="395" alt="Check the docs jobs" src="https://github.com/user-attachments/assets/5d7c196b-2d40-49ad-87e3-f57de6e14a5b" /> You might also see a comment on the PR like this: <img width="651" height="246" alt="PR Comment" src="https://github.com/user-attachments/assets/27e0120a-ba33-4b1c-b4a5-bf3064520586" /> We can see that some of these issues are relevant to our docs. Open the logs by clicking on the `gh` link: <img width="873" height="360" alt="View Logs" src="https://github.com/user-attachments/assets/ab5b862f-8026-489c-b95e-a6cd4257e4b7" /> And here we can see there is a doc-related error: <img width="1117" height="433" alt="Doc Error" src="https://github.com/user-attachments/assets/0a275921-736d-43a7-ab0f-3e8854d43280" /> You can always find the relevant doc builds by going to the `Checks` tab on your PR, and scrolling down to `pull`. <img width="481" height="561" alt="checks" src="https://github.com/user-attachments/assets/eef18f2b-7134-4e2e-bd90-bcdc12800132" /> You can either click through or toggle the accordion to see all of the jobs here, where you can see the docs jobs highlighted: <img width="570" height="611" alt="jobs" src="https://github.com/user-attachments/assets/f62812ca-caee-421b-863c-54f38fd28d46" /> If you click through, you'll see the doc jobs at the bottom, like this: <img width="354" height="312" alt="View Docs jobs" src="https://github.com/user-attachments/assets/8fadb935-5314-4c4b-a1b5-133781754f03" /> #### Building a PDF To compile a PDF of all PyTorch documentation, ensure you have `texlive` and LaTeX installed. On macOS, you can install them using: ``` brew install --cask mactex ``` To create the PDF: 1. Run: ``` make latexpdf ``` This will generate the necessary files in the `build/latex` directory. 2. Navigate to this directory and execute: ``` make LATEXOPTS="-interaction=nonstopmode" ``` This will produce a `pytorch.pdf` with the desired content. Run this command one more time so that it generates the correct table of contents and index. > [!NOTE] > To view the Table of Contents, switch to the **Table of Contents** > view in your PDF viewer. ### Previous Versions Installation instructions and binaries for previous PyTorch versions may be found on [our website](https://pytorch.org/get-started/previous-versions). ## Getting Started Pointers to get you started: - [Tutorials: get you started with understanding and using PyTorch](https://pytorch.org/tutorials/) - [Examples: easy to understand PyTorch code across all domains](https://github.com/pytorch/examples) - [The API Reference](https://pytorch.org/docs/) - [Glossary](https://github.com/pytorch/pytorch/blob/main/GLOSSARY.md) ## Resources * [PyTorch.org](https://pytorch.org/) * [PyTorch Tutorials](https://pytorch.org/tutorials/) * [PyTorch Examples](https://github.com/pytorch/examples) * [PyTorch Models](https://pytorch.org/hub/) * [Intro to Deep Learning with PyTorch from Udacity](https://www.udacity.com/course/deep-learning-pytorch--ud188) * [Intro to Machine Learning with PyTorch from Udacity](https://www.udacity.com/course/intro-to-machine-learning-nanodegree--nd229) * [Deep Neural Networks with PyTorch from Coursera](https://www.coursera.org/learn/deep-neural-networks-with-pytorch) * [PyTorch Twitter](https://twitter.com/PyTorch) * [PyTorch Blog](https://pytorch.org/blog/) * [PyTorch YouTube](https://www.youtube.com/channel/UCWXI5YeOsh03QvJ59PMaXFw) ## Communication * Forums: Discuss implementations, research, etc. https://discuss.pytorch.org * GitHub Issues: Bug reports, feature requests, install issues, RFCs, thoughts, etc. * Slack: The [PyTorch Slack](https://pytorch.slack.com/) hosts a primary audience of moderate to experienced PyTorch users and developers for general chat, online discussions, collaboration, etc. If you are a beginner looking for help, the primary medium is [PyTorch Forums](https://discuss.pytorch.org). If you need a slack invite, please fill this form: https://goo.gl/forms/PP1AGvNHpSaJP8to1 * Newsletter: No-noise, a one-way email newsletter with important announcements about PyTorch. You can sign-up here: https://eepurl.com/cbG0rv * Facebook Page: Important announcements about PyTorch. https://www.facebook.com/pytorch * For brand guidelines, please visit our website at [pytorch.org](https://pytorch.org/) ## Releases and Contributing Typically, PyTorch has three minor releases a year. Please let us know if you encounter a bug by [filing an issue](https://github.com/pytorch/pytorch/issues). We appreciate all contributions. If you are planning to contribute back bug-fixes, please do so without any further discussion. If you plan to contribute new features, utility functions, or extensions to the core, please first open an issue and discuss the feature with us. Sending a PR without discussion might end up resulting in a rejected PR because we might be taking the core in a different direction than you might be aware of. To learn more about making a contribution to PyTorch, please see our [Contribution page](CONTRIBUTING.md). For more information about PyTorch releases, see [Release page](RELEASE.md). ## The Team PyTorch is a community-driven project with several skillful engineers and researchers contributing to it. PyTorch is currently maintained by [Soumith Chintala](http://soumith.ch), [Gregory Chanan](https://github.com/gchanan), [Dmytro Dzhulgakov](https://github.com/dzhulgakov), [Edward Yang](https://github.com/ezyang), [Alban Desmaison](https://github.com/albanD), [Piotr Bialecki](https://github.com/ptrblck) and [Nikita Shulga](https://github.com/malfet) with major contributions coming from hundreds of talented individuals in various forms and means. A non-exhaustive but growing list needs to mention: [Trevor Killeen](https://github.com/killeent), [Sasank Chilamkurthy](https://github.com/chsasank), [Sergey Zagoruyko](https://github.com/szagoruyko), [Adam Lerer](https://github.com/adamlerer), [Francisco Massa](https://github.com/fmassa), [Alykhan Tejani](https://github.com/alykhantejani), [Luca Antiga](https://github.com/lantiga), [Alban Desmaison](https://github.com/albanD), [Andreas Koepf](https://github.com/andreaskoepf), [James Bradbury](https://github.com/jekbradbury), [Zeming Lin](https://github.com/ebetica), [Yuandong Tian](https://github.com/yuandong-tian), [Guillaume Lample](https://github.com/glample), [Marat Dukhan](https://github.com/Maratyszcza), [Natalia Gimelshein](https://github.com/ngimel), [Christian Sarofeen](https://github.com/csarofeen), [Martin Raison](https://github.com/martinraison), [Edward Yang](https://github.com/ezyang), [Zachary Devito](https://github.com/zdevito). <!-- codespell:ignore --> Note: This project is unrelated to [hughperkins/pytorch](https://github.com/hughperkins/pytorch) with the same name. Hugh is a valuable contributor to the Torch community and has helped with many things Torch and PyTorch. ## License PyTorch has a BSD-style license, as found in the [LICENSE](LICENSE) file.
▸ 中文总结(生成于 2026-07-19 13:06)

pytorch/pytorch 项目介绍

一句话概括

PyTorch 是一个以 Python 优先、支持 GPU 加速的张量计算和动态神经网络构建的开源深度学习框架。

核心功能与定位

  • 张量计算库:提供类似 NumPy 的张量(Tensor)操作,但能利用 GPU 实现大幅加速,支持 CPU 和 GPU 两种运行环境。
  • 动态神经网络框架:基于磁带式自动微分(tape-based autograd)系统构建深度神经网络,允许网络结构在运行时动态改变,无需预定义静态图。

核心技术架构

  • torch:核心张量库,支持 GPU,提供切片、索引、数学运算、线性代数、归约等丰富操作。
  • torch.autograd:磁带式自动微分库,记录所有张量操作并自动计算梯度。
  • torch.jit:TorchScript 编译栈,可将 PyTorch 模型序列化并优化,用于生产部署。
  • torch.nn:与 autograd 深度集成的神经网络库,追求最大灵活性。
  • torch.multiprocessing:支持跨进程共享张量内存的多进程工具,适用于数据加载和 Hogwild 训练。
  • torch.utils:提供 DataLoader 等实用工具。

技术亮点与设计理念

  • GPU 就绪的张量库:张量可驻留 CPU 或 GPU,计算速度远超纯 NumPy 实现。
  • 动态图机制:与 TensorFlow、Theano、Caffe、CNTK 等静态图框架不同,PyTorch 使用反向模式自动微分,允许随意改变网络行为,无需从头重建计算图。这是目前最快的实现之一。
  • Python 优先:PyTorch 不是将 Python 绑定到 C++ 框架,而是深度集成到 Python 生态中,可自然地与 NumPy、SciPy、scikit-learn 等库协同使用,新层可直接用 Python 编写。
  • 命令式体验:代码逐行立即执行,没有异步视图。调试时堆栈跟踪直接指向代码定义位置,错误信息直观易懂。
  • 极低框架开销:集成了 Intel MKL、NVIDIA cuDNN、NCCL 等加速库,CPU 和 GPU 后端经过多年成熟测试。内存使用效率极高,针对 GPU 编写了自定义内存分配器,可训练更大的模型。
  • 无痛扩展:可用 Python 通过 torch API 或 SciPy 等库编写新层;若需用 C/C++ 编写,提供简洁高效的扩展 API,无需编写包装代码。

性能与对比

  • README 中明确提到:PyTorch 的动态图机制是“目前最快的实现之一”。
  • 内存效率比 Torch 或其他替代方案“极其高效”。
  • 无论运行小型还是大型神经网络,PyTorch 都“相当快”。

安装方式

  • 二进制安装:通过 Conda 或 pip 安装,官方指导页面为 https://pytorch.org/get-started/locally/。NVIDIA Jetson 平台有专门提供的 Python wheels。
  • 源码编译:需要 Python 3.10+、支持 C++20 的编译器(Linux 上需 gcc 11.3.0+)、Visual Studio(Windows)、至少 10 GB 磁盘空间、首次编译约 30-60 分钟。
  • GPU 支持:可选 NVIDIA CUDA(需 cuDNN v9.0+)、AMD ROCm(4.0+,仅 Linux)、Intel GPU(Linux 和 Windows)。
  • Docker 镜像:提供预构建镜像(pytorch/pytorch:latest),也支持用户自行构建。

社区与维护

  • 项目由 Soumith Chintala、Gregory Chanan、Dmytro Dzhulgakov 等核心维护者领导,数百名贡献者参与。
  • 每年约三个次要版本发布。
  • 社区沟通渠道包括论坛(discuss.pytorch.org)、GitHub Issues、Slack、新闻通讯、Facebook 页面。
  • 采用 BSD 风格许可证。