torch¶
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 |
is_conj |
Returns True if the |
is_floating_point |
Returns True if the data type of |
is_nonzero |
Returns True if the |
set_default_dtype |
Sets the default floating point dtype to |
get_default_dtype |
Get the current default floating point |
set_default_device |
Sets the default |
set_default_tensor_type |
Sets the default |
numel |
Returns the total number of elements in the |
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 |
sparse_coo_tensor |
Constructs a sparse tensor in COO(rdinate) format with specified values at the given |
sparse_csr_tensor |
Constructs a sparse tensor in CSR (Compressed Sparse Row) with specified values at the given |
sparse_csc_tensor |
Constructs a sparse tensor in CSC (Compressed Sparse Column) with specified values at the given |
sparse_bsr_tensor |
Constructs a sparse tensor in BSR (Block Compressed Sparse Row)) with specified 2-dimensional blocks at the given |
sparse_bsc_tensor |
Constructs a sparse tensor in BSC (Block Compressed Sparse Column)) with specified 2-dimensional blocks at the given |
asarray |
Converts |
as_tensor |
Converts |
as_strided |
Create a view of an existing torch.Tensor |
from_numpy |
Creates a |
from_dlpack |
Converts a tensor from an external library into a |
frombuffer |
Creates a 1-dimensional |
zeros |
Returns a tensor filled with the scalar value 0, with the shape defined by the variable argument |
zeros_like |
Returns a tensor filled with the scalar value 0, with the same size as |
ones |
Returns a tensor filled with the scalar value 1, with the shape defined by the variable argument |
ones_like |
Returns a tensor filled with the scalar value 1, with the same size as |
arange |
Returns a 1-D tensor of size with values from the interval |
range |
Returns a 1-D tensor of size with values from |
linspace |
Creates a one-dimensional tensor of size |
logspace |
Creates a one-dimensional tensor of size |
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 |
empty_strided |
Creates a tensor with the specified |
full |
Creates a tensor of size |
full_like |
Returns a tensor with the same size as |
quantize_per_tensor |
Converts a float tensor to a quantized tensor with given scale and zero point. |
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 |
polar |
Constructs a complex tensor whose elements are Cartesian coordinates corresponding to the polar coordinates with absolute value |
heaviside |
Computes the Heaviside step function for each element in |
Indexing, Slicing, Joining, Mutating Ops¶
adjoint |
Returns a view of the tensor conjugated and with the last two dimensions transposed. |
argwhere |
Returns a tensor containing the indices of all non-zero elements of |
cat |
Concatenates the given sequence of |
concat |
Alias of |
concatenate |
Alias of |
conj |
Returns a view of |
chunk |
Attempts to split a tensor into the specified number of chunks. |
dsplit |
Splits |
column_stack |
Creates a new tensor by horizontally stacking the tensors in |
dstack |
Stack tensors in sequence depthwise (along third axis). |
gather |
Gathers values along an axis specified by dim. |
hsplit |
Splits |
hstack |
Stack tensors in sequence horizontally (column wise). |
index_add |
See |
index_copy |
See |
index_reduce |
See |
index_select |
Returns a new tensor which indexes the |
masked_select |
Returns a new 1-D tensor which indexes the |
movedim |
Moves the dimension(s) of |
moveaxis |
Alias for |
narrow |
Returns a new tensor that is a narrowed version of |
narrow_copy |
Same as |
nonzero |
|
permute |
Returns a view of the original tensor |
reshape |
Returns a tensor with the same data and number of elements as |
row_stack |
Alias of |
select |
Slices the |
scatter |
Out-of-place version of |
diagonal_scatter |
Embeds the values of the |
select_scatter |
Embeds the values of the |
slice_scatter |
Embeds the values of the |
scatter_add |
Out-of-place version of |
scatter_reduce |
Out-of-place version of |
split |
Splits the tensor into chunks. |
squeeze |
Returns a tensor with all specified dimensions of |
stack |
Concatenates a sequence of tensors along a new dimension. |
swapaxes |
Alias for |
swapdims |
Alias for |
t |
Expects |
take |
Returns a new tensor with the elements of |
take_along_dim |
Selects values from |
tensor_split |
Splits a tensor into multiple sub-tensors, all of which are views of |
tile |
Constructs a tensor by repeating the elements of |
transpose |
Returns a tensor that is a transposed version of |
unbind |
Removes a tensor dimension. |
unsqueeze |
Returns a new tensor with a dimension of size one inserted at the specified position. |
vsplit |
Splits |
vstack |
Stack tensors in sequence vertically (row wise). |
where |
Return a tensor of elements selected from either |
Generators¶
Generator |
Creates and returns a generator object that manages the state of the algorithm which produces pseudo random numbers. |
Random sampling¶
seed |
Sets the seed for generating random numbers to a non-deterministic random number. |
manual_seed |
Sets the seed for generating random numbers. |
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 |
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 |
rand |
Returns a tensor filled with random numbers from a uniform distribution on the interval |
rand_like |
Returns a tensor with the same size as |
randint |
Returns a tensor filled with random integers generated uniformly between |
randint_like |
Returns a tensor with the same shape as Tensor |
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 |
randperm |
Returns a random permutation of integers from |
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:
torch.Tensor.bernoulli_()
- in-place version oftorch.bernoulli()
torch.Tensor.cauchy_()
- numbers drawn from the Cauchy distributiontorch.Tensor.exponential_()
- numbers drawn from the exponential distributiontorch.Tensor.geometric_()
- elements drawn from the geometric distributiontorch.Tensor.log_normal_()
- samples from the log-normal distributiontorch.Tensor.normal_()
- in-place version oftorch.normal()
torch.Tensor.random_()
- numbers sampled from the discrete uniform distributiontorch.Tensor.uniform_()
- numbers sampled from the continuous uniform distribution
Quasi-random sampling¶
The |
Serialization¶
save |
Saves an object to a disk file. |
load |
Loads an object saved with |
Parallelism¶
get_num_threads |
Returns the number of threads used for parallelizing CPU operations |
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. |
set_num_interop_threads |
Sets the number of threads used for interop parallelism (e.g. |
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 disabled gradient calculation. |
enable_grad |
Context-manager that enables gradient calculation. |
set_grad_enabled |
Context-manager that sets gradient calculation on or off. |
is_grad_enabled |
Returns True if grad mode is currently enabled. |
inference_mode |
Context-manager that enables or disables inference mode |
is_inference_mode_enabled |
Returns True if inference mode is currently enabled. |
Math operations¶
Pointwise Ops¶
abs |
Computes the absolute value of each element in |
absolute |
Alias for |
acos |
Computes the inverse cosine of each element in |
arccos |
Alias for |
acosh |
Returns a new tensor with the inverse hyperbolic cosine of the elements of |
arccosh |
Alias for |
add |
Adds |
addcdiv |
Performs the element-wise division of |
addcmul |
Performs the element-wise multiplication of |
angle |
Computes the element-wise angle (in radians) of the given |
asin |
Returns a new tensor with the arcsine of the elements of |
arcsin |
Alias for |
asinh |
Returns a new tensor with the inverse hyperbolic sine of the elements of |
arcsinh |
Alias for |
atan |
Returns a new tensor with the arctangent of the elements of |
arctan |
Alias for |
atanh |
Returns a new tensor with the inverse hyperbolic tangent of the elements of |
arctanh |
Alias for |
atan2 |
Element-wise arctangent of with consideration of the quadrant. |
arctan2 |
Alias for |
bitwise_not |
Computes the bitwise NOT of the given input tensor. |
bitwise_and |
Computes the bitwise AND of |
bitwise_or |
Computes the bitwise OR of |
bitwise_xor |
Computes the bitwise XOR of |
bitwise_left_shift |
Computes the left arithmetic shift of |
bitwise_right_shift |
Computes the right arithmetic shift of |
ceil |
Returns a new tensor with the ceil of the elements of |
clamp |
|
clip |
Alias for |
conj_physical |
Computes the element-wise conjugate of the given |
copysign |
Create a new floating-point tensor with the magnitude of |
cos |
Returns a new tensor with the cosine of the elements of |
cosh |
Returns a new tensor with the hyperbolic cosine of the elements of |
deg2rad |
Returns a new tensor with each of the elements of |
div |
Divides each element of the input |
divide |
Alias for |
digamma |
Alias for |
erf |
Alias for |
erfc |
Alias for |
erfinv |
Alias for |
exp |
Returns a new tensor with the exponential of the elements of the input tensor |
exp2 |
Alias for |
expm1 |
Alias for |
fake_quantize_per_channel_affine |
Returns a new tensor with the data in |
fake_quantize_per_tensor_affine |
Returns a new tensor with the data in |
fix |
Alias for |
float_power |
Raises |
floor |
Returns a new tensor with the floor of the elements of |
floor_divide |
|
fmod |
Applies C++'s std::fmod entrywise. |
frac |
Computes the fractional portion of each element in |
frexp |
Decomposes |
gradient |
Estimates the gradient of a function 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 |
ldexp |
Multiplies |
lerp |
Does a linear interpolation of two tensors |
lgamma |
Computes the natural logarithm of the absolute value of the gamma function on |
log |
Returns a new tensor with the natural logarithm of the elements of |
log10 |
Returns a new tensor with the logarithm to the base 10 of the elements of |
log1p |
Returns a new tensor with the natural logarithm of (1 + |
log2 |
Returns a new tensor with the logarithm to the base 2 of the elements of |
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 |
hypot |
Given the legs of a right triangle, return its hypotenuse. |
i0 |
Alias for |
igamma |
Alias for |
igammac |
Alias for |
mul |
Multiplies |
multiply |
Alias for |
mvlgamma |
Alias for |
nan_to_num |
Replaces |
neg |
Returns a new tensor with the negative of the elements of |
negative |
Alias for |
nextafter |
Return the next floating-point value after |
polygamma |
Alias for |
positive |
Returns |
pow |
Takes the power of each element in |
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 |
real |
Returns a new tensor containing real values of the |
reciprocal |
Returns a new tensor with the reciprocal of the elements of |
remainder |
Computes Python's modulus operation entrywise. |
round |
Rounds elements of |
rsqrt |
Returns a new tensor with the reciprocal of the square-root of each of the elements of |
sigmoid |
Alias for |
sign |
Returns a new tensor with the signs of the elements of |
sgn |
This function is an extension of torch.sign() to complex tensors. |
signbit |
Tests if each element of |
sin |
Returns a new tensor with the sine of the elements of |
sinc |
Alias for |
sinh |
Returns a new tensor with the hyperbolic sine of the elements of |
softmax |
Alias for |
sqrt |
Returns a new tensor with the square-root of the elements of |
square |
Returns a new tensor with the square of the elements of |
sub |
Subtracts |
subtract |
Alias for |
tan |
Returns a new tensor with the tangent of the elements of |
tanh |
Returns a new tensor with the hyperbolic tangent of the elements of |
true_divide |
Alias for |
trunc |
Returns a new tensor with the truncated integer values of the elements of |
xlogy |
Alias for |
Reduction Ops¶
argmax |
Returns the indices of the maximum value of all elements in the |
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 |
amin |
Returns the minimum value of each slice of the |
aminmax |
Computes the minimum and maximum values of the |
all |
Tests if all elements in |
any |
Tests if any element in |
max |
Returns the maximum value of all elements in the |
min |
Returns the minimum value of all elements in the |
dist |
Returns the p-norm of ( |
logsumexp |
Returns the log of summed exponentials of each row of the |
mean |
Returns the mean value of all elements in the |
nanmean |
Computes the mean of all non-NaN elements along the specified dimensions. |
median |
Returns the median of the values in |
nanmedian |
Returns the median of the values in |
mode |
Returns a namedtuple |
norm |
Returns the matrix norm or vector norm of a given tensor. |
nansum |
Returns the sum of all elements, treating Not a Numbers (NaNs) as zero. |
prod |
Returns the product of all elements in the |
quantile |
Computes the q-th quantiles of each row of the |
nanquantile |
This is a variant of |
std |
Calculates the standard deviation over the dimensions specified by |
std_mean |
Calculates the standard deviation and mean over the dimensions specified by |
sum |
Returns the sum of all elements in the |
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 |
var_mean |
Calculates the variance and mean over the dimensions specified by |
count_nonzero |
Counts the number of non-zero values in the tensor |
Comparison Ops¶
allclose |
This function checks if |
argsort |
Returns the indices that sort a tensor along a given dimension in ascending order by value. |
eq |
Computes element-wise equality |
equal |
|
ge |
Computes element-wise. |
greater_equal |
Alias for |
gt |
Computes element-wise. |
greater |
Alias for |
isclose |
Returns a new tensor with boolean elements representing if each element of |
isfinite |
Returns a new tensor with boolean elements representing if each element is finite or not. |
isin |
Tests if each element of |
isinf |
Tests if each element of |
isposinf |
Tests if each element of |
isneginf |
Tests if each element of |
isnan |
Returns a new tensor with boolean elements representing if each element of |
isreal |
Returns a new tensor with boolean elements representing if each element of |
kthvalue |
Returns a namedtuple |
le |
Computes element-wise. |
less_equal |
Alias for |
lt |
Computes element-wise. |
less |
Alias for |
maximum |
Computes the element-wise maximum of |
minimum |
Computes the element-wise minimum of |
fmax |
Computes the element-wise maximum of |
fmin |
Computes the element-wise minimum of |
ne |
Computes element-wise. |
not_equal |
Alias for |
sort |
Sorts the elements of the |
topk |
Returns the |
msort |
Sorts the elements of the |
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 |
Other Operations¶
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. |
bincount |
Count the frequency of each value in an array of non-negative ints. |
block_diag |
Create a block diagonal matrix from provided tensors. |
broadcast_tensors |
Broadcasts the given tensors according to Broadcasting semantics. |
broadcast_to |
Broadcasts |
broadcast_shapes |
Similar to |
bucketize |
Returns the indices of the buckets to which each value in the |
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. |
clone |
Returns a copy of |
combinations |
Compute combinations of length of the given tensor. |
corrcoef |
Estimates the Pearson product-moment correlation coefficient matrix of the variables given by the |
cov |
Estimates the covariance matrix of the variables given by the |
cross |
Returns the cross product of vectors in dimension |
cummax |
Returns a namedtuple |
cummin |
Returns a namedtuple |
cumprod |
Returns the cumulative product of elements of |
cumsum |
Returns the cumulative sum of elements of |
diag |
|
diag_embed |
Creates a tensor whose diagonals of certain 2D planes (specified by |
diagflat |
|
diagonal |
Returns a partial view of |
diff |
Computes the n-th forward difference along the given dimension. |
einsum |
Sums the product of the elements of the input |
flatten |
Flattens |
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. |
kron |
Computes the Kronecker product, denoted by , of |
rot90 |
Rotate an n-D tensor by 90 degrees in the plane specified by dims axis. |
gcd |
Computes the element-wise greatest common divisor (GCD) of |
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. |
meshgrid |
Creates grids of coordinates specified by the 1D inputs in attr:tensors. |
lcm |
Computes the element-wise least common multiple (LCM) of |
logcumsumexp |
Returns the logarithm of the cumulative summation of the exponentiation of elements of |
ravel |
Return a contiguous flattened tensor. |
renorm |
Returns a tensor where each sub-tensor of |
repeat_interleave |
Repeat elements of a tensor. |
roll |
Roll the tensor |
searchsorted |
Find the indices from the innermost dimension of |
tensordot |
Returns a contraction of a and b over multiple dimensions. |
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 |
tril_indices |
Returns the indices of the lower triangular part of a |
triu |
Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices |
triu_indices |
Returns the indices of the upper triangular part of a |
unflatten |
Expands a dimension of the input tensor over multiple dimensions. |
vander |
Generates a Vandermonde matrix. |
view_as_real |
Returns a view of |
view_as_complex |
Returns a view of |
resolve_conj |
Returns a new tensor with materialized conjugation if |
resolve_neg |
Returns a new tensor with materialized negation if |
BLAS and LAPACK Operations¶
addbmm |
Performs a batch matrix-matrix product of matrices stored in |
addmm |
Performs a matrix multiplication of the matrices |
addmv |
Performs a matrix-vector product of the matrix |
addr |
Performs the outer-product of vectors |
baddbmm |
Performs a batch matrix-matrix product of matrices in |
bmm |
Performs a batch matrix-matrix product of matrices stored in |
chain_matmul |
Returns the matrix product of the 2-D tensors. |
cholesky |
Computes the Cholesky decomposition of a symmetric positive-definite matrix or for batches of symmetric positive-definite matrices. |
cholesky_inverse |
Computes the inverse of a symmetric positive-definite matrix using its Cholesky factor : returns matrix |
cholesky_solve |
Solves a linear system of equations with a positive semidefinite matrix to be inverted given its Cholesky factor matrix . |
dot |
Computes the dot product of two 1D tensors. |
geqrf |
This is a low-level function for calling LAPACK's geqrf directly. |
ger |
Alias of |
inner |
Computes the dot product for 1D tensors. |
inverse |
Alias for |
det |
Alias for |
logdet |
Calculates log determinant of a square matrix or batches of square matrices. |
slogdet |
Alias for |
lu |
Computes the LU factorization of a matrix or batches of matrices |
lu_solve |
Returns the LU solve of the linear system using the partially pivoted LU factorization of A from |
lu_unpack |
Unpacks the LU decomposition returned by |
matmul |
Matrix product of two tensors. |
matrix_power |
Alias for |
matrix_exp |
Alias for |
mm |
Performs a matrix multiplication of the matrices |
mv |
Performs a matrix-vector product of the matrix |
orgqr |
Alias for |
ormqr |
Computes the matrix-matrix multiplication of a product of Householder matrices with a general matrix. |
outer |
Outer product of |
pinverse |
Alias for |
qr |
Computes the QR decomposition of a matrix or a batch of matrices |
svd |
Computes the singular value decomposition of either a matrix or batch of matrices |
svd_lowrank |
Return the singular value decomposition |
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 |
trapezoid |
Computes the trapezoidal rule along |
cumulative_trapezoid |
Cumulatively computes the trapezoidal rule along |
triangular_solve |
Solves a system of equations with a square upper or lower triangular invertible matrix and multiple right-hand sides . |
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 |
_foreach_abs_ |
Apply |
_foreach_acos |
Apply |
_foreach_acos_ |
Apply |
_foreach_asin |
Apply |
_foreach_asin_ |
Apply |
_foreach_atan |
Apply |
_foreach_atan_ |
Apply |
_foreach_ceil |
Apply |
_foreach_ceil_ |
Apply |
_foreach_cos |
Apply |
_foreach_cos_ |
Apply |
_foreach_cosh |
Apply |
_foreach_cosh_ |
Apply |
_foreach_erf |
Apply |
_foreach_erf_ |
Apply |
_foreach_erfc |
Apply |
_foreach_erfc_ |
Apply |
_foreach_exp |
Apply |
_foreach_exp_ |
Apply |
_foreach_expm1 |
Apply |
_foreach_expm1_ |
Apply |
_foreach_floor |
Apply |
_foreach_floor_ |
Apply |
_foreach_log |
Apply |
_foreach_log_ |
Apply |
_foreach_log10 |
Apply |
_foreach_log10_ |
Apply |
_foreach_log1p |
Apply |
_foreach_log1p_ |
Apply |
_foreach_log2 |
Apply |
_foreach_log2_ |
Apply |
_foreach_neg |
Apply |
_foreach_neg_ |
Apply |
_foreach_tan |
Apply |
_foreach_tan_ |
Apply |
_foreach_sin |
Apply |
_foreach_sin_ |
Apply |
_foreach_sinh |
Apply |
_foreach_sinh_ |
Apply |
_foreach_round |
Apply |
_foreach_round_ |
Apply |
_foreach_sqrt |
Apply |
_foreach_sqrt_ |
Apply |
_foreach_lgamma |
Apply |
_foreach_lgamma_ |
Apply |
_foreach_frac |
Apply |
_foreach_frac_ |
Apply |
_foreach_reciprocal |
Apply |
_foreach_reciprocal_ |
Apply |
_foreach_sigmoid |
Apply |
_foreach_sigmoid_ |
Apply |
_foreach_trunc |
Apply |
_foreach_trunc_ |
Apply |
_foreach_zero_ |
Apply |
Utilities¶
compiled_with_cxx11_abi |
Returns whether PyTorch was built with _GLIBCXX_USE_CXX11_ABI=1 |
result_type |
Returns the |
can_cast |
Determines if a type conversion is allowed under PyTorch casting rules described in the type promotion documentation. |
promote_types |
Returns the |
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; |
_assert |
A wrapper around Python's assert which is symbolically traceable. |
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.
- class torch.SymFloat(node)[source]¶
Like an 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.
- class torch.SymBool(node)[source]¶
Like an 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_float |
SymInt-aware utility for float casting. |
sym_int |
SymInt-aware utility for int casting. |
sym_max |
SymInt-aware utility for max(). |
sym_min |
SymInt-aware utility for max(). |
sym_not |
SymInt-aware utility for logical negation. |
Optimizations¶
compile |
Optimizes given model/function using TorchDynamo and specified backend. |
Engine Configuration¶
set_multithreading_enabled |
Context-manager that sets multithreaded backwards on or off. |