### GET /torch.xpu/is_available Source: https://docs.pytorch.org/docs/2.10/generated/torch.atleast_1d.html Checks if XPU (Intel GPU) hardware is available on the current system. ```APIDOC ## GET /torch.xpu/is_available ### Description Returns a boolean indicating whether the XPU device is available for use. ### Method GET ### Endpoint torch.xpu.is_available ### Response #### Success Response (200) - **available** (bool) - True if XPU is available, False otherwise. #### Response Example { "available": true } ``` -------------------------------- ### GET /torch.xpu.is_available Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.forward_ad.unpack_dual.html Checks if XPU (Intel GPU) support is available in the current environment. ```APIDOC ## GET /torch.xpu.is_available ### Description Returns a boolean indicating whether the XPU device is available for computation. ### Method GET ### Endpoint torch.xpu.is_available() ### Response #### Success Response (200) - **available** (bool) - True if XPU is available, False otherwise. #### Response Example { "available": true } ``` -------------------------------- ### GET /torch.distributed.elastic.torchrun Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.forward_ad.unpack_dual.html Launches distributed training jobs using the elastic agent for fault tolerance. ```APIDOC ## GET /torch.distributed.elastic.torchrun ### Description Interface for launching distributed training scripts with elastic capabilities. ### Method GET ### Endpoint torchrun --nproc_per_node=N script.py ### Parameters #### Query Parameters - **nproc_per_node** (int) - Required - Number of processes to spawn per node. ### Request Example { "command": "torchrun", "args": ["--nproc_per_node=4", "train.py"] } ### Response #### Success Response (200) - **status** (string) - Execution status of the distributed job. ``` -------------------------------- ### GET /torch.xpu/is_available Source: https://docs.pytorch.org/docs/2.10/generated/torch.atanh.html Checks if the XPU (Intel GPU) device is available on the current system. ```APIDOC ## GET /torch.xpu/is_available ### Description Returns a boolean indicating whether the XPU backend is initialized and available for computation. ### Method GET ### Endpoint torch.xpu.is_available ### Response #### Success Response (200) - **available** (bool) - True if XPU is available, False otherwise. #### Response Example { "available": true } ``` -------------------------------- ### Tensor Creation and Initialization Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.function.FunctionCtx.mark_dirty.html Documentation for functions that create or initialize tensors, such as `atleast_1d`, `block_diag`, `meshgrid`. ```APIDOC ## Tensor Creation and Initialization ### Description Functions for creating and initializing tensors, including ensuring minimum dimensions, creating block diagonal matrices, and generating coordinate grids. ### Method GET ### Endpoint /torch/create ### Parameters #### Path Parameters None #### Query Parameters - **operation** (string) - Required - The creation operation (e.g., `atleast_1d`, `atleast_2d`, `atleast_3d`, `block_diag`, `meshgrid`, `cartesian_prod`). #### Request Body - **input_tensors** (list of Tensors) - Required - The input tensors or values to use for creation. - **indexing** (string) - Optional - For `meshgrid`, specifies the indexing mode ('xy' or 'ij'). ### Request Example ```json { "input_tensors": [[1, 2], [3, 4]], "operation": "block_diag" } ``` ### Response #### Success Response (200) - **output_tensor** (Tensor) - The newly created or initialized tensor. #### Response Example ```json { "output_tensor": [[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]] } ``` ``` -------------------------------- ### GET /torch/accelerator/memory Source: https://docs.pytorch.org/docs/2.10/generated/torch.asin.html Retrieves memory statistics and management utilities for hardware accelerators. ```APIDOC ## GET /torch/accelerator/memory ### Description Provides access to memory management functions for hardware accelerators, allowing users to monitor allocation, reservation, and clear caches. ### Method GET ### Endpoint /torch/accelerator/memory/{action} ### Parameters #### Path Parameters - **action** (string) - Required - The specific memory operation (e.g., 'memory_allocated', 'empty_cache', 'memory_stats') ### Request Example { "action": "memory_allocated" } ### Response #### Success Response (200) - **value** (int/object) - The requested memory metric or confirmation of cache clearing. #### Response Example { "memory_allocated": 1024576 } ``` -------------------------------- ### GET /torch.compiler/compile Source: https://docs.pytorch.org/docs/2.10/generated/torch.atleast_3d.html Compiles a function or module using the PyTorch 2.0 compiler stack. ```APIDOC ## GET /torch.compiler/compile ### Description Compiles a given function or module into an optimized representation using the specified backend. ### Method GET ### Endpoint torch.compiler.compile ### Parameters #### Query Parameters - **model** (callable) - Required - The function or nn.Module to compile. - **backend** (str) - Optional - The compiler backend to use (e.g., 'inductor'). ### Request Example { "model": "my_model", "backend": "inductor" } ### Response #### Success Response (200) - **compiled_model** (object) - The optimized callable object. #### Response Example { "status": "success", "compiled": true } ``` -------------------------------- ### POST /torch/distributed/elastic/torchrun Source: https://docs.pytorch.org/docs/2.10/generated/torch.atleast_2d.html Launches a distributed training job using the elastic agent. ```APIDOC ## POST /torch/distributed/elastic/torchrun ### Description Initiates a distributed training session using the elastic launch utility. ### Method POST ### Endpoint torch.distributed.elastic.torchrun ### Parameters #### Request Body - **nproc_per_node** (int) - Required - Number of processes per node. - **script** (str) - Required - The training script to execute. ### Request Example { "nproc_per_node": 8, "script": "train.py" } ### Response #### Success Response (200) - **job_id** (str) - The unique identifier for the distributed job. #### Response Example { "status": "started", "job_id": "job_12345" } ``` -------------------------------- ### GET /torch.asin Source: https://docs.pytorch.org/docs/2.10/generated/torch.asin.html Calculates the arcsine of each element in the input tensor, returning the result in radians. ```APIDOC ## GET torch.asin ### Description Returns a new tensor with the arcsine of the elements (in radians) in the input tensor. ### Method GET ### Endpoint torch.asin(input, *, out=None) ### Parameters #### Path Parameters - **input** (Tensor) - Required - The input tensor containing values in the range [-1, 1]. #### Request Body - **out** (Tensor) - Optional - The output tensor to store the result. ### Request Example ``` import torch a = torch.tensor([-0.5962, 1.4985, -0.4396, 1.4525]) result = torch.asin(a) ``` ### Response #### Success Response (200) - **output** (Tensor) - A tensor containing the arcsine of the input elements. #### Response Example ``` tensor([-0.6387, nan, -0.4552, nan]) ``` ``` -------------------------------- ### torch.jit Source: https://docs.pytorch.org/docs/2.10/generated/torch.asin.html Tools for TorchScript, PyTorch's subset of Python for optimized performance. ```APIDOC ## Module: torch.jit ### Description The `torch.jit` module provides functionalities for TorchScript, a domain-specific language that allows PyTorch models to be compiled into a static graph representation. This enables optimizations, serialization, and deployment across different environments. ### Key Concepts - **TorchScript Language Reference**: Documentation on the supported subset of Python and PyTorch operations. - **Python Language Reference Coverage**: Details on which Python constructs are supported. - **TorchScript Unsupported PyTorch Constructs**: Information on features not compatible with TorchScript. ### Core Functions - **torch.jit.supported_ops**: Lists supported PyTorch operations in TorchScript. - **torch.jit.script**: Compiles Python code into TorchScript. - **torch.jit.trace**: Traces a Python function with given inputs to create a TorchScript graph. - **torch.jit.script_if_tracing**: Scripts a function only if tracing is enabled. - **torch.jit.trace_module**: Traces a `nn.Module` to create a TorchScript module. - **torch.jit.fork**: Creates a new thread for concurrent execution. - **torch.jit.wait**: Waits for a forked thread to complete. - **torch.jit.freeze**: Optimizes and freezes a TorchScript module. - **torch.jit.optimize_for_inference**: Optimizes a module for inference. - **torch.jit.enable_onednn_fusion**: Enables oneDNN fusion optimizations. - **torch.jit.onednn_fusion_enabled**: Checks if oneDNN fusion is enabled. - **torch.jit.set_fusion_strategy**: Sets the fusion strategy for the JIT compiler. - **strict_fusion**: A flag to control strictness in fusion. - **torch.jit.save**: Saves a TorchScript module to disk. - **torch.jit.load**: Loads a TorchScript module from disk. - **torch.jit.ignore**: Marks a function or method to be ignored by the TorchScript compiler. - **torch.jit.unused**: Marks a variable or attribute as unused. - **torch.jit.interface**: Defines an interface for TorchScript modules. - **torch.jit.isinstance**: Checks if an object is an instance of a TorchScript type. - **Attribute**: Represents an attribute within a TorchScript module. - **torch.jit.annotate**: Annotates types for TorchScript compilation. ``` -------------------------------- ### GET /torch.cuda/device_management Source: https://docs.pytorch.org/docs/2.10/generated/torch.atleast_3d.html Endpoints and methods for managing CUDA device state, availability, and properties. ```APIDOC ## GET /torch.cuda/device_management ### Description Retrieves information about available CUDA devices, their capabilities, and current status. ### Method GET ### Endpoint torch.cuda.is_available / torch.cuda.device_count / torch.cuda.get_device_properties ### Parameters #### Query Parameters - **device_id** (int) - Optional - The index of the GPU to query. ### Response #### Success Response (200) - **is_available** (bool) - Returns true if CUDA is supported. - **device_count** (int) - Total number of available GPUs. - **properties** (object) - Detailed hardware specifications. ### Response Example { "is_available": true, "device_count": 1, "properties": { "name": "NVIDIA GeForce RTX 3090", "major": 8, "minor": 6 } } ``` -------------------------------- ### torch.jit Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.forward_ad.enter_dual_level.html TorchScript API for compiling and optimizing Python code for PyTorch. ```APIDOC ## Module: torch.jit ### Description The `torch.jit` module provides tools for compiling and optimizing PyTorch models using TorchScript. It allows you to convert Python code into a statically typed graph representation that can be run independently of Python. ### Key Concepts - **TorchScript Language Reference**: Documentation on the TorchScript language syntax and features. - **Python Language Reference Coverage**: Information on which Python constructs are supported by TorchScript. - **TorchScript Unsupported PyTorch Constructs**: Details on PyTorch features that are not compatible with TorchScript. ### Core Functions - `torch.jit.script`: Compiles Python code into TorchScript. - `torch.jit.trace`: Traces Python code to create a TorchScript graph. - `torch.jit.script_if_tracing`: Scripts a function if tracing is enabled. - `torch.jit.trace_module`: Traces a `nn.Module` to create a TorchScript module. - `torch.jit.fork`: Forks a computation in TorchScript. - `torch.jit.wait`: Waits for a forked computation to complete. - `torch.jit.freeze`: Freezes a TorchScript module, optimizing it for inference. - `torch.jit.optimize_for_inference`: Optimizes a TorchScript module for inference. - `torch.jit.enable_onednn_fusion`: Enables oneDNN fusion. - `torch.jit.onednn_fusion_enabled`: Checks if oneDNN fusion is enabled. - `torch.jit.set_fusion_strategy`: Sets the fusion strategy. - `torch.jit.save`: Saves a TorchScript module to a file. - `torch.jit.load`: Loads a TorchScript module from a file. - `torch.jit.ignore`: Ignores a function or method during compilation. - `torch.jit.unused`: Marks a variable as unused. - `torch.jit.interface`: Defines an interface for TorchScript objects. - `torch.jit.isinstance`: Checks if an object is an instance of a type in TorchScript. ### Data Types and Annotations - `ScriptModule`: Represents a TorchScript module. - `ScriptFunction`: Represents a TorchScript function. - `Attribute`: Represents an attribute in TorchScript. - `torch.jit.annotate`: Annotates types in TorchScript. ``` -------------------------------- ### torch.jit Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.forward_ad.dual_level.html TorchScript module for compiling and optimizing Python code. ```APIDOC ## Module: torch.jit ### Description The `torch.jit` module provides tools for compiling and optimizing Python code for PyTorch, enabling deployment in environments where Python might not be available or for performance-critical applications. It includes functionalities for scripting, tracing, and managing TorchScript modules and functions. ### Submodules and Key Features - **TorchScript Language Reference**: Documentation on the TorchScript language syntax and semantics. - **Python Language Reference Coverage**: Information on which Python constructs are supported by TorchScript. - **TorchScript Unsupported PyTorch Constructs**: Details on PyTorch features that are not compatible with TorchScript. ### Core Functions - `torch.jit.supported_ops()`: Lists supported operations. - `torch.jit.script()`: Compiles Python code into a TorchScript `ScriptFunction` or `ScriptModule`. - `torch.jit.trace()`: Traces Python code to create a TorchScript `ScriptFunction` or `ScriptModule`. - `torch.jit.script_if_tracing()`: Scripts a function if tracing is enabled. - `torch.jit.trace_module()`: Traces a `nn.Module` to create a TorchScript `ScriptModule`. - `torch.jit.fork()`: Forks a computation in TorchScript. - `torch.jit.wait()`: Waits for a forked computation to complete. - `torch.jit.freeze()`: Freezes a TorchScript module, making it immutable. - `torch.jit.optimize_for_inference()`: Optimizes a TorchScript module for inference. - `torch.jit.enable_onednn_fusion()`: Enables oneDNN fusion. - `torch.jit.onednn_fusion_enabled()`: Checks if oneDNN fusion is enabled. - `torch.jit.set_fusion_strategy()`: Sets the fusion strategy. - `strict_fusion`: A flag for strict fusion. - `torch.jit.save()`: Saves a TorchScript module to a file. - `torch.jit.load()`: Loads a TorchScript module from a file. - `torch.jit.ignore()`: Ignores a function or method during compilation. - `torch.jit.unused()`: Marks a function or method as unused. - `torch.jit.interface()`: Defines an interface for TorchScript. - `torch.jit.isinstance()`: Checks if an object is an instance of a TorchScript type. - `torch.jit.annotate()`: Annotates a variable with a type. ### Key Classes - `ScriptModule`: Represents a compiled PyTorch module in TorchScript. - `ScriptFunction`: Represents a compiled Python function in TorchScript. - `Attribute`: Represents an attribute within a TorchScript module. ``` -------------------------------- ### GET /torch.compiler/compile Source: https://docs.pytorch.org/docs/2.10/generated/torch.atleast_1d.html Compiles a model or function using the PyTorch 2.0 compiler backend. ```APIDOC ## GET /torch.compiler/compile ### Description Compiles a Python function or module using the specified backend to optimize execution performance. ### Method GET ### Endpoint torch.compiler.compile ### Parameters #### Request Body - **model** (Callable) - Required - The function or module to compile. - **backend** (str) - Optional - The compiler backend to use (e.g., 'inductor'). ### Request Example { "model": "my_model_function", "backend": "inductor" } ### Response #### Success Response (200) - **compiled_model** (Callable) - The optimized version of the input model. #### Response Example { "status": "success", "message": "Model compiled successfully" } ``` -------------------------------- ### Configuration and Settings Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.function.FunctionCtx.mark_non_differentiable.html Functions to configure default data types, devices, and printing options for tensors. ```APIDOC ## Configuration and Settings ### Description Functions to configure default data types, devices, and printing options for tensors. ### Endpoints - **torch.set_default_dtype(dtype)**: Sets the default floating-point data type for tensors. - **torch.get_default_dtype()**: Returns the default floating-point data type. - **torch.set_default_device(device)**: Sets the default device for tensor creation. - **torch.get_default_device()**: Returns the default device. - **torch.set_default_tensor_type(value)**: Sets the default tensor type. - **torch.set_printoptions(**kwargs)**: Sets the printing options for tensors. - **torch.set_flush_denormal(flag)**: Sets the flush-denormal mode. ### Request Example ```python torch.set_default_dtype(torch.float64) print(torch.get_default_dtype()) ``` ### Response #### Success Response (200) - **value** - The configured value or the current setting. #### Response Example ```json { "example": "torch.float64" } ``` ``` -------------------------------- ### GET /torch/compiler/compile Source: https://docs.pytorch.org/docs/2.10/generated/torch.atleast_2d.html Compiles a model or function using the PyTorch 2.0+ compiler infrastructure. ```APIDOC ## GET /torch/compiler/compile ### Description Compiles a Python function or module using the specified backend to optimize execution. ### Method GET ### Endpoint torch.compiler.compile ### Parameters #### Request Body - **model** (callable) - Required - The function or module to compile. - **backend** (str) - Optional - The compiler backend to use (e.g., 'inductor'). ### Request Example { "model": "my_model", "backend": "inductor" } ### Response #### Success Response (200) - **compiled_model** (object) - The optimized model instance. #### Response Example { "status": "success", "compiled": true } ``` -------------------------------- ### Array Creation and Utility Functions Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.function.FunctionCtx.mark_non_differentiable.html Functions for creating arrays, binning, and broadcasting. ```APIDOC ## Array Creation and Utility Functions ### Description This section includes functions for creating arrays, binning data, and managing tensor broadcasting. ### Functions - `torch.bincount` - `torch.histc` - `torch.histogram` - `torch.histogramdd` - `torch.gcd` - `torch.lcm` ``` -------------------------------- ### GET /torch.linalg.norm Source: https://docs.pytorch.org/docs/2.10/generated/torch.atleast_3d.html Computes the matrix or vector norm of a given tensor, supporting various p-norms. ```APIDOC ## GET /torch.linalg.norm ### Description Calculates the norm of a tensor. This is a wrapper for various norm computations including vector and matrix norms. ### Method GET ### Endpoint torch.linalg.norm ### Parameters #### Query Parameters - **input** (Tensor) - Required - The input tensor. - **ord** (int/float/str) - Optional - Order of the norm. ### Request Example { "input": "tensor([1.0, 2.0, 3.0])", "ord": 2 } ### Response #### Success Response (200) - **result** (Tensor) - The computed norm value. ### Response Example { "result": 3.7416 } ``` -------------------------------- ### Accelerator Utilities Source: https://docs.pytorch.org/docs/2.10/generated/torch.atleast_3d.html This section provides utilities for managing and interacting with different hardware accelerators like CPU and CUDA. ```APIDOC ## Accelerator Utilities This section covers utilities for managing hardware accelerators. ### General Accelerator Functions - `torch.accelerator.device_count()`: Returns the number of available accelerators. - `torch.accelerator.is_available()`: Checks if an accelerator is available. - `torch.accelerator.current_accelerator()`: Returns the current accelerator. - `torch.accelerator.set_device_index(index)`: Sets the current device index. - `torch.accelerator.set_device_idx(idx)`: Sets the current device index (alias). - `torch.accelerator.current_device_index()`: Returns the current device index. - `torch.accelerator.current_device_idx()`: Returns the current device index (alias). - `torch.accelerator.set_stream(stream)`: Sets the current stream for the accelerator. - `torch.accelerator.current_stream()`: Returns the current stream. - `torch.accelerator.synchronize()`: Synchronizes the accelerator. ### Memory Management - `torch.accelerator.memory.empty_cache()`: Empties the accelerator's memory cache. - `torch.accelerator.memory.get_memory_info(device)`: Returns memory information for a device. - `torch.accelerator.memory.max_memory_allocated(device=None)`: Returns the maximum memory allocated. - `torch.accelerator.memory.max_memory_reserved(device=None)`: Returns the maximum memory reserved. - `torch.accelerator.memory.memory_allocated(device=None)`: Returns the current memory allocated. - `torch.accelerator.memory.memory_reserved(device=None)`: Returns the current memory reserved. - `torch.accelerator.memory.memory_stats(device=None)`: Returns detailed memory statistics. - `torch.accelerator.memory.reset_accumulated_memory_stats(device=None)`: Resets accumulated memory statistics. - `torch.accelerator.memory.reset_peak_memory_stats(device=None)`: Resets peak memory statistics. ### CPU Specific Functions - `torch.cpu.current_device()`: Returns the current CPU device. - `torch.cpu.current_stream(device=None)`: Returns the current CPU stream. - `torch.cpu.is_available()`: Checks if CPU is available. - `torch.cpu.is_initialized()`: Checks if CPU is initialized. - `torch.cpu.synchronize(event=None)`: Synchronizes CPU operations. - `torch.cpu.stream(device=None)`: Returns a CPU stream object. - `torch.cpu.set_device(device)`: Sets the current CPU device. - `torch.cpu.device_count()`: Returns the number of CPU devices. ### CUDA Specific Functions - `torch.cuda.current_device()`: Returns the current CUDA device. - `torch.cuda.current_stream(device=None)`: Returns the current CUDA stream. - `torch.cuda.is_available()`: Checks if CUDA is available. - `torch.cuda.synchronize(device=None)`: Synchronizes CUDA operations. - `torch.cuda.set_device(device)`: Sets the current CUDA device. - `torch.cuda.device_count()`: Returns the number of CUDA devices. ``` -------------------------------- ### GET /torch.compiler.compile Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.forward_ad.unpack_dual.html Compiles a given model or function using the specified backend to optimize performance. ```APIDOC ## GET /torch.compiler.compile ### Description Compiles a Python function or nn.Module into an optimized representation using the specified backend. ### Method GET ### Endpoint torch.compiler.compile(model, *, backend="inductor", ...) ### Parameters #### Request Body - **model** (Callable/nn.Module) - Required - The function or module to compile. - **backend** (str) - Optional - The compiler backend to use (default: "inductor"). ### Request Example { "model": "my_model", "backend": "inductor" } ### Response #### Success Response (200) - **compiled_model** (Callable) - The optimized version of the input model. #### Response Example { "status": "success", "message": "Model compiled successfully" } ``` -------------------------------- ### Quantization Configuration (QConfig) Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.Function.vmap.html This section describes the QConfig objects, which define the quantization configuration, including default configurations for various scenarios. ```APIDOC ## Quantization Configuration (QConfig) ### Description Defines the quantization configuration, specifying observers and fake quantize modules to be used for a given layer or module. ### Methods - `QConfig`: Base class for quantization configurations. - `default_qconfig`: Default quantization configuration. - `default_debug_qconfig`: Default debug quantization configuration. - `default_per_channel_qconfig`: Default per-channel quantization configuration. - `default_dynamic_qconfig`: Default dynamic quantization configuration. - `float16_dynamic_qconfig`: Dynamic quantization configuration for float16. - `float16_static_qconfig`: Static quantization configuration for float16. - `per_channel_dynamic_qconfig`: Dynamic quantization configuration with per-channel granularity. - `float_qparams_weight_only_qconfig`: Weight-only quantization configuration for float qparams. - `default_qat_qconfig`: Default quantization-aware training configuration. - `default_weight_only_qconfig`: Default weight-only quantization configuration. - `default_activation_only_qconfig`: Default activation-only quantization configuration. - `default_qat_qconfig_v2`: Version 2 of the default QAT configuration. ### Aliases in torch.ao - `QConfig` - `default_qconfig` - `default_debug_qconfig` - `default_per_channel_qconfig` - `default_dynamic_qconfig` - `float16_dynamic_qconfig` - `float16_static_qconfig` - `per_channel_dynamic_qconfig` - `float_qparams_weight_only_qconfig` - `default_qat_qconfig` - `default_weight_only_qconfig` - `default_activation_only_qconfig` - `default_qat_qconfig_v2 ``` -------------------------------- ### Accelerator Interface Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.forward_ad.make_dual.html APIs for managing and interacting with hardware accelerators like XPU. ```APIDOC ## Accelerator Interface ### Description Provides a unified interface for interacting with various hardware accelerators, including device management, stream control, and memory operations. ### Device Management - `torch.accelerator.device_count()`: Returns the number of available accelerators. - `torch.accelerator.is_available()`: Checks if an accelerator is available. - `torch.accelerator.current_accelerator()`: Returns the current accelerator. - `torch.accelerator.set_device_index(index)`: Sets the current device index. - `torch.accelerator.set_device_idx(idx)`: Sets the current device index (alias). - `torch.accelerator.current_device_index()`: Returns the index of the current device. - `torch.accelerator.current_device_idx()`: Returns the index of the current device (alias). ### Stream Management - `torch.accelerator.set_stream(stream)`: Sets the current stream for the accelerator. - `torch.accelerator.current_stream()`: Returns the current stream for the accelerator. - `torch.accelerator.synchronize()`: Synchronizes all streams on the current device. ### Memory Management - `torch.accelerator.memory.empty_cache()`: Empties the accelerator's memory cache. - `torch.accelerator.memory.get_memory_info(device=None)`: Returns memory usage information for a device. - `torch.accelerator.memory.max_memory_allocated(device=None)`: Returns the maximum memory allocated on a device. - `torch.accelerator.memory.max_memory_reserved(device=None)`: Returns the maximum memory reserved on a device. - `torch.accelerator.memory.memory_allocated(device=None)`: Returns the current memory allocated on a device. - `torch.accelerator.memory.memory_reserved(device=None)`: Returns the current memory reserved on a device. - `torch.accelerator.memory.memory_stats(device=None)`: Returns detailed memory statistics for a device. - `torch.accelerator.memory.reset_accumulated_memory_stats(device=None)`: Resets accumulated memory statistics. - `torch.accelerator.memory.reset_peak_memory_stats(device=None)`: Resets peak memory statistics. ``` -------------------------------- ### GET /torch/cuda/device_management Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.forward_ad.unpack_dual.html Provides methods to query and manage CUDA device state, availability, and properties. ```APIDOC ## GET /torch/cuda/device_management ### Description Retrieves information about the current CUDA environment, including device counts, names, and capability flags. ### Method GET ### Endpoint torch.cuda.get_device_properties(device) ### Parameters #### Path Parameters - **device** (int/torch.device) - Required - The device index or object to query. ### Response #### Success Response (200) - **name** (string) - The name of the GPU. - **major** (int) - Major compute capability. - **minor** (int) - Minor compute capability. ### Response Example { "name": "NVIDIA GeForce RTX 3090", "major": 8, "minor": 6 } ``` -------------------------------- ### GET /torch.mps/profiler Source: https://docs.pytorch.org/docs/2.10/generated/torch.atleast_3d.html Interface for controlling the Metal Performance Shaders (MPS) profiler on Apple Silicon devices. ```APIDOC ## POST /torch.mps/profiler ### Description Starts or stops the MPS profiler to capture Metal performance data. ### Method POST ### Endpoint torch.mps.profiler.start / torch.mps.profiler.stop ### Parameters #### Request Body - **command** (string) - Required - "start" or "stop". ### Response #### Success Response (200) - **capturing** (bool) - Current capture state. ### Response Example { "capturing": true } ``` -------------------------------- ### torch.fx.experimental.unification.unification_tools Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.forward_ad.enter_dual_level.html Tools for unification of data structures in PyTorch FX. ```APIDOC ## Module: torch.fx.experimental.unification.unification_tools ### Description This module provides a set of tools for performing unification operations on data structures, useful for comparing and merging symbolic representations. ### Functions - `assoc`: Associates a key-value pair. - `assoc_in`: Associates a key-value pair deeply. - `dissoc`: Dissociates a key-value pair. - `first`: Retrieves the first element. - `keyfilter`: Filters a dictionary by keys. - `keymap`: Maps a function over dictionary keys. - `merge`: Merges two dictionaries. - `merge_with`: Merges two dictionaries with a combining function. - `update_in`: Updates a value deeply. - `valfilter`: Filters a dictionary by values. - `valmap`: Maps a function over dictionary values. - `itemfilter`: Filters dictionary items. - `itemmap`: Maps a function over dictionary items. ``` -------------------------------- ### GET /torch/mps/memory_stats Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.forward_ad.unpack_dual.html Retrieves memory usage statistics for Metal Performance Shaders (MPS) devices on macOS. ```APIDOC ## GET /torch/mps/memory_stats ### Description Returns current memory allocation metrics for the MPS backend. ### Method GET ### Endpoint torch.mps.current_allocated_memory() ### Response #### Success Response (200) - **bytes** (int) - Total memory currently allocated by the MPS driver. ### Response Example { "bytes": 104857600 } ``` -------------------------------- ### torch.Tensor Methods Source: https://docs.pytorch.org/docs/2.10/generated/torch.atanh.html This section details various methods available on torch.Tensor objects, covering tensor creation, properties, and mathematical operations. ```APIDOC ## torch.Tensor Methods ### Description Provides a comprehensive list of methods available on `torch.Tensor` objects, enabling manipulation, inspection, and computation with tensors. ### Tensor Creation Methods - `new_tensor(data, dtype, device, requires_grad)`: Creates a new tensor with the same device and dtype as the original tensor. - `new_full(size, fill_value, dtype, device, requires_grad)`: Creates a new tensor filled with a specified value. - `new_empty(size, dtype, device, requires_grad)`: Creates a new empty tensor. - `new_ones(size, dtype, device, requires_grad)`: Creates a new tensor filled with ones. - `new_zeros(size, dtype, device, requires_grad)`: Creates a new tensor filled with zeros. ### Tensor Properties - `is_cuda`: Returns `True` if the tensor is on a CUDA enabled GPU. - `is_quantized`: Returns `True` if the tensor is quantized. - `is_meta`: Returns `True` if the tensor is a meta tensor. - `device`: The device the tensor is located on. - `grad`: The gradient of the tensor. - `ndim`: The number of dimensions of the tensor. - `real`: The real part of a complex tensor. - `imag`: The imaginary part of a complex tensor. - `nbytes`: The number of bytes of the tensor. - `itemsize`: The size of each element in bytes. ### Mathematical and Manipulation Methods - `abs()`: Returns the absolute value of each element. - `abs_()`: In-place absolute value. - `absolute()`: Alias for `abs()`. - `absolute_()`: Alias for `abs_()`. - `acos()`: Computes the arc cosine of each element. - `acos_()`: In-place arc cosine. - `arccos()`: Alias for `acos()`. - `arccos_()`: Alias for `acos_()`. - `add(other, alpha)`: Adds the tensor with `other`. - `add_(other, alpha)`: In-place addition. - `addbmm(batch1, batch2, beta, alpha)`: Adds the result of batch matrix multiplication. - `addbmm_(batch1, batch2, beta, alpha)`: In-place batch matrix multiplication addition. - `addcdiv(value, tensor1, tensor2, value)`: Adds `value * (tensor1 / tensor2)` to the tensor. - `addcdiv_(value, tensor1, tensor2, value)`: In-place `addcdiv`. - `addcmul(value, tensor1, tensor2)`: Adds `value * tensor1 * tensor2` to the tensor. - `addcmul_(value, tensor1, tensor2)`: In-place `addcmul`. - `addmm(mat1, mat2, beta, alpha)`: Adds the result of matrix multiplication. - `addmm_(mat1, mat2, beta, alpha)`: In-place matrix multiplication addition. - `sspaddmm(mat1, mat2, beta, alpha)`: Adds the result of sparse sparse matrix multiplication. - `addmv(mat, vec, beta, alpha)`: Adds the result of matrix-vector multiplication. - `addmv_(mat, vec, beta, alpha)`: In-place matrix-vector multiplication addition. - `addr(vec1, vec2, beta, alpha)`: Adds the result of outer product of vectors. - `addr_(vec1, vec2, beta, alpha)`: In-place outer product addition. - `adjoint()`: Returns the adjoint of a matrix. - `allclose(other, rtol, atol, equal_nan)`: Checks if two tensors are element-wise equal within a given tolerance. - `amax(dim, keepdim)`: Returns the maximum value of each element in the input tensor. - `amin(dim, keepdim)`: Returns the minimum value of each element in the input tensor. - `aminmax(dim, keepdim)`: Returns the maximum and minimum values of each element in the input tensor. - `angle()`: Returns the angle of each element. - `apply_(func)`: Applies a function to each element of the tensor in-place. - `argmax(dim, keepdim)`: Returns the index of the maximum value of each element. - `argmin(dim, keepdim)`: Returns the index of the minimum value of each element. - `argsort(dim, descending)`: Returns the indices that sort a tensor. - `argwhere()`: Returns the indices of elements that are non-zero. - `asin()`: Computes the arc sine of each element. - `asin_()`: In-place arc sine. - `arcsin()`: Alias for `asin()`. - `arcsin_()`: Alias for `asin_()`. - `as_strided(size, stride, storage_offset)`: Creates a tensor pointing to the same storage as the original tensor but with different size and stride. - `atan()`: Computes the arc tangent of each element. - `atan_()`: In-place arc tangent. - `arctan()`: Alias for `atan()`. - `arctan_()`: Alias for `atan_()`. - `atan2(other)`: Computes the arc tangent of each element in `other` with respect to the corresponding element in the tensor. - `atan2_()`: In-place `atan2`. - `arctan2(other)`: Alias for `atan2()`. - `arctan2_(other)`: Alias for `atan2_()`. - `all(dim, keepdim)`: Checks if all elements in the given dimension are true. - `any(dim, keepdim)`: Checks if any element in the given dimension is true. - `backward(gradient, retain_graph, create_graph)`: Computes the gradient of the tensor with respect to the graph. - `baddbmm(batch1, batch2, beta, alpha)`: Adds the result of batch matrix multiplication. - `baddbmm_(batch1, batch2, beta, alpha)`: In-place `baddbmm`. - `bernoulli()`: Returns a tensor with Bernoulli distribution samples. - `bernoulli_()`: In-place Bernoulli distribution samples. - `bfloat16()`: Casts the tensor to bfloat16. - `bincount(weights, minlength)`: Counts the occurrences of each value in the input tensor. - `bitwise_not()`: Computes the bitwise NOT of the tensor. - `bitwise_not_()`: In-place bitwise NOT. - `bitwise_and(other)`: Computes the bitwise AND of the tensor with `other`. - `bitwise_and_(other)`: In-place bitwise AND. - `bitwise_or(other)`: Computes the bitwise OR of the tensor with `other`. - `bitwise_or_(other)`: In-place bitwise OR. - `bitwise_xor(other)`: Computes the bitwise XOR of the tensor with `other`. - `bitwise_xor_(other)`: In-place bitwise XOR. - `bitwise_left_shift(other)`: Computes the bitwise left shift. - `bitwise_left_shift_(other)`: In-place bitwise left shift. - `bitwise_right_shift(other)`: Computes the bitwise right shift. - `bitwise_right_shift_(other)`: In-place bitwise right shift. - `bmm(batch2)`: Performs batch matrix multiplication. - `bool()`: Casts the tensor to boolean. - `byte()`: Casts the tensor to unsigned byte. - `broadcast_to(size)`: Broadcasts the tensor to a specified size. - `cauchy_()`: Fills the tensor with Cauchy random numbers. - `ceil()`: Returns the ceiling of each element. - `ceil_()`: In-place ceiling. - `char()`: Casts the tensor to character. - `cholesky()`: Computes the Cholesky decomposition of a matrix. - `cholesky_inverse()`: Computes the inverse of the Cholesky decomposition of a matrix. ### Notes - Methods ending with `_` perform the operation in-place. - Many methods have `dim`, `keepdim`, `dtype`, `device`, `requires_grad` parameters that control the operation's behavior and the resulting tensor's properties. ``` -------------------------------- ### Quantization Observers and Utilities Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.Function.vmap.html This section covers the base classes and specific implementations for observers used in quantization, along with utility functions for managing observer states. ```APIDOC ## Quantization Observers and Utilities ### Description Provides observer classes for tracking statistics during quantization, including MinMax, MovingAverage, and Histogram observers, as well as functions for state management. ### Methods - `ObserverBase`: Base class for all observers. - `MinMaxObserver`: Observes the minimum and maximum values. - `MovingAverageMinMaxObserver`: MinMax observer with moving average. - `PerChannelMinMaxObserver`: MinMax observer for per-channel statistics. - `MovingAveragePerChannelMinMaxObserver`: Per-channel MinMax observer with moving average. - `HistogramObserver`: Observes histogram of values. - `PlaceholderObserver`: A placeholder observer. - `RecordingObserver`: Records observer state. - `NoopObserver`: No-operation observer. - `get_observer_state_dict`: Gets the state dictionary of observers. - `load_observer_state_dict`: Loads the state dictionary into observers. - `default_observer`: Default observer configuration. - `default_placeholder_observer`: Default placeholder observer configuration. - `default_debug_observer`: Default debug observer configuration. - `default_weight_observer`: Default weight observer configuration. - `default_histogram_observer`: Default histogram observer configuration. - `default_per_channel_weight_observer`: Default per-channel weight observer configuration. - `default_dynamic_quant_observer`: Default dynamic quantization observer configuration. - `default_float_qparams_observer`: Default observer for float qparams. ### Aliases in torch.ao - `ObserverBase` - `MinMaxObserver` - `MovingAverageMinMaxObserver` - `PerChannelMinMaxObserver` - `MovingAveragePerChannelMinMaxObserver` - `HistogramObserver` - `PlaceholderObserver - `RecordingObserver - `NoopObserver - `get_observer_state_dict - `load_observer_state_dict - `default_observer - `default_placeholder_observer - `default_debug_observer - `default_weight_observer - `default_histogram_observer - `default_per_channel_weight_observer - `default_dynamic_quant_observer - `default_float_qparams_observer ``` -------------------------------- ### torch.cuda Stream Management Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.backward.html Functions for managing CUDA streams, including getting the current stream and synchronizing operations. ```APIDOC ## GET /torch/cuda/current_stream ### Description Returns the current CUDA stream for the current device. ### Method GET ### Endpoint /torch/cuda/current_stream ### Parameters None ### Response #### Success Response (200) - **stream_id** (string) - Identifier for the current stream. #### Response Example ```json { "stream_id": "" } ``` ## POST /torch/cuda/set_stream ### Description Sets the current CUDA stream for the current device. ### Method POST ### Endpoint /torch/cuda/set_stream ### Parameters #### Query Parameters - **stream_id** (string) - Required - The identifier of the stream to set as current. ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Stream set to " } ``` ## POST /torch/cuda/synchronize ### Description Blocks until all CUDA operations on the current device have completed. ### Method POST ### Endpoint /torch/cuda/synchronize ### Parameters None ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "CUDA synchronization complete." } ``` ``` -------------------------------- ### Tensor Shape and Dimension Operations Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.forward_ad.enter_dual_level.html This section covers operations related to the shape and dimensions of PyTorch Tensors, including getting dimensions, sizes, and reshaping. ```APIDOC ## Tensor Shape and Dimension Operations ### Description Provides methods for querying and manipulating tensor shapes and dimensions. ### Methods - `torch.Tensor.ndimension()`: Returns the number of dimensions of the tensor. - `torch.Tensor.nelement()`: Returns the total number of elements in the tensor. - `torch.Tensor.numel()`: Alias for `nelement()`. - `torch.Tensor.shape`: Returns the shape of the tensor as a tuple. - `torch.Tensor.size()`: Returns the size of the tensor. - `torch.Tensor.squeeze()`: Removes dimensions of size 1 from the tensor. - `torch.Tensor.squeeze_()`: Removes dimensions of size 1 from the tensor in-place. - `torch.Tensor.movedim()`: Moves dimensions of the tensor to the given position. - `torch.Tensor.moveaxis()`: Moves dimensions of the tensor to the given position. - `torch.Tensor.permute()`: Permutes the dimensions of the tensor. - `torch.Tensor.ravel()`: Returns a flattened tensor. - `torch.Tensor.roll()`: Rolls the tensor along the given dimension(s). - `torch.Tensor.rot90()`: Rotates the tensor by 90 degrees along the specified dimensions. ``` -------------------------------- ### torch.compiler API Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.function.FunctionCtx.mark_dirty.html APIs for compiling PyTorch models for performance optimization. ```APIDOC ## torch.compiler API ### Description The `torch.compiler` module provides functionalities to compile PyTorch models for improved performance. It allows users to specify compilation backends, control graph capture, and manage compilation settings. ### Core Functions - **`torch.compiler.compile(model, *, backend='inductor', ...)`**: Compiles a PyTorch model using the specified backend. - **`torch.compiler.reset()`**: Resets the compiler cache and state. - **`torch.compiler.allow_in_graph(obj)`**: Allows a Python object to be captured within the compiled graph. - **`torch.compiler.substitute_in_graph(old, new)`**: Substitutes occurrences of `old` with `new` within the graph. - **`torch.compiler.assume_constant_result(fn)`**: Assumes that the result of function `fn` is constant within the graph. - **`torch.compiler.list_backends()`**: Lists the available compilation backends. - **`torch.compiler.disable()`**: Disables the PyTorch compiler globally. - **`torch.compiler.set_stance(stance)`**: Sets the compiler's stance or behavior. ``` -------------------------------- ### Define Custom Autograd Function Forward Pass (Separate ctx) Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.Function.forward.html This snippet illustrates the second usage pattern for defining the `forward` method of a custom autograd Function, where `forward` does not accept `ctx`. The `setup_context` method must be overridden to handle context setup. ```python @staticmethod def forward(*args: Any, **kwargs: Any) -> Any: pass @staticmethod def setup_context(ctx: Any, inputs: Tuple[Any, ...], output: Any) -> None: pass ``` -------------------------------- ### Marking Tensors as Modified with mark_dirty Source: https://docs.pytorch.org/docs/2.10/generated/torch.autograd.function.FunctionCtx.mark_dirty.html Demonstrates how to use `ctx.mark_dirty(x)` within a custom PyTorch Function's `forward` method to indicate that a tensor `x` has been modified in-place. This is crucial for maintaining the integrity of gradient calculations, especially when dealing with operations that alter tensors directly. The example shows a scenario where failing to mark a dirty tensor can lead to runtime errors during gradient computation. ```python class Inplace(Function): @staticmethod def forward(ctx, x): x_npy = x.numpy() # x_npy shares storage with x x_npy += 1 ctx.mark_dirty(x) return x @staticmethod @once_differentiable def backward(ctx, grad_output): return grad_output a = torch.tensor(1., requires_grad=True, dtype=torch.double).clone() b = a * a Inplace.apply(a) # This would lead to wrong gradients! # but the engine would not know unless we mark_dirty b.backward() # RuntimeError: one of the variables needed for gradient # computation has been modified by an inplace operation ```