We are excited to announce the release of PyTorch® 2.6 (release notes)! This release features multiple improvements for PT2: torch.compile can now be used with Python 3.13; new performance-related knob torch.compiler.set_stance; several AOTInductor enhancements. Besides the PT2 improvements, another highlight is FP16 support on X86 CPUs.
For this release the experimental Linux binaries shipped with CUDA 12.6.3 (as well as Linux Aarch64, Linux ROCm 6.2.4, and Linux XPU binaries) are built with CXX11_ABI=1 and are using the Manylinux 2.28 build platform. If you build PyTorch extensions with custom C++ or CUDA extensions, please update these builds to use CXX_ABI=1 as well and report any issues you are seeing. For the next PyTorch 2.7 release we plan to switch all Linux builds to Manylinux 2.28 and CXX11_ABI=1, please see [RFC] PyTorch next wheel build platform: manylinux-2.28 for the details and discussion.
Also in this release as an important security improvement measure we have changed the default value for weights_only parameter of torch.load. This is a backward compatibility-breaking change, please see this forum post for more details.
This release is composed of 3892 commits from 520 contributors since PyTorch 2.5. We want to sincerely thank our dedicated community for your contributions. As always, we encourage you to try these out and report any issues as we improve PyTorch. More information about how to get started with the PyTorch 2-series can be found at our Getting Started page.
Beta
Prototype
torch.compiler.set_stance
Improved PyTorch user experience on Intel GPUs
torch.library.triton_op
FlexAttention support on X86 CPU for LLMs
torch.compile support for Python 3.13
Dim.AUTO
New packaging APIs for AOTInductor
CUTLASS and CK GEMM/CONV Backends for AOTInductor
AOTInductor: minifier
AOTInductor: ABI-compatible mode code generation
FP16 support for X86 CPUs
*To see a full list of public feature submissions click here.
BETA FEATURES
[Beta] torch.compiler.set_stance
This feature enables the user to specify different behaviors (“stances”) that torch.compile can take between different invocations of compiled functions. One of the stances, for example, is
“eager_on_recompile”, that instructs PyTorch to code eagerly when a recompile is necessary, reusing cached compiled code when possible.
torch.library.triton_op offers a standard way of creating custom operators that are backed by user-defined triton kernels.
When users turn user-defined triton kernels into custom operators, torch.library.triton_op allows torch.compile to peek into the implementation, enabling torch.compile to optimize the triton kernel inside it.
torch.compile previously only supported Python up to version 3.12. Users can now optimize models with torch.compile in Python 3.13.
[Beta] New packaging APIs for AOTInductor
A new package format, “PT2 archive”, has been introduced. This essentially contains a zipfile of all the files that need to be used by AOTInductor, and allows users to send everything needed to other environments. There is also functionality to package multiple models into one artifact, and to store additional metadata inside of the package.
AOTInductor-generated model code has dependency on Pytorch cpp libraries. As Pytorch evolves quickly, it’s important to make sure previously AOTInductor compiled models can continue to run on newer Pytorch versions, i.e. AOTInductor is backward compatible.
In order to guarantee application binary interface (ABI) backward compatibility, we have carefully defined a set of stable C interfaces in libtorch and make sure AOTInductor generates code that only refers to the specific set of APIs and nothing else in libtorch. We will keep the set of C APIs stable across Pytorch versions and thus provide backward compatibility guarantees for AOTInductor-compiled models.
[Beta] FP16 support for X86 CPUs (both eager and Inductor modes)
Float16 datatype is commonly used for reduced memory usage and faster computation in AI inference and training. CPUs like the recently launched Intel® Xeon® 6 with P-Cores support Float16 datatype with native accelerator AMX. Float16 support on X86 CPUs was introduced in PyTorch 2.5 as a prototype feature, and now it has been further improved for both eager mode and Torch.compile + Inductor mode, making it Beta level feature with both functionality and performance verified with a broad scope of workloads.
PROTOTYPE FEATURES
[Prototype] Improved PyTorch user experience on Intel GPUs
PyTorch user experience on Intel GPUs is further improved with simplified installation steps, Windows release binary distribution and expanded coverage of supported GPU models including the latest Intel® Arc™ B-Series discrete graphics. Application developers and researchers seeking to fine-tune, inference and develop with PyTorch models on Intel® Core™ Ultra AI PCs and Intel® Arc™ discrete graphics will now be able to directly install PyTorch with binary releases for Windows, Linux and Windows Subsystem for Linux 2.
Simplified Intel GPU software stack setup to enable one-click installation of the torch-xpu PIP wheels to run deep learning workloads in an out of the box fashion, eliminating the complexity of installing and activating Intel GPU development software bundles.
Further enhanced coverage of Aten operators on Intel GPUs with SYCL* kernels for smooth eager mode execution, as well as bug fixes and performance optimizations for torch.compile on Intel GPUs.
For more information regarding Intel GPU support, please refer to Getting Started Guide.
[Prototype] FlexAttention support on X86 CPU for LLMs
FlexAttention was initially introduced in PyTorch 2.5 to provide optimized implementations for Attention variants with a flexible API. In PyTorch 2.6, X86 CPU support for FlexAttention was added through TorchInductor CPP backend. This new feature leverages and extends current CPP template abilities to support broad attention variants (e.x.: PageAttention, which is critical for LLMs inference) based on the existing FlexAttention API, and brings optimized performance on x86 CPUs. With this feature, it’s easy to use FlexAttention API to compose Attention solutions on CPU platforms and achieve good performance.
[Prototype] Dim.AUTO
Dim.AUTO allows usage of automatic dynamic shapes with torch.export. Users can export with Dim.AUTO and “discover” the dynamic behavior of their models, with min/max ranges, relations between dimensions, and static/dynamic behavior being automatically inferred.
This is a more user-friendly experience compared to the existing named-Dims approach for specifying dynamic shapes, which requires the user to fully understand the dynamic behavior of their models at export time. Dim.AUTO allows users to write generic code that isn’t model-dependent, increasing ease-of-use for exporting with dynamic shapes.
[Prototype] CUTLASS and CK GEMM/CONV Backends for AOTInductor
The CUTLASS and CK backend adds kernel choices for GEMM autotuning in Inductor. This is now also available in AOTInductor which can run in C++ runtime environments. A major improvement to the two backends is improved compile-time speed by eliminating redundant kernel binary compilations and dynamic shapes support.
Tracked Regressions
torch.device(0) makes CUDA init fail in subprocess
There is a known regression (#144152) that torch.device(0) makes CUDA init fail in subprocess since PyTorch 2.5.0.
There was an attempt to fix the regressions, but it caused some complications and was reverted.
An easy workaround is to use torch.device('cuda') or torch.device('cuda:0') instead.
Regression in the compilation of the torch.all operation with out= variant
A regressions (https://github.com/pytorch/pytorch/issues/145220) was reported for PyTorch 2.6.0 with
compilation of the out= variant of the torch.all operator. This should be a rare use case, a workaround can be
rewriting the model code to avoid the out= variant.
We are closing the loop on the deprecation that started in 2.4 and flipped torch.load to use weights_only=True by default.
When this flag is set, instead of using the usual pickle module, torch.load uses a custom unpickler constrained to call only functions and classes needed for loading state dictionaries and basic types.
While this change is disruptive for users serializing more than basic types, we expect the increased security by default is a tradeoff that is worth it. Do note that, even though this default is safer, we still recommend only loading trusted checkpoints and rely on more constrained (and even safer) formats like safetensors for un-trusted checkpoints.
PyTorch will stop publishing Anaconda packages that depend on Anaconda’s default packages. We are directing users to utilize our official wheel packages from download.pytorch.org or PyPI, or switch to utilizing conda-forge (pytorch) packages if they would like to continue to use conda. For more details refer to this announcement
The PyTorch binaries shipped with CUDA 12.6.3 are built with CXX11_ABI=1 and are using the Manylinux 2.28 build platform. If you are building PyTorch extensions with custom C++ or CUDA extensions, please update these builds to use CXX_ABI=1 as well and report any issues you are seeing. For the next PyTorch 2.7 release we plan to switch all Linux builds to Manylinux 2.28 and CXX11_ABI=1, please see [RFC] PyTorch next wheel build platform: manylinux-2.28 for the details and discussion.
ONNX
torch.onnx.export(..., dynamo=True) now creates ONNX models using IR version 10 (#141207)
ONNX ir_version=10 is used to add support for UINT4, INT4 data types and include metadata in GraphProto and NodeProto. Make sure model consumers are able to accept IR version 10 ONNX models. You may read more about IRv10 on https://github.com/onnx/onnx/releases/tag/v1.16.0.
Some logging APIs, torch.onnx.ExportTypes, torch.onnx.export_to_pretty_string are removed. Users should remove usage of the APIs above.
torch.onnx.ONNXProgram has been reimplemented and improved (#136281)
All ONNX "dynamo" APIs will return the new ONNXProgram class. Some notable methods available are save(), optimize(). It can also be directly applied on PyTorch tensors to leverage ONNX Runtime to verify the ONNX graph. Some legacy methods are no longer available.
pg = dist.init_process_group()
def hook(work_info: torch._C._distributed_c10d.WorkInfo):
# do something
pg._register_on_completion_hook(hook)
# The hook will be triggered after the collective complete
pg.broadcast([tensor]).wait()
Starting from PT 2.6, when users write the code above, they will get get a warning message “ProcessGroupNCCL OnCompletion hook will be deprecated in favor of Flight Recorder”
Instead of setting TORCHINDUCTOR_STACK_ALLOCATION, update your torch.compile call: torch.compile(options={"aot_inductor.allow_stack_allocation": True})(foo).
New features
Python Frontend
Introduce a device-agnostic runtime API design (#132204)
Add validation for ambiguous behavior in Tensor.dim_order() (#141632)
Add type check for ord argument for torch.linalg.{vector,matrix}_norm() (#137463)
Intel GPU enablement in CI/CD. Upgrade XPU support packages to Intel® Deep Learning Essentials 2025.0. Add prototype Linux and Windows binary builds with XPU runtime pypi packages dependencies. (#138189) (#139050) (#139604) (#139775) (#140373) (#141546) (#141775) (#141135) (#142210) (#135638) ()
Added faster HW support for packed bfloat16 and fp16 for MI300 (#135770)
Improved performance of reductions on 1D and 2D tensors. (#137737)
XPU
Add torch.xpu.mem_get_info API: Introduces a new API to retrieve memory information for XPU devices. (#141230)
Add architecture property to XPU device: Adds new properties to XPU devices to query architecture details. (#138186)
Add elapsed_time method for XPU events: Introduces a method to measure elapsed time between XPU events. (#140865)
Add torch.xpu.get_arch_list and torch.xpu.get_gencode_flags: Introduces new APIs to retrieve architecture lists and code generation flags for XPU. (#137773)
Add quantized convolution support for XPU backend (#133080)
Enable XPU device support for LSTMCell operators (#140246)
Add functionality to call dump function of NCCL profiler plugin (#137523)
Export
Add torch.export.export_for_training() API to perform export that can run training. Note that this replaces the non-documented capture_pre_autograd_graph feature (#135374, #135918, #135549, #143224)
New packaging APIs for AOTInductor torch._inductor.aoti_compile_and_package
Previously, AOTInductor (through torch._export.aot_compile), would return a path to a .so. However, this does not have a great user experience as actually there are other files that are used along with the .so, for example .cubin files and serialized extern kernels. So, we introduce a new package format, “PT2 archive”, which is what we intend to have AOTInductor return. This essentially contains a zipfile of all the files that need to be used by AOTInductor, and allows users to send to other environments. There is also functionality to package multiple models into one artifact, and to store additional metadata inside of the package.
AOTInductor Minifier. If you encounter an error while using AOT Inductor APIs such as torch._inductor.aoti_compile_and_package, torch._indcutor.aoti_load_package, or running the loaded model of aoti_load_package on some inputs, you can use the AOTInductor Minifier to create a minimal nn.Module that reproduces the error. (#139351,#140999, #141159, #141156)
AOTInductor: ABI-compatible mode code generation. In order to guarantee ABI backward compatibility, we have carefully defined a set of stable C interfaces in libtorch and make sure AOTInductor generates code that only refers to the specific set of APIs and nothing else in libtorch. We will keep the set of C APIs stable across Pytorch versions and thus provide BC guarantees for AOTInductor-compiled models.
export.export_for_inference and export.exported_program.core_aten_decompositions API. export_for_inference returns a functional, post-dispatch ATen IR. (#135912).
Inductor
Move stack allocation related configs in AOTI (#139093). All stack allocation related configs now have a aot_inductor prefix, so torch.compile(options={"use_minimal_arrayref_interface": True})(foo) is now torch.compile(options={"aot_inductor.use_minimal_arrayref_interface": True})(foo) and torch.compile(options={"allow_stack_allocation": True})(foo) is now torch.compile(options={"aot_inductor.allow_stack_allocation": True})(foo).
Move torch._utils.is_compiling to torch.compiler.is_compiling (#127690) Rewrite torch._utils.is_compiling() to torch.compiler.is_compiling().
Added option autotune_num_choices_displayed to control number of kernel options displayed (#138788)
Added option force_pointwise_cat concat support through inductor using pointwise kernels (#141966). This forces concat to be generated as a pointwise op with masked loads.
New config option annotate_training that adds Inductor annotations to NVTX. (#130429)
Introduces an option triton_kernel_default_layout_constraint to tweak stride settings for user-defined Triton kernels, enhancing customization and flexibility (#135530).
User can patch inductor config to enable strict custom kernel layout constraints by changing torch.compile(options={"triton_kernel_default_layout_constraint": "needs_fixed_stride_order"})(foo) (#135581).
External callable registration API register_external_matmul for Matmul tuning candidates in Inductor (#130774).
Adds support for Windows Arm64 to enhance platform compatibility (#133088).
Integrates support for AMD triton stream pipeliner in ROCm to enhance performance (#139881).
Adds support for TRITON_INTERPRET in Inductor (#140841).
Adds update_constant_buffer pybind support in AOTInductor (#140755).
Provides an option package_constants_in_so to exclude weights from .so files in AOTInductor (#141997).
torch.cond is the recommended way to introduce control flows that can be converted to an ONNX model.
Users can provide a custom_translation_table to provide custom implementations for converting operators to ONNX (#135403)
This is useful when you need to override an implementation or provide one that is not currently implemented. Refer to the tutorials for a more complete description of the operator registration mechanism.
# Define the translation using ONNX Script
from onnxscript import opset18 as op
def sym_not_onnx(input):
return op.Not(input)
torch.onnx.export(...
dynamo=True,
custom_translation_table = { # Then provide it here
torch.sym_not: sym_not_onnx,
})
Users can run optimize() to flatten nested structures in the ONNX graph, perform constant folding and remove redundancies in the ONNX model. Calling optimize() after exporting to ONNX is recommended.
onnx_program = torch.onnx.export(..., dynamo=True)
onnx_program.optimize() # Optimize the graph before saving is recommended
onnx_program.save(...)
Users can now use complex constants in their models and export to ONNX (#138279)
Improvements
Python Frontend
Add support for fp16 and bf16 to torch.special.i1 (#137899)
Add option to disable checksum computation in torch.save (#137735)
Add support for fp16 for torch.adaptive_pool3d on cpu (#136091)
Add support for fp8* to torch.masked_select (#141928)
Add support for complex fp16 to fill_empty_deterministic_ (#137488)
Remove dependency on numpy for serialization for XLA/open registration devices without numpy (#137444, #137600)
Fix torch.{linalg.}norm complex half support (#133661)
NN Frontend
Allow global module hook to accept keyword arguments (#137403)
Add APIs to separate norm calculation and gradient scaling in nn.utils.clip_grad_norm_ (#139662)
Add Half support for reflection and replication padding on CPU (#135931)
Add weight argument to MSELoss, HuberLoss and L1Loss (#132049)
Gaussian nll loss scalar variance support (#138931)
Added validation for input types for torch.nn.Linear and torch.nn.Bilinear (#135596)
Optim
Improve ReduceLROnPlateau and Optimizer.add_param_group interaction by auto-updating min_lrs (#137637)
Allow SequentialLR to include ChainedScheduler (#133450)
Composability
Decompositions, FakeTensor and meta tensors
Operator decompositions, FakeTensors and meta tensors are used to trace out a graph in torch.compile and torch.export. They received several improvements:
Several operator decomps received improvements/bugfixes:
Improves performance by avoiding atomic add operations in scatter_add for XPU. (#137966)
Inductor
Turn on TORCHINDUCTOR_REORDER_FOR_PEAK_MEMORY by default (#137205). If old behavior is desired, add "reorder_for_peak_memory": False to options in your torch.compile call.
Cache weight tiles in L1D for AMX int8 WoQ GEMM (#136688)
Add and use borrow_arrayref_tensor_as_tensor (#142183)
Support for accelerated sorting with x86-simd-sort (#127936)
Improve exception handling for XPU device initialization. (#141658)
Enhance unit tests for XPU memory allocation. (#141325)
Make XPU libraries publicly accessible for developers. (#136974)
Improve code formatting for XPU oneDNN integration. (#139721)
Make XPU oneDNN headers publicly available for documentation purposes. (#139177)
Ensure XPU compiler version control in CMake for backward compatibility. Users should align their XPU compiler version with supported versions in PyTorch. (#139258)