Rate this Page

torch#

Created On: Dec 23, 2016 | Last Updated On: May 11, 2026

The torch package contains data structures for multi-dimensional tensors and defines mathematical operations over these tensors. Additionally, it provides many utilities for efficient serialization of Tensors and arbitrary types, and other useful utilities.

It has a CUDA counterpart, that enables you to run your tensor computations on an NVIDIA GPU with compute capability >= 3.0.

Tensors#

is_tensor

Returns True if obj is a PyTorch tensor.

is_storage

Returns True if obj is a PyTorch storage object.

is_complex

Returns True if the data type of input is a complex data type i.e., one of torch.complex64, and torch.complex128.

is_conj

Returns True if the input is a conjugated tensor, i.e. its conjugate bit is set to True.

is_floating_point

Returns True if the data type of input is a floating point data type i.e., one of torch.float64, torch.float32, torch.float16, and torch.bfloat16.

is_inference

Returns True if input is an inference tensor.

is_neg

is_nonzero

Returns True if the input is a single element tensor which is not equal to zero after type conversions.

is_same_size

is_signed

set_default_dtype

Sets the default floating point dtype to d.

get_default_dtype

Get the current default floating point torch.dtype.

set_default_device

Sets the default torch.Tensor to be allocated on device.

get_default_device

Gets the default torch.Tensor to be allocated on device

set_default_tensor_type

numel

Returns the total number of elements in the input tensor.

set_printoptions

Set options for printing.

set_flush_denormal

Disables denormal floating numbers on CPU.

Creation Ops#

Note

Random sampling creation ops are listed under Random sampling and include: torch.rand() torch.rand_like() torch.randn() torch.randn_like() torch.randint() torch.randint_like() torch.randperm() You may also use torch.empty() with the In-place random sampling methods to create torch.Tensor s with values sampled from a broader range of distributions.

tensor

Constructs a tensor with no autograd history (also known as a "leaf tensor", see Autograd mechanics) by copying data.

sparse_coo_tensor

Constructs a sparse tensor in COO(rdinate) format with specified values at the given indices.

sparse_csr_tensor

Constructs a sparse tensor in CSR (Compressed Sparse Row) with specified values at the given crow_indices and col_indices.

sparse_csc_tensor

Constructs a sparse tensor in CSC (Compressed Sparse Column) with specified values at the given ccol_indices and row_indices.

sparse_bsr_tensor

Constructs a sparse tensor in BSR (Block Compressed Sparse Row)) with specified 2-dimensional blocks at the given crow_indices and col_indices.

sparse_bsc_tensor

Constructs a sparse tensor in BSC (Block Compressed Sparse Column)) with specified 2-dimensional blocks at the given ccol_indices and row_indices.

asarray

Converts obj to a tensor.

as_tensor

Converts data into a tensor, sharing data and preserving autograd history if possible.

as_strided

Create a view of an existing torch.Tensor input with specified size, stride and storage_offset.

from_file

Creates a CPU tensor with a storage backed by a memory-mapped file.

from_numpy

Creates a Tensor from a numpy.ndarray.

from_dlpack

Converts a tensor from an external library into a torch.Tensor.

frombuffer

Creates a 1-dimensional Tensor from an object that implements the Python buffer protocol.

zeros

Returns a tensor filled with the scalar value 0, with the shape defined by the variable argument size.

zeros_like

Returns a tensor filled with the scalar value 0, with the same size as input.

ones

Returns a tensor filled with the scalar value 1, with the shape defined by the variable argument size.

ones_like

Returns a tensor filled with the scalar value 1, with the same size as input.

arange

Returns a 1-D tensor of size endstartstep\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil with values from the interval [start, end) taken with common difference step beginning from start.

range

Returns a 1-D tensor of size endstartstep+1\left\lfloor \frac{\text{end} - \text{start}}{\text{step}} \right\rfloor + 1 with values from start to end with step step.

linspace

Creates a one-dimensional tensor of size steps whose values are evenly spaced from start to end, inclusive.

logspace

Creates a one-dimensional tensor of size steps whose values are evenly spaced from basestart{{\text{{base}}}}^{{\text{{start}}}} to baseend{{\text{{base}}}}^{{\text{{end}}}}, inclusive, on a logarithmic scale with base base.

eye

Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.

empty

Returns a tensor filled with uninitialized data.

empty_like

Returns an uninitialized tensor with the same size as input.

empty_permuted

Creates an uninitialized, non-overlapping and dense tensor with the specified size, with physical_layout specifying how the dimensions are physically laid out in memory (each logical dimension is listed from outermost to innermost).

empty_quantized

empty_strided

Creates a tensor with the specified size and stride and filled with undefined data.

full

Creates a tensor of size size filled with fill_value.

full_like

Returns a tensor with the same size as input filled with fill_value.

quantize_per_tensor

Converts a float tensor to a quantized tensor with given scale and zero point.

quantize_per_tensor_dynamic

Converts a float tensor to a quantized tensor with scale and zero_point calculated dynamically based on the input.

quantize_per_channel

Converts a float tensor to a per-channel quantized tensor with given scales and zero points.

dequantize

Returns an fp32 Tensor by dequantizing a quantized Tensor

complex

Constructs a complex tensor with its real part equal to real and its imaginary part equal to imag.

polar

Constructs a complex tensor whose elements are Cartesian coordinates corresponding to the polar coordinates with absolute value abs and angle angle.

scalar_tensor

heaviside

Computes the Heaviside step function for each element in input.

Indexing, Slicing, Joining, Mutating Ops#

adjoint

Returns a view of the tensor conjugated and with the last two dimensions transposed.

alias_copy

Performs the same operation as torch.alias(), but all output tensors are freshly created instead of aliasing the input.

argwhere

Returns a tensor containing the indices of all non-zero elements of input.

as_strided_copy

Performs the same operation as torch.as_strided(), but all output tensors are freshly created instead of aliasing the input.

as_strided_scatter

Embeds the values of the src tensor into input along the elements corresponding to the result of calling input.as_strided(size, stride, storage_offset).

cat

Concatenates the given sequence of tensors in tensors in the given dimension.

ccol_indices_copy

col_indices_copy

Performs the same operation as torch.col_indices(), but all output tensors are freshly created instead of aliasing the input.

concat

Alias of torch.cat().

concatenate

Alias of torch.cat().

conj

Returns a view of input with a flipped conjugate bit.

chunk

Attempts to split a tensor into the specified number of chunks.

crow_indices_copy

Performs the same operation as torch.crow_indices(), but all output tensors are freshly created instead of aliasing the input.

detach

detach_copy

Performs the same operation as torch.detach(), but all output tensors are freshly created instead of aliasing the input.

diagonal_copy

Performs the same operation as torch.diagonal(), but all output tensors are freshly created instead of aliasing the input.

dsplit

Splits input, a tensor with three or more dimensions, into multiple tensors depthwise according to indices_or_sections.

column_stack

Creates a new tensor by horizontally stacking the tensors in tensors.

dstack

Stack tensors in sequence depthwise (along third axis).

expand_copy

Performs the same operation as torch.Tensor.expand(), but all output tensors are freshly created instead of aliasing the input.

fill

gather

Gathers values along an axis specified by dim.

hsplit

Splits input, a tensor with one or more dimensions, into multiple tensors horizontally according to indices_or_sections.

hstack

Stack tensors in sequence horizontally (column wise).

index_add

See index_add_() for function description.

index_copy

See index_copy_() for function description.

index_put_

index_reduce

See index_reduce_() for function description.

index_select

Returns a new tensor which indexes the input tensor along dimension dim using the entries in index.

indices_copy

Performs the same operation as torch.indices(), but all output tensors are freshly created instead of aliasing the input.

masked_fill

masked_select

Returns a new 1-D tensor which indexes the input tensor according to the boolean mask mask which is a BoolTensor.

movedim

Moves the dimension(s) of input at the position(s) in source to the position(s) in destination.

moveaxis

Alias for torch.movedim().

narrow

Returns a new tensor that is a narrowed version of input tensor.

narrow_copy

Same as Tensor.narrow() except this returns a copy rather than shared storage.

nonzero

nonzero_static

permute

Returns a view of the original tensor input with its dimensions permuted.

permute_copy

Performs the same operation as torch.permute(), but all output tensors are freshly created instead of aliasing the input.

put

reshape

Returns a tensor with the same data and number of elements as input, but with the specified shape.

row_indices_copy

row_stack

Alias of torch.vstack().

select

Slices the input tensor along the selected dimension at the given index.

select_copy

Performs the same operation as torch.select(), but all output tensors are freshly created instead of aliasing the input.

scatter

Out-of-place version of torch.Tensor.scatter_()

diagonal_scatter

Embeds the values of the src tensor into input along the diagonal elements of input, with respect to dim1 and dim2.

select_scatter

Embeds the values of the src tensor into input at the given index.

slice_copy

Performs the same operation as torch.slice(), but all output tensors are freshly created instead of aliasing the input.

slice_inverse

slice_scatter

Embeds the values of the src tensor into input at the given dimension.

scatter_add

Out-of-place version of torch.Tensor.scatter_add_()

scatter_reduce

Out-of-place version of torch.Tensor.scatter_reduce_()

segment_reduce

Perform a segment reduction operation on the input tensor along the specified axis.

split

Splits the tensor into chunks.

split_copy

Performs the same operation as torch.split(), but all output tensors are freshly created instead of aliasing the input.

split_with_sizes_copy

Performs the same operation as torch.split_with_sizes(), but all output tensors are freshly created instead of aliasing the input.

squeeze

Returns a tensor with all specified dimensions of input of size 1 removed.

squeeze_copy

Performs the same operation as torch.squeeze(), but all output tensors are freshly created instead of aliasing the input.

stack

Concatenates a sequence of tensors along a new dimension.

swapaxes

Alias for torch.transpose().

swapdims

Alias for torch.transpose().

t

Expects input to be <= 2-D tensor and transposes dimensions 0 and 1.

t_copy

Performs the same operation as torch.t(), but all output tensors are freshly created instead of aliasing the input.

take

Returns a new tensor with the elements of input at the given indices.

take_along_dim

Selects values from input at the 1-dimensional indices from indices along the given dim.

tensor_split

Splits a tensor into multiple sub-tensors, all of which are views of input, along dimension dim according to the indices or number of sections specified by indices_or_sections.

tile

Constructs a tensor by repeating the elements of input.

transpose

Returns a tensor that is a transposed version of input.

transpose_copy

Performs the same operation as torch.transpose(), but all output tensors are freshly created instead of aliasing the input.

unbind

Removes a tensor dimension.

unbind_copy

Performs the same operation as torch.unbind(), but all output tensors are freshly created instead of aliasing the input.

unfold_copy

Performs the same operation as torch.unfold(), but all output tensors are freshly created instead of aliasing the input.

unravel_index

Converts a tensor of flat indices into a tuple of coordinate tensors that index into an arbitrary tensor of the specified shape.

unsqueeze

Returns a new tensor with a dimension of size one inserted at the specified position.

unsqueeze_copy

Performs the same operation as torch.unsqueeze(), but all output tensors are freshly created instead of aliasing the input.

values_copy

Performs the same operation as torch.values(), but all output tensors are freshly created instead of aliasing the input.

view_as_complex_copy

Performs the same operation as torch.view_as_complex(), but all output tensors are freshly created instead of aliasing the input.

view_as_real_copy

Performs the same operation as torch.view_as_real(), but all output tensors are freshly created instead of aliasing the input.

view_copy

Performs the same operation as torch.view(), but all output tensors are freshly created instead of aliasing the input.

vsplit

Splits input, a tensor with two or more dimensions, into multiple tensors vertically according to indices_or_sections.

vstack

Stack tensors in sequence vertically (row wise).

where

Return a tensor of elements selected from either input or other, depending on condition.

Accelerators#

Within the PyTorch repo, we define an “Accelerator” as a torch.device that is being used alongside a CPU to speed up computation. These devices use an asynchronous execution scheme, using torch.Stream and torch.Event as their main way to perform synchronization. We also assume that only one such accelerator can be available at once on a given host. This allows us to use the current accelerator as the default device for relevant concepts such as pinned memory, Stream device_type, FSDP, etc.

As of today, accelerator devices are (in no particular order) “CUDA”, “MTIA”, “XPU”, “MPS”, “HPU”, and PrivateUse1 (many device not in the PyTorch repo itself).

Many tools in the PyTorch Ecosystem use fork to create subprocesses (for example dataloading or intra-op parallelism), it is thus important to delay as much as possible any operation that would prevent further forks. This is especially important here as most accelerator’s initialization has such effect. In practice, you should keep in mind that checking torch.accelerator.current_accelerator() is a compile-time check by default, it is thus always fork-safe. On the contrary, passing the check_available=True flag to this function or calling torch.accelerator.is_available() will usually prevent later fork.

Some backends provide an experimental opt-in option to make the runtime availability check fork-safe. When using the CUDA device PYTORCH_NVML_BASED_CUDA_CHECK=1 can be used for example.

Stream

An in-order queue of executing the respective tasks asynchronously in first in first out (FIFO) order.

Event

Query and record Stream status to identify or control dependencies across Stream and measure timing.

Generators#

Random sampling#

seed

Sets the seed for generating random numbers to a non-deterministic random number on all devices.

manual_seed

Sets the seed for generating random numbers on all devices.

initial_seed

Returns the initial seed for generating random numbers as a Python long.

get_rng_state

Returns the random number generator state as a torch.ByteTensor.

set_rng_state

Sets the random number generator state.

torch.default_generator Returns the default CPU torch.Generator#

bernoulli

Draws binary random numbers (0 or 1) from a Bernoulli distribution.

multinomial

Returns a tensor where each row contains num_samples indices sampled from the multinomial (a stricter definition would be multivariate, refer to torch.distributions.multinomial.Multinomial for more details) probability distribution located in the corresponding row of tensor input.

normal

Returns a tensor of random numbers drawn from separate normal distributions whose mean and standard deviation are given.

poisson

Returns a tensor of the same size as input with each element sampled from a Poisson distribution with rate parameter given by the corresponding element in input i.e.,

rand

Returns a tensor filled with random numbers from a uniform distribution on the interval [0,1)[0, 1)

rand_like

Returns a tensor with the same size as input that is filled with random numbers from a uniform distribution on the interval [0,1)[0, 1).

randint

Returns a tensor filled with random integers generated uniformly between low (inclusive) and high (exclusive).

randint_like

Returns a tensor with the same shape as Tensor input filled with random integers generated uniformly between low (inclusive) and high (exclusive).

randn

Returns a tensor filled with random numbers from a normal distribution with mean 0 and variance 1 (also called the standard normal distribution).

randn_like

Returns a tensor with the same size as input that is filled with random numbers from a normal distribution with mean 0 and variance 1.

randperm

Returns a random permutation of integers from 0 to n - 1.

In-place random sampling#

There are a few more in-place random sampling functions defined on Tensors as well. Click through to refer to their documentation:

Quasi-random sampling#

quasirandom.SobolEngine

The torch.quasirandom.SobolEngine is an engine for generating (scrambled) Sobol sequences.

Serialization#

save

Saves an object to a disk file.

load

Loads an object saved with torch.save() from a file.

torch.serialization.check_module_version_greater_or_equal(module, req_version_tuple, error_if_malformed=True)[source]#

Check if a module’s version satisfies requirements

Usually, a module’s version string will be like ‘x.y.z’, which would be represented as a tuple (x, y, z), but sometimes it could be an unexpected format. If the version string does not match the given tuple’s format up to the length of the tuple, then error and exit or emit a warning.

Parameters:
  • module – the module to check the version of

  • req_version_tuple – tuple (usually of ints) representing the required version

  • error_if_malformed – whether we should exit if module version string is malformed

Returns:

bool

Return type:

requirement_is_met

torch.serialization.default_restore_location(storage, location)[source]#

Restores storage using a deserializer function registered for the location.

This function looks in the registry for deserializer functions that match the location. If found, it attempts to use them, in priority order, to restore storage until one returns a not None result. If no deserializer can be found in the registry, or all found fail to bear a result, it raises a RuntimeError.

Parameters:
  • storage (STORAGE) – the storage object to restore

  • location (str) – the location tag associated with the storage object

Returns:

Optional[STORAGE]

Return type:

storage

Raises:

RuntimeError – If no deserializer matching location is found in the registry or if all matching ones return None.

Parallelism#

fork

get_num_threads

Returns the number of threads used for parallelizing CPU operations

init_num_threads

init_num_threads()

set_num_threads

Sets the number of threads used for intraop parallelism on CPU.

get_num_interop_threads

Returns the number of threads used for inter-op parallelism on CPU (e.g. in JIT interpreter).

set_num_interop_threads

Sets the number of threads used for interop parallelism (e.g. in JIT interpreter) on CPU.

wait

Locally disabling gradient computation#

The context managers torch.no_grad(), torch.enable_grad(), and torch.set_grad_enabled() are helpful for locally disabling and enabling gradient computation. See Locally disabling gradient computation for more details on their usage. These context managers are thread local, so they won’t work if you send work to another thread using the threading module, etc.

Examples:

>>> x = torch.zeros(1, requires_grad=True)
>>> with torch.no_grad():
...     y = x * 2
>>> y.requires_grad
False

>>> is_train = False
>>> with torch.set_grad_enabled(is_train):
...     y = x * 2
>>> y.requires_grad
False

>>> torch.set_grad_enabled(True)  # this can also be used as a function
>>> y = x * 2
>>> y.requires_grad
True

>>> torch.set_grad_enabled(False)
>>> y = x * 2
>>> y.requires_grad
False

no_grad

Context-manager that disables gradient calculation.

enable_grad

Context-manager that enables gradient calculation.

autograd.grad_mode.set_grad_enabled

Context-manager that sets gradient calculation on or off.

is_grad_enabled

Returns True if grad mode is currently enabled.

autograd.grad_mode.inference_mode

Context manager that enables or disables inference mode.

is_inference_mode_enabled

Returns True if inference mode is currently enabled.

Math operations#

Constants#

e

Euler’s number, the base of natural logarithms (~2.7183). Alias for math.e.

inf

A floating-point positive infinity. Alias for math.inf.

nan

A floating-point “not a number” value. This value is not a legal number. Alias for math.nan.

pi

The ratio of a circle’s circumference to its diameter (~3.1416). Alias for math.pi.

Pointwise Ops#

abs

Computes the absolute value of each element in input.

abs_

absolute

Alias for torch.abs()

acos

Returns a new tensor with the arccosine (in radians) of each element in input.

acos_

arccos

Alias for torch.acos().

arccos_

acosh

Returns a new tensor with the inverse hyperbolic cosine of the elements of input.

acosh_

arccosh

Alias for torch.acosh().

arccosh_

add

Adds other, scaled by alpha, to input.

addcdiv

Performs the element-wise division of tensor1 by tensor2, multiplies the result by the scalar value and adds it to input.

addcmul

Performs the element-wise multiplication of tensor1 by tensor2, multiplies the result by the scalar value and adds it to input.

angle

Computes the element-wise angle (in radians) of the given input tensor.

asin

Returns a new tensor with the arcsine of the elements (in radians) in the input tensor.

asin_

arcsin

Alias for torch.asin().

arcsin_

asinh

Returns a new tensor with the inverse hyperbolic sine of the elements of input.

asinh_

arcsinh

Alias for torch.asinh().

arcsinh_

atan

Returns a new tensor with the arctangent of the elements (in radians) in the input tensor.

atan_

arctan

Alias for torch.atan().

arctan_

atanh

Returns a new tensor with the inverse hyperbolic tangent of the elements of input.

atanh_

arctanh

Alias for torch.atanh().

arctanh_

atan2

Element-wise arctangent of inputi/otheri\text{input}_{i} / \text{other}_{i} with consideration of the quadrant.

arctan2

Alias for torch.atan2().

bitwise_not

Computes the bitwise NOT of the given input tensor.

bitwise_and

Computes the bitwise AND of input and other.

bitwise_or

Computes the bitwise OR of input and other.

bitwise_xor

Computes the bitwise XOR of input and other.

bitwise_left_shift

Computes the left arithmetic shift of input by other bits.

bitwise_right_shift

Computes the right arithmetic shift of input by other bits.

ceil

Returns a new tensor with the ceil of the elements of input, the smallest integer greater than or equal to each element.

ceil_

clamp

Clamps all elements in input into the range [ min, max ].

clamp_

clamp_max_

clamp_min_

clip

Alias for torch.clamp().

clip_

conj_physical

Computes the element-wise conjugate of the given input tensor.

conj_physical_

copysign

Create a new floating-point tensor with the magnitude of input and the sign of other, elementwise.

cos

Returns a new tensor with the cosine of the elements of input given in radians.

cos_

cosh

Returns a new tensor with the hyperbolic cosine of the elements of input.

cosh_

deg2rad

Returns a new tensor with each of the elements of input converted from angles in degrees to radians.

deg2rad_

div

Divides each element of the input input by the corresponding element of other.

divide

Alias for torch.div().

digamma

Alias for torch.special.digamma().

erf

Alias for torch.special.erf().

erf_

erfc

Alias for torch.special.erfc().

erfc_

erfinv

Alias for torch.special.erfinv().

exp

Returns a new tensor with the exponential of the elements of the input tensor input.

exp_

exp2

Alias for torch.special.exp2().

exp2_

expm1

Alias for torch.special.expm1().

expm1_

fake_quantize_per_channel_affine

Returns a new tensor with the data in input fake quantized per channel using scale, zero_point, quant_min and quant_max, across the channel specified by axis.

fake_quantize_per_tensor_affine

Returns a new tensor with the data in input fake quantized using scale, zero_point, quant_min and quant_max.

fill_

fix

Alias for torch.trunc()

fix_

float_power

Raises input to the power of exponent, elementwise, in double precision.

floor

Returns a new tensor with the floor of the elements of input, the largest integer less than or equal to each element.

floor_

floor_divide

fmod

Applies C++'s std::fmod entrywise.

frac

Computes the fractional portion of each element in input.

frac_

frexp

Decomposes input into mantissa and exponent tensors such that input=mantissa×2exponent\text{input} = \text{mantissa} \times 2^{\text{exponent}}.

gradient

Estimates the gradient of a function g:RnRg : \mathbb{R}^n \rightarrow \mathbb{R} in one or more dimensions using the second-order accurate central differences method and either first or second order estimates at the boundaries.

imag

Returns a new tensor containing imaginary values of the self tensor.

ldexp

Multiplies input by 2 ** other.

ldexp_

lerp

Does a linear interpolation of two tensors start (given by input) and end based on a scalar or tensor weight and returns the resulting out tensor.

lgamma

Computes the natural logarithm of the absolute value of the gamma function on input.

log

Returns a new tensor with the natural logarithm of the elements of input.

log_

log10

Returns a new tensor with the logarithm to the base 10 of the elements of input.

log10_

log1p

Returns a new tensor with the natural logarithm of (1 + input).

log1p_

log2

Returns a new tensor with the logarithm to the base 2 of the elements of input.

log2_

logaddexp

Logarithm of the sum of exponentiations of the inputs.

logaddexp2

Logarithm of the sum of exponentiations of the inputs in base-2.

logical_and

Computes the element-wise logical AND of the given input tensors.

logical_not

Computes the element-wise logical NOT of the given input tensor.

logical_or

Computes the element-wise logical OR of the given input tensors.

logical_xor

Computes the element-wise logical XOR of the given input tensors.

logit

Alias for torch.special.logit().

logit_

hypot

Given the legs of a right triangle, return its hypotenuse.

i0

Alias for torch.special.i0().

i0_

igamma

Alias for torch.special.gammainc().

igammac

Alias for torch.special.gammaincc().

mul

Multiplies input by other.

multiply

Alias for torch.mul().

mvlgamma

Alias for torch.special.multigammaln().

nan_to_num

Replaces NaN, positive infinity, and negative infinity values in input with the values specified by nan, posinf, and neginf, respectively.

nan_to_num_

neg

Returns a new tensor with the negative of the elements of input.

neg_

negative

Alias for torch.neg()

negative_

nextafter

Return the next floating-point value after input towards other, elementwise.

polygamma

Alias for torch.special.polygamma().

positive

Returns input.

pow

Takes the power of each element in input with exponent and returns a tensor with the result.

quantized_batch_norm

Applies batch normalization on a 4D (NCHW) quantized tensor.

quantized_max_pool1d

Applies a 1D max pooling over an input quantized tensor composed of several input planes.

quantized_max_pool2d

Applies a 2D max pooling over an input quantized tensor composed of several input planes.

rad2deg

Returns a new tensor with each of the elements of input converted from angles in radians to degrees.

rad2deg_

real

Returns a new tensor containing real values of the self tensor.

reciprocal

Returns a new tensor with the reciprocal of the elements of input

reciprocal_

remainder

Computes Python's modulus operation entrywise.

round

Rounds elements of input to the nearest integer.

round_

rsqrt

Returns a new tensor with the reciprocal of the square-root of each of the elements of input.

rsqrt_

sigmoid

Alias for torch.special.expit().

sigmoid_

sign

Returns a new tensor with the signs of the elements of input.

sgn

This function is an extension of torch.sign() to complex tensors.

signbit

Tests if each element of input has its sign bit set or not.

sin

Returns a new tensor with the sine of the elements in the input tensor, where each value in this input tensor is in radians.

sin_

sinc

Alias for torch.special.sinc().

sinc_

sinh

Returns a new tensor with the hyperbolic sine of the elements of input.

sinh_

softmax

Alias for torch.nn.functional.softmax().

sqrt

Returns a new tensor with the square-root of the elements of input.

sqrt_

square

Returns a new tensor with the square of the elements of input.

square_

sub

Subtracts other, scaled by alpha, from input.

subtract

Alias for torch.sub().

tan

Returns a new tensor with the tangent of the elements in the input tensor, where each value in this input tensor is in radians.

tan_

tanh

Returns a new tensor with the hyperbolic tangent of the elements of input.

tanh_

true_divide

Alias for torch.div() with rounding_mode=None.

trunc

Returns a new tensor with the truncated integer values of the elements of input.

trunc_

xlogy

Alias for torch.special.xlogy().

xlogy_

zero_

Reduction Ops#

argmax

Returns the indices of the maximum value of all elements in the input tensor.

argmin

Returns the indices of the minimum value(s) of the flattened tensor or along a dimension

amax

Returns the maximum value of each slice of the input tensor in the given dimension(s) dim.

amin

Returns the minimum value of each slice of the input tensor in the given dimension(s) dim.

aminmax

Computes the minimum and maximum values of the input tensor.

all

Tests if all elements in input evaluate to True.

any

Tests if any element in input evaluates to True.

max

Returns the maximum value of all elements in the input tensor.

min

Returns the minimum value of all elements in the input tensor.

dist

Returns the p-norm of (input - other)

logsumexp

Returns the log of summed exponentials of each row of the input tensor in the given dimension dim.

mean

nanmean

Computes the mean of all non-NaN elements along the specified dimensions.

median

Returns the median of the values in input.

nanmedian

Returns the median of the values in input, ignoring NaN values.

mode

Returns a namedtuple (values, indices) where values is the mode value of each row of the input tensor in the given dimension dim, i.e. a value which appears most often in that row, and indices is the index location of each mode value found.

norm

Returns the matrix norm or vector norm of a given tensor.

norm_except_dim

nuclear_norm

nansum

Returns the sum of all elements, treating Not a Numbers (NaNs) as zero.

prod

Returns the product of all elements in the input tensor.

quantile

Computes the q-th quantiles of each row of the input tensor along the dimension dim.

nanquantile

This is a variant of torch.quantile() that "ignores" NaN values, computing the quantiles q as if NaN values in input did not exist.

std

Calculates the standard deviation over the dimensions specified by dim.

std_mean

Calculates the standard deviation and mean over the dimensions specified by dim.

sum

Returns the sum of all elements in the input tensor.

unique

Returns the unique elements of the input tensor.

unique_consecutive

Eliminates all but the first element from every consecutive group of equivalent elements.

var

Calculates the variance over the dimensions specified by dim.

var_mean

Calculates the variance and mean over the dimensions specified by dim.

count_nonzero

Counts the number of non-zero values in the tensor input along the given dim.

hash_tensor

Returns a hash of all elements in the input tensor.

Comparison Ops#

allclose

This function checks if input and other satisfy the condition:

argsort

Returns the indices that sort a tensor along a given dimension in ascending order by value.

eq

Computes element-wise equality

equal

True if two tensors have the same size and elements, False otherwise.

ge

Computes inputother\text{input} \geq \text{other} element-wise.

greater_equal

Alias for torch.ge().

gt

Computes input>other\text{input} > \text{other} element-wise.

greater

Alias for torch.gt().

isclose

Returns a new tensor with boolean elements representing if each element of input is "close" to the corresponding element of other.

isfinite

Returns a new tensor with boolean elements representing if each element is finite or not.

isin

Tests if each element of elements is in test_elements.

isinf

Tests if each element of input is infinite (positive or negative infinity) or not.

isposinf

Tests if each element of input is positive infinity or not.

isneginf

Tests if each element of input is negative infinity or not.

isnan

Returns a new tensor with boolean elements representing if each element of input is NaN or not.

isreal

Returns a new tensor with boolean elements representing if each element of input is real-valued or not.

kthvalue

Returns a namedtuple (values, indices) where values is the k th smallest element of each row of the input tensor in the given dimension dim.

le

Computes inputother\text{input} \leq \text{other} element-wise.

less_equal

Alias for torch.le().

lt

Computes input<other\text{input} < \text{other} element-wise.

less

Alias for torch.lt().

maximum

Computes the element-wise maximum of input and other.

minimum

Computes the element-wise minimum of input and other.

fmax

Computes the element-wise maximum of input and other.

fmin

Computes the element-wise minimum of input and other.

ne

Computes inputother\text{input} \neq \text{other} element-wise.

not_equal

Alias for torch.ne().

sort

Sorts the elements of the input tensor along a given dimension in ascending order by value.

topk

Returns the k largest elements of the given input tensor along a given dimension.

msort

Sorts the elements of the input tensor along its first dimension in ascending order by value.

Spectral Ops#

stft

Short-time Fourier transform (STFT).

istft

Inverse short time Fourier Transform.

bartlett_window

Bartlett window function.

blackman_window

Blackman window function.

hamming_window

Hamming window function.

hann_window

Hann window function.

kaiser_window

Computes the Kaiser window with window length window_length and shape parameter beta.

Other Operations#

adaptive_avg_pool1d

Applies a 1D adaptive average pooling over an input signal composed of several input planes.

adaptive_max_pool1d

affine_grid_generator

alpha_dropout

alpha_dropout_

as_strided_

atleast_1d

Returns a 1-dimensional view of each input tensor with zero dimensions.

atleast_2d

Returns a 2-dimensional view of each input tensor with zero dimensions.

atleast_3d

Returns a 3-dimensional view of each input tensor with zero dimensions.

avg_pool1d

Applies a 1D average pooling over an input signal composed of several input planes.

batch_norm_backward_elemt

batch_norm_backward_reduce

batch_norm_elemt

batch_norm_gather_stats

batch_norm_gather_stats_with_counts

batch_norm_stats

batch_norm_update_stats

bilinear

Applies a bilinear transformation to the incoming data: y=x1TAx2+by = x_1^T A x_2 + b

bincount

Count the frequency of each value in an array of non-negative ints.

binomial

block_diag

Create a block diagonal matrix from provided tensors.

broadcast_tensors

Broadcasts the given tensors according to Broadcasting semantics.

broadcast_to

Broadcasts input to the shape shape.

broadcast_shapes

Similar to broadcast_tensors() but for shapes.

bucketize

Returns the indices of the buckets to which each value in the input belongs, where the boundaries of the buckets are set by boundaries.

cartesian_prod

Do cartesian product of the given sequence of tensors.

cdist

Computes batched the p-norm distance between each pair of the two collections of row vectors.

celu_

In-place version of celu().

channel_shuffle

Divide the channels in a tensor of shape (,C,H,W)(*, C , H, W) into g groups and rearrange them as (,Cg,g,H,W)(*, C \frac g, g, H, W), while keeping the original tensor shape.

choose_qparams_optimized

clone

Returns a copy of input.

combinations

Compute combinations of length rr of the given tensor.

conv1d

Applies a 1D convolution over an input signal composed of several input planes.

conv3d

Applies a 3D convolution over an input image composed of several input planes.

conv_tbc

Applies a 1-dimensional sequence convolution over an input sequence.

conv_transpose1d

Applies a 1D transposed convolution operator over an input signal composed of several input planes, sometimes also called "deconvolution".

conv_transpose2d

Applies a 2D transposed convolution operator over an input image composed of several input planes, sometimes also called "deconvolution".

conv_transpose3d

Applies a 3D transposed convolution operator over an input image composed of several input planes, sometimes also called "deconvolution"

convolution

corrcoef

Estimates the Pearson product-moment correlation coefficient matrix of the variables given by the input matrix, where rows are the variables and columns are the observations.

cosine_embedding_loss

cosine_similarity

Returns cosine similarity between x1 and x2, computed along dim.

cov

Estimates the covariance matrix of the variables given by the input matrix, where rows are the variables and columns are the observations.

cross

Returns the cross product of vectors in dimension dim of input and other.

ctc_loss

cudnn_affine_grid_generator

cudnn_batch_norm

cudnn_convolution

cudnn_convolution_add_relu

cudnn_convolution_relu

cudnn_convolution_transpose

cudnn_grid_sampler

cudnn_is_acceptable

cummax

Returns a namedtuple (values, indices) where values is the cumulative maximum of elements of input in the dimension dim.

cummin

Returns a namedtuple (values, indices) where values is the cumulative minimum of elements of input in the dimension dim.

cumprod

Returns the cumulative product of elements of input in the dimension dim.

cumsum

Returns the cumulative sum of elements of input in the dimension dim.

detach_

diag

  • If input is a vector (1-D tensor), then returns a 2-D square tensor

diag_embed

Creates a tensor whose diagonals of certain 2D planes (specified by dim1 and dim2) are filled by input.

diagflat

  • If input is a vector (1-D tensor), then returns a 2-D square tensor

diagonal

Returns a partial view of input with the its diagonal elements with respect to dim1 and dim2 appended as a dimension at the end of the shape.

diff

Computes the n-th forward difference along the given dimension.

dropout_

einsum

Sums the product of the elements of the input operands along dimensions specified using a notation based on the Einstein summation convention.

embedding

embedding_renorm_

fbgemm_linear_fp16_weight

fbgemm_linear_fp16_weight_fp32_activation

fbgemm_linear_int8_weight

fbgemm_linear_int8_weight_fp32_activation

fbgemm_linear_quantize_weight

fbgemm_pack_gemm_matrix_fp16

fbgemm_pack_quantized_matrix

feature_alpha_dropout

feature_alpha_dropout_

feature_dropout

feature_dropout_

flatten

Flattens input by reshaping it into a one-dimensional tensor.

flip

Reverse the order of an n-D tensor along given axis in dims.

fliplr

Flip tensor in the left/right direction, returning a new tensor.

flipud

Flip tensor in the up/down direction, returning a new tensor.

fused_moving_avg_obs_fake_quant

gcd

Computes the element-wise greatest common divisor (GCD) of input and other.

gcd_

grid_sampler_2d

grid_sampler_3d

group_norm

gru

gru_cell

hardshrink

Applies the hard shrinkage function element-wise

hinge_embedding_loss

histc

Computes the histogram of a tensor.

histogram

Computes a histogram of the values in a tensor.

histogramdd

Computes a multi-dimensional histogram of the values in a tensor.

instance_norm

int_repr

kl_div

kron

Computes the Kronecker product, denoted by \otimes, of input and other.

lcm

Computes the element-wise least common multiple (LCM) of input and other.

lcm_

logcumsumexp

Returns the logarithm of the cumulative summation of the exponentiation of elements of input in the dimension dim.

lstm

lstm_cell

margin_ranking_loss

max_pool1d

max_pool3d

meshgrid

Creates grids of coordinates specified by the 1D inputs in attr:tensors.

miopen_batch_norm

miopen_convolution

miopen_convolution_add_relu

miopen_convolution_relu

miopen_convolution_transpose

miopen_ctc_loss

miopen_depthwise_convolution

miopen_rnn

mkldnn_adaptive_avg_pool2d

mkldnn_convolution

mkldnn_linear_backward_weights

mkldnn_max_pool2d

mkldnn_max_pool3d

mkldnn_rnn_layer

native_batch_norm

native_channel_shuffle

Native kernel level implementation of the channel_shuffle.

native_group_norm

native_layer_norm

native_norm

pairwise_distance

See torch.nn.PairwiseDistance for details

pdist

Computes the p-norm distance between every pair of row vectors in the input.

pixel_unshuffle

Reverses the PixelShuffle operation by rearranging elements in a tensor of shape (,C,H×r,W×r)(*, C, H \times r, W \times r) to a tensor of shape (,C×r2,H,W)(*, C \times r^2, H, W), where r is the downscale_factor.

poisson_nll_loss

prelu

Applies element-wise the function PReLU(x)=max(0,x)+weightmin(0,x)\text{PReLU}(x) = \max(0,x) + \text{weight} * \min(0,x) where weight is a learnable parameter.

q_per_channel_axis

q_per_channel_scales

q_per_channel_zero_points

q_scale

q_zero_point

quantized_gru_cell

quantized_lstm_cell

quantized_max_pool3d

quantized_rnn_relu_cell

quantized_rnn_tanh_cell

ravel

Return a contiguous flattened tensor.

relu_

In-place version of relu().

renorm

Returns a tensor where each sub-tensor of input along dimension dim is normalized such that the p-norm of the sub-tensor is lower than the value maxnorm

repeat_interleave

Repeat elements of a tensor.

resize_as_

resize_as_sparse_

rms_norm

rnn_relu

rnn_relu_cell

rnn_tanh

rnn_tanh_cell

roll

Roll the tensor input along the given dimension(s).

rot90

Rotate an n-D tensor by 90 degrees in the plane specified by dims axis.

rrelu

rrelu_

In-place version of rrelu().

rsub

searchsorted

Find the indices from the innermost dimension of sorted_sequence such that, if the corresponding values in values were inserted before the indices, when sorted, the order of the corresponding innermost dimension within sorted_sequence would be preserved.

selu

selu_

In-place version of selu().

tensordot

Returns a contraction of a and b over multiple dimensions.

threshold

threshold_

In-place version of threshold().

trace

Returns the sum of the elements of the diagonal of the input 2-D matrix.

tril

Returns the lower triangular part of the matrix (2-D tensor) or batch of matrices input, the other elements of the result tensor out are set to 0.

tril_indices

Returns the indices of the lower triangular part of a row-by- col matrix in a 2-by-N Tensor, where the first row contains row coordinates of all indices and the second row contains column coordinates.

triu

Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input, the other elements of the result tensor out are set to 0.

triu_indices

Returns the indices of the upper triangular part of a row by col matrix in a 2-by-N Tensor, where the first row contains row coordinates of all indices and the second row contains column coordinates.

triplet_margin_loss

unflatten

Expands a dimension of the input tensor over multiple dimensions.

vander

Generates a Vandermonde matrix.

view_as_real

Returns a view of input as a real tensor.

view_as_complex

Returns a view of input as a complex tensor.

resolve_conj

Returns a new tensor with materialized conjugation if input's conjugate bit is set to True, else returns input.

resolve_neg

Returns a new tensor with materialized negation if input's negative bit is set to True, else returns input.

BLAS and LAPACK Operations#

addbmm

Performs a batch matrix-matrix product of matrices stored in batch1 and batch2, with a reduced add step (all matrix multiplications get accumulated along the first dimension).

addmm

Performs a matrix multiplication of the matrices mat1 and mat2.

addmv

Performs a matrix-vector product of the matrix mat and the vector vec.

addmv_

addr

Performs the outer-product of vectors vec1 and vec2 and adds it to the matrix input.

baddbmm

Performs a batch matrix-matrix product of matrices in batch1 and batch2.

bmm

Performs a batch matrix-matrix product of matrices stored in input and mat2.

chain_matmul

Returns the matrix product of the NN 2-D tensors.

cholesky

Computes the Cholesky decomposition of a symmetric positive-definite matrix AA or for batches of symmetric positive-definite matrices.

cholesky_inverse

Computes the inverse of a complex Hermitian or real symmetric positive-definite matrix given its Cholesky decomposition.

cholesky_solve

Computes the solution of a system of linear equations with complex Hermitian or real symmetric positive-definite lhs given its Cholesky decomposition.

dot

Computes the dot product of two 1D tensors.

dsmm

geqrf

This is a low-level function for calling LAPACK's geqrf directly.

ger

Alias of torch.outer().

hsmm

inner

Computes the dot product for 1D tensors.

inverse

Alias for torch.linalg.inv()

det

Alias for torch.linalg.det()

logdet

Calculates log determinant of a square matrix or batches of square matrices.

slogdet

Alias for torch.linalg.slogdet()

lu

Computes the LU factorization of a matrix or batches of matrices A.

lu_solve

Returns the LU solve of the linear system Ax=bAx = b using the partially pivoted LU factorization of A from lu_factor().

lu_unpack

Unpacks the LU decomposition returned by lu_factor() into the P, L, U matrices.

matmul

Matrix product of two tensors.

matrix_power

Alias for torch.linalg.matrix_power()

matrix_exp

Alias for torch.linalg.matrix_exp().

mm

Performs a matrix multiplication of the matrices input and mat2.

mv

Performs a matrix-vector product of the matrix input and the vector vec.

orgqr

Alias for torch.linalg.householder_product().

ormqr

Computes the matrix-matrix multiplication of a product of Householder matrices with a general matrix.

outer

Outer product of input and vec2.

pinverse

Alias for torch.linalg.pinv()

saddmm

spmm

qr

Computes the QR decomposition of a matrix or a batch of matrices input, and returns a namedtuple (Q, R) of tensors such that input=QR\text{input} = Q R with QQ being an orthogonal matrix or batch of orthogonal matrices and RR being an upper triangular matrix or batch of upper triangular matrices.

svd

Computes the singular value decomposition of either a matrix or batch of matrices input.

svd_lowrank

Return the singular value decomposition (U, S, V) of a matrix, batches of matrices, or a sparse matrix AA such that AUdiag(S)VHA \approx U \operatorname{diag}(S) V^{\text{H}}.

pca_lowrank

Performs linear Principal Component Analysis (PCA) on a low-rank matrix, batches of such matrices, or sparse matrix.

lobpcg

Find the k largest (or smallest) eigenvalues and the corresponding eigenvectors of a symmetric positive definite generalized eigenvalue problem using matrix-free LOBPCG methods.

trapz

Alias for torch.trapezoid().

trapezoid

Computes the trapezoidal rule along dim.

cumulative_trapezoid

Cumulatively computes the trapezoidal rule along dim.

triangular_solve

Solves a system of equations with a square upper or lower triangular invertible matrix AA and multiple right-hand sides bb.

vdot

Computes the dot product of two 1D vectors along a dimension.

Foreach Operations#

Warning

This API is in beta and subject to future changes. Forward-mode AD is not supported.

_foreach_abs

Apply torch.abs() to each Tensor of the input list.

_foreach_abs_

Apply torch.abs() to each Tensor of the input list.

_foreach_acos

Apply torch.acos() to each Tensor of the input list.

_foreach_acos_

Apply torch.acos() to each Tensor of the input list.

_foreach_asin

Apply torch.asin() to each Tensor of the input list.

_foreach_asin_

Apply torch.asin() to each Tensor of the input list.

_foreach_atan

Apply torch.atan() to each Tensor of the input list.

_foreach_atan_

Apply torch.atan() to each Tensor of the input list.

_foreach_ceil

Apply torch.ceil() to each Tensor of the input list.

_foreach_ceil_

Apply torch.ceil() to each Tensor of the input list.

_foreach_clone

_foreach_cos

Apply torch.cos() to each Tensor of the input list.

_foreach_cos_

Apply torch.cos() to each Tensor of the input list.

_foreach_cosh

Apply torch.cosh() to each Tensor of the input list.

_foreach_cosh_

Apply torch.cosh() to each Tensor of the input list.

_foreach_erf

Apply torch.erf() to each Tensor of the input list.

_foreach_erf_

Apply torch.erf() to each Tensor of the input list.

_foreach_erfc

Apply torch.erfc() to each Tensor of the input list.

_foreach_erfc_

Apply torch.erfc() to each Tensor of the input list.

_foreach_exp

Apply torch.exp() to each Tensor of the input list.

_foreach_exp_

Apply torch.exp() to each Tensor of the input list.

_foreach_expm1

Apply torch.expm1() to each Tensor of the input list.

_foreach_expm1_

Apply torch.expm1() to each Tensor of the input list.

_foreach_floor

Apply torch.floor() to each Tensor of the input list.

_foreach_floor_

Apply torch.floor() to each Tensor of the input list.

_foreach_log

Apply torch.log() to each Tensor of the input list.

_foreach_log_

Apply torch.log() to each Tensor of the input list.

_foreach_log10

Apply torch.log10() to each Tensor of the input list.

_foreach_log10_

Apply torch.log10() to each Tensor of the input list.

_foreach_log1p

Apply torch.log1p() to each Tensor of the input list.

_foreach_log1p_

Apply torch.log1p() to each Tensor of the input list.

_foreach_log2

Apply torch.log2() to each Tensor of the input list.

_foreach_log2_

Apply torch.log2() to each Tensor of the input list.

_foreach_neg

Apply torch.neg() to each Tensor of the input list.

_foreach_neg_

Apply torch.neg() to each Tensor of the input list.

_foreach_tan

Apply torch.tan() to each Tensor of the input list.

_foreach_tan_

Apply torch.tan() to each Tensor of the input list.

_foreach_sin

Apply torch.sin() to each Tensor of the input list.

_foreach_sin_

Apply torch.sin() to each Tensor of the input list.

_foreach_sinh

Apply torch.sinh() to each Tensor of the input list.

_foreach_sinh_

Apply torch.sinh() to each Tensor of the input list.

_foreach_round

Apply torch.round() to each Tensor of the input list.

_foreach_round_

Apply torch.round() to each Tensor of the input list.

_foreach_sqrt

Apply torch.sqrt() to each Tensor of the input list.

_foreach_sqrt_

Apply torch.sqrt() to each Tensor of the input list.

_foreach_lgamma

Apply torch.lgamma() to each Tensor of the input list.

_foreach_lgamma_

Apply torch.lgamma() to each Tensor of the input list.

_foreach_frac

Apply torch.frac() to each Tensor of the input list.

_foreach_frac_

Apply torch.frac() to each Tensor of the input list.

_foreach_reciprocal

Apply torch.reciprocal() to each Tensor of the input list.

_foreach_reciprocal_

Apply torch.reciprocal() to each Tensor of the input list.

_foreach_sigmoid

Apply torch.sigmoid() to each Tensor of the input list.

_foreach_sigmoid_

Apply torch.sigmoid() to each Tensor of the input list.

_foreach_trunc

Apply torch.trunc() to each Tensor of the input list.

_foreach_trunc_

Apply torch.trunc() to each Tensor of the input list.

_foreach_zero_

Apply torch.zero() to each Tensor of the input list.

Utilities#

autocast_decrement_nesting

autocast_increment_nesting

clear_autocast_cache

compiled_with_cxx11_abi

Returns whether PyTorch was built with _GLIBCXX_USE_CXX11_ABI=1

get_autocast_cpu_dtype

get_autocast_dtype

get_autocast_gpu_dtype

get_autocast_ipu_dtype

get_autocast_xla_dtype

get_device

get_device_module

Returns the module associated with a given device(e.g., torch.device('cuda'), "mtia:0", "xpu", ...).

import_ir_module

import_ir_module_from_buffer

is_anomaly_check_nan_enabled

is_anomaly_enabled

is_autocast_cache_enabled

is_autocast_cpu_enabled

is_autocast_enabled

is_autocast_ipu_enabled

is_autocast_xla_enabled

is_distributed

is_vulkan_available

merge_type_from_type_comment

parse_ir

parse_schema

parse_type_comment

result_type

Returns the torch.dtype that would result from performing an arithmetic operation on the provided input tensors.

can_cast

Determines if a type conversion is allowed under PyTorch casting rules described in the type promotion documentation.

promote_types

Returns the torch.dtype with the smallest size and scalar kind that is not smaller nor of lower kind than either type1 or type2.

set_anomaly_enabled

set_autocast_cache_enabled

set_autocast_cpu_dtype

set_autocast_cpu_enabled

set_autocast_dtype

set_autocast_enabled

set_autocast_gpu_dtype

set_autocast_ipu_dtype

set_autocast_ipu_enabled

set_autocast_xla_dtype

set_autocast_xla_enabled

use_deterministic_algorithms

Sets whether PyTorch operations must use "deterministic" algorithms.

are_deterministic_algorithms_enabled

Returns True if the global deterministic flag is turned on.

is_deterministic_algorithms_warn_only_enabled

Returns True if the global deterministic flag is set to warn only.

set_deterministic_debug_mode

Sets the debug mode for deterministic operations.

get_deterministic_debug_mode

Returns the current value of the debug mode for deterministic operations.

set_float32_matmul_precision

Sets the internal precision of float32 matrix multiplications.

get_float32_matmul_precision

Returns the current value of float32 matrix multiplication precision.

set_warn_always

When this flag is False (default) then some PyTorch warnings may only appear once per process.

is_warn_always_enabled

Returns True if the global warn_always flag is turned on.

vmap

vmap is the vectorizing map; vmap(func) returns a new function that maps func over some dimension of the inputs.

_assert

A wrapper around Python's assert which is symbolically traceable.

typename

String representation of the type of an object.

Type Information#

class torch.TensorType#

Symbolic Numbers#

class torch.SymInt(node)[source]#

Like an int (including magic methods), but redirects all operations on the wrapped node. This is used in particular to symbolically record operations in the symbolic shape workflow.

as_integer_ratio()[source]#

Represent this int as an exact integer ratio

Return type:

tuple[SymInt, int]

class torch.SymFloat(node)[source]#

Like a float (including magic methods), but redirects all operations on the wrapped node. This is used in particular to symbolically record operations in the symbolic shape workflow.

as_integer_ratio()[source]#

Represent this float as an exact integer ratio

Return type:

tuple[int, int]

conjugate()[source]#

Returns the complex conjugate of the float.

Return type:

SymFloat

hex()[source]#

Returns the hexadecimal representation of the float.

Return type:

str

is_integer()[source]#

Return True if the float is an integer.

class torch.SymBool(node)[source]#

Like a bool (including magic methods), but redirects all operations on the wrapped node. This is used in particular to symbolically record operations in the symbolic shape workflow.

Unlike regular bools, regular boolean operators will force extra guards instead of symbolically evaluate. Use the bitwise operators instead to handle this.

sym_constrain_range

sym_constrain_range_for_size

sym_float

SymInt-aware utility for float casting.

sym_fresh_size

sym_int

SymInt-aware utility for int casting.

sym_max

SymInt-aware utility for max which avoids branching on a < b.

sym_min

SymInt-aware utility for min().

sym_not

SymInt-aware utility for logical negation.

sym_ite

SymInt-aware utility for ternary operator (t if b else f.)

sym_sqrt

sym_sum

N-ary add which is faster to compute for long lists than iterated binary addition.

Export Path#

Warning

This feature is a prototype and may have compatibility breaking changes in the future.

export generated/exportdb/index

Control Flow#

Warning

This feature is a prototype and may have compatibility breaking changes in the future.

cond

Conditionally applies true_fn or false_fn.

Optimizations#

compile

Optimizes given model/function using TorchDynamo and specified backend.

torch.compile documentation

Operator Tags#

class torch.Tag#

Members:

core

cudagraph_unsafe

data_dependent_output

dynamic_output_shape

flexible_layout

generated

inplace

inplace_view

maybe_aliasing_or_mutating

needs_contiguous_strides

needs_exact_strides

needs_fixed_stride_order

nondeterministic_bitwise

nondeterministic_seeded

out

out_variant

pointwise

pt2_compliant_tag

reduction

view_copy

property name#

get_inline_skeleton

Get a fully-inlined skeleton of the frontend.

get_model_info

Get JSON-friendly information about a model.