Functions 545
as_tensor
functionFull reference ↗- tensorplay.as_tensor(data, dtype=None, device=None)[source]
Convert
datainto a tensor, sharing storage when possible.If
datais already a tensor with the requested dtype and device, it is returned as-is (no copy). Otherwise it is converted to the requested dtype and device.- Parameters:
data (tensor, list, or scalar) – Initial data for the tensor.
dtype (
tensorplay.DType, optional) – the desired data type of the returned tensor.device (
tensorplay.Device, str, optional) – the device of the constructed tensor.
Example:
>>> x = tensorplay.tensor([1.0, 2.0]) >>> tensorplay.as_tensor(x) is x True >>> tensorplay.as_tensor([0, 1, 2], dtype=tensorplay.int64).dtype == tensorplay.int64 True
absolute_
functionFull reference ↗- tensorplay.absolute_(input)[source]
adaptive_avg_pool2d
functionFull reference ↗- tensorplay.adaptive_avg_pool2d(input, output_size, *, out=None)[source]
adaptive_avg_pool3d
functionFull reference ↗- tensorplay.adaptive_avg_pool3d(input, output_size, *, out=None)[source]
adaptive_max_pool2d_with_indices
functionFull reference ↗- tensorplay.adaptive_max_pool2d_with_indices(input, output_size)[source]
adaptive_max_pool2d
functionFull reference ↗- tensorplay.adaptive_max_pool2d(input, output_size, *, out=None)[source]
adaptive_max_pool3d
functionFull reference ↗- tensorplay.adaptive_max_pool3d(input, output_size, *, out=None)[source]
add_
functionFull reference ↗- tensorplay.add_(input, other, alpha=1)[source]
add_relu
functionFull reference ↗- tensorplay.add_relu(input, other)[source]
addbmm_
functionFull reference ↗- tensorplay.addbmm_(input, batch1, batch2, beta=1, alpha=1)[source]
addcdiv_
functionFull reference ↗- tensorplay.addcdiv_(input, tensor1, tensor2, value=1)[source]
addcmul_
functionFull reference ↗- tensorplay.addcmul_(input, tensor1, tensor2, value=1)[source]
addmm_
functionFull reference ↗- tensorplay.addmm_(input, mat1, mat2, beta=1, alpha=1)[source]
addr_
functionFull reference ↗- tensorplay.addr_(input, vec1, vec2, beta=1, alpha=1)[source]
airy_ai
functionFull reference ↗- tensorplay.airy_ai(input)[source]
alias
functionFull reference ↗- tensorplay.alias(input)[source]
arctan2_
functionFull reference ↗- tensorplay.arctan2_(input, other)[source]
are_deterministic_algorithms_enabled
functionFull reference ↗- tensorplay.are_deterministic_algorithms_enabled() bool[source]
Returns True if the global deterministic flag is turned on. Refer to
tensorplay.use_deterministic_algorithms()documentation for more details.
asarray
functionFull reference ↗atan2_
functionFull reference ↗- tensorplay.atan2_(input, other)[source]
audio_to_tensor
functionFull reference ↗- tensorplay.audio_to_tensor(audio: object) tensorplay::Tensor
Optimized conversion for audio: (Time, Channels) -> (Channels, Time) with normalization
autocast_decrement_nesting
functionFull reference ↗- tensorplay.autocast_decrement_nesting() int
autocast_increment_nesting
functionFull reference ↗- tensorplay.autocast_increment_nesting() int
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]
baddbmm_
functionFull reference ↗- tensorplay.baddbmm_(input, batch1, batch2, beta=1, alpha=1)[source]
batch_norm
functionFull reference ↗- tensorplay.batch_norm(input, weight, bias, running_mean, running_var, training, momentum, eps)[source]
bernoulli_
functionFull reference ↗- tensorplay.bernoulli_(input, p, generator=None)[source]
bessel_j0
functionFull reference ↗- tensorplay.bessel_j0(input)[source]
bessel_j1
functionFull reference ↗- tensorplay.bessel_j1(input)[source]
bessel_y0
functionFull reference ↗- tensorplay.bessel_y0(input)[source]
bessel_y1
functionFull reference ↗- tensorplay.bessel_y1(input)[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]
bitwise_and_
functionFull reference ↗- tensorplay.bitwise_and_(input, other)[source]
bitwise_left_shift_
functionFull reference ↗- tensorplay.bitwise_left_shift_(input, other)[source]
bitwise_not_
functionFull reference ↗- tensorplay.bitwise_not_(input)[source]
bitwise_or_
functionFull reference ↗- tensorplay.bitwise_or_(input, other)[source]
bitwise_right_shift_
functionFull reference ↗- tensorplay.bitwise_right_shift_(input, other)[source]
bitwise_xor_
functionFull reference ↗- tensorplay.bitwise_xor_(input, other)[source]
cauchy_
functionFull reference ↗- tensorplay.cauchy_(input, median=0.0, sigma=1.0)[source]
ccol_indices
functionFull reference ↗- tensorplay.ccol_indices(input)[source]
celu
functionFull reference ↗- tensorplay.celu(input, alpha=1.0)[source]
chebyshev_polynomial_t
functionFull reference ↗- tensorplay.chebyshev_polynomial_t(x, n)[source]
chebyshev_polynomial_u
functionFull reference ↗- tensorplay.chebyshev_polynomial_u(x, n)[source]
chebyshev_polynomial_v
functionFull reference ↗- tensorplay.chebyshev_polynomial_v(x, n)[source]
chebyshev_polynomial_w
functionFull reference ↗- tensorplay.chebyshev_polynomial_w(x, n)[source]
cholesky
functionFull reference ↗- tensorplay.cholesky(input, upper=False)[source]
circular_pad_nd
functionFull reference ↗- tensorplay.circular_pad_nd(input, pad)[source]
clamp_max
functionFull reference ↗- tensorplay.clamp_max(input, max)[source]
clamp_min
functionFull reference ↗- tensorplay.clamp_min(input, min)[source]
clear_autocast_cache
functionFull reference ↗- tensorplay.clear_autocast_cache() None
coalesce
functionFull reference ↗- tensorplay.coalesce(input)[source]
col_indices
functionFull reference ↗- tensorplay.col_indices(input)[source]
col2im
functionFull reference ↗- tensorplay.col2im(input, output_size, kernel_size, dilation=[], padding=[], stride=[], *, out=None)[source]
constant_pad_nd
functionFull reference ↗- tensorplay.constant_pad_nd(input, pad, value)[source]
contiguous
functionFull reference ↗- tensorplay.contiguous(input, memory_format=MemoryFormat.CONTIGUOUS)[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]
copy_
functionFull reference ↗- tensorplay.copy_(input, src, non_blocking=False)[source]
copy_sparse_to_sparse_
functionFull reference ↗- tensorplay.copy_sparse_to_sparse_(input, src, non_blocking=False)[source]
copy
functionFull reference ↗- tensorplay.copy(input, src, non_blocking=False)[source]
copysign_
functionFull reference ↗- tensorplay.copysign_(input, other)[source]
cross_entropy_loss
functionFull reference ↗- tensorplay.cross_entropy_loss(input, target, weight=None, reduction=1, ignore_index=-100, label_smoothing=0.0)[source]
crow_indices
functionFull reference ↗- tensorplay.crow_indices(input)[source]
cumprod_
functionFull reference ↗- tensorplay.cumprod_(input, dim, dtype=None)[source]
cumsum_
functionFull reference ↗- tensorplay.cumsum_(input, dim=0, dtype=None)[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 thatbackwardexecutes with the same autocast state asforward.- 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
forwardmethods 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.dtypeor None, optional, default=None) – If notNone, whenforwardruns in an autocast-enabled region, casts incoming floating-point Tensors to the target dtype (non-floating-point Tensors are not affected), then executesforwardwith autocast disabled. IfNone,forward’s internal ops execute with the current autocast state.
Note
If the decorated
forwardis called outside an autocast-enabled region,custom_fwdis a no-op andcast_inputshas no effect.
data
functionFull reference ↗- tensorplay.data(input)[source]
dense_dim
functionFull reference ↗- tensorplay.dense_dim(input)[source]
digamma_
functionFull reference ↗- tensorplay.digamma_(input)[source]
dim
functionFull reference ↗- tensorplay.dim(input)[source]
div_
functionFull reference ↗- tensorplay.div_(input, other, rounding_mode=None)[source]
divide_
functionFull reference ↗- tensorplay.divide_(input, other, rounding_mode=None)[source]
dropout
functionFull reference ↗- tensorplay.dropout(input, p=0.5, train=True)[source]
elu_
functionFull reference ↗- tensorplay.elu_(input, alpha=1, scale=1, input_scale=1)[source]
elu
functionFull reference ↗- tensorplay.elu(input, alpha=1, scale=1, input_scale=1, *, out=None)[source]
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()
entr
functionFull reference ↗- tensorplay.entr(input)[source]
eq_
functionFull reference ↗- tensorplay.eq_(input, other)[source]
erfcx
functionFull reference ↗- tensorplay.erfcx(input)[source]
erfinv_
functionFull reference ↗- tensorplay.erfinv_(input)[source]
expand_as
functionFull reference ↗- tensorplay.expand_as(input, other)[source]
expand
functionFull reference ↗- tensorplay.expand(input, size, implicit=False)[source]
exponential_
functionFull reference ↗- tensorplay.exponential_(input, lambd=1.0)[source]
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_fft
functionFull reference ↗- tensorplay.fft_fft(input, n=-1, dim=-1, norm='backward', *, out=None)[source]
fft_fft2
functionFull reference ↗- tensorplay.fft_fft2(input, s=None, dim=[-2, -1], norm='backward', *, out=None)[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_fftn
functionFull reference ↗- tensorplay.fft_fftn(input, s=None, dim=None, norm=None, *, out=None)[source]
fft_fftshift
functionFull reference ↗- tensorplay.fft_fftshift(input, dim=None)[source]
fft_hfft
functionFull reference ↗- tensorplay.fft_hfft(input, n=None, dim=-1, norm=None, *, out=None)[source]
fft_hfft2
functionFull reference ↗- tensorplay.fft_hfft2(input, s=None, dim=[-2, -1], norm=None, *, out=None)[source]
fft_hfftn
functionFull reference ↗- tensorplay.fft_hfftn(input, s=None, dim=None, norm=None, *, out=None)[source]
fft_ifft
functionFull reference ↗- tensorplay.fft_ifft(input, n=-1, dim=-1, norm='backward', *, out=None)[source]
fft_ifft2
functionFull reference ↗- tensorplay.fft_ifft2(input, s=None, dim=[-2, -1], norm='backward', *, out=None)[source]
fft_ifftn
functionFull reference ↗- tensorplay.fft_ifftn(input, s=None, dim=None, norm=None, *, out=None)[source]
fft_ifftshift
functionFull reference ↗- tensorplay.fft_ifftshift(input, dim=None)[source]
fft_ihfft
functionFull reference ↗- tensorplay.fft_ihfft(input, n=None, dim=-1, norm=None, *, out=None)[source]
fft_ihfft2
functionFull reference ↗- tensorplay.fft_ihfft2(input, s=None, dim=[-2, -1], norm=None, *, out=None)[source]
fft_ihfftn
functionFull reference ↗- tensorplay.fft_ihfftn(input, s=None, dim=None, norm=None, *, out=None)[source]
fft_irfft
functionFull reference ↗- tensorplay.fft_irfft(input, n=-1, dim=-1, norm='backward', *, out=None)[source]
fft_irfft2
functionFull reference ↗- tensorplay.fft_irfft2(input, s=None, dim=[-2, -1], norm='backward', *, out=None)[source]
fft_irfftn
functionFull reference ↗- tensorplay.fft_irfftn(input, s=None, dim=None, norm=None, *, out=None)[source]
fft_rfft
functionFull reference ↗- tensorplay.fft_rfft(input, n=-1, dim=-1, norm='backward', *, out=None)[source]
fft_rfft2
functionFull reference ↗- tensorplay.fft_rfft2(input, s=None, dim=[-2, -1], norm='backward', *, 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]
fft_rfftn
functionFull reference ↗- tensorplay.fft_rfftn(input, s=None, dim=None, norm=None, *, out=None)[source]
fill_diagonal_
functionFull reference ↗- tensorplay.fill_diagonal_(input, fill_value, wrap=False)[source]
flatten_dense_tensors
functionFull reference ↗- tensorplay.flatten_dense_tensors(*args)[source]
float_power_
functionFull reference ↗- tensorplay.float_power_(input, exponent)[source]
floor_divide_
functionFull reference ↗- tensorplay.floor_divide_(input, other)[source]
fmod_
functionFull reference ↗- tensorplay.fmod_(input, other)[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 on entry and restores it on exit, so random operations inside the block do not advance the outer stream. The saved state is restored
forward_add
functionFull reference ↗- tensorplay.forward_add(a, da, b, db)[source]
forward_cos
functionFull reference ↗- tensorplay.forward_cos(a, da)[source]
forward_div
functionFull reference ↗- tensorplay.forward_div(a, da, b, db)[source]
forward_exp
functionFull reference ↗- tensorplay.forward_exp(a, da)[source]
forward_log
functionFull reference ↗- tensorplay.forward_log(a, da)[source]
forward_mm
functionFull reference ↗- tensorplay.forward_mm(a, da, b, db)[source]
forward_mul
functionFull reference ↗- tensorplay.forward_mul(a, da, b, db)[source]
forward_neg
functionFull reference ↗- tensorplay.forward_neg(a, da)[source]
forward_pow
functionFull reference ↗- tensorplay.forward_pow(a, da, b, db)[source]
forward_relu
functionFull reference ↗- tensorplay.forward_relu(a, da)[source]
forward_sigmoid
functionFull reference ↗- tensorplay.forward_sigmoid(a, da)[source]
forward_sin
functionFull reference ↗- tensorplay.forward_sin(a, da)[source]
forward_sqrt
functionFull reference ↗- tensorplay.forward_sqrt(a, da)[source]
forward_sub
functionFull reference ↗- tensorplay.forward_sub(a, da, b, db)[source]
forward_tanh
functionFull reference ↗- tensorplay.forward_tanh(a, da)[source]
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]
frobenius_norm
functionFull reference ↗- tensorplay.frobenius_norm(input, dim, keepdim=False, *, out=None)[source]
from_dlpack
functionFull reference ↗- tensorplay.from_dlpack(obj: object) tensorplay::Tensor
from_numpy
functionFull reference ↗- tensorplay.from_numpy(*args, **kwargs)
Overloaded function.
from_numpy(ndarray: object) -> tensorplay::Tensor
from_numpy(array: numpy.ndarray) -> tensorplay::Tensor
frombuffer
functionFull reference ↗- tensorplay.frombuffer(buffer: object, dtype: tensorplay._C.DType = <DType.float32: 8>, count: SupportsInt | SupportsIndex = -1, offset: SupportsInt | SupportsIndex = 0, requires_grad: bool = False) tensorplay::Tensor
full
functionFull reference ↗- tensorplay.full()
fused_mul_add
functionFull reference ↗- tensorplay.fused_mul_add(input, other, addend)[source]
fused_rope
functionFull reference ↗- tensorplay.fused_rope(query, key, cos, sin, position_offset=0)[source]
fused_swiglu
functionFull reference ↗- tensorplay.fused_swiglu(gate, up)[source]
gammainc
functionFull reference ↗- tensorplay.gammainc(a, x)[source]
gammaincc
functionFull reference ↗- tensorplay.gammaincc(a, x)[source]
ge_
functionFull reference ↗- tensorplay.ge_(input, other)[source]
gelu_
functionFull reference ↗- tensorplay.gelu_(input, approximate='none')[source]
gelu
functionFull reference ↗- tensorplay.gelu(input, approximate='none', *, out=None)[source]
geometric_
functionFull reference ↗- tensorplay.geometric_(input, p)[source]
get_autocast_dtype
functionFull reference ↗- tensorplay.get_autocast_dtype(device_type: str = 'cuda') tensorplay._C.DType
get_default_device
functionFull reference ↗get_default_dtype
functionFull reference ↗- tensorplay.get_default_dtype() DType[source]
Returns the current default floating point dtype (float32 initially, changed by
set_default_dtype()).
get_deterministic_debug_mode
functionFull reference ↗- tensorplay.get_deterministic_debug_mode() int[source]
Returns the current value of the debug mode for deterministic operations. Refer to
tensorplay.set_deterministic_debug_mode()documentation for more details.
get_float32_matmul_precision
functionFull reference ↗- tensorplay.get_float32_matmul_precision() str[source]
Returns the current value of float32 matrix multiplication precision. Refer to
tensorplay.set_float32_matmul_precision()documentation for more details.
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_rng_state
functionFull reference ↗- tensorplay.get_rng_state() tensorplay::Tensor
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
glu_backward_jvp
functionFull reference ↗- tensorplay.glu_backward_jvp(grad_x, grad_glu, x, dgrad_glu, dx, dim)[source]
glu_jvp
functionFull reference ↗- tensorplay.glu_jvp(glu, x, dx, dim)[source]
glu
functionFull reference ↗- tensorplay.glu(input, dim=-1, *, out=None)[source]
gradient
functionFull reference ↗- tensorplay.gradient(input, *, spacing=None, dim=None, edge_order=1)[source]
The native binding only takes
Tensor[]spacing /int[]dim; materialize python numbers into scalar tensors typed likeinput(a single scalar applies to every dimension).
greater_
functionFull reference ↗- tensorplay.greater_(input, other)[source]
greater_equal_
functionFull reference ↗- tensorplay.greater_equal_(input, other)[source]
grid_sampler
functionFull reference ↗- tensorplay.grid_sampler(input, grid, interpolation_mode, padding_mode, align_corners)[source]
grouped_mm
functionFull reference ↗- tensorplay.grouped_mm(input, mat2, offs)[source]
gt_
functionFull reference ↗- tensorplay.gt_(input, other)[source]
hardsigmoid_
functionFull reference ↗- tensorplay.hardsigmoid_(input)[source]
hardsigmoid
functionFull reference ↗- tensorplay.hardsigmoid(input, *, out=None)[source]
hardswish_
functionFull reference ↗- tensorplay.hardswish_(input)[source]
hardswish
functionFull reference ↗- tensorplay.hardswish(input, *, out=None)[source]
hardtanh_
functionFull reference ↗- tensorplay.hardtanh_(input, min_val=-1, max_val=1)[source]
hardtanh
functionFull reference ↗- tensorplay.hardtanh(input, min_val=-1, max_val=1, *, out=None)[source]
heaviside_
functionFull reference ↗- tensorplay.heaviside_(input, values)[source]
hermite_polynomial_h
functionFull reference ↗- tensorplay.hermite_polynomial_h(x, n)[source]
hermite_polynomial_he
functionFull reference ↗- tensorplay.hermite_polynomial_he(x, n)[source]
hspmm
functionFull reference ↗- tensorplay.hspmm(mat1, mat2, *, out=None)[source]
huber_loss
functionFull reference ↗- tensorplay.huber_loss(input, target, reduction=1, delta=1.0, *, out=None)[source]
hypot_
functionFull reference ↗- tensorplay.hypot_(input, other)[source]
i0e
functionFull reference ↗- tensorplay.i0e(input)[source]
i1
functionFull reference ↗- tensorplay.i1(input)[source]
i1e
functionFull reference ↗- tensorplay.i1e(input)[source]
igamma_
functionFull reference ↗- tensorplay.igamma_(input, other)[source]
igammac_
functionFull reference ↗- tensorplay.igammac_(input, other)[source]
im2col
functionFull reference ↗- tensorplay.im2col(input, kernel_size, dilation=[], padding=[], stride=[], *, out=None)[source]
in_parallel_region
functionFull reference ↗- tensorplay.in_parallel_region() bool
Checks whether the code runs in a parallel region
index_add_
functionFull reference ↗- tensorplay.index_add_(input, dim, index, source)[source]
index_copy_
functionFull reference ↗- tensorplay.index_copy_(input, dim, index, source)[source]
index_fill_
functionFull reference ↗- tensorplay.index_fill_(input, dim, index, value)[source]
index_fill
functionFull reference ↗- tensorplay.index_fill(input, dim, index, value)[source]
index_put
functionFull reference ↗- tensorplay.index_put(input, indices, values, accumulate=False)[source]
index_reduce_
functionFull reference ↗- tensorplay.index_reduce_(input, dim, index, source, reduce, include_self=True)[source]
index
functionFull reference ↗- tensorplay.index(input, indices, *, out=None)[source]
indices
functionFull reference ↗- tensorplay.indices(input)[source]
initial_seed
functionFull reference ↗- tensorplay.initial_seed() int
inner_backward_other
functionFull reference ↗- tensorplay.inner_backward_other(grad_output, input, other)[source]
inner_backward_self
functionFull reference ↗- tensorplay.inner_backward_self(grad_output, input, other)[source]
inspect_checkpoint
functionFull reference ↗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_autocast_cache_enabled
functionFull reference ↗- tensorplay.is_autocast_cache_enabled() bool
is_autocast_enabled
functionFull reference ↗is_coalesced
functionFull reference ↗- tensorplay.is_coalesced(input)[source]
is_contiguous
functionFull reference ↗- tensorplay.is_contiguous(input)[source]
is_deterministic_algorithms_warn_only_enabled
functionFull reference ↗- tensorplay.is_deterministic_algorithms_warn_only_enabled() bool[source]
Returns True if the global deterministic flag is set to warn only. Refer to
tensorplay.use_deterministic_algorithms()documentation for more details.
is_leaf
functionFull reference ↗- tensorplay.is_leaf(input)[source]
is_pinned
functionFull reference ↗- tensorplay.is_pinned(input, device=None)[source]
is_quantized
functionFull reference ↗- tensorplay.is_quantized(input)[source]
is_set_to
functionFull reference ↗- tensorplay.is_set_to(input, tensor)[source]
is_storage
functionFull reference ↗is_tensor
functionFull reference ↗- tensorplay.is_tensor(obj: Any, /) TypeIs[TensorBase][source]
Returns True if obj is a TensorPlay tensor.
Note that this function is simply doing
isinstance(obj, Tensor). Using thatisinstancecheck is better for type checking with mypy, and more explicit - so it’s recommended to use that instead ofis_tensor.- Parameters:
obj (object) – Object to test
Example:
>>> x = tensorplay.tensor([1, 2, 3]) >>> tensorplay.is_tensor(x) True
item
functionFull reference ↗- tensorplay.item(input)[source]
l1_loss
functionFull reference ↗- tensorplay.l1_loss(input, target)[source]
laguerre_polynomial_l
functionFull reference ↗- tensorplay.laguerre_polynomial_l(x, n)[source]
layer_norm
functionFull reference ↗- tensorplay.layer_norm(input, normalized_shape, weight=None, bias=None, eps=1e-05)[source]
le_
functionFull reference ↗- tensorplay.le_(input, other)[source]
leaky_relu_
functionFull reference ↗- tensorplay.leaky_relu_(input, negative_slope=0.01)[source]
leaky_relu
functionFull reference ↗- tensorplay.leaky_relu(input, negative_slope=0.01, *, out=None)[source]
legendre_polynomial_p
functionFull reference ↗- tensorplay.legendre_polynomial_p(x, n)[source]
lerp_
functionFull reference ↗- tensorplay.lerp_(input, end, weight)[source]
less_
functionFull reference ↗- tensorplay.less_(input, other)[source]
less_equal_
functionFull reference ↗- tensorplay.less_equal_(input, other)[source]
lgamma_
functionFull reference ↗- tensorplay.lgamma_(input)[source]
lift_fresh_copy
functionFull reference ↗- tensorplay.lift_fresh_copy(input)[source]
lift_fresh
functionFull reference ↗- tensorplay.lift_fresh(input)[source]
lift
functionFull reference ↗- tensorplay.lift(input)[source]
linear
functionFull reference ↗- tensorplay.linear(input, weight, bias=None)[source]
log_ndtr
functionFull reference ↗- tensorplay.log_ndtr(input)[source]
log_normal_
functionFull reference ↗- tensorplay.log_normal_(input, mean=1.0, std=2.0)[source]
log_sigmoid_forward
functionFull reference ↗- tensorplay.log_sigmoid_forward(input, *, out=None)[source]
log_sigmoid
functionFull reference ↗- tensorplay.log_sigmoid(input, *, out=None)[source]
log_softmax
functionFull reference ↗- tensorplay.log_softmax(input, dim, dtype=<DType.undefined: 22>, *, out=None)[source]
logical_and_
functionFull reference ↗- tensorplay.logical_and_(input, other)[source]
logical_not_
functionFull reference ↗- tensorplay.logical_not_(input)[source]
logical_or_
functionFull reference ↗- tensorplay.logical_or_(input, other)[source]
logical_xor_
functionFull reference ↗- tensorplay.logical_xor_(input, other)[source]
lt_
functionFull reference ↗- tensorplay.lt_(input, other)[source]
manual_seed
functionFull reference ↗- tensorplay.manual_seed(seed: SupportsInt | SupportsIndex) None
masked_fill_
functionFull reference ↗- tensorplay.masked_fill_(input, mask, value)[source]
masked_scatter_
functionFull reference ↗- tensorplay.masked_scatter_(input, mask, source)[source]
masked_scatter
functionFull reference ↗- tensorplay.masked_scatter(input, mask, source)[source]
matmul_backward_other
functionFull reference ↗- tensorplay.matmul_backward_other(grad_output, input, other)[source]
matmul_backward_self
functionFull reference ↗- tensorplay.matmul_backward_self(grad_output, input, other)[source]
matrix_H
functionFull reference ↗- tensorplay.matrix_H(input)[source]
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_unpool2d
functionFull reference ↗- tensorplay.max_unpool2d(input, indices, output_size, *, out=None)[source]
max_unpool3d
functionFull reference ↗- tensorplay.max_unpool3d(input, indices, output_size, stride, padding, *, out=None)[source]
max
functionFull reference ↗- tensorplay.max(input, other=None, *, dim=None, keepdim=False)[source]
mH
functionFull reference ↗- tensorplay.mH(input)[source]
min
functionFull reference ↗- tensorplay.min(input, other=None, *, dim=None, keepdim=False)[source]
mish_
functionFull reference ↗- tensorplay.mish_(input)[source]
mish
functionFull reference ↗- tensorplay.mish(input, *, out=None)[source]
mkldnn_linear_backward_input
functionFull reference ↗- tensorplay.mkldnn_linear_backward_input(input_size, grad_output, weight)[source]
mkldnn_linear
functionFull reference ↗- tensorplay.mkldnn_linear(input, weight, bias=None)[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]
modified_bessel_i0
functionFull reference ↗- tensorplay.modified_bessel_i0(input)[source]
modified_bessel_i1
functionFull reference ↗- tensorplay.modified_bessel_i1(input)[source]
modified_bessel_k0
functionFull reference ↗- tensorplay.modified_bessel_k0(input)[source]
modified_bessel_k1
functionFull reference ↗- tensorplay.modified_bessel_k1(input)[source]
mse_loss
functionFull reference ↗- tensorplay.mse_loss(input, target, reduction=1, *, out=None)[source]
mT
functionFull reference ↗- tensorplay.mT(input)[source]
mul_
functionFull reference ↗- tensorplay.mul_(input, other)[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]
multilabel_margin_loss
functionFull reference ↗- tensorplay.multilabel_margin_loss(input, target, reduction=1, *, out=None)[source]
multilabel_soft_margin_loss
functionFull reference ↗- tensorplay.multilabel_soft_margin_loss(input, target)[source]
multiply_
functionFull reference ↗- tensorplay.multiply_(input, other)[source]
mvlgamma_
functionFull reference ↗- tensorplay.mvlgamma_(input, p)[source]
native_alpha_dropout
functionFull reference ↗- tensorplay.native_alpha_dropout(input, p)[source]
native_dropout
functionFull reference ↗- tensorplay.native_dropout(input, p)[source]
native_feature_dropout
functionFull reference ↗- tensorplay.native_feature_dropout(input, p)[source]
ndtr
functionFull reference ↗- tensorplay.ndtr(input)[source]
ndtri
functionFull reference ↗- tensorplay.ndtri(input)[source]
ne_
functionFull reference ↗- tensorplay.ne_(input, other)[source]
nested_to_padded_tensor
functionFull reference ↗- tensorplay.nested_to_padded_tensor(input, padding, output_size=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_empty
functionFull reference ↗- tensorplay.new_empty(input, size, 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]
new_ones
functionFull reference ↗- tensorplay.new_ones(input, size, dtype=None, layout=None, device=None, pin_memory=None)[source]
new_zeros
functionFull reference ↗- tensorplay.new_zeros(input, size, dtype=None, layout=None, device=None, pin_memory=None)[source]
nextafter_
functionFull reference ↗- tensorplay.nextafter_(input, other)[source]
nll_loss_forward
functionFull reference ↗- tensorplay.nll_loss_forward(input, target, weight, reduction, ignore_index, *, out=None)[source]
nll_loss_nd
functionFull reference ↗- tensorplay.nll_loss_nd(input, target, weight=None, reduction=1, ignore_index=-100)[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]
nonzero_numpy
functionFull reference ↗- tensorplay.nonzero_numpy(input)[source]
normal_
functionFull reference ↗- tensorplay.normal_(input, mean=0.0, std=1.0, generator=None)[source]
normal_functional
functionFull reference ↗- tensorplay.normal_functional(input, mean=0, std=1, generator=None)[source]
not_equal_
functionFull reference ↗- tensorplay.not_equal_(input, other)[source]
numpy_T
functionFull reference ↗- tensorplay.numpy_T(input)[source]
one_hot
functionFull reference ↗- tensorplay.one_hot(input, num_classes=-1)[source]
ones
functionFull reference ↗- tensorplay.ones()
output_nr
functionFull reference ↗- tensorplay.output_nr(input)[source]
pad_sequence
functionFull reference ↗- tensorplay.pad_sequence(sequences, batch_first=False, padding_value=0.0, padding_side='right')[source]
pad
functionFull reference ↗- tensorplay.pad(input, pad, mode='constant', value=None)[source]
pin_memory
functionFull reference ↗- tensorplay.pin_memory(input, device=None)[source]
pixel_shuffle
functionFull reference ↗- tensorplay.pixel_shuffle(input, upscale_factor)[source]
polygamma_
functionFull reference ↗- tensorplay.polygamma_(input, n)[source]
pow_
functionFull reference ↗- tensorplay.pow_(input, exponent)[source]
put_
functionFull reference ↗- tensorplay.put_(input, index, source, accumulate=False)[source]
qscheme
functionFull reference ↗- tensorplay.qscheme(input)[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)[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()
randn
functionFull reference ↗- tensorplay.randn()
random_
functionFull reference ↗- tensorplay.random_(input, low=0, high=0)[source]
reflection_pad_nd
functionFull reference ↗- tensorplay.reflection_pad_nd(input, pad)[source]
reflection_pad1d
functionFull reference ↗- tensorplay.reflection_pad1d(input, padding, *, out=None)[source]
reflection_pad2d
functionFull reference ↗- tensorplay.reflection_pad2d(input, padding, *, out=None)[source]
reflection_pad3d
functionFull reference ↗- tensorplay.reflection_pad3d(input, padding, *, out=None)[source]
relu
functionFull reference ↗- tensorplay.relu(input)[source]
relu6_
functionFull reference ↗- tensorplay.relu6_(input)[source]
relu6
functionFull reference ↗- tensorplay.relu6(input)[source]
remainder_
functionFull reference ↗- tensorplay.remainder_(input, other)[source]
renorm_
functionFull reference ↗- tensorplay.renorm_(input, p, dim, maxnorm)[source]
repeat
functionFull reference ↗- tensorplay.repeat(input, repeats)[source]
replication_pad_nd
functionFull reference ↗- tensorplay.replication_pad_nd(input, pad)[source]
replication_pad1d
functionFull reference ↗- tensorplay.replication_pad1d(input, padding, *, out=None)[source]
replication_pad2d
functionFull reference ↗- tensorplay.replication_pad2d(input, padding, *, out=None)[source]
replication_pad3d
functionFull reference ↗- tensorplay.replication_pad3d(input, padding, *, out=None)[source]
requires_grad_
functionFull reference ↗- tensorplay.requires_grad_(input, requires_grad=True)[source]
reshape_as
functionFull reference ↗- tensorplay.reshape_as(input, other)[source]
resize_
functionFull reference ↗- tensorplay.resize_(input, size)[source]
retain_grad
functionFull reference ↗- tensorplay.retain_grad(input)[source]
retains_grad
functionFull reference ↗- tensorplay.retains_grad(input)[source]
rotary_embedding
functionFull reference ↗- tensorplay.rotary_embedding(input, cos, sin, position_offset=0)[source]
row_indices
functionFull reference ↗- tensorplay.row_indices(input)[source]
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, *, out=None)[source]
sample
functionFull reference ↗- tensorplay.sample(logits, temperature=1.0, top_k=0, top_p=1.0, impl=0)[source]
scaled_dot_product_attention
functionFull reference ↗- tensorplay.scaled_dot_product_attention(query, key, value, is_causal=False, impl=0)[source]
scaled_modified_bessel_k0
functionFull reference ↗- tensorplay.scaled_modified_bessel_k0(input)[source]
scaled_modified_bessel_k1
functionFull reference ↗- tensorplay.scaled_modified_bessel_k1(input)[source]
scatter_
functionFull reference ↗- tensorplay.scatter_(input, dim, index, src)[source]
scatter_add_
functionFull reference ↗- tensorplay.scatter_add_(input, dim, index, src)[source]
scatter_reduce_
functionFull reference ↗- tensorplay.scatter_reduce_(input, dim, index, src, reduce, include_self=True)[source]
seed
functionFull reference ↗- tensorplay.seed() int
set_
functionFull reference ↗- tensorplay.set_(input, source)[source]
set_autocast_cache_enabled
functionFull reference ↗set_autocast_dtype
functionFull reference ↗set_autocast_enabled
functionFull reference ↗set_data
functionFull reference ↗- tensorplay.set_data(input, new_data)[source]
set_default_device
functionFull reference ↗- tensorplay.set_default_device(device: Device) None[source]
Sets the default
tensorplay.Tensorto be allocated ondevice. This does not affect factory function calls which are called with an explicitdeviceargument. Factory calls will be performed as if they were passeddeviceas 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 aftertensorplay.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()andtensorplay.frombuffer()- Parameters:
device (
tensorplay.device, str, int, or None) – the device to set as default, orNoneto 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:
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.
Infer the dtype for tensors constructed using Python floats or complex Python numbers. See examples below.
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.
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(nthreads: SupportsInt | SupportsIndex) None
Sets the number of threads used for intraop parallelism on CPU.
set_printoptions
functionFull reference ↗- tensorplay.set_printoptions(edge_items: SupportsInt | SupportsIndex = -1, threshold: SupportsInt | SupportsIndex = -1, precision: SupportsInt | SupportsIndex = -1, linewidth: SupportsInt | SupportsIndex = -1) None
Set print options
set_rng_state
functionFull reference ↗- tensorplay.set_rng_state(new_state: tensorplay::Tensor) None
sgn_
functionFull reference ↗- tensorplay.sgn_(input)[source]
shifted_chebyshev_polynomial_t
functionFull reference ↗- tensorplay.shifted_chebyshev_polynomial_t(x, n)[source]
shifted_chebyshev_polynomial_u
functionFull reference ↗- tensorplay.shifted_chebyshev_polynomial_u(x, n)[source]
shifted_chebyshev_polynomial_v
functionFull reference ↗- tensorplay.shifted_chebyshev_polynomial_v(x, n)[source]
shifted_chebyshev_polynomial_w
functionFull reference ↗- tensorplay.shifted_chebyshev_polynomial_w(x, n)[source]
sign_
functionFull reference ↗- tensorplay.sign_(input)[source]
silu_
functionFull reference ↗- tensorplay.silu_(input)[source]
silu_and_mul
functionFull reference ↗- tensorplay.silu_and_mul(input)[source]
silu_mul
functionFull reference ↗- tensorplay.silu_mul(gate, up)[source]
silu
functionFull reference ↗- tensorplay.silu(input, *, out=None)[source]
size
functionFull reference ↗- tensorplay.size(input, dim)[source]
slice
functionFull reference ↗- tensorplay.slice(input, dim=0, start=None, end=None, step=1)[source]
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, mat2)[source]
smooth_l1_loss
functionFull reference ↗- tensorplay.smooth_l1_loss(input, target, reduction=1, beta=1.0, *, out=None)[source]
soft_margin_loss
functionFull reference ↗- tensorplay.soft_margin_loss(input, target, *, out=None)[source]
softplus
functionFull reference ↗- tensorplay.softplus(input, beta=1, threshold=20, *, out=None)[source]
softshrink
functionFull reference ↗- tensorplay.softshrink(input, lambd=0.5, *, out=None)[source]
sparse_add
functionFull reference ↗- tensorplay.sparse_add(input, other)[source]
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)[source]
sparse_dim
functionFull reference ↗- tensorplay.sparse_dim(input)[source]
sparse_mask
functionFull reference ↗- tensorplay.sparse_mask(input, mask)[source]
sparse_mm
functionFull reference ↗- tensorplay.sparse_mm(input, dense)[source]
sparse_mul
functionFull reference ↗- tensorplay.sparse_mul(input, other)[source]
sparse_resize_
functionFull reference ↗- tensorplay.sparse_resize_(input, size, sparse_dim, dense_dim)[source]
sparse_resize_and_clear_
functionFull reference ↗- tensorplay.sparse_resize_and_clear_(input, size, sparse_dim, dense_dim)[source]
sparse_sampled_addmm
functionFull reference ↗- tensorplay.sparse_sampled_addmm(input, mat1, mat2, *, beta=1, alpha=1, out=None)[source]
sparse_sum
functionFull reference ↗- tensorplay.sparse_sum(input, dim=None, dtype=None)[source]
spdiags
functionFull reference ↗- tensorplay.spdiags(diagonals, offsets, shape, layout=None)[source]
special_airy_ai
functionFull reference ↗- tensorplay.special_airy_ai(x, *, out=None)[source]
special_bessel_j0
functionFull reference ↗- tensorplay.special_bessel_j0(input, *, out=None)[source]
special_bessel_j1
functionFull reference ↗- tensorplay.special_bessel_j1(input, *, out=None)[source]
special_bessel_y0
functionFull reference ↗- tensorplay.special_bessel_y0(input, *, out=None)[source]
special_bessel_y1
functionFull reference ↗- tensorplay.special_bessel_y1(input, *, out=None)[source]
special_chebyshev_polynomial_t
functionFull reference ↗- tensorplay.special_chebyshev_polynomial_t(x, n, *, out=None)[source]
special_chebyshev_polynomial_u
functionFull reference ↗- tensorplay.special_chebyshev_polynomial_u(x, n, *, out=None)[source]
special_chebyshev_polynomial_v
functionFull reference ↗- tensorplay.special_chebyshev_polynomial_v(x, n, *, out=None)[source]
special_chebyshev_polynomial_w
functionFull reference ↗- tensorplay.special_chebyshev_polynomial_w(x, n, *, out=None)[source]
special_digamma
functionFull reference ↗- tensorplay.special_digamma(input, *, out=None)[source]
special_entr
functionFull reference ↗- tensorplay.special_entr(input, *, out=None)[source]
special_erf
functionFull reference ↗- tensorplay.special_erf(input, *, out=None)[source]
special_erfc
functionFull reference ↗- tensorplay.special_erfc(input, *, out=None)[source]
special_erfcx
functionFull reference ↗- tensorplay.special_erfcx(input, *, out=None)[source]
special_erfinv
functionFull reference ↗- tensorplay.special_erfinv(input, *, out=None)[source]
special_exp2
functionFull reference ↗- tensorplay.special_exp2(input, *, out=None)[source]
special_expit
functionFull reference ↗- tensorplay.special_expit(input, *, out=None)[source]
special_expm1
functionFull reference ↗- tensorplay.special_expm1(input, *, out=None)[source]
special_gammainc
functionFull reference ↗- tensorplay.special_gammainc(input, other, *, out=None)[source]
special_gammaincc
functionFull reference ↗- tensorplay.special_gammaincc(input, other, *, out=None)[source]
special_gammaln
functionFull reference ↗- tensorplay.special_gammaln(input, *, out=None)[source]
special_hermite_polynomial_h
functionFull reference ↗- tensorplay.special_hermite_polynomial_h(x, n, *, out=None)[source]
special_hermite_polynomial_he
functionFull reference ↗- tensorplay.special_hermite_polynomial_he(x, n, *, out=None)[source]
special_i0
functionFull reference ↗- tensorplay.special_i0(input, *, out=None)[source]
special_i0e
functionFull reference ↗- tensorplay.special_i0e(input, *, out=None)[source]
special_i1
functionFull reference ↗- tensorplay.special_i1(input, *, out=None)[source]
special_i1e
functionFull reference ↗- tensorplay.special_i1e(input, *, out=None)[source]
special_laguerre_polynomial_l
functionFull reference ↗- tensorplay.special_laguerre_polynomial_l(x, n, *, out=None)[source]
special_legendre_polynomial_p
functionFull reference ↗- tensorplay.special_legendre_polynomial_p(x, n, *, out=None)[source]
special_log_ndtr
functionFull reference ↗- tensorplay.special_log_ndtr(input, *, out=None)[source]
special_log_softmax
functionFull reference ↗- tensorplay.special_log_softmax(input, dim, dtype=None)[source]
special_log1p
functionFull reference ↗- tensorplay.special_log1p(input, *, out=None)[source]
special_logit
functionFull reference ↗- tensorplay.special_logit(input, eps=None, *, out=None)[source]
special_logsumexp
functionFull reference ↗- tensorplay.special_logsumexp(input, dim, keepdim=False, *, out=None)[source]
special_modified_bessel_i0
functionFull reference ↗- tensorplay.special_modified_bessel_i0(input, *, out=None)[source]
special_modified_bessel_i1
functionFull reference ↗- tensorplay.special_modified_bessel_i1(input, *, out=None)[source]
special_modified_bessel_k0
functionFull reference ↗- tensorplay.special_modified_bessel_k0(input, *, out=None)[source]
special_modified_bessel_k1
functionFull reference ↗- tensorplay.special_modified_bessel_k1(input, *, out=None)[source]
special_multigammaln
functionFull reference ↗- tensorplay.special_multigammaln(input, p, *, out=None)[source]
special_ndtr
functionFull reference ↗- tensorplay.special_ndtr(input, *, out=None)[source]
special_ndtri
functionFull reference ↗- tensorplay.special_ndtri(input, *, out=None)[source]
special_polygamma
functionFull reference ↗- tensorplay.special_polygamma(n, input, *, out=None)[source]
special_psi
functionFull reference ↗- tensorplay.special_psi(input, *, out=None)[source]
special_round
functionFull reference ↗- tensorplay.special_round(input, *, decimals=0, out=None)[source]
special_scaled_modified_bessel_k0
functionFull reference ↗- tensorplay.special_scaled_modified_bessel_k0(x, *, out=None)[source]
special_scaled_modified_bessel_k1
functionFull reference ↗- tensorplay.special_scaled_modified_bessel_k1(x, *, 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]
special_sinc
functionFull reference ↗- tensorplay.special_sinc(input, *, out=None)[source]
special_softmax
functionFull reference ↗- tensorplay.special_softmax(input, dim, dtype=None)[source]
special_spherical_bessel_j0
functionFull reference ↗- tensorplay.special_spherical_bessel_j0(x, *, out=None)[source]
special_xlog1py
functionFull reference ↗- tensorplay.special_xlog1py(input, other, *, out=None)[source]
special_xlogy
functionFull reference ↗- tensorplay.special_xlogy(input, other, *, out=None)[source]
special_zeta
functionFull reference ↗- tensorplay.special_zeta(input, other, *, out=None)[source]
spherical_bessel_j0
functionFull reference ↗- tensorplay.spherical_bessel_j0(input)[source]
split_with_sizes
functionFull reference ↗- tensorplay.split_with_sizes(input, split_sizes, dim=0)[source]
squeeze_
functionFull reference ↗- tensorplay.squeeze_(input)[source]
sspaddmm
functionFull reference ↗- tensorplay.sspaddmm(input, mat1, mat2, *, beta=1, alpha=1, out=None)[source]
storage_offset
functionFull reference ↗- tensorplay.storage_offset(input)[source]
stride
functionFull reference ↗- tensorplay.stride(input, dim)[source]
sub_
functionFull reference ↗- tensorplay.sub_(input, other, alpha=1)[source]
subtract_
functionFull reference ↗- tensorplay.subtract_(input, other, alpha=1)[source]
sum_to_size
functionFull reference ↗- tensorplay.sum_to_size(input, size)[source]
swapaxes_
functionFull reference ↗- tensorplay.swapaxes_(input, axis0, axis1)[source]
swapdims_
functionFull reference ↗- tensorplay.swapdims_(input, dim0, dim1)[source]
sym_float
functionFull reference ↗sym_int
functionFull reference ↗sym_is_contiguous
functionFull reference ↗- tensorplay.sym_is_contiguous(input, memory_format=MemoryFormat.CONTIGUOUS)[source]
sym_ite
functionFull reference ↗sym_max
functionFull reference ↗sym_min
functionFull reference ↗sym_not
functionFull reference ↗sym_numel
functionFull reference ↗- tensorplay.sym_numel(input)[source]
sym_size
functionFull reference ↗- tensorplay.sym_size(input, dim)[source]
sym_sqrt
functionFull reference ↗sym_storage_offset
functionFull reference ↗- tensorplay.sym_storage_offset(input)[source]
sym_stride
functionFull reference ↗- tensorplay.sym_stride(input, dim)[source]
sym_sum
functionFull reference ↗- tensorplay.sym_sum(*args) object
t_
functionFull reference ↗- tensorplay.t_(input)[source]
tensor
functionFull reference ↗thnn_conv2d
functionFull reference ↗- tensorplay.thnn_conv2d(input, weight, kernel_size, bias=None, stride=1, padding=0, *, out=None)[source]
to_dense
functionFull reference ↗- tensorplay.to_dense(input)[source]
to_mkldnn
functionFull reference ↗- tensorplay.to_mkldnn(input, dtype=None)[source]
to_padded_tensor
functionFull reference ↗- tensorplay.to_padded_tensor(input, padding, output_size=None)[source]
to_sparse_bsc
functionFull reference ↗- tensorplay.to_sparse_bsc(input, blocksize, dense_dim=None)[source]
to_sparse_bsr
functionFull reference ↗- tensorplay.to_sparse_bsr(input, blocksize, dense_dim=None)[source]
to_sparse_csc
functionFull reference ↗- tensorplay.to_sparse_csc(input, dense_dim=None)[source]
to_sparse_csr
functionFull reference ↗- tensorplay.to_sparse_csr(input)[source]
to_sparse
functionFull reference ↗- tensorplay.to_sparse(input, sparse_dim=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_hinge_embedding_loss
functionFull reference ↗- tensorplay.tp_hinge_embedding_loss(input, target, margin=1.0, reduction=1)[source]
tp_kl_div
functionFull reference ↗- tensorplay.tp_kl_div(input, target, reduction=1, log_target=False)[source]
tp_l1_loss
functionFull reference ↗- tensorplay.tp_l1_loss(input, target, 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]
tp_soft_margin_loss
functionFull reference ↗- tensorplay.tp_soft_margin_loss(input, target, reduction=1)[source]
transpose_
functionFull reference ↗- tensorplay.transpose_(input, dim0, dim1)[source]
tril_
functionFull reference ↗- tensorplay.tril_(input, diagonal=0)[source]
triu_
functionFull reference ↗- tensorplay.triu_(input, diagonal=0)[source]
true_divide_
functionFull reference ↗- tensorplay.true_divide_(input, other)[source]
type_as
functionFull reference ↗- tensorplay.type_as(input, other)[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:
Example
>>> x = tensorplay.tensor([1, 2, 3]) >>> tensorplay.typename(x) 'tensorplay.LongTensor' >>> tensorplay.typename(tensorplay.nn.Parameter) 'tensorplay.nn.parameter.Parameter'
unflatten_dense_tensors
functionFull reference ↗- tensorplay.unflatten_dense_tensors(flat, tensors)[source]
unfold
functionFull reference ↗- tensorplay.unfold(input, dimension, size, step)[source]
uniform_
functionFull reference ↗- tensorplay.uniform_(input, from_=0.0, to=1.0, generator=None)[source]
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)[source]
unsafe_split_with_sizes
functionFull reference ↗- tensorplay.unsafe_split_with_sizes(input, split_sizes, dim=0)[source]
unsafe_split
functionFull reference ↗- tensorplay.unsafe_split(input, split_size, dim=0)[source]
unsqueeze_
functionFull reference ↗- tensorplay.unsqueeze_(input, dim)[source]
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_nearest1d
functionFull reference ↗- tensorplay.upsample_nearest1d(input, output_size, 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
RuntimeErrorwhen 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
outargument 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)
values
functionFull reference ↗- tensorplay.values(input)[source]
view_as
functionFull reference ↗- tensorplay.view_as(input, other)[source]
view
functionFull reference ↗- tensorplay.view(input, shape)[source]
vision_to_tensor
functionFull reference ↗- tensorplay.vision_to_tensor(image: Annotated[numpy.typing.ArrayLike, numpy.uint8]) tensorplay::Tensor
Optimized conversion from HWC uint8 image to CHW float32 tensor (div 255)
xlog1py_
functionFull reference ↗- tensorplay.xlog1py_(input, other)[source]
xlog1py
functionFull reference ↗- tensorplay.xlog1py(input, other)[source]
zeros
functionFull reference ↗- tensorplay.zeros()
zeta
functionFull reference ↗- tensorplay.zeta(input, other)[source]
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
autocastserve 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()orbfloat16()on your model(s) or inputs when using autocasting.autocastshould 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()autocastcan also be used as a decorator, e.g., on theforwardmethod 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 tofloat32(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 particulardtype.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:
Truedtype (tensorplay.dtype, optional) – Data type for ops run in autocast. It uses the default value (
tensorplay.float16for CUDA andtensorplay.bfloat16for CPU), given byget_autocast_dtype(), ifdtypeisNone. Default:Nonecache_enabled (bool, optional) – Whether the weight cache inside autocast should be enabled. Default:
True
Device
classFull reference ↗DeviceType
classFull reference ↗- class tensorplay.DeviceType
Members:
CPU
CUDA
Vulkan
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
AutogradCPU
AutogradCUDA
AutogradVulkan
AutocastCPU
AutocastCUDA
AutocastVulkan
VmapCPU
VmapCUDA
VmapVulkan
Composite
VmapMode
DynamicLayerFrontMode
DynamicLayerBackMode
- 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
qint8
quint8
qint32
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
finfo
classFull reference ↗- class tensorplay.finfo(dtype)[source]
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
- 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
- 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
scalerofGradScaler.Helps perform the steps of gradient scaling conveniently.
scaler.scale(loss)multiplies a given loss byscaler’s current scale factor.scaler.step(optimizer)safely unscales gradients and callsoptimizer.step().scaler.update()updatesscaler’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()scalerdynamically estimates the scale factor each iteration. To minimize gradient underflow, a large scale factor should be used. However,float16values 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.scalerapproximates the optimal scale factor over time by checking the gradients for infs and NaNs during everyscaler.step(optimizer)(or optional separatescaler.unscale_(optimizer), seeunscale_()).If infs/NaNs are found,
scaler.step(optimizer)skips the underlyingoptimizer.step()(so the params themselves remain uncorrupted) andupdate()multiplies the scale bybackoff_factor.If no infs/NaNs are found,
scaler.step(optimizer)runs the underlyingoptimizer.step()as usual. Ifgrowth_intervalunskipped iterations occur consecutively,update()multiplies the scale bygrowth_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 forgrowth_intervalconsecutive 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 underlyingoptimizer.step(), and other methods become no-ops. Default:True
- get_scale() float[source]
Return a Python float containing the current scale, or 1.0 if scaling is disabled.
- 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: TensorBase) TensorBase[source]
- scale(outputs: list[TensorBase]) list[TensorBase]
- scale(outputs: tuple[TensorBase, ...]) tuple[TensorBase, ...]
- 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
GradScaleris 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 afterupdate().
- 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:Internally invokes
unscale_(optimizer)(unlessunscale_()was explicitly called foroptimizerearlier in the iteration). As part of theunscale_(), gradients are checked for infs/NaNs.If no inf/NaN gradients are found, invokes
optimizer.step()using the unscaled gradients. Otherwise,optimizer.step()is skipped to avoid corrupting the params.
*argsand**kwargsare forwarded tooptimizer.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) andstep(). Ifunscale_()is not called explicitly, gradients will be unscaled automatically duringstep().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 perstep()call, and only after all gradients for that optimizer’s assigned parameters have been accumulated. Callingunscale_()twice for a given optimizer between eachstep()triggers a RuntimeError.
- update(new_scale: float | TensorBase | None = None) None[source]
Update the scale factor.
If any optimizer steps were skipped the scale is multiplied by
backoff_factorto reduce it. Ifgrowth_intervalunskipped iterations occurred consecutively, the scale is multiplied bygrowth_factorto increase it.Passing
new_scalesets the new scale value manually. (new_scaleis not used directly, it’s used to fill GradScaler’s internal scale tensor. So ifnew_scalewas 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, afterscaler.step(optimizer)has been invoked for all optimizers used this iteration.
iinfo
classFull reference ↗- class tensorplay.iinfo(dtype)[source]
Layout
classFull reference ↗- class tensorplay.Layout(*values)[source]
tensor.layoutreturns 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)
Node
classFull reference ↗- class tensorplay.Node
- add_post_hook(self: tensorplay._C.Node, hook: collections.abc.Callable[[list[tensorplay._C.TensorBase], list[tensorplay._C.TensorBase]], collections.abc.Sequence[tensorplay._C.TensorBase]]) None
- add_pre_hook(self: tensorplay._C.Node, hook: collections.abc.Callable[[list[tensorplay._C.TensorBase]], collections.abc.Sequence[tensorplay._C.TensorBase]]) None
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)
Scalar
classFull reference ↗- class tensorplay.Scalar
- is_complex(self: tensorplay._C.Scalar) bool
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
- 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
- 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
- min(self: tensorplay._C.SymFloat, arg0: tensorplay._C.SymFloat) tensorplay._C.SymFloat
- 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
-
- 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
- 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
Tensor
attributeFull reference ↗- tensorplay.Tensor
alias of
TensorBase
Exceptions 1
DeviceMismatchError
exceptionFull reference ↗- exception tensorplay.DeviceMismatchError

