TensorPlay
API reference
latest (dev)
Copy
View Markdown

Latest development documentation · Updated 2026-10-15

tensorplay API

Functions 543

#

as_tensor

functionFull reference ↗
tensorplay.as_tensor(data: Any, dtype: Optional[dtype] = None, device: Optional[DeviceLikeType]) → Tensor[source]

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

If data is already a tensor with the requested dtype and device then data itself is returned, but if data is a tensor with a different dtype or device then it’s copied as if using data.to(dtype=dtype, device=device).

If data is a NumPy array (an ndarray) with the same dtype and device then a tensor is constructed using tensorplay.from_numpy().

If data is a CuPy array, the returned tensor will be located on the same device as the CuPy array unless specifically overwritten by device or a default device. The device of the CuPy array is inferred from the pointer of the array using cudaPointerGetAttributes unless device is provided with an explicit device index.

See also

tensorplay.tensor() never shares its data and creates a new “leaf tensor” (see Autograd mechanics).

Parameters:
  • data (array_like) – Initial data for the tensor. Can be a list, tuple, NumPy ndarray, scalar, and other types.

  • dtype (tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, infers data type from data.

  • device (tensorplay.device, optional) – the device of the constructed tensor. If None and data is a tensor then the device of data is used. If None and data is not a tensor then the result tensor is constructed on the current device.

Example:

>>> a = numpy.array([1, 2, 3])
>>> t = tensorplay.as_tensor(a)
>>> t
tensor([ 1,  2,  3])
>>> t[0] = -1
>>> a
array([-1,  2,  3])

>>> a = numpy.array([1, 2, 3])
>>> t = tensorplay.as_tensor(a, device=tensorplay.device('cuda'))
>>> t
tensor([ 1,  2,  3])
>>> t[0] = -1
>>> a
array([1,  2,  3])
#

asarray

functionFull reference ↗
tensorplay.asarray(obj: Any, *, dtype: dtype | None, device: DeviceLikeType | None, copy: bool | None = None, requires_grad: bool = False) → Tensor

Converts obj to a tensor.

obj can be one of:

  1. a tensor

  2. a NumPy array or a NumPy scalar

  3. a DLPack capsule

  4. an object that implements Python’s buffer protocol

  5. a scalar

  6. a sequence of scalars

When obj is a tensor, NumPy array, or DLPack capsule the returned tensor will, by default, not require a gradient, have the same datatype as obj, be on the same device, and share memory with it. These properties can be controlled with the dtype, device, copy, and requires_grad keyword arguments. If the returned tensor is of a different datatype, on a different device, or a copy is requested then it will not share its memory with obj. If requires_grad is True then the returned tensor will require a gradient, and if obj is also a tensor with an autograd history then the returned tensor will have the same history.

When obj is not a tensor, NumPy array, or DLPack capsule but implements Python’s buffer protocol then the buffer is interpreted as an array of bytes grouped according to the size of the datatype passed to the dtype keyword argument. (If no datatype is passed then the default floating point datatype is used, instead.) The returned tensor will have the specified datatype (or default floating point datatype if none is specified) and, by default, be on the CPU device and share memory with the buffer.

When obj is a NumPy scalar, the returned tensor will be a 0-dimensional tensor on the CPU and that doesn’t share its memory (i.e. copy=True). By default datatype will

When obj is none of the above but a scalar, or a sequence of scalars then the returned tensor will, by default, infer its datatype from the scalar values, be on the current default device, and not share its memory.

See also

tensorplay.tensor() creates a tensor that always copies the data from the input object. tensorplay.from_numpy() creates a tensor that always shares memory from NumPy arrays. tensorplay.frombuffer() creates a tensor that always shares memory from objects that implement the buffer protocol. tensorplay.from_dlpack() creates a tensor that always shares memory from DLPack capsules.

Parameters:

obj (object) – a tensor, NumPy array, DLPack Capsule, object that implements Python’s buffer protocol, scalar, or sequence of scalars.

Keyword Arguments:
  • dtype (tensorplay.dtype, optional) – the datatype of the returned tensor. Default: None, which causes the datatype of the returned tensor to be inferred from obj.

  • copy (bool, optional) – controls whether the returned tensor shares memory with obj. Default: None, which causes the returned tensor to share memory with obj whenever possible. If True then the returned tensor does not share its memory. If False then the returned tensor shares its memory with obj and an error is thrown if it cannot.

  • device (tensorplay.device, optional) – the device of the returned tensor. Default: None, which causes the device of obj to be used. Or, if obj is a Python sequence, the current default device will be used.

  • requires_grad (bool, optional) – whether the returned tensor requires grad. Default: False, which causes the returned tensor not to require a gradient. If True, then the returned tensor will require a gradient, and if obj is also a tensor with an autograd history then the returned tensor will have the same history.

Example:

>>> a = tensorplay.tensor([1, 2, 3])
>>> # Shares memory with tensor 'a'
>>> b = tensorplay.asarray(a)
>>> a.data_ptr() == b.data_ptr()
True
>>> # Forces memory copy
>>> c = tensorplay.asarray(a, copy=True)
>>> a.data_ptr() == c.data_ptr()
False

>>> a = tensorplay.tensor([1., 2., 3.], requires_grad=True)
>>> b = a + 2
>>> b
tensor([3., 4., 5.], grad_fn=<AddBackward0>)
>>> # Shares memory with tensor 'b', with no grad
>>> c = tensorplay.asarray(b)
>>> c
tensor([3., 4., 5.])
>>> # Shares memory with tensor 'b', retaining autograd history
>>> d = tensorplay.asarray(b, requires_grad=True)
>>> d
tensor([3., 4., 5.], grad_fn=<AddBackward0>)

>>> array = numpy.array([1, 2, 3])
>>> # Shares memory with array 'array'
>>> t1 = tensorplay.asarray(array)
>>> array.__array_interface__['data'][0] == t1.data_ptr()
True
>>> # Copies memory due to dtype mismatch
>>> t2 = tensorplay.asarray(array, dtype=tensorplay.float32)
>>> array.__array_interface__['data'][0] == t2.data_ptr()
False

>>> scalar = numpy.float64(0.5)
>>> tensorplay.asarray(scalar)
tensor(0.5000, dtype=tensorplay.float64)
#

avg_pool2d

functionFull reference ↗
tensorplay.avg_pool2d(input, kernel_size, stride=[], padding=[], ceil_mode=False, count_include_pad=True, divisor_override=None, *, out=None)[source]
#

avg_pool3d

functionFull reference ↗
tensorplay.avg_pool3d(input, kernel_size, stride=[], padding=[], ceil_mode=False, count_include_pad=True, divisor_override=None, *, out=None)[source]
#

batch_norm

functionFull reference ↗
tensorplay.batch_norm(input, weight, bias, running_mean, running_var, training, momentum, eps)[source]
#

binary_cross_entropy_with_logits

functionFull reference ↗
tensorplay.binary_cross_entropy_with_logits(input, target, weight=None, pos_weight=None)[source]
#

binary_cross_entropy

functionFull reference ↗
tensorplay.binary_cross_entropy(input, target, weight=None, reduction=1, *, out=None)[source]
#

cholesky

functionFull reference ↗
tensorplay.cholesky(input, upper=False, *, out=None) → Tensor[source]

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

If upper is True, the returned matrix U is upper-triangular, and the decomposition has the form:

A=UTUA = U^TU

If upper is False, the returned matrix L is lower-triangular, and the decomposition has the form:

A=LLTA = LL^T

If upper is True, and AA is a batch of symmetric positive-definite matrices, then the returned tensor will be composed of upper-triangular Cholesky factors of each of the individual matrices. Similarly, when upper is False, the returned tensor will be composed of lower-triangular Cholesky factors of each of the individual matrices.

Warning

tensorplay.cholesky() is deprecated in favor of tensorplay.linalg.cholesky()

L = tensorplay.cholesky(A) should be replaced with

L = tensorplay.linalg.cholesky(A)

U = tensorplay.cholesky(A, upper=True) should be replaced with

U = tensorplay.linalg.cholesky(A).mH

This transform will produce equivalent results for all valid (symmetric positive definite) inputs.

Parameters:
  • input (Tensor) – the input tensor AA of size (∗,n,n)(*, n, n) where * is zero or more batch dimensions consisting of symmetric positive-definite matrices.

  • upper (bool, optional) – flag that indicates whether to return a upper or lower triangular matrix. Default: False

Keyword Arguments:

out (Tensor, optional) – the output matrix

Example:

>>> a = tensorplay.randn(3, 3)
>>> a = a @ a.mT + 1e-3 # make symmetric positive-definite
>>> l = tensorplay.cholesky(a)
>>> a
tensor([[ 2.4112, -0.7486,  1.4551],
        [-0.7486,  1.3544,  0.1294],
        [ 1.4551,  0.1294,  1.6724]])
>>> l
tensor([[ 1.5528,  0.0000,  0.0000],
        [-0.4821,  1.0592,  0.0000],
        [ 0.9371,  0.5487,  0.7023]])
>>> l @ l.mT
tensor([[ 2.4112, -0.7486,  1.4551],
        [-0.7486,  1.3544,  0.1294],
        [ 1.4551,  0.1294,  1.6724]])
>>> a = tensorplay.randn(3, 2, 2) # Example for batched input
>>> a = a @ a.mT + 1e-03 # make symmetric positive-definite
>>> l = tensorplay.cholesky(a)
>>> z = l @ l.mT
>>> tensorplay.dist(z, a)
tensor(2.3842e-07)
#

col2im

functionFull reference ↗
tensorplay.col2im(input, output_size, kernel_size, dilation=[], padding=[], stride=[], *, out=None)[source]
#

conv_depthwise3d

functionFull reference ↗
tensorplay.conv_depthwise3d(input, weight, kernel_size, bias, stride, padding, dilation)[source]
#

conv_transpose1d_grad_bias

functionFull reference ↗
tensorplay.conv_transpose1d_grad_bias(grad_output, input, weight, stride, padding, output_padding, groups, dilation)[source]
#

conv_transpose1d_grad_input

functionFull reference ↗
tensorplay.conv_transpose1d_grad_input(grad_output, input, weight, stride, padding, output_padding, groups, dilation)[source]
#

conv_transpose1d_grad_weight

functionFull reference ↗
tensorplay.conv_transpose1d_grad_weight(grad_output, input, weight, stride, padding, output_padding, groups, dilation)[source]
#

conv_transpose2d_grad_bias

functionFull reference ↗
tensorplay.conv_transpose2d_grad_bias(grad_output, input, weight, stride, padding, output_padding, groups, dilation)[source]
#

conv_transpose2d_grad_input

functionFull reference ↗
tensorplay.conv_transpose2d_grad_input(grad_output, input, weight, stride, padding, output_padding, groups, dilation)[source]
#

conv_transpose2d_grad_weight

functionFull reference ↗
tensorplay.conv_transpose2d_grad_weight(grad_output, input, weight, stride, padding, output_padding, groups, dilation)[source]
#

conv_transpose3d_grad_bias

functionFull reference ↗
tensorplay.conv_transpose3d_grad_bias(grad_output, input, weight, stride, padding, output_padding, groups, dilation)[source]
#

conv_transpose3d_grad_input

functionFull reference ↗
tensorplay.conv_transpose3d_grad_input(grad_output, input, weight, stride, padding, output_padding, groups, dilation)[source]
#

conv_transpose3d_grad_weight

functionFull reference ↗
tensorplay.conv_transpose3d_grad_weight(grad_output, input, weight, stride, padding, output_padding, groups, dilation)[source]
#

conv1d_grad_bias

functionFull reference ↗
tensorplay.conv1d_grad_bias(grad_output, input, weight, stride, padding, dilation, groups)[source]
#

conv1d_grad_input

functionFull reference ↗
tensorplay.conv1d_grad_input(grad_output, input, weight, stride, padding, dilation, groups)[source]
#

conv1d_grad_weight

functionFull reference ↗
tensorplay.conv1d_grad_weight(grad_output, input, weight, stride, padding, dilation, groups)[source]
#

conv2d_grad_bias

functionFull reference ↗
tensorplay.conv2d_grad_bias(grad_output, input, weight, stride, padding, dilation, groups)[source]
#

conv2d_grad_input

functionFull reference ↗
tensorplay.conv2d_grad_input(grad_output, input, weight, stride, padding, dilation, groups)[source]
#

conv2d_grad_weight

functionFull reference ↗
tensorplay.conv2d_grad_weight(grad_output, input, weight, stride, padding, dilation, groups)[source]
#

conv2d_relu

functionFull reference ↗
tensorplay.conv2d_relu(input, weight, bias=None, stride=[1, 1], padding=[0, 0], dilation=[1, 1], groups=1)[source]
#

conv2d

functionFull reference ↗
tensorplay.conv2d(input, weight, bias=None, stride=[1, 1], padding=[0, 0], dilation=[1, 1], groups=1)[source]
#

conv3d_grad_bias

functionFull reference ↗
tensorplay.conv3d_grad_bias(grad_output, input, weight, stride, padding, dilation, groups)[source]
#

conv3d_grad_input

functionFull reference ↗
tensorplay.conv3d_grad_input(grad_output, input, weight, stride, padding, dilation, groups)[source]
#

conv3d_grad_weight

functionFull reference ↗
tensorplay.conv3d_grad_weight(grad_output, input, weight, stride, padding, dilation, groups)[source]
#

convolution_backward_overrideable

functionFull reference ↗
tensorplay.convolution_backward_overrideable(grad_output, input, weight, stride, padding, dilation, transposed, output_padding, groups, output_mask)[source]
#

convolution_overrideable

functionFull reference ↗
tensorplay.convolution_overrideable(input, weight, bias, stride, padding, dilation, transposed, output_padding, groups)[source]
#

cross_entropy_loss

functionFull reference ↗
tensorplay.cross_entropy_loss(input, target, weight=None, reduction=1, ignore_index=-100, label_smoothing=0.0)[source]
#

custom_bwd

functionFull reference ↗
tensorplay.custom_bwd(bwd=None, *, device_type: str)[source]

Create a helper decorator for backward methods of custom autograd functions.

Autograd functions are subclasses of tensorplay.autograd.Function. Ensures that backward executes with the same autocast state as forward.

Parameters:

device_type (str) – Device type to use. ‘cuda’, ‘cpu’. The type is the same as the type attribute of a tensorplay.device. Thus, you may obtain the device type of a tensor using Tensor.device.type.

#

custom_fwd

functionFull reference ↗
tensorplay.custom_fwd(fwd=None, *, device_type: str, cast_inputs=None)[source]

Create a helper decorator for forward methods of custom autograd functions.

Autograd functions are subclasses of tensorplay.autograd.Function.

Parameters:
  • device_type (str) – Device type to use. ‘cuda’, ‘cpu’. The type is the same as the type attribute of a tensorplay.device. Thus, you may obtain the device type of a tensor using Tensor.device.type.

  • cast_inputs (tensorplay.dtype or None, optional, default=None) – If not None, when forward runs in an autocast-enabled region, casts incoming floating-point Tensors to the target dtype (non-floating-point Tensors are not affected), then executes forward with autocast disabled. If None, forward’s internal ops execute with the current autocast state.

Note

If the decorated forward is called outside an autocast-enabled region, custom_fwd is a no-op and cast_inputs has no effect.

#

embedding_bag

functionFull reference ↗
tensorplay.embedding_bag(input, indices=None, offsets=None, scale_grad_by_freq=False, mode=0, sparse=False, per_sample_weights=None, include_last_offset=False, padding_idx=None)[source]
#

empty

functionFull reference ↗
tensorplay.empty()

empty(*size, *, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False, pin_memory=False, memory_format=tensorplay.contiguous_format) -> Tensor

Returns a tensor filled with uninitialized data. The shape of the tensor is defined by the variable argument size.

Note

The returned storage is uninitialized, and tensorplay.use_deterministic_algorithms() does not change that. If the contents matter, allocate with tensorplay.zeros() or fill the tensor before reading it, otherwise the output becomes a source of nondeterminism. Floating point and complex tensors are filled with NaN, and integer tensors are filled with the maximum value.

Parameters:

size (int...) – a sequence of integers defining the shape of the output tensor. Can be a variable number of arguments or a collection like a list or tuple.

Keyword Arguments:
  • out (Tensor, optional) – the output tensor.

  • dtype (tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.layout, optional) – the desired layout of returned Tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see tensorplay.set_default_device()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

  • pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False.

  • memory_format (tensorplay.memory_format, optional) – the desired memory format of returned Tensor. Default: tensorplay.contiguous_format.

Example:

>>> tensorplay.empty((2,3), dtype=tensorplay.int64)
tensor([[ 9.4064e+13,  2.8000e+01,  9.3493e+13],
        [ 7.5751e+18,  7.1428e+18,  7.5955e+18]])
#

fake_quantize_per_channel_affine_cachemask

functionFull reference ↗
tensorplay.fake_quantize_per_channel_affine_cachemask(input, scale, zero_point, axis, quant_min, quant_max)[source]
#

fake_quantize_per_tensor_affine_cachemask

functionFull reference ↗
tensorplay.fake_quantize_per_tensor_affine_cachemask(input, scale, zero_point, quant_min, quant_max)[source]
#

fft_fftfreq

functionFull reference ↗
tensorplay.fft_fftfreq(n, d=1.0, *, dtype=None, layout=None, device=None, pin_memory=None, out=None)[source]
#

fft_rfftfreq

functionFull reference ↗
tensorplay.fft_rfftfreq(n, d=1.0, *, dtype=None, layout=None, device=None, pin_memory=None, out=None)[source]
#

fork_rng

functionFull reference ↗
tensorplay.fork_rng(devices=None, enabled=True, _caller='fork_rng', _devices_kw='devices')[source]

Forks the RNG state: code inside the context gets a pristine RNG.

Saves the CPU RNG state and the RNG state of every CUDA device listed in devices on entry and restores them on exit, so random operations inside the block do not advance the outer streams. devices=[] forks only the CPU generator.

#

fractional_max_pool2d

functionFull reference ↗
tensorplay.fractional_max_pool2d(input, kernel_size, output_size, random_samples, *, out=None)[source]
#

fractional_max_pool3d

functionFull reference ↗
tensorplay.fractional_max_pool3d(input, kernel_size, output_size, random_samples, *, out=None)[source]
#

from_numpy

functionFull reference ↗
tensorplay.from_numpy(ndarray) → Tensor

Creates a Tensor from a numpy.ndarray.

The returned tensor and ndarray share the same memory. Modifications to the tensor will be reflected in the ndarray and vice versa. The returned tensor is not resizable.

It currently accepts ndarray with dtypes of numpy.float64, numpy.float32, numpy.float16, numpy.complex64, numpy.complex128, numpy.int64, numpy.int32, numpy.int16, numpy.int8, numpy.uint8, and bool.

Warning

Writing to a tensor created from a read-only NumPy array is not supported and will result in undefined behavior.

Example:

>>> a = numpy.array([1, 2, 3])
>>> t = tensorplay.from_numpy(a)
>>> t
tensor([ 1,  2,  3])
>>> t[0] = -1
>>> a
array([-1,  2,  3])
#

frombuffer

functionFull reference ↗
tensorplay.frombuffer(buffer, *, dtype, count=-1, offset=0, requires_grad=False) → Tensor

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

Skips the first offset bytes in the buffer, and interprets the rest of the raw bytes as a 1-dimensional tensor of type dtype with count elements.

Note that either of the following must be true:

1. count is a positive non-zero number, and the total number of bytes in the buffer is more than offset plus count times the size (in bytes) of dtype.

2. count is negative, and the length (number of bytes) of the buffer subtracted by the offset is a multiple of the size (in bytes) of dtype.

The returned tensor and buffer share the same memory. Modifications to the tensor will be reflected in the buffer and vice versa. The returned tensor is not resizable.

Note

This function increments the reference count for the object that owns the shared memory. Therefore, such memory will not be deallocated before the returned tensor goes out of scope.

Warning

This function’s behavior is undefined when passed an object implementing the buffer protocol whose data is not on the CPU. Doing so is likely to cause a segmentation fault.

Warning

This function does not try to infer the dtype (hence, it is not optional). Passing a different dtype than its source may result in unexpected behavior.

Parameters:

buffer (object) – a Python object that exposes the buffer interface.

Keyword Arguments:
  • dtype (tensorplay.dtype) – the desired data type of returned tensor.

  • count (int, optional) – the number of desired elements to be read. If negative, all the elements (until the end of the buffer) will be read. Default: -1.

  • offset (int, optional) – the number of bytes to skip at the start of the buffer. Default: 0.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

Example:

>>> import array
>>> a = array.array('i', [1, 2, 3])
>>> t = tensorplay.frombuffer(a, dtype=tensorplay.int32)
>>> t
tensor([ 1,  2,  3])
>>> t[0] = -1
>>> a
array([-1,  2,  3])

>>> # Interprets the signed char bytes as 32-bit integers.
>>> # Each 4 signed char elements will be interpreted as
>>> # 1 signed 32-bit integer.
>>> import array
>>> a = array.array('b', [-1, 0, 0, 0])
>>> tensorplay.frombuffer(a, dtype=tensorplay.int32)
tensor([255], dtype=tensorplay.int32)
#

full

functionFull reference ↗
tensorplay.full(size, fill_value, \*, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) → Tensor

Creates a tensor of size size filled with fill_value. The tensor’s dtype is inferred from fill_value.

Parameters:
  • size (int...) – a list, tuple, or tensorplay.Size of integers defining the shape of the output tensor.

  • fill_value (Scalar) – the value to fill the output tensor with.

Keyword Arguments:
  • out (Tensor, optional) – the output tensor.

  • dtype (tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.layout, optional) – the desired layout of returned Tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see tensorplay.set_default_device()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

Example:

>>> tensorplay.full((2, 3), 3.141592)
tensor([[ 3.1416,  3.1416,  3.1416],
        [ 3.1416,  3.1416,  3.1416]])
#

get_autocast_dtype

functionFull reference ↗
tensorplay.get_autocast_dtype(device_type: str = 'cuda') → tensorplay._C.DType
#

get_default_dtype

functionFull reference ↗
tensorplay.get_default_dtype() → tensorplay.dtype[source]

Get the current default floating point tensorplay.dtype.

Example:

>>> tensorplay.get_default_dtype()  # initial default for floating point is tensorplay.float32
tensorplay.float32
>>> tensorplay.set_default_dtype(tensorplay.float64)
>>> tensorplay.get_default_dtype()  # default is now changed to tensorplay.float64
tensorplay.float64
#

get_num_threads

functionFull reference ↗
tensorplay.get_num_threads() → int

Returns the number of threads used for parallelizing CPU operations

#

get_parallel_info

functionFull reference ↗
tensorplay.get_parallel_info() → str

Returns a detailed string describing parallelization settings

#

get_thread_num

functionFull reference ↗
tensorplay.get_thread_num() → int

Returns the current thread number (starting from 0) in the current parallel region, or 0 in the sequential region

#

gradient

functionFull reference ↗
tensorplay.gradient(input, *, spacing=1, dim=None, edge_order=1) → List of Tensors[source]

Estimates the gradient of a function g:Rn→Rg : \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.

The gradient of gg is estimated using samples. By default, when spacing is not specified, the samples are entirely described by input, and the mapping of input coordinates to an output is the same as the tensor’s mapping of indices to values. For example, for a three-dimensional input the function described is g:R3→Rg : \mathbb{R}^3 \rightarrow \mathbb{R}, and g(1,2,3) ==input[1,2,3]g(1, 2, 3)\ == input[1, 2, 3].

When spacing is specified, it modifies the relationship between input and input coordinates. This is detailed in the “Keyword Arguments” section below.

The gradient is estimated by estimating each partial derivative of gg independently. This estimation is accurate if gg is in C3C^3 (it has at least 3 continuous derivatives), and the estimation can be improved by providing closer samples. Mathematically, the value at each interior point of a partial derivative is estimated using Taylor’s theorem with remainder. Letting xx be an interior point with x−hlx-h_l and x+hrx+h_r be points neighboring it to the left and right respectively, f(x+hr)f(x+h_r) and f(x−hl)f(x-h_l) can be estimated using:

f(x+hr)=f(x)+hrf′(x)+hr2f′′(x)2+hr3f′′′(ξ1)6,ξ1∈(x,x+hr)f(x−hl)=f(x)−hlf′(x)+hl2f′′(x)2−hl3f′′′(ξ2)6,ξ2∈(x,x−hl)\begin{aligned} f(x+h_r) = f(x) + h_r f'(x) + {h_r}^2 \frac{f''(x)}{2} + {h_r}^3 \frac{f'''(\xi_1)}{6}, \xi_1 \in (x, x+h_r) \\ f(x-h_l) = f(x) - h_l f'(x) + {h_l}^2 \frac{f''(x)}{2} - {h_l}^3 \frac{f'''(\xi_2)}{6}, \xi_2 \in (x, x-h_l) \\ \end{aligned}

Using the fact that f∈C3f \in C^3 and solving the linear system, we derive:

f′(x)≈hl2f(x+hr)−hr2f(x−hl)+(hr2−hl2)f(x)hrhl2+hr2hlf'(x) \approx \frac{ {h_l}^2 f(x+h_r) - {h_r}^2 f(x-h_l) + ({h_r}^2-{h_l}^2 ) f(x) }{ {h_r} {h_l}^2 + {h_r}^2 {h_l} }

Note

We estimate the gradient of functions in complex domain g:Cn→Cg : \mathbb{C}^n \rightarrow \mathbb{C} in the same way.

The value of each partial derivative at the boundary points is computed differently. See edge_order below.

Parameters:

input (Tensor) – the tensor that represents the values of the function

Keyword Arguments:
  • spacing (scalar, list of scalar, list of Tensor, optional) – spacing can be used to modify how the input tensor’s indices relate to sample coordinates. If spacing is a scalar then the indices are multiplied by the scalar to produce the coordinates. For example, if spacing=2 the indices (1, 2, 3) become coordinates (2, 4, 6). If spacing is a list of scalars then the corresponding indices are multiplied. For example, if spacing=(2, -1, 3) the indices (1, 2, 3) become coordinates (2, -2, 9). Finally, if spacing is a list of one-dimensional tensors then each tensor specifies the coordinates for the corresponding dimension. For example, if the indices are (1, 2, 3) and the tensors are (t0, t1, t2), then the coordinates are (t0[1], t1[2], t2[3])

  • dim (int, list of int, optional) – the dimension or dimensions to approximate the gradient over. By default the partial gradient in every dimension is computed. Note that when dim is specified the elements of the spacing argument must correspond with the specified dims.”

  • edge_order (int, optional) – 1 or 2, for first-order or second-order estimation of the boundary (“edge”) values, respectively. Note that when edge_order is specified, each dimension size of input should be at least edge_order+1

Examples:

>>> # Estimates the gradient of f(x)=x^2 at points [-2, -1, 2, 4]
>>> coordinates = (tensorplay.tensor([-2., -1., 1., 4.]),)
>>> values = tensorplay.tensor([4., 1., 1., 16.], )
>>> tensorplay.gradient(values, spacing = coordinates)
(tensor([-3., -2., 2., 5.]),)

>>> # Estimates the gradient of the R^2 -> R function whose samples are
>>> # described by the tensor t. Implicit coordinates are [0, 1] for the outermost
>>> # dimension and [0, 1, 2, 3] for the innermost dimension, and function estimates
>>> # partial derivative for both dimensions.
>>> t = tensorplay.tensor([[1, 2, 4, 8], [10, 20, 40, 80]])
>>> tensorplay.gradient(t)
(tensor([[ 9., 18., 36., 72.],
         [ 9., 18., 36., 72.]]),
 tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
         [10.0000, 15.0000, 30.0000, 40.0000]]))

>>> # A scalar value for spacing modifies the relationship between tensor indices
>>> # and input coordinates by multiplying the indices to find the
>>> # coordinates. For example, below the indices of the innermost
>>> # 0, 1, 2, 3 translate to coordinates of [0, 2, 4, 6], and the indices of
>>> # the outermost dimension 0, 1 translate to coordinates of [0, 2].
>>> tensorplay.gradient(t, spacing = 2.0) # dim = None (implicitly [0, 1])
(tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
          [ 4.5000, 9.0000, 18.0000, 36.0000]]),
 tensor([[ 0.5000, 0.7500, 1.5000, 2.0000],
          [ 5.0000, 7.5000, 15.0000, 20.0000]]))
>>> # doubling the spacing between samples halves the estimated partial gradients.

>>>
>>> # Estimates only the partial derivative for dimension 1
>>> tensorplay.gradient(t, dim = 1) # spacing = None (implicitly 1.)
(tensor([[ 1.0000, 1.5000, 3.0000, 4.0000],
         [10.0000, 15.0000, 30.0000, 40.0000]]),)

>>> # When spacing is a list of scalars, the relationship between the tensor
>>> # indices and input coordinates changes based on dimension.
>>> # For example, below, the indices of the innermost dimension 0, 1, 2, 3 translate
>>> # to coordinates of [0, 3, 6, 9], and the indices of the outermost dimension
>>> # 0, 1 translate to coordinates of [0, 2].
>>> tensorplay.gradient(t, spacing = [3., 2.])
(tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
         [ 4.5000, 9.0000, 18.0000, 36.0000]]),
 tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
         [ 3.3333, 5.0000, 10.0000, 13.3333]]))

>>> # The following example is a replication of the previous one with explicit
>>> # coordinates.
>>> coords = (tensorplay.tensor([0, 2]), tensorplay.tensor([0, 3, 6, 9]))
>>> tensorplay.gradient(t, spacing = coords)
(tensor([[ 4.5000, 9.0000, 18.0000, 36.0000],
         [ 4.5000, 9.0000, 18.0000, 36.0000]]),
 tensor([[ 0.3333, 0.5000, 1.0000, 1.3333],
         [ 3.3333, 5.0000, 10.0000, 13.3333]]))
#

hspmm

functionFull reference ↗
tensorplay.hspmm(mat1, mat2, *, out=None) → Tensor[source]

Performs a matrix multiplication of a sparse COO matrix mat1 and a strided matrix mat2. The result is a (1 + 1)-dimensional hybrid COO matrix.

Parameters:
  • mat1 (Tensor) – the first sparse matrix to be matrix multiplied

  • mat2 (Tensor) – the second strided matrix to be matrix multiplied

Keyword Arguments:

out (Tensor, optional) – the output tensor.

#

in_parallel_region

functionFull reference ↗
tensorplay.in_parallel_region() → bool

Checks whether the code runs in a parallel region

#

is_autocast_available

functionFull reference ↗
tensorplay.is_autocast_available(device_type: str) → bool[source]

Return a bool indicating if autocast is available on device_type.

Parameters:

device_type (str) – Device type to use. Possible values are: ‘cuda’, ‘cpu’. The type is the same as the type attribute of a tensorplay.device. Thus, you may obtain the device type of a tensor using Tensor.device.type.

#

is_tensor

functionFull reference ↗
tensorplay.is_tensor(obj: Any, /) → TypeIs[Tensor][source]

Returns True if obj is a TensorPlay tensor.

Note that this function is simply doing isinstance(obj, Tensor). Using that isinstance check is better for type checking with mypy, and more explicit - so it’s recommended to use that instead of is_tensor.

Parameters:

obj (object) – Object to test

Example:

>>> x = tensorplay.tensor([1, 2, 3])
>>> tensorplay.is_tensor(x)
True
#

max_pool1d_with_indices

functionFull reference ↗
tensorplay.max_pool1d_with_indices(input, kernel_size, stride=[], padding=0, dilation=1, ceil_mode=False)[source]
#

max_pool2d_with_indices

functionFull reference ↗
tensorplay.max_pool2d_with_indices(input, kernel_size, stride=[], padding=[], dilation=[], ceil_mode=False, *, out=None)[source]
#

max_pool2d

functionFull reference ↗
tensorplay.max_pool2d(input, kernel_size, stride=[], padding=[0, 0], dilation=[1, 1], ceil_mode=False)[source]
#

max_pool3d_with_indices

functionFull reference ↗
tensorplay.max_pool3d_with_indices(input, kernel_size, stride=[], padding=[], dilation=[], ceil_mode=False, *, out=None)[source]
#

max

functionFull reference ↗
tensorplay.max(input, *, out=None) → Tensor[source]

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

Note

The difference between max/min and amax/amin is:
  • amax/amin supports reducing on multiple dimensions,

  • amax/amin does not return indices.

Both amax/amin evenly distribute gradients between equal values when there are multiple input elements with the same minimum or maximum value.

For max/min:
  • If reduce over all dimensions(no dim specified), gradients evenly distribute between equally max/min values.

  • If reduce over one specified axis, only propagate to the indexed element.

Parameters:

input (Tensor) – the input tensor.

Keyword Arguments:

out (Tensor, optional) – the output tensor.

Example:

>>> a = tensorplay.randn(1, 3)
>>> a
tensor([[ 0.6763,  0.7445, -2.2369]])
>>> tensorplay.max(a)
tensor(0.7445)
tensorplay.max(input, dim, keepdim=False, *, out=None)[source]

Returns a namedtuple (values, indices) where values is the maximum value of each row of the input tensor in the given dimension dim. And indices is the index location of each maximum value found (argmax).

If keepdim is True, the output tensors are of the same size as input except in the dimension dim where they are of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensors having 1 fewer dimension than input.

Note

If there are multiple maximal values in a reduced row then the indices of the first maximal value are returned.

Parameters:
  • input (Tensor) – the input tensor.

  • dim (int, optional) –

    the dimension to reduce. If omitted, all dimensions are reduced. Explicit None is not supported.

    keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False.

Keyword Arguments:

out (tuple, optional) – the result tuple of two output tensors (max, max_indices)

Example:

>>> a = tensorplay.randn(4, 4)
>>> a
tensor([[-1.2360, -0.2942, -0.1222,  0.8475],
        [ 1.1949, -1.1127, -2.2379, -0.6702],
        [ 1.5717, -0.9207,  0.1297, -1.8768],
        [-0.6172,  1.0036, -0.6060, -0.2432]])
>>> tensorplay.max(a, 1)
tensorplay.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
>>> a = tensorplay.tensor([[1.0, 2.0], [3.0, 4.0]])
>>> a.max(dim=1, keepdim=True)
tensorplay.return_types.max(
values=tensor([[2.], [4.]]),
indices=tensor([[1], [1]]))
>>> a.max(dim=1, keepdim=False)
tensorplay.return_types.max(
values=tensor([2., 4.]),
indices=tensor([1, 1]))
tensorplay.max(input, other, *, out=None) → Tensor[source]

See tensorplay.maximum().

#

min

functionFull reference ↗
tensorplay.min(input, *, out=None) → Tensor[source]

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

Note

The difference between max/min and amax/amin is:
  • amax/amin supports reducing on multiple dimensions,

  • amax/amin does not return indices.

Both amax/amin evenly distribute gradients between equal values when there are multiple input elements with the same minimum or maximum value.

For max/min:
  • If reduce over all dimensions(no dim specified), gradients evenly distribute between equally max/min values.

  • If reduce over one specified axis, only propagate to the indexed element.

Parameters:

input (Tensor) – the input tensor.

Keyword Arguments:

out (Tensor, optional) – the output tensor.

Example:

>>> a = tensorplay.randn(1, 3)
>>> a
tensor([[ 0.6750,  1.0857,  1.7197]])
>>> tensorplay.min(a)
tensor(0.6750)
tensorplay.min(input, dim, keepdim=False, *, out=None)[source]

Returns a namedtuple (values, indices) where values is the minimum value of each row of the input tensor in the given dimension dim. And indices is the index location of each minimum value found (argmin).

If keepdim is True, the output tensors are of the same size as input except in the dimension dim where they are of size 1. Otherwise, dim is squeezed (see tensorplay.squeeze()), resulting in the output tensors having 1 fewer dimension than input.

Note

If there are multiple minimal values in a reduced row then the indices of the first minimal value are returned.

Parameters:
  • input (Tensor) – the input tensor.

  • dim (int, optional) –

    the dimension to reduce. If omitted, all dimensions are reduced. Explicit None is not supported.

    keepdim (bool, optional): whether the output tensor has dim retained or not. Default: False.

Keyword Arguments:

out (tuple, optional) – the tuple of two output tensors (min, min_indices)

Example:

>>> a = tensorplay.randn(4, 4)
>>> a
tensor([[-0.6248,  1.1334, -1.1899, -0.2803],
        [-1.4644, -0.2635, -0.3651,  0.6134],
        [ 0.2457,  0.0384,  1.0128,  0.7015],
        [-0.1153,  2.9849,  2.1458,  0.5788]])
>>> tensorplay.min(a, 1)
tensorplay.return_types.min(values=tensor([-1.1899, -1.4644,  0.0384, -0.1153]), indices=tensor([2, 0, 1, 0]))
tensorplay.min(input, other, *, out=None) → Tensor[source]

See tensorplay.minimum().

#

mkldnn_linear_backward_input

functionFull reference ↗
tensorplay.mkldnn_linear_backward_input(input_size, grad_output, weight)[source]
#

mkldnn_reorder_conv2d_weight

functionFull reference ↗
tensorplay.mkldnn_reorder_conv2d_weight(input, padding=0, stride=1, dilation=1, groups=1, input_size=None)[source]
#

mkldnn_reorder_conv3d_weight

functionFull reference ↗
tensorplay.mkldnn_reorder_conv3d_weight(input, padding=0, stride=1, dilation=1, groups=1, input_size=None)[source]
#

multi_margin_loss

functionFull reference ↗
tensorplay.multi_margin_loss(input, target, p=1, margin=1, weight=None, reduction=1, *, out=None)[source]
#

multilabel_margin_loss_forward

functionFull reference ↗
tensorplay.multilabel_margin_loss_forward(input, target, reduction, *, out=None)[source]
#

new_empty_strided

functionFull reference ↗
tensorplay.new_empty_strided(input, size, stride, dtype=None, layout=None, device=None, pin_memory=None)[source]
#

new_full

functionFull reference ↗
tensorplay.new_full(input, size, fill_value, dtype=None, layout=None, device=None, pin_memory=None)[source]
#

nll_loss_forward

functionFull reference ↗
tensorplay.nll_loss_forward(input, target, weight, reduction, ignore_index, *, out=None)[source]
#

nll_loss

functionFull reference ↗
tensorplay.nll_loss(input, target, weight=None, reduction=1, ignore_index=-100, *, out=None)[source]
#

nll_loss2d_forward

functionFull reference ↗
tensorplay.nll_loss2d_forward(input, target, weight, reduction, ignore_index, *, out=None)[source]
#

nll_loss2d

functionFull reference ↗
tensorplay.nll_loss2d(input, target, weight=None, reduction=1, ignore_index=-100, *, out=None)[source]
#

ones

functionFull reference ↗
tensorplay.ones(\*size, \*, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) → Tensor

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

Parameters:

size (int...) – a sequence of integers defining the shape of the output tensor. Can be a variable number of arguments or a collection like a list or tuple.

Keyword Arguments:
  • out (Tensor, optional) – the output tensor.

  • dtype (tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.layout, optional) – the desired layout of returned Tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see tensorplay.set_default_device()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

Example:

>>> tensorplay.ones(2, 3)
tensor([[ 1.,  1.,  1.],
        [ 1.,  1.,  1.]])

>>> tensorplay.ones(5)
tensor([ 1.,  1.,  1.,  1.,  1.])
#

pad_sequence

functionFull reference ↗
tensorplay.pad_sequence(sequences, batch_first=False, padding_value=0.0, padding_side='right')[source]
#

quantized_add

functionFull reference ↗
tensorplay.quantized_add(a, b, a_scale, a_zero_point, b_scale, b_zero_point, out_scale, out_zero_point)[source]
#

quantized_clamp

functionFull reference ↗
tensorplay.quantized_clamp(input, self_scale, self_zero_point, out_scale, out_zero_point, min=None, max=None)[source]
#

quantized_conv2d_prepack

functionFull reference ↗
tensorplay.quantized_conv2d_prepack(weight, weight_scales, weight_zero_points, bias=None, transposed=False)[source]
#

quantized_conv2d_run

functionFull reference ↗
tensorplay.quantized_conv2d_run(input, weight_packed, bias_packed, weight_sizes, input_scale, input_zero_point, out_scale, out_zero_point, stride=1, padding=0, dilation=1, output_padding=0, groups=1, transposed=False, output_min=None, output_max=None)[source]
#

quantized_conv2d_unpack

functionFull reference ↗
tensorplay.quantized_conv2d_unpack(weight_packed, bias_packed, weight_sizes, transposed=False, depthwise=False)[source]
#

quantized_conv2d

functionFull reference ↗
tensorplay.quantized_conv2d(input, weight, bias, input_scale, input_zero_point, weight_scale, weight_zero_point, out_scale, out_zero_point, stride=1, padding=0, dilation=1, groups=1)[source]
#

quantized_div

functionFull reference ↗
tensorplay.quantized_div(a, b, a_scale, a_zero_point, b_scale, b_zero_point, out_scale, out_zero_point)[source]
#

quantized_linear

functionFull reference ↗
tensorplay.quantized_linear(input, weight, input_scale, input_zero_point, weight_scales, weight_zero_points, bias=None, out_scale=1.0, out_zero_point=0)[source]
#

quantized_mul

functionFull reference ↗
tensorplay.quantized_mul(a, b, a_scale, a_zero_point, b_scale, b_zero_point, out_scale, out_zero_point)[source]
#

quantized_sub

functionFull reference ↗
tensorplay.quantized_sub(a, b, a_scale, a_zero_point, b_scale, b_zero_point, out_scale, out_zero_point)[source]
#

rand

functionFull reference ↗
tensorplay.rand()

rand(*size, *, generator=None, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor

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

The shape of the tensor is defined by the variable argument size.

Parameters:

size (int...) – a sequence of integers defining the shape of the output tensor. Can be a variable number of arguments or a collection like a list or tuple.

Keyword Arguments:
  • generator (tensorplay.Generator, optional) – a pseudorandom number generator for sampling

  • out (Tensor, optional) – the output tensor.

  • dtype (tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.layout, optional) – the desired layout of returned Tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see tensorplay.set_default_device()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

  • pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False.

Example:

>>> tensorplay.rand(4)
tensor([ 0.5204,  0.2503,  0.3525,  0.5673])
>>> tensorplay.rand(2, 3)
tensor([[ 0.8237,  0.5781,  0.6879],
        [ 0.3816,  0.7249,  0.0998]])
#

randn

functionFull reference ↗
tensorplay.randn()

randn(*size, *, generator=None, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False, pin_memory=False) -> Tensor

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

outi∼N(0,1)\text{out}_{i} \sim \mathcal{N}(0, 1)

For complex dtypes, the tensor is i.i.d. sampled from a complex normal distribution with zero mean and unit variance as

outi∼CN(0,1)\text{out}_{i} \sim \mathcal{CN}(0, 1)

This is equivalent to separately sampling the real (Re⁡)(\operatorname{Re}) and imaginary (Im⁡)(\operatorname{Im}) part of outi\text{out}_i as

Re⁡(outi)∼N(0,12),Im⁡(outi)∼N(0,12)\operatorname{Re}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2}),\quad \operatorname{Im}(\text{out}_{i}) \sim \mathcal{N}(0, \frac{1}{2})

The shape of the tensor is defined by the variable argument size.

Parameters:

size (int...) – a sequence of integers defining the shape of the output tensor. Can be a variable number of arguments or a collection like a list or tuple.

Keyword Arguments:
  • generator (tensorplay.Generator, optional) – a pseudorandom number generator for sampling

  • out (Tensor, optional) – the output tensor.

  • dtype (tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.layout, optional) – the desired layout of returned Tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see tensorplay.set_default_device()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

  • pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False.

Example:

>>> tensorplay.randn(4)
tensor([-2.1436,  0.9966,  2.3426, -0.6366])
>>> tensorplay.randn(2, 3)
tensor([[ 1.5954,  2.8929, -1.0923],
        [ 1.1719, -0.4709, -0.1996]])
#

rrelu_with_noise_

functionFull reference ↗
tensorplay.rrelu_with_noise_(input, noise, lower=0.125, upper=0.3333333333333333, training=False, generator=None)[source]
#

rrelu_with_noise

functionFull reference ↗
tensorplay.rrelu_with_noise(input, noise, lower=0.125, upper=0.3333333333333333, training=False, generator=None, *, out=None)[source]
#

scaled_dot_product_attention

functionFull reference ↗
tensorplay.scaled_dot_product_attention(query, key, value, attn_mask=None, dropout_p=0.0, is_causal=False, scale=None, enable_gqa=False)[source]
#

set_autocast_dtype

functionFull reference ↗
tensorplay.set_autocast_dtype(device_type: str, dtype: tensorplay._C.DType) → None
#

set_default_device

functionFull reference ↗
tensorplay.set_default_device(device: device) → None[source]

Sets the default tensorplay.Tensor to be allocated on device. This does not affect factory function calls which are called with an explicit device argument. Factory calls will be performed as if they were passed device as an argument.

To only temporarily change the default device instead of setting it globally, use with tensorplay.device(device): instead.

The default device is initially cpu. If you set the default tensor device to another device (e.g., cuda) without a device index, tensors will be allocated on whatever the current device for the device type, even after tensorplay.cuda.set_device() is called.

Warning

This function imposes a slight performance cost on every Python call to the tensorplay API (not just factory functions).

Note

This doesn’t affect functions that create tensors that share the same memory as the input, like: tensorplay.from_numpy() and tensorplay.frombuffer()

Parameters:

device (tensorplay.device, str, int, or None) – the device to set as default, or None to clear the override. An integer is interpreted as an index for the current accelerator.

Example:

>>> # xdoctest: +SKIP("requires cuda, changes global state")
>>> tensorplay.get_default_device()
device(type='cpu')
>>> tensorplay.set_default_device('cuda')  # current device is 0
>>> tensorplay.get_default_device()
device(type='cuda', index=0)
>>> tensorplay.set_default_device('cuda')
>>> tensorplay.cuda.set_device('cuda:1')  # current device is 1
>>> tensorplay.get_default_device()
device(type='cuda', index=1)
>>> tensorplay.set_default_device('cuda:1')
>>> tensorplay.get_default_device()
device(type='cuda', index=1)
#

set_default_dtype

functionFull reference ↗
tensorplay.set_default_dtype(d: dtype, /) → None[source]

Sets the default floating point dtype to d. Supports floating point dtype as inputs. Other dtypes will cause tensorplay to raise an exception.

When TensorPlay is initialized its default floating point dtype is float32, and the intent of set_default_dtype(float64) is to facilitate NumPy-like type inference. The default floating point dtype is used to:

  1. Implicitly determine the default complex dtype. When the default floating type is float16, the default complex dtype is complex32. For float32, the default complex dtype is complex64. For float64, it is complex128. For bfloat16, an exception will be raised because there is no corresponding complex type for bfloat16.

  2. Infer the dtype for tensors constructed using Python floats or complex Python numbers. See examples below.

  3. Determine the result of type promotion between bool and integer tensors and Python floats and complex Python numbers.

Parameters:

d (tensorplay.dtype) – the floating point dtype to make the default.

Example

>>> # xdoctest: +SKIP("Other tests may have changed the default type. Can we reset it?")
>>> # initial default for floating point is float32
>>> # Python floats are interpreted as float32
>>> tensorplay.tensor([1.2, 3]).dtype
tensorplay.float32
>>> # initial default for floating point is complex64
>>> # Complex Python numbers are interpreted as complex64
>>> tensorplay.tensor([1.2, 3j]).dtype
tensorplay.complex64
>>> tensorplay.set_default_dtype(tensorplay.float64)
>>> # Python floats are now interpreted as float64
>>> tensorplay.tensor([1.2, 3]).dtype  # a new floating point tensor
tensorplay.float64
>>> # Complex Python numbers are now interpreted as complex128
>>> tensorplay.tensor([1.2, 3j]).dtype  # a new complex tensor
tensorplay.complex128
>>> tensorplay.set_default_dtype(tensorplay.float16)
>>> # Python floats are now interpreted as float16
>>> tensorplay.tensor([1.2, 3]).dtype  # a new floating point tensor
tensorplay.float16
>>> # Complex Python numbers are now interpreted as complex128
>>> tensorplay.tensor([1.2, 3j]).dtype  # a new complex tensor
tensorplay.complex32
#

set_deterministic_debug_mode

functionFull reference ↗
tensorplay.set_deterministic_debug_mode(debug_mode: int | str) → None[source]

Sets the debug mode for deterministic operations.

Note

This is an alternative interface for tensorplay.use_deterministic_algorithms(). Refer to that function’s documentation for details about affected operations.

Parameters:

debug_mode (str or int) – If “default” or 0, don’t error or warn on nondeterministic operations. If “warn” or 1, warn on nondeterministic operations. If “error” or 2, error on nondeterministic operations.

#

set_float32_matmul_precision

functionFull reference ↗
tensorplay.set_float32_matmul_precision(precision: str) → None[source]

Sets the internal precision of float32 matrix multiplications.

Running float32 matrix multiplications in lower precision may significantly increase performance, and in some programs the loss of precision has a negligible impact.

Supports three settings:

  • “highest”, float32 matrix multiplications use the float32 datatype (24 mantissa bits with 23 bits explicitly stored) for internal computations.

  • “high”, float32 matrix multiplications either use the TensorFloat32 datatype (10 mantissa bits explicitly stored) or treat each float32 number as the sum of two bfloat16 numbers (approximately 16 mantissa bits with 14 bits explicitly stored), if the appropriate fast matrix multiplication algorithms are available. Otherwise float32 matrix multiplications are computed as if the precision is “highest”. See below for more information on the bfloat16 approach.

  • “medium”, float32 matrix multiplications use the bfloat16 datatype (8 mantissa bits with 7 bits explicitly stored) for internal computations, if a fast matrix multiplication algorithm using that datatype internally is available. Otherwise float32 matrix multiplications are computed as if the precision is “high”.

Note

This does not change the output dtype of float32 matrix multiplications, it controls how the internal computation of the matrix multiplication is performed.

Note

This does not change the precision of convolution operations. Other flags, like tensorplay.backends.cudnn.allow_tf32, may control the precision of convolution operations.

Note

This flag currently only affects one native device type: CUDA. If “high” or “medium” are set then the TensorFloat32 datatype will be used when computing float32 matrix multiplications, equivalent to setting tensorplay.backends.cuda.matmul.allow_tf32 = True. When “highest” (the default) is set then the float32 datatype is used for internal computations, equivalent to setting tensorplay.backends.cuda.matmul.allow_tf32 = False.

Parameters:

precision (str) – can be set to “highest” (default), “high”, or “medium” (see above).

#

set_num_threads

functionFull reference ↗
tensorplay.set_num_threads(int)

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

Warning

To ensure that the correct number of threads is used, set_num_threads must be called before running eager, JIT or autograd code.

#

set_printoptions

functionFull reference ↗
tensorplay.set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None, edge_items=None, **kwargs)[source]

Set printing options for tensor output.

Parameters:
  • precision (int, optional) – digits after the decimal point.

  • threshold (int, optional) – total elements above which large tensors are summarized instead of printed fully.

  • edgeitems (int, optional) – edge items printed per dimension when summarizing. edge_items is accepted as an alias.

  • linewidth (int, optional) – line width for wrapping output.

Unset (None) arguments keep their current values.

#

slow_conv_dilated2d

functionFull reference ↗
tensorplay.slow_conv_dilated2d(input, weight, kernel_size, bias=None, stride=1, padding=0, dilation=1)[source]
#

slow_conv_dilated3d

functionFull reference ↗
tensorplay.slow_conv_dilated3d(input, weight, kernel_size, bias=None, stride=1, padding=0, dilation=1)[source]
#

slow_conv_transpose2d

functionFull reference ↗
tensorplay.slow_conv_transpose2d(input, weight, kernel_size, bias=None, stride=1, padding=0, output_padding=0, dilation=1, *, out=None)[source]
#

slow_conv_transpose3d

functionFull reference ↗
tensorplay.slow_conv_transpose3d(input, weight, kernel_size, bias=None, stride=1, padding=0, output_padding=0, dilation=1, *, out=None)[source]
#

slow_conv3d_forward

functionFull reference ↗
tensorplay.slow_conv3d_forward(input, weight, kernel_size, bias, stride, padding, *, out=None)[source]
#

slow_conv3d

functionFull reference ↗
tensorplay.slow_conv3d(input, weight, kernel_size, bias=None, stride=1, padding=0, *, out=None)[source]
#

smm

functionFull reference ↗
tensorplay.smm(input, mat) → Tensor[source]

Performs a matrix multiplication of the sparse matrix input with the dense matrix mat.

Parameters:
  • input (Tensor) – a sparse matrix to be matrix multiplied

  • mat (Tensor) – a dense matrix to be matrix multiplied

#

sparse_compressed_tensor

functionFull reference ↗
tensorplay.sparse_compressed_tensor(compressed_indices, plain_indices, values, size=None, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) → Tensor[source]

Constructs a sparse tensor in Compressed Sparse format - CSR, CSC, BSR, or BSC - with specified values at the given compressed_indices and plain_indices. Sparse matrix multiplication operations in Compressed Sparse format are typically faster than that for sparse tensors in COO format. Make you have a look at the note on the data type of the indices.

Note

If the device argument is not specified the device of the given values and indices tensor(s) must match. If, however, the argument is specified the input Tensors will be converted to the given device and in turn determine the device of the constructed sparse tensor.

Parameters:
  • compressed_indices (array_like) – (B+1)-dimensional array of size (*batchsize, compressed_dim_size + 1). The last element of each batch is the number of non-zero elements or blocks. This tensor encodes the index in values and plain_indices depending on where the given compressed dimension (row or column) starts. Each successive number in the tensor subtracted by the number before it denotes the number of elements or blocks in a given compressed dimension.

  • plain_indices (array_like) – Plain dimension (column or row) coordinates of each element or block in values. (B+1)-dimensional tensor with the same length as values.

  • values (array_list) – Initial values for the tensor. Can be a list, tuple, NumPy ndarray, scalar, and other types. that represents a (1+K)-dimensional (for CSR and CSC layouts) or (1+2+K)-dimensional tensor (for BSR and BSC layouts) where K is the number of dense dimensions.

  • size (list, tuple, tensorplay.Size, optional) – Size of the sparse tensor: (*batchsize, nrows * blocksize[0], ncols * blocksize[1], *densesize) where blocksize[0] == blocksize[1] == 1 for CSR and CSC formats. If not provided, the size will be inferred as the minimum size big enough to hold all non-zero elements or blocks.

Keyword Arguments:
  • dtype (tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, infers data type from values.

  • layout (tensorplay.layout, required) – the desired layout of returned tensor: tensorplay.sparse_csr, tensorplay.sparse_csc, tensorplay.sparse_bsr, or tensorplay.sparse_bsc.

  • device (tensorplay.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see tensorplay.set_default_device()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

  • pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

  • check_invariants (bool, optional) – If sparse tensor invariants are checked. Default: as returned by tensorplay.sparse.check_sparse_tensor_invariants.is_enabled(), initially False.

Example:

>>> compressed_indices = [0, 2, 4]
>>> plain_indices = [0, 1, 0, 1]
>>> values = [1, 2, 3, 4]
>>> tensorplay.sparse_compressed_tensor(tensorplay.tensor(compressed_indices, dtype=tensorplay.int64),
...                                tensorplay.tensor(plain_indices, dtype=tensorplay.int64),
...                                tensorplay.tensor(values), dtype=tensorplay.double, layout=tensorplay.sparse_csr)
tensor(crow_indices=tensor([0, 2, 4]),
       col_indices=tensor([0, 1, 0, 1]),
       values=tensor([1., 2., 3., 4.]), size=(2, 2), nnz=4,
       dtype=tensorplay.float64, layout=tensorplay.sparse_csr)
#

sparse_sampled_addmm

functionFull reference ↗
tensorplay.sparse_sampled_addmm(input, mat1, mat2, *, beta=1, alpha=1, out=None)[source]
#

special_shifted_chebyshev_polynomial_t

functionFull reference ↗
tensorplay.special_shifted_chebyshev_polynomial_t(x, n, *, out=None)[source]
#

special_shifted_chebyshev_polynomial_u

functionFull reference ↗
tensorplay.special_shifted_chebyshev_polynomial_u(x, n, *, out=None)[source]
#

special_shifted_chebyshev_polynomial_v

functionFull reference ↗
tensorplay.special_shifted_chebyshev_polynomial_v(x, n, *, out=None)[source]
#

special_shifted_chebyshev_polynomial_w

functionFull reference ↗
tensorplay.special_shifted_chebyshev_polynomial_w(x, n, *, out=None)[source]
#

sspaddmm

functionFull reference ↗
tensorplay.sspaddmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) → Tensor[source]

Matrix multiplies a sparse tensor mat1 with a dense tensor mat2, then adds the sparse tensor input to the result.

Note: This function is equivalent to tensorplay.addmm(), except input and mat1 are sparse.

Parameters:
  • input (Tensor) – a sparse matrix to be added

  • mat1 (Tensor) – a sparse matrix to be matrix multiplied

  • mat2 (Tensor) – a dense matrix to be matrix multiplied

Keyword Arguments:
  • beta (Number, optional) – multiplier for mat (β\beta)

  • alpha (Number, optional) – multiplier for mat1 &#64; mat2 (α\alpha)

  • out (Tensor, optional) – the output tensor.

#

tensor

functionFull reference ↗
tensorplay.tensor(data, *, dtype=None, device=None, requires_grad=False, pin_memory=False) → Tensor

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

Warning

When working with tensors prefer using tensorplay.Tensor.clone(), tensorplay.Tensor.detach(), and tensorplay.Tensor.requires_grad_() for readability. Letting t be a tensor, tensorplay.tensor(t) is equivalent to t.detach().clone(), and tensorplay.tensor(t, requires_grad=True) is equivalent to t.detach().clone().requires_grad_(True).

See also

tensorplay.as_tensor() preserves autograd history and avoids copies where possible. tensorplay.from_numpy() creates a tensor that shares storage with a NumPy array.

Parameters:

data (array_like) – Initial data for the tensor. Can be a list, tuple, NumPy ndarray, scalar, and other types.

Keyword Arguments:
  • dtype (tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, infers data type from data.

  • device (tensorplay.device, optional) – the device of the constructed tensor. If None and data is a tensor then the device of data is used. If None and data is not a tensor then the result tensor is constructed on the current device.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

  • pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False.

Example:

>>> tensorplay.tensor([[0.1, 1.2], [2.2, 3.1], [4.9, 5.2]])
tensor([[ 0.1000,  1.2000],
        [ 2.2000,  3.1000],
        [ 4.9000,  5.2000]])

>>> tensorplay.tensor([0, 1])  # Type inference on data
tensor([ 0,  1])

>>> tensorplay.tensor([[0.11111, 0.222222, 0.3333333]],
...              dtype=tensorplay.float64,
...              device=tensorplay.device('cuda:0'))  # creates a double tensor on a CUDA device
tensor([[ 0.1111,  0.2222,  0.3333]], dtype=tensorplay.float64, device='cuda:0')

>>> tensorplay.tensor(3.14159)  # Create a zero-dimensional (scalar) tensor
tensor(3.1416)

>>> tensorplay.tensor([])  # Create an empty tensor (of size (0,))
tensor([])
#

thnn_conv2d

functionFull reference ↗
tensorplay.thnn_conv2d(input, weight, kernel_size, bias=None, stride=1, padding=0, *, out=None)[source]
#

to

functionFull reference ↗
tensorplay.to(input, dtype=None, layout=None, device=None, pin_memory=None, non_blocking=False, copy=False, memory_format=None)[source]
#

tp_cosine_embedding_loss

functionFull reference ↗
tensorplay.tp_cosine_embedding_loss(input1, input2, target, margin=0.0, reduction=1)[source]
#

tp_margin_ranking_loss

functionFull reference ↗
tensorplay.tp_margin_ranking_loss(input1, input2, target, margin=0.0, reduction=1)[source]
#

tp_poisson_nll_loss

functionFull reference ↗
tensorplay.tp_poisson_nll_loss(input, target, log_input=True, full=False, eps=1e-08, reduction=1)[source]
#

typename

functionFull reference ↗
tensorplay.typename(obj: Any, /) → str[source]

String representation of the type of an object.

This function returns a fully qualified string representation of an object’s type. :param obj: The object whose type to represent :type obj: object

Returns:

the type of the object o

Return type:

str

Example

>>> x = tensorplay.tensor([1, 2, 3])
>>> tensorplay.typename(x)
'tensorplay.LongTensor'
>>> tensorplay.typename(tensorplay.nn.Parameter)
'tensorplay.nn.parameter.Parameter'
#

unique_dim_consecutive

functionFull reference ↗
tensorplay.unique_dim_consecutive(input, dim, return_inverse=False, return_counts=False)[source]
#

unique_dim

functionFull reference ↗
tensorplay.unique_dim(input, dim, sorted=True, return_inverse=False, return_counts=False)[source]
#

unsafe_chunk

functionFull reference ↗
tensorplay.unsafe_chunk(input, chunks, dim=0) → List of Tensors[source]

Works like tensorplay.chunk() but without enforcing the autograd restrictions on inplace modification of the outputs.

Warning

This function is safe to use as long as only the input, or only the outputs are modified inplace after calling this function. It is user’s responsibility to ensure that is the case. If both the input and one or more of the outputs are modified inplace, gradients computed by autograd will be silently incorrect.

#

unsafe_split

functionFull reference ↗
tensorplay.unsafe_split(tensor, split_size_or_sections, dim=0) → List of Tensors[source]

Works like tensorplay.split() but without enforcing the autograd restrictions on inplace modification of the outputs.

Warning

This function is safe to use as long as only the input, or only the outputs are modified inplace after calling this function. It is user’s responsibility to ensure that is the case. If both the input and one or more of the outputs are modified inplace, gradients computed by autograd will be silently incorrect.

#

upsample_bicubic2d

functionFull reference ↗
tensorplay.upsample_bicubic2d(input, output_size, align_corners, scales_h=None, scales_w=None, *, out=None)[source]
#

upsample_bilinear2d

functionFull reference ↗
tensorplay.upsample_bilinear2d(input, output_size, align_corners, scales_h=None, scales_w=None, *, out=None)[source]
#

upsample_linear1d

functionFull reference ↗
tensorplay.upsample_linear1d(input, output_size, align_corners, scales=None, *, out=None)[source]
#

upsample_nearest2d

functionFull reference ↗
tensorplay.upsample_nearest2d(input, output_size, scales_h=None, scales_w=None, *, out=None)[source]
#

upsample_nearest3d

functionFull reference ↗
tensorplay.upsample_nearest3d(input, output_size, scales_d=None, scales_h=None, scales_w=None, *, out=None)[source]
#

upsample_trilinear3d

functionFull reference ↗
tensorplay.upsample_trilinear3d(input, output_size, align_corners, scales_d=None, scales_h=None, scales_w=None, *, out=None)[source]
#

use_deterministic_algorithms

functionFull reference ↗
tensorplay.use_deterministic_algorithms(mode: bool, *, warn_only: bool = False) → None[source]

Sets whether TensorPlay operations must use “deterministic” algorithms. That is, algorithms which, given the same input, and when run on the same software and hardware, always produce the same output. When enabled, operations will use deterministic algorithms when available, and if only nondeterministic algorithms are available they will throw a RuntimeError when called.

Note

This setting alone is not always enough to make an application reproducible. Refer to Reproducibility for more information.

Note

tensorplay.set_deterministic_debug_mode() offers an alternative interface for this feature.

Note that deterministic operations tend to have worse performance than nondeterministic operations.

Note

This flag does not detect or prevent nondeterministic behavior caused by calling an inplace operation on a tensor with an internal memory overlap or by giving such a tensor as the out argument for an operation. In these cases, multiple writes of different data may target a single memory location, and the order of writes is not guaranteed.

Parameters:

mode (bool) – If True, makes potentially nondeterministic operations switch to a deterministic algorithm or throw a runtime error. If False, allows nondeterministic operations.

Keyword Arguments:

warn_only (bool, optional) – If True, operations that do not have a deterministic implementation will throw a warning instead of an error. Default: False

Example:

>>> # xdoctest: +SKIP
>>> tensorplay.use_deterministic_algorithms(True)
#

zeros

functionFull reference ↗
tensorplay.zeros(\*size, \*, out=None, dtype=None, layout=tensorplay.strided, device=None, requires_grad=False) → Tensor

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

Parameters:

size (int...) – a sequence of integers defining the shape of the output tensor. Can be a variable number of arguments or a collection like a list or tuple.

Keyword Arguments:
  • out (Tensor, optional) – the output tensor.

  • dtype (tensorplay.dtype, optional) – the desired data type of returned tensor. Default: if None, uses a global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.layout, optional) – the desired layout of returned Tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see tensorplay.set_default_device()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

Example:

>>> tensorplay.zeros(2, 3)
tensor([[ 0.,  0.,  0.],
        [ 0.,  0.,  0.]])

>>> tensorplay.zeros(5)
tensor([ 0.,  0.,  0.,  0.,  0.])

Classes 21

#

autocast

classFull reference ↗
class tensorplay.autocast(device_type: str, dtype: Any | None = None, enabled: bool = True, cache_enabled: bool | None = None)[source]

Instances of autocast serve as context managers or decorators that allow regions of your script to run in mixed precision.

In these regions, ops run in an op-specific dtype chosen by autocast to improve performance while maintaining accuracy.

When entering an autocast-enabled region, Tensors may be any type. You should not call half() or bfloat16() on your model(s) or inputs when using autocasting.

autocast should wrap only the forward pass(es) of your network, including the loss computation(s). Backward passes under autocast are not recommended. Backward ops run in the same type that autocast used for corresponding forward ops.

Example for CUDA Devices:

# Creates model and optimizer in default precision
model = Net().cuda()
optimizer = optim.SGD(model.parameters(), ...)

for input, target in data:
    optimizer.zero_grad()

    # Enables autocasting for the forward pass (model + loss)
    with tensorplay.autocast(device_type="cuda"):
        output = model(input)
        loss = loss_fn(output, target)

    # Exits the context manager before backward()
    loss.backward()
    optimizer.step()

autocast can also be used as a decorator, e.g., on the forward method of your model:

class AutocastModel(nn.Module):
    ...

    @tensorplay.autocast(device_type="cuda")
    def forward(self, input): ...

Floating-point Tensors produced in an autocast-enabled region may be float16. After returning to an autocast-disabled region, using them with floating-point Tensors of different dtypes may cause type mismatch errors. If so, cast the Tensor(s) produced in the autocast region back to float32 (or other dtype if desired).

autocast(enabled=False) subregions can be nested in autocast-enabled regions. Locally disabling autocast can be useful, for example, if you want to force a subregion to run in a particular dtype.

The autocast state is thread-local. If you want it enabled in a new thread, the context manager or decorator must be invoked in that thread.

Parameters:
  • device_type (str, required) – Device type to use. Possible values are: ‘cuda’ and ‘cpu’. The type is the same as the type attribute of a tensorplay.device. Thus, you may obtain the device type of a tensor using Tensor.device.type.

  • enabled (bool, optional) – Whether autocasting should be enabled in the region. Default: True

  • dtype (tensorplay.dtype, optional) – Data type for ops run in autocast. It uses the default value (tensorplay.float16 for CUDA and tensorplay.bfloat16 for CPU), given by get_autocast_dtype(), if dtype is None. Default: None

  • cache_enabled (bool, optional) – Whether the weight cache inside autocast should be enabled. Default: True

#

Device

classFull reference ↗
class tensorplay.Device
is_cpu(self: tensorplay._C.Device) → bool
is_cuda(self: tensorplay._C.Device) → bool
is_meta(self: tensorplay._C.Device) → bool
is_vulkan(self: tensorplay._C.Device) → bool
#

DeviceType

classFull reference ↗
class tensorplay.DeviceType

Members:

CPU

CUDA

Vulkan

META

Unknown

DeviceType.name -> str
#

DispatchKey

classFull reference ↗
class tensorplay.DispatchKey

Dispatch keys of the runtime, in dispatch-priority order: autocast keys outrank autograd keys, which outrank backend keys.

Members:

CPU

CUDA

Vulkan

SparseCPU

SparseCUDA

Sparse

AutogradCPU

AutogradCUDA

AutogradVulkan

AutogradSparseCPU

AutogradSparseCUDA

AutogradSparse

AutocastCPU

AutocastCUDA

AutocastVulkan

AutocastSparseCPU

AutocastSparseCUDA

AutocastSparse

VmapCPU

VmapCUDA

VmapVulkan

VmapSparseCPU

VmapSparseCUDA

VmapSparse

Composite

VmapMode

DynamicLayerFrontMode

DynamicLayerBackMode

Python

DispatchKey.name -> str
#

DType

classFull reference ↗
class tensorplay.DType

Members:

uint8

int8

int16

int32

int64

uint16

uint32

uint64

float16

bfloat16

float32

float64

complex32

complex64

complex128

bcomplex32

float8_e4m3fn

float8_e4m3fnuz

float8_e5m2

float8_e5m2fnuz

float8_e8m0fnu

qint8

quint8

qint32

quint2x4

quint4x2

quint1x8

bool

undefined

DType.name -> str
#

FileCheck

classFull reference ↗
class tensorplay.FileCheck
check(self: tensorplay._C.FileCheck, test_string: str) → tensorplay._C.FileCheck
check_count(self: tensorplay._C.FileCheck, test_string: str, count: SupportsInt | SupportsIndex, exactly: bool = False) → tensorplay._C.FileCheck
check_dag(self: tensorplay._C.FileCheck, test_string: str) → tensorplay._C.FileCheck
check_next(self: tensorplay._C.FileCheck, test_string: str) → tensorplay._C.FileCheck
check_not(self: tensorplay._C.FileCheck, test_string: str) → tensorplay._C.FileCheck
check_regex(self: tensorplay._C.FileCheck, test_string: str) → tensorplay._C.FileCheck
check_same(self: tensorplay._C.FileCheck, test_string: str) → tensorplay._C.FileCheck
check_source_highlighted(self: tensorplay._C.FileCheck, test_string: str) → tensorplay._C.FileCheck
run(self: tensorplay._C.FileCheck, test_string: str) → None
#

Future

classFull reference ↗
class tensorplay.Future
add_done_callback(self: object, callback: collections.abc.Callable) → None
done(self: tensorplay._C.Future) → bool
is_done(self: tensorplay._C.Future) → bool
set_exception(self: tensorplay._C.Future, result: object) → None
set_result(self: tensorplay._C.Future, result: object) → None
then(self: object, callback: collections.abc.Callable) → tensorplay._C.Future
value(self: tensorplay._C.Future) → object
wait(self: tensorplay._C.Future) → object
#

Generator

classFull reference ↗
class tensorplay.Generator(device='cpu') → Generator

Creates and returns a generator object that manages the state of the algorithm which produces pseudo random numbers. Used as a keyword argument in many in-place random sampling functions.

Parameters:

device (tensorplay.device, optional) – the desired device for the generator.

Returns:

An tensorplay.Generator object.

Return type:

Generator

Example:

>>> g_cpu = tensorplay.Generator()
>>> g_cuda = tensorplay.Generator(device='cuda')
property device

Generator.device -> device

Gets the current device of the generator.

Example:

>>> g_cpu = tensorplay.Generator()
>>> g_cpu.device
device(type='cpu')
get_state(self: tensorplay._C.Generator) → tensorplay::Tensor
initial_seed(self: tensorplay._C.Generator) → int
manual_seed(self: tensorplay._C.Generator, seed: SupportsInt | SupportsIndex) → int
seed(self: tensorplay._C.Generator) → int
set_state(self: tensorplay._C.Generator, new_state: tensorplay::Tensor) → None
#

GradScaler

classFull reference ↗
class tensorplay.GradScaler(device: str = 'cuda', init_scale: float = 65536.0, growth_factor: float = 2.0, backoff_factor: float = 0.5, growth_interval: int = 2000, enabled: bool = True)[source]

An instance scaler of GradScaler.

Helps perform the steps of gradient scaling conveniently.

  • scaler.scale(loss) multiplies a given loss by scaler’s current scale factor.

  • scaler.step(optimizer) safely unscales gradients and calls optimizer.step().

  • scaler.update() updates scaler’s scale factor.

Example:

# Creates a GradScaler once at the beginning of training.
scaler = GradScaler()

for epoch in epochs:
    for input, target in data:
        optimizer.zero_grad()
        output = model(input)
        loss = loss_fn(output, target)

        # Scales loss.  Calls backward() on scaled loss to create scaled gradients.
        scaler.scale(loss).backward()

        # scaler.step() first unscales gradients of the optimizer's params.
        # If gradients don't contain infs/NaNs, optimizer.step() is then called,
        # otherwise, optimizer.step() is skipped.
        scaler.step(optimizer)

        # Updates the scale for next iteration.
        scaler.update()

scaler dynamically estimates the scale factor each iteration. To minimize gradient underflow, a large scale factor should be used. However, float16 values can “overflow” (become inf or NaN) if the scale factor is too large. Therefore, the optimal scale factor is the largest factor that can be used without incurring inf or NaN gradient values. scaler approximates the optimal scale factor over time by checking the gradients for infs and NaNs during every scaler.step(optimizer) (or optional separate scaler.unscale_(optimizer), see unscale_()).

  • If infs/NaNs are found, scaler.step(optimizer) skips the underlying optimizer.step() (so the params themselves remain uncorrupted) and update() multiplies the scale by backoff_factor.

  • If no infs/NaNs are found, scaler.step(optimizer) runs the underlying optimizer.step() as usual. If growth_interval unskipped iterations occur consecutively, update() multiplies the scale by growth_factor.

Parameters:
  • device (str, optional, default="cuda") – Device type to use. Possible values are: ‘cuda’ and ‘cpu’. The type is the same as the type attribute of a tensorplay.device. Thus, you may obtain the device type of a tensor using Tensor.device.type.

  • init_scale (float, optional, default=2.**16) – Initial scale factor.

  • growth_factor (float, optional, default=2.0) – Factor by which the scale is multiplied during update() if no inf/NaN gradients occur for growth_interval consecutive iterations.

  • backoff_factor (float, optional, default=0.5) – Factor by which the scale is multiplied during update() if inf/NaN gradients occur in an iteration.

  • growth_interval (int, optional, default=2000) – Number of consecutive iterations without inf/NaN gradients that must occur for the scale to be multiplied by growth_factor.

  • enabled (bool, optional) – If False, disables gradient scaling. step() simply invokes the underlying optimizer.step(), and other methods become no-ops. Default: True

get_backoff_factor() → float[source]

Return a Python float containing the scale backoff factor.

get_growth_factor() → float[source]

Return a Python float containing the scale growth factor.

get_growth_interval() → int[source]

Return a Python int containing the growth interval.

get_scale() → float[source]

Return a Python float containing the current scale, or 1.0 if scaling is disabled.

is_enabled() → bool[source]

Return a bool indicating whether this instance is enabled.

load_state_dict(state_dict: dict[str, Any]) → None[source]

Load the scaler state.

If this instance is disabled, load_state_dict() is a no-op.

Parameters:

state_dict (dict) – scaler state. Should be an object returned from a call to state_dict().

scale(outputs: Tensor) → Tensor[source]
scale(outputs: list[Tensor]) → list[Tensor]
scale(outputs: tuple[Tensor, ...]) → tuple[Tensor, ...]
scale(outputs: Iterable[tensorplay.Tensor]) → Iterable[tensorplay.Tensor]

Multiplies (‘scales’) a tensor or list of tensors by the scale factor.

Returns scaled outputs. If this instance of GradScaler is not enabled, outputs are returned unmodified.

Parameters:

outputs (Tensor or iterable of Tensors) – Outputs to scale.

set_backoff_factor(new_factor: float) → None[source]

Set a new scale backoff factor.

Parameters:

new_scale (float) – Value to use as the new scale backoff factor.

set_growth_factor(new_factor: float) → None[source]

Set a new scale growth factor.

Parameters:

new_scale (float) – Value to use as the new scale growth factor.

set_growth_interval(new_interval: int) → None[source]

Set a new growth interval.

Parameters:

new_interval (int) – Value to use as the new growth interval.

state_dict() → dict[str, Any][source]

Return the state of the scaler as a dict.

It contains five entries:

  • "scale" - a Python float containing the current scale

  • "growth_factor" - a Python float containing the current growth factor

  • "backoff_factor" - a Python float containing the current backoff factor

  • "growth_interval" - a Python int containing the current growth interval

  • "_growth_tracker" - a Python int containing the number of recent consecutive unskipped steps.

If this instance is not enabled, returns an empty dict.

Note

If you wish to checkpoint the scaler’s state after a particular iteration, state_dict() should be called after update().

step(optimizer: Optimizer, *args: Any, **kwargs: Any) → Any[source]

Invoke unscale_(optimizer) followed by parameter update, if gradients are not infs/NaN.

step() carries out the following two operations:

  1. Internally invokes unscale_(optimizer) (unless unscale_() was explicitly called for optimizer earlier in the iteration). As part of the unscale_(), gradients are checked for infs/NaNs.

  2. If no inf/NaN gradients are found, invokes optimizer.step() using the unscaled gradients. Otherwise, optimizer.step() is skipped to avoid corrupting the params.

*args and **kwargs are forwarded to optimizer.step().

Returns the return value of optimizer.step(*args, **kwargs).

Parameters:
  • optimizer (tensorplay.optim.Optimizer) – Optimizer that applies the gradients.

  • args – Any arguments.

  • kwargs – Any keyword arguments.

Warning

Closure use is not currently supported.

unscale_(optimizer: Optimizer) → None[source]

Divides (“unscales”) the optimizer’s gradient tensors by the scale factor.

unscale_() is optional, serving cases where you need to modify or inspect gradients between the backward pass(es) and step(). If unscale_() is not called explicitly, gradients will be unscaled automatically during step().

Simple example, using unscale_() to enable clipping of unscaled gradients:

...
scaler.scale(loss).backward()
scaler.unscale_(optimizer)
tensorplay.nn.utils.clip_grad_norm_(model.parameters(), max_norm)
scaler.step(optimizer)
scaler.update()
Parameters:

optimizer (tensorplay.optim.Optimizer) – Optimizer that owns the gradients to be unscaled.

Warning

unscale_() should only be called once per optimizer per step() call, and only after all gradients for that optimizer’s assigned parameters have been accumulated. Calling unscale_() twice for a given optimizer between each step() triggers a RuntimeError.

update(new_scale: float | Tensor | None = None) → None[source]

Update the scale factor.

If any optimizer steps were skipped the scale is multiplied by backoff_factor to reduce it. If growth_interval unskipped iterations occurred consecutively, the scale is multiplied by growth_factor to increase it.

Passing new_scale sets the new scale value manually. (new_scale is not used directly, it’s used to fill GradScaler’s internal scale tensor. So if new_scale was a tensor, later in-place changes to that tensor will not further affect the scale GradScaler uses internally.)

Parameters:

new_scale (float or tensorplay.Tensor, optional, default=None) – New scale factor.

Warning

update() should only be called at the end of the iteration, after scaler.step(optimizer) has been invoked for all optimizers used this iteration.

#

Layout

classFull reference ↗
class tensorplay.Layout(*values)[source]

tensor.layout returns one of these values; dense tensors report STRIDED.

as_integer_ratio()

Return a pair of integers, whose ratio is equal to the original int.

The ratio is in lowest terms and has a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
bit_count()

Number of ones in the binary representation of the absolute value of self.

Also known as the population count.

>>> bin(13)
'0b1101'
>>> (13).bit_count()
3
bit_length()

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
conjugate()

Returns self, the complex conjugate of any int.

denominator

the denominator of a rational number in lowest terms

classmethod from_bytes(bytes, byteorder='big', *, signed=False)
imag

the imaginary part of a complex number

is_integer()

Returns True. Exists for duck type compatibility with float.is_integer.

numerator

the numerator of a rational number in lowest terms

real

the real part of a complex number

to_bytes(length=1, byteorder='big', *, signed=False)
#

MemoryFormat

classFull reference ↗
class tensorplay.MemoryFormat(*values)[source]
as_integer_ratio()

Return a pair of integers, whose ratio is equal to the original int.

The ratio is in lowest terms and has a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
bit_count()

Number of ones in the binary representation of the absolute value of self.

Also known as the population count.

>>> bin(13)
'0b1101'
>>> (13).bit_count()
3
bit_length()

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
conjugate()

Returns self, the complex conjugate of any int.

denominator

the denominator of a rational number in lowest terms

classmethod from_bytes(bytes, byteorder='big', *, signed=False)
imag

the imaginary part of a complex number

is_integer()

Returns True. Exists for duck type compatibility with float.is_integer.

numerator

the numerator of a rational number in lowest terms

real

the real part of a complex number

to_bytes(length=1, byteorder='big', *, signed=False)
#

QScheme

classFull reference ↗
class tensorplay.QScheme(*values)[source]

Quantization scheme attached to a quantized tensor’s quantizer.

as_integer_ratio()

Return a pair of integers, whose ratio is equal to the original int.

The ratio is in lowest terms and has a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
bit_count()

Number of ones in the binary representation of the absolute value of self.

Also known as the population count.

>>> bin(13)
'0b1101'
>>> (13).bit_count()
3
bit_length()

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
conjugate()

Returns self, the complex conjugate of any int.

denominator

the denominator of a rational number in lowest terms

classmethod from_bytes(bytes, byteorder='big', *, signed=False)
imag

the imaginary part of a complex number

is_integer()

Returns True. Exists for duck type compatibility with float.is_integer.

numerator

the numerator of a rational number in lowest terms

real

the real part of a complex number

to_bytes(length=1, byteorder='big', *, signed=False)
#

Size

classFull reference ↗
class tensorplay.Size(iterable=(), /)

Sequence of tensor dimension sizes (tuple subclass).

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

numel()

Product of the dimensions.

#

SymBool

classFull reference ↗
class tensorplay.SymBool
expect_bool(self: tensorplay._C.SymBool) → bool
guard_bool(self: tensorplay._C.SymBool, file: str = '', line: SupportsInt | SupportsIndex = 0) → bool
guard_or_false(self: tensorplay._C.SymBool, file: str = '', line: SupportsInt | SupportsIndex = 0) → bool
guard_or_true(self: tensorplay._C.SymBool, file: str = '', line: SupportsInt | SupportsIndex = 0) → bool
guard_size_oblivious(self: tensorplay._C.SymBool, file: str = '', line: SupportsInt | SupportsIndex = 0) → bool
has_hint(self: tensorplay._C.SymBool) → bool
is_symbolic(self: tensorplay._C.SymBool) → bool
maybe_as_bool(self: tensorplay._C.SymBool) → bool | None
statically_known_true(self: tensorplay._C.SymBool, file: str = '', line: SupportsInt | SupportsIndex = 0) → bool
sym_and(self: tensorplay._C.SymBool, arg0: tensorplay._C.SymBool) → tensorplay._C.SymBool
sym_not(self: tensorplay._C.SymBool) → tensorplay._C.SymBool
sym_or(self: tensorplay._C.SymBool, arg0: tensorplay._C.SymBool) → tensorplay._C.SymBool
sym_xor(self: tensorplay._C.SymBool, arg0: tensorplay._C.SymBool) → tensorplay._C.SymBool
static symbolic(name: str, hint: bool | None = None) → tensorplay._C.SymBool
to_sym_float(self: tensorplay._C.SymBool) → tensorplay._C.SymFloat
to_sym_int(self: tensorplay._C.SymBool) → tensorplay._C.SymInt
#

SymFloat

classFull reference ↗
class tensorplay.SymFloat
acos(self: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
as_integer_ratio(self: tensorplay._C.SymFloat) → object
asin(self: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
atan(self: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
ceil(self: tensorplay._C.SymFloat) → tensorplay._C.SymInt
conjugate(self: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
cos(self: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
cosh(self: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
expect_float(self: tensorplay._C.SymFloat) → float
floor(self: tensorplay._C.SymFloat) → tensorplay._C.SymInt
guard_float(self: tensorplay._C.SymFloat, file: str = '', line: SupportsInt | SupportsIndex = 0) → float
has_hint(self: tensorplay._C.SymFloat) → bool
hex(self: tensorplay._C.SymFloat) → object
is_integer(self: tensorplay._C.SymFloat) → tensorplay._C.SymBool
is_symbolic(self: tensorplay._C.SymFloat) → bool
log2(self: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
max(self: tensorplay._C.SymFloat, arg0: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
maybe_as_float(self: tensorplay._C.SymFloat) → float | None
min(self: tensorplay._C.SymFloat, arg0: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
round(self: tensorplay._C.SymFloat, ndigits: object = None) → object
sin(self: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
sinh(self: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
sqrt(self: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
sym_eq(self: tensorplay._C.SymFloat, arg0: tensorplay._C.SymFloat) → tensorplay._C.SymBool
sym_float(self: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
sym_ge(self: tensorplay._C.SymFloat, arg0: tensorplay._C.SymFloat) → tensorplay._C.SymBool
sym_gt(self: tensorplay._C.SymFloat, arg0: tensorplay._C.SymFloat) → tensorplay._C.SymBool
sym_int(self: tensorplay._C.SymFloat) → tensorplay._C.SymInt
sym_le(self: tensorplay._C.SymFloat, arg0: tensorplay._C.SymFloat) → tensorplay._C.SymBool
sym_lt(self: tensorplay._C.SymFloat, arg0: tensorplay._C.SymFloat) → tensorplay._C.SymBool
sym_ne(self: tensorplay._C.SymFloat, arg0: tensorplay._C.SymFloat) → tensorplay._C.SymBool
static symbolic(name: str, hint: SupportsFloat | SupportsIndex | None = None) → tensorplay._C.SymFloat
tan(self: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
tanh(self: tensorplay._C.SymFloat) → tensorplay._C.SymFloat
trunc(self: tensorplay._C.SymFloat) → tensorplay._C.SymInt
#

SymInt

classFull reference ↗
class tensorplay.SymInt
as_integer_ratio(self: tensorplay._C.SymInt) → tuple[tensorplay._C.SymInt, int]
bit_length(self: tensorplay._C.SymInt) → int
ceil(self: tensorplay._C.SymInt) → tensorplay._C.SymInt
clone(self: tensorplay._C.SymInt) → tensorplay._C.SymInt
conjugate(self: tensorplay._C.SymInt) → tensorplay._C.SymInt
expect_int(self: tensorplay._C.SymInt) → int
floor(self: tensorplay._C.SymInt) → tensorplay._C.SymInt
guard_int(self: tensorplay._C.SymInt, file: str = '', line: SupportsInt | SupportsIndex = 0) → int
has_hint(self: tensorplay._C.SymInt) → bool
is_heap_allocated(self: tensorplay._C.SymInt) → bool
is_same(self: tensorplay._C.SymInt, arg0: tensorplay._C.SymInt) → bool
is_symbolic(self: tensorplay._C.SymInt) → bool
max(self: tensorplay._C.SymInt, arg0: tensorplay._C.SymInt) → tensorplay._C.SymInt
maybe_as_int(self: tensorplay._C.SymInt) → int | None
min(self: tensorplay._C.SymInt, arg0: tensorplay._C.SymInt) → tensorplay._C.SymInt
pow_by_natural(self: tensorplay._C.SymInt, arg0: tensorplay._C.SymInt) → tensorplay._C.SymInt
round(self: tensorplay._C.SymInt) → tensorplay._C.SymInt
sym_eq(self: tensorplay._C.SymInt, arg0: tensorplay._C.SymInt) → tensorplay._C.SymBool
sym_float(self: tensorplay._C.SymInt) → tensorplay._C.SymFloat
sym_ge(self: tensorplay._C.SymInt, arg0: tensorplay._C.SymInt) → tensorplay._C.SymBool
sym_gt(self: tensorplay._C.SymInt, arg0: tensorplay._C.SymInt) → tensorplay._C.SymBool
sym_le(self: tensorplay._C.SymInt, arg0: tensorplay._C.SymInt) → tensorplay._C.SymBool
sym_lt(self: tensorplay._C.SymInt, arg0: tensorplay._C.SymInt) → tensorplay._C.SymBool
sym_ne(self: tensorplay._C.SymInt, arg0: tensorplay._C.SymInt) → tensorplay._C.SymBool
static symbolic(name: str, hint: SupportsInt | SupportsIndex | None = None) → tensorplay._C.SymInt
to_sym_float(self: tensorplay._C.SymInt) → tensorplay._C.SymFloat
trunc(self: tensorplay._C.SymInt) → tensorplay._C.SymInt
#

UntypedStorage

classFull reference ↗
class tensorplay.UntypedStorage
data_ptr(self: tensorplay._C.UntypedStorage) → int
nbytes(self: tensorplay._C.UntypedStorage) → int
resizable(self: tensorplay._C.UntypedStorage) → bool
resize_(self: tensorplay._C.UntypedStorage, nbytes: SupportsInt | SupportsIndex) → tensorplay._C.UntypedStorage
size(self: tensorplay._C.UntypedStorage) → int

Attributes 1

Exceptions 1

On this page

Functions 543as_tensorabsolute_adaptive_avg_pool2dadaptive_avg_pool3dadaptive_max_pool2d_with_indicesadaptive_max_pool2dadaptive_max_pool3dadd_add_reluaddbmm_addcdiv_addcmul_addmm_addr_airy_aialiasarctan2_are_deterministic_algorithms_enabledasarrayatan2_autocast_decrement_nestingautocast_increment_nestingavg_pool2davg_pool3dbaddbmm_batch_normbernoulli_bessel_j0bessel_j1bessel_y0bessel_y1binary_cross_entropy_with_logitsbinary_cross_entropybitwise_and_bitwise_left_shift_bitwise_not_bitwise_or_bitwise_right_shift_bitwise_xor_cauchy_ccol_indicesceluchebyshev_polynomial_tchebyshev_polynomial_uchebyshev_polynomial_vchebyshev_polynomial_wcholeskycircular_pad_ndclamp_maxclamp_minclear_autocast_cachecoalescecol_indicescol2imconstant_pad_ndcontiguousconv_depthwise3dconv_transpose1d_grad_biasconv_transpose1d_grad_inputconv_transpose1d_grad_weightconv_transpose2d_grad_biasconv_transpose2d_grad_inputconv_transpose2d_grad_weightconv_transpose3d_grad_biasconv_transpose3d_grad_inputconv_transpose3d_grad_weightconv1d_grad_biasconv1d_grad_inputconv1d_grad_weightconv2d_grad_biasconv2d_grad_inputconv2d_grad_weightconv2d_reluconv2dconv3d_grad_biasconv3d_grad_inputconv3d_grad_weightconvolution_backward_overrideableconvolution_overrideablecopy_copy_sparse_to_sparse_copycopysign_cross_entropy_losscrow_indicescumprod_cumsum_custom_bwdcustom_fwddatadense_dimdigamma_dimdiv_divide_dropoutelu_eluembedding_bagemptyentreq_erfcxerfinv_expand_asexpandexponential_fake_quantize_per_channel_affine_cachemaskfake_quantize_per_tensor_affine_cachemaskfft_fftfft_fft2fft_fftfreqfft_fftnfft_fftshiftfft_hfftfft_hfft2fft_hfftnfft_ifftfft_ifft2fft_ifftnfft_ifftshiftfft_ihfftfft_ihfft2fft_ihfftnfft_irfftfft_irfft2fft_irfftnfft_rfftfft_rfft2fft_rfftfreqfft_rfftnfill_diagonal_flatten_dense_tensorsfloat_power_floor_divide_fmod_fork_rngforward_addforward_cosforward_divforward_expforward_logforward_mmforward_mulforward_negforward_powforward_reluforward_sigmoidforward_sinforward_sqrtforward_subforward_tanhfractional_max_pool2dfractional_max_pool3dfrobenius_normfrom_dlpackfrom_numpyfrombufferfullfused_mul_addfused_ropefused_swiglugammaincgammainccge_gelu_gelugeometric_get_autocast_dtypeget_default_deviceget_default_dtypeget_deterministic_debug_modeget_float32_matmul_precisionget_num_threadsget_parallel_infoget_rng_stateget_thread_numglu_backward_jvpglu_jvpglugradientgreater_greater_equal_grid_samplergrouped_mmgt_hardsigmoid_hardsigmoidhardswish_hardswishhardtanh_hardtanhheaviside_hermite_polynomial_hhermite_polynomial_hehspmmhuber_losshypot_i0ei1i1eigamma_igammac_im2colin_parallel_regionindex_add_index_copy_index_fill_index_fillindex_putindex_reduce_indexindicesinitial_seedinner_backward_otherinner_backward_selfinspect_checkpointis_autocast_availableis_autocast_cache_enabledis_autocast_enabledis_coalescedis_contiguousis_deterministic_algorithms_warn_only_enabledis_leafis_pinnedis_quantizedis_set_tois_storageis_tensoriteml1_losslaguerre_polynomial_llayer_normle_leaky_relu_leaky_relulegendre_polynomial_plerp_less_less_equal_lgamma_lift_fresh_copylift_freshliftlinearlog_ndtrlog_normal_log_sigmoid_forwardlog_sigmoidlog_softmaxlogical_and_logical_not_logical_or_logical_xor_lt_manual_seedmasked_fill_masked_scatter_masked_scattermatmul_backward_othermatmul_backward_selfmatrix_Hmax_pool1d_with_indicesmax_pool2d_with_indicesmax_pool2dmax_pool3d_with_indicesmax_unpool2dmax_unpool3dmaxmHminmish_mishmkldnn_linear_backward_inputmkldnn_linearmkldnn_reorder_conv2d_weightmkldnn_reorder_conv3d_weightmodified_bessel_i0modified_bessel_i1modified_bessel_k0modified_bessel_k1mse_lossmTmul_multi_margin_lossmultilabel_margin_loss_forwardmultilabel_margin_lossmultilabel_soft_margin_lossmultiply_mvlgamma_native_alpha_dropoutnative_dropoutnative_feature_dropoutndtrndtrine_nested_to_padded_tensornew_empty_stridednew_emptynew_fullnew_onesnew_zerosnextafter_nll_loss_forwardnll_loss_ndnll_lossnll_loss2d_forwardnll_loss2dnonzero_numpynormal_normal_functionalnot_equal_numpy_Tone_hotonesoutput_nrpad_sequencepadpin_memorypixel_shufflepolygamma_pow_put_qschemequantized_addquantized_clampquantized_conv2d_prepackquantized_conv2d_runquantized_conv2d_unpackquantized_conv2dquantized_divquantized_linearquantized_mulquantized_subrandrandnrandom_reflection_pad_ndreflection_pad1dreflection_pad2dreflection_pad3drelurelu6_relu6remainder_renorm_repeatreplication_pad_ndreplication_pad1dreplication_pad2dreplication_pad3drequires_grad_reshape_asresize_retain_gradretains_gradrotary_embeddingrow_indicesrrelu_with_noise_rrelu_with_noisesamplescaled_dot_product_attentionscaled_modified_bessel_k0scaled_modified_bessel_k1scatter_scatter_add_scatter_reduce_seedset_set_autocast_cache_enabledset_autocast_dtypeset_autocast_enabledset_dataset_default_deviceset_default_dtypeset_deterministic_debug_modeset_float32_matmul_precisionset_num_threadsset_printoptionsset_rng_statesgn_shifted_chebyshev_polynomial_tshifted_chebyshev_polynomial_ushifted_chebyshev_polynomial_vshifted_chebyshev_polynomial_wsign_silu_silu_and_mulsilu_mulsilusizesliceslow_conv_dilated2dslow_conv_dilated3dslow_conv_transpose2dslow_conv_transpose3dslow_conv3d_forwardslow_conv3dsmmsmooth_l1_losssoft_margin_losssoftplussoftshrinksparse_addsparse_compressed_tensorsparse_dimsparse_masksparse_mmsparse_mulsparse_resize_sparse_resize_and_clear_sparse_sampled_addmmsparse_sumspdiagsspecial_airy_aispecial_bessel_j0special_bessel_j1special_bessel_y0special_bessel_y1special_chebyshev_polynomial_tspecial_chebyshev_polynomial_uspecial_chebyshev_polynomial_vspecial_chebyshev_polynomial_wspecial_digammaspecial_entrspecial_erfspecial_erfcspecial_erfcxspecial_erfinvspecial_exp2special_expitspecial_expm1special_gammaincspecial_gammainccspecial_gammalnspecial_hermite_polynomial_hspecial_hermite_polynomial_hespecial_i0special_i0especial_i1special_i1especial_laguerre_polynomial_lspecial_legendre_polynomial_pspecial_log_ndtrspecial_log_softmaxspecial_log1pspecial_logitspecial_logsumexpspecial_modified_bessel_i0special_modified_bessel_i1special_modified_bessel_k0special_modified_bessel_k1special_multigammalnspecial_ndtrspecial_ndtrispecial_polygammaspecial_psispecial_roundspecial_scaled_modified_bessel_k0special_scaled_modified_bessel_k1special_shifted_chebyshev_polynomial_tspecial_shifted_chebyshev_polynomial_uspecial_shifted_chebyshev_polynomial_vspecial_shifted_chebyshev_polynomial_wspecial_sincspecial_softmaxspecial_spherical_bessel_j0special_xlog1pyspecial_xlogyspecial_zetaspherical_bessel_j0split_with_sizessqueeze_sspaddmmstorage_offsetstridesub_subtract_sum_to_sizeswapaxes_swapdims_sym_floatsym_intsym_is_contiguoussym_itesym_maxsym_minsym_notsym_numelsym_sizesym_sqrtsym_storage_offsetsym_stridesym_sumt_tensorthnn_conv2dto_denseto_mkldnnto_padded_tensorto_sparse_bscto_sparse_bsrto_sparse_cscto_sparse_csrto_sparsetotp_cosine_embedding_losstp_hinge_embedding_losstp_kl_divtp_l1_losstp_margin_ranking_losstp_poisson_nll_losstp_soft_margin_losstranspose_tril_triu_true_divide_type_astypenameunflatten_dense_tensorsunfolduniform_unique_dim_consecutiveunique_dimunsafe_chunkunsafe_split_with_sizesunsafe_splitunsqueeze_upsample_bicubic2dupsample_bilinear2dupsample_linear1dupsample_nearest1dupsample_nearest2dupsample_nearest3dupsample_trilinear3duse_deterministic_algorithmsvaluesview_asviewxlog1py_xlog1pyzeroszetaClasses 21autocastDeviceDeviceTypeDispatchKeyDTypeFileCheckfinfoFutureGeneratorGradScaleriinfoLayoutMemoryFormatNodeQSchemeScalarSizeSymBoolSymFloatSymIntUntypedStorageAttributes 1TensorExceptions 1DeviceMismatchError
Ask DeepWiki