TensorPlay

Latest development documentation · Updated 2026-09-08. A documentation snapshot for package 1.0.0.dev20260909 is not available.

On this page

Functions 137

#

adaptive_avg_pool3d

functionFull reference ↗
tensorplay.nn.functional.adaptive_avg_pool3d(input: TensorBase, output_size) TensorBase[source]

Apply a 3D adaptive average pooling over an input signal.

#

adaptive_max_pool1d_with_indices

functionFull reference ↗
tensorplay.nn.functional.adaptive_max_pool1d_with_indices(input: TensorBase, output_size, return_indices: bool = True)[source]

Applies a 1D adaptive max pooling over an input signal, returning (output, indices).

See AdaptiveMaxPool1d for details.

#

adaptive_max_pool2d_with_indices

functionFull reference ↗
tensorplay.nn.functional.adaptive_max_pool2d_with_indices(input: TensorBase, output_size, return_indices: bool = True)[source]

Applies a 2D adaptive max pooling over an input signal composed of several input planes, returning (output, indices).

See AdaptiveMaxPool2d for details.

#

adaptive_max_pool3d_with_indices

functionFull reference ↗
tensorplay.nn.functional.adaptive_max_pool3d_with_indices(input: TensorBase, output_size, return_indices: bool = True)[source]

Applies a 3D adaptive max pooling over an input signal, returning (output, indices).

See AdaptiveMaxPool3d for details.

#

adaptive_max_pool3d

functionFull reference ↗
tensorplay.nn.functional.adaptive_max_pool3d(input, output_size, return_indices=False)[source]

Applies a 3D adaptive max pooling over an input signal composed of several input planes. Input shape (N, C, D, H, W) or unbatched (C, D, H, W).

See AdaptiveMaxPool3d for details.

#

affine_grid

functionFull reference ↗
tensorplay.nn.functional.affine_grid(theta: TensorBase, size, align_corners=None) TensorBase[source]

Generate 2D or 3D flow field (sampling grid), given a batch of affine matrices theta.

#

avg_pool1d

functionFull reference ↗
tensorplay.nn.functional.avg_pool1d(input: TensorBase, kernel_size, stride=None, padding=0, ceil_mode: bool = False, count_include_pad: bool = True, divisor_override=None) TensorBase[source]

avg_pool1d(input, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True, divisor_override=None) -> Tensor

Applies a 1D average pooling over an input signal composed of several input planes. Input shape (N, C, L) or unbatched (C, L).

#

avg_pool2d

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

avg_pool3d

functionFull reference ↗
tensorplay.nn.functional.avg_pool3d(input: TensorBase, kernel_size, stride=None, padding=0, ceil_mode: bool = False, count_include_pad: bool = True, divisor_override=None) TensorBase[source]

avg_pool3d(input, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True, divisor_override=None) -> Tensor

Applies a 3D average pooling over an input signal composed of several input planes. Input shape (N, C, D, H, W) or unbatched (C, D, H, W).

#

batch_norm

functionFull reference ↗
tensorplay.nn.functional.batch_norm(input, running_mean=None, running_var=None, weight=None, bias=None, training=False, momentum=0.1, eps=1e-05)[source]
#

binary_cross_entropy_with_logits

functionFull reference ↗
tensorplay.nn.functional.binary_cross_entropy_with_logits(input: TensorBase, target: TensorBase, weight: TensorBase | None = None, size_average=None, reduce=None, reduction: str = 'mean', pos_weight: TensorBase | None = None) TensorBase[source]

Compute Binary Cross Entropy between target and input logits.

optionally rescaled by weight, then reduced. See BCEWithLogitsLoss for details.

#

binary_cross_entropy

functionFull reference ↗
tensorplay.nn.functional.binary_cross_entropy(input: TensorBase, target: TensorBase, weight: TensorBase | None = None, size_average=None, reduce=None, reduction: str = 'mean') TensorBase[source]

Compute Binary Cross Entropy between the target and input probabilities.

See BCELoss for details.

#

celu_

functionFull reference ↗
tensorplay.nn.functional.celu_(Tensor(a!) self, Scalar alpha=1.0) -> Tensor(a!)
#

channel_shuffle

functionFull reference ↗
tensorplay.nn.functional.channel_shuffle(input: TensorBase, groups: int) TensorBase[source]

Divide the channels in a tensor into g groups and rearrange them as in ShuffleNet: (*, C, H, W) -> (*, C, H, W) with channels interleaved across groups.

#

conv_tbc

functionFull reference ↗
tensorplay.nn.functional.conv_tbc(input, weight, bias=None, pad=0)[source]

Applies a 1D convolution over an input of shape (T, B, C) along the (kernel_width, in_channels, out_channels); the math is a standard cross-channel conv1d after permuting to (B, C, T).

#

conv_transpose1d

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

conv_transpose2d

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

conv_transpose3d

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

conv1d

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

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

See Conv1d for details and output shape.

Parameters:
  • input – input tensor of shape (minibatch,in_channels,iW)(\text{minibatch} , \text{in\_channels} , iW)

  • weight – filters of shape (out_channels,in_channelsgroups,kW)(\text{out\_channels} , \frac{\text{in\_channels}}{\text{groups}} , kW)

  • bias – optional bias of shape (out_channels)(\text{out\_channels}). Default: None

  • stride – the stride of the convolving kernel. Can be a single number or a one-element tuple (sW,). Default: 1

  • padding – implicit paddings on both sides of the input. Can be a single number or a one-element tuple (padW,). Default: 0

  • dilation – the spacing between kernel elements. Can be a single number or a one-element tuple (dW,). Default: 1

  • groups – split input into groups, in_channels\text{in\_channels} should be divisible by the number of groups. Default: 1

Examples:

>>> inputs = tp.randn(33, 16, 30)
>>> filters = tp.randn(20, 16, 5)
>>> F.conv1d(inputs, filters)
#

conv2d

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

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

See Conv2d for details and output shape.

Parameters:
  • input – input tensor of shape (minibatch,in_channels,iH,iW)(\text{minibatch} , \text{in\_channels} , iH , iW)

  • weight – filters of shape (out_channels,in_channelsgroups,kH,kW)(\text{out\_channels} , \frac{\text{in\_channels}}{\text{groups}} , kH , kW)

  • bias – optional bias tensor of shape (out_channels)(\text{out\_channels}). Default: None

  • stride – the stride of the convolving kernel. Can be a single number or a tuple (sH, sW). Default: 1

  • padding – implicit paddings on both sides of the input. Can be a single number or a tuple (padH, padW). Default: 0

  • dilation – the spacing between kernel elements. Can be a single number or a tuple (dH, dW). Default: 1

  • groups – split input into groups, both in_channels\text{in\_channels} and out_channels\text{out\_channels} should be divisible by the number of groups. Default: 1

Examples:

>>> # With square kernels and equal stride
>>> filters = tp.randn(8, 4, 3, 3)
>>> inputs = tp.randn(1, 4, 5, 5)
>>> F.conv2d(inputs, filters, padding=1)
#

conv3d

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

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

See Conv3d for details and output shape.

Parameters:
  • input – input tensor of shape (minibatch,in_channels,iD,iH,iW)(\text{minibatch} , \text{in\_channels} , iD, iH , iW)

  • weight – filters of shape (out_channels,in_channelsgroups,kD,kH,kW)(\text{out\_channels} , \frac{\text{in\_channels}}{\text{groups}} , kD, kH , kW)

  • bias – optional bias tensor of shape (out_channels)(\text{out\_channels}). Default: None

  • stride – the stride of the convolving kernel. Can be a single number or a tuple (sD, sH, sW). Default: 1

  • padding – implicit paddings on both sides of the input. Can be a single number or a tuple (padD, padH, padW). Default: 0

  • dilation – the spacing between kernel elements. Can be a single number or a tuple (dD, dH, dW). Default: 1

  • groups – split input into groups, both in_channels\text{in\_channels} and out_channels\text{out\_channels} should be divisible by the number of groups. Default: 1

Examples:

>>> # With square kernels and equal stride
>>> filters = tp.randn(8, 4, 3, 3, 3)
>>> inputs = tp.randn(1, 4, 5, 5, 5)
>>> F.conv3d(inputs, filters, padding=1)
#

cosine_embedding_loss

functionFull reference ↗
tensorplay.nn.functional.cosine_embedding_loss(input1: TensorBase, input2: TensorBase, target: TensorBase, margin: float = 0, size_average=None, reduce=None, reduction: str = 'mean') TensorBase[source]

Compute the cosine embedding loss.

See CosineEmbeddingLoss for details.

#

cosine_similarity

functionFull reference ↗
tensorplay.nn.functional.cosine_similarity(x1: TensorBase, x2: TensorBase, dim: int = 1, eps: float = 1e-08) TensorBase[source]

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

#

cross_entropy

functionFull reference ↗
tensorplay.nn.functional.cross_entropy(input, target, weight=None, size_average=None, ignore_index=-100, reduce=None, reduction='mean', label_smoothing=0.0)[source]

Compute the cross entropy loss between input logits and target.

the class-probability path, positive label_smoothing blends the NLL with a smoothed uniform term, and otherwise this is nll_loss(log_softmax(input), target) with N-d support.

See CrossEntropyLoss for details.

#

ctc_loss

functionFull reference ↗
tensorplay.nn.functional.ctc_loss(log_probs: TensorBase, targets: TensorBase, input_lengths, target_lengths, blank: int = 0, reduction: str = 'mean', zero_infinity: bool = False) TensorBase[source]

Compute the Connectionist Temporal Classification loss.

(alpha recurrence over the blank-extended target sequence); autograd flows through log_probs via the composed primitives.

Parameters:
  • log_probs(T,N,C)(T, N, C) or (T,C)(T, C) log-softmax outputs.

  • targets(N,S)(N, S) or concatenated (Sn,)(\sum S_n,).

  • target_lengths (input_lengths /) – (N,)(N,) or scalars.

  • blank – index of the blank label. Default: 0.

  • reduction'none' | 'mean' | 'sum'.

  • zero_infinity – zero out infinite losses (targets too long for T).

#

dropout1d

functionFull reference ↗
tensorplay.nn.functional.dropout1d(input: TensorBase, p: float = 0.5, training: bool = True, inplace: bool = False) TensorBase[source]

Randomly zero out entire channels (a channel is a 1D feature map).

See Dropout1d for details.

#

elu_

functionFull reference ↗
tensorplay.nn.functional.elu_(Tensor(a!) self, Scalar alpha=1, Scalar scale=1, Scalar input_scale=1) -> Tensor(a!)
#

embedding_bag

functionFull reference ↗
tensorplay.nn.functional.embedding_bag(input: TensorBase, weight: TensorBase, offsets=None, max_norm=None, norm_type: float = 2, scale_grad_by_freq: bool = False, mode: str = 'mean', sparse: bool = False, per_sample_weights=None, include_last_offset: bool = False, padding_idx=None) TensorBase[source]

Compute sums, means or maxes of bags of embeddings.

1-D inputs with offsets (incl. include_last_offset), fixed length 2-D inputs, per_sample_weights (sum mode), padding_idx exclusion and max_norm renormalization. See tensorplay.nn.EmbeddingBag for details.

#

embedding

functionFull reference ↗
tensorplay.nn.functional.embedding(input, weight, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False, sparse=False)[source]
#

feature_alpha_dropout

functionFull reference ↗
tensorplay.nn.functional.feature_alpha_dropout(input: TensorBase, p: float = 0.5, training: bool = False, inplace: bool = False) TensorBase[source]

Randomly masks out entire channels, setting activations to the negative saturation value of the SELU activation function.

See FeatureAlphaDropout for details.

#

feature_dropout

functionFull reference ↗
tensorplay.nn.functional.feature_dropout(input, p=0.5, training=False, inplace=False)[source]

Randomly zeroes entire channels (dim 1).

#

fold

functionFull reference ↗
tensorplay.nn.functional.fold(input, output_size, kernel_size, dilation=1, padding=0, stride=1)[source]

Combine an array of sliding local blocks into a tensor containing

#

fractional_max_pool2d_with_indices

functionFull reference ↗
tensorplay.nn.functional.fractional_max_pool2d_with_indices(input: TensorBase, kernel_size, output_size=None, output_ratio=None, return_indices: bool = True, _random_samples=None)[source]

Applies 2D fractional max pooling over an input signal composed of several input planes, returning (output, indices).

The max-pooling operation is applied in kH×kWkH \times kW regions by a stochastic step size determined by the target output size. The number of output features is equal to the number of input planes.

Parameters:
  • kernel_size – the size of the window, k or (kH, kW)

  • output_size – target output size oH x oW

  • output_ratio – alternative to output_size, in range (0, 1)

  • return_indices – return pooling indices as well

  • _random_samples – optional (B, C, 2) random starts override

See FractionalMaxPool2d for details.

#

fractional_max_pool2d

functionFull reference ↗
tensorplay.nn.functional.fractional_max_pool2d(input: TensorBase, kernel_size, output_size=None, output_ratio=None, return_indices: bool = False, _random_samples=None)[source]

Applies 2D fractional max pooling over an input signal.

If return_indices is True, returns (output, indices); otherwise just the output.

#

fractional_max_pool3d_with_indices

functionFull reference ↗
tensorplay.nn.functional.fractional_max_pool3d_with_indices(input: TensorBase, kernel_size, output_size=None, output_ratio=None, return_indices: bool = True, _random_samples=None)[source]

Applies 3D fractional max pooling over an input signal composed of several input planes, returning (output, indices).

Each plane consumes three random samples ordered (T, H, W), matching

#

fractional_max_pool3d

functionFull reference ↗
tensorplay.nn.functional.fractional_max_pool3d(input: TensorBase, kernel_size, output_size=None, output_ratio=None, return_indices: bool = False, _random_samples=None)[source]

Applies 3D fractional max pooling over an input signal.

If return_indices is True, returns (output, indices); otherwise just the output.

#

gaussian_nll_loss

functionFull reference ↗
tensorplay.nn.functional.gaussian_nll_loss(input: TensorBase, target: TensorBase, var, full: bool = False, eps: float = 1e-06, reduction: str = 'mean') TensorBase[source]

Compute the Gaussian negative log likelihood loss.

See GaussianNLLLoss for details.

#

gelu

functionFull reference ↗
tensorplay.nn.functional.gelu(input, approximate='none') Tensor[source]

When approximate is ‘none’, applies GELU(x)=xΦ(x)\text{GELU}(x) = x * \Phi(x); ‘tanh’ uses the tanh estimation.

#

glu

functionFull reference ↗
tensorplay.nn.functional.glu(input, dim=-1) Tensor[source]

Gated Linear Unit: aσ(b)a * \sigma(b) where the input is split in half along dim.

#

grid_sample

functionFull reference ↗
tensorplay.nn.functional.grid_sample(input: TensorBase, grid: TensorBase, mode: str = 'bilinear', padding_mode: str = 'zeros', align_corners=None) TensorBase[source]

Compute grid sample.

Given an input and a flow-field grid, computes the output using input values and pixel locations from grid. Currently, only spatial (4-D) and volumetric (5-D) input are supported.

Parameters:
  • input (Tensor) – input of shape (N,C,Hin,Win)(N, C, H_\text{in}, W_\text{in}) (4-D case) or (N,C,Din,Hin,Win)(N, C, D_\text{in}, H_\text{in}, W_\text{in}) (5-D case)

  • grid (Tensor) – flow-field of shape (N,Hout,Wout,2)(N, H_\text{out}, W_\text{out}, 2) (4-D case) or (N,Dout,Hout,Wout,3)(N, D_\text{out}, H_\text{out}, W_\text{out}, 3) (5-D case)

  • mode (str) – 'bilinear' | 'nearest' | 'bicubic'. Default: 'bilinear'

  • padding_mode (str) – 'zeros' | 'border' | 'reflection'. Default: 'zeros'

  • align_corners (bool, optional) – extrema treatment, default False.

Dispatches to the native grid_sampler_2d / grid_sampler_3d kernels both input and grid.

#

group_norm

functionFull reference ↗
tensorplay.nn.functional.group_norm(input, num_groups, weight=None, bias=None, eps=1e-05)[source]
#

gru_cell

functionFull reference ↗
tensorplay.nn.functional.gru_cell(input, hx, w_ih, w_hh, b_ih=None, b_hh=None) Tensor[source]

One time step of a gated recurrent unit cell.

#

gumbel_softmax

functionFull reference ↗
tensorplay.nn.functional.gumbel_softmax(logits: TensorBase, tau: float = 1, hard: bool = False, eps: float = 1e-10, dim: int = -1) TensorBase[source]

Sample from the Gumbel-Softmax distribution and optionally discretize.

straight-through when hard=True).

#

hardshrink

functionFull reference ↗
tensorplay.nn.functional.hardshrink(input, lambd=0.5) Tensor[source]

Applies the hard shrinkage function element-wise.

See Hardshrink for more details.

#

hardtanh_

functionFull reference ↗
tensorplay.nn.functional.hardtanh_(Tensor(a!) self, Scalar min_val=-1, Scalar max_val=1) -> Tensor(a!)
#

hinge_embedding_loss

functionFull reference ↗
tensorplay.nn.functional.hinge_embedding_loss(input: TensorBase, target: TensorBase, margin: float = 1.0, size_average=None, reduce=None, reduction: str = 'mean') TensorBase[source]

Compute the hinge embedding loss.

See HingeEmbeddingLoss for details.

#

huber_loss

functionFull reference ↗
tensorplay.nn.functional.huber_loss(input: TensorBase, target: TensorBase, reduction: str = 'mean', delta: float = 1.0, weight: TensorBase | None = None) TensorBase[source]

Compute the Huber loss, with optional weighting.

Function uses a squared term if the absolute error falls below delta and a delta-scaled L1 term otherwise. See HuberLoss for details.

#

instance_norm

functionFull reference ↗
tensorplay.nn.functional.instance_norm(input, running_mean=None, running_var=None, weight=None, bias=None, use_input_stats=True, momentum=0.1, eps=1e-05)[source]
#

interpolate

functionFull reference ↗
tensorplay.nn.functional.interpolate(input: TensorBase, size=None, scale_factor=None, mode: str = 'nearest', align_corners=None, recompute_scale_factor=None, antialias: bool = False) TensorBase[source]

interpolate(input, size=None, scale_factor=None, mode=’nearest’, align_corners=None) -> Tensor

Routes to the native upsample_* ops exactly like

#

kl_div

functionFull reference ↗
tensorplay.nn.functional.kl_div(input: TensorBase, target: TensorBase, size_average=None, reduce=None, reduction: str = 'mean', log_target: bool = False) TensorBase[source]

Compute the KL Divergence loss.

input holds log-probabilities; see KLDivLoss. Note that reduction='mean' divides by the number of elements and does not return the true KL divergence value — use 'batchmean'.

#

l1_loss

functionFull reference ↗
tensorplay.nn.functional.l1_loss(input: TensorBase, target: TensorBase, size_average=None, reduce=None, reduction: str = 'mean', weight: TensorBase | None = None) TensorBase[source]

Compute the L1 loss, with optional weighting.

Function that takes the mean element-wise absolute value difference. See L1Loss for details.

#

layer_norm

functionFull reference ↗
tensorplay.nn.functional.layer_norm(input, normalized_shape, weight=None, bias=None, eps=1e-05)[source]
#

leaky_relu_

functionFull reference ↗
tensorplay.nn.functional.leaky_relu_(Tensor(a!) self, Scalar negative_slope=0.01) -> Tensor(a!)
#

linear_cross_entropy

functionFull reference ↗
tensorplay.nn.functional.linear_cross_entropy(input: TensorBase, linear_weight: TensorBase, target: TensorBase, *, linear_bias=None, weight=None, reduction: str = 'mean', ignore_index=None, label_smoothing: float = 0.0, options=None) TensorBase[source]

Compute cross entropy between input, transformed linearly, and target.

Equivalent to cross_entropy(linear(input, linear_weight), target, **kwargs) (reference path; chunked/fused options are ignored).

#

linear

functionFull reference ↗
tensorplay.nn.functional.linear(input: TensorBase, weight: TensorBase, bias: TensorBase | None = None) TensorBase[source]

Applies a linear transformation to the incoming data: y=xAT+by = xA^T + b.

Shape:
  • Input: (,Hin)(*, H_\text{in}) where * means any number of dimensions including none and Hin=in_featuresH_\text{in} = \text{in\_features}.

  • Weight: (Hout,Hin)(H_\text{out}, H_\text{in}) where Hout=out_featuresH_\text{out} = \text{out\_features}.

  • Bias: (Hout)(H_\text{out})

  • Output: (,Hout)(*, H_\text{out})

See Linear for more details.

#

local_response_norm

functionFull reference ↗
tensorplay.nn.functional.local_response_norm(input: TensorBase, size: int, alpha: float = 0.0001, beta: float = 0.75, k: float = 1.0) TensorBase[source]

Apply local response normalization over an input signal.

The input signal is composed of several input planes, where channels occupy the second dimension. Normalization is applied across channels.

See LocalResponseNorm for details.

#

logsigmoid

functionFull reference ↗
tensorplay.nn.functional.logsigmoid(input) Tensor[source]

Applies element-wise LogSigmoid(xi)=log(11+exp(xi))\text{LogSigmoid}(x_i) = \log \left(\frac{1}{1 + \exp(-x_i)}\right)

See LogSigmoid for more details.

#

lp_pool1d

functionFull reference ↗
tensorplay.nn.functional.lp_pool1d(input: TensorBase, norm_type, kernel_size, stride=None, ceil_mode: bool = False) TensorBase[source]

Apply a 1D power-average pooling over an input signal.

See LPPool1d for details.

#

lp_pool2d

functionFull reference ↗
tensorplay.nn.functional.lp_pool2d(input: TensorBase, norm_type, kernel_size, stride=None, ceil_mode: bool = False) TensorBase[source]

Apply a 2D power-average pooling over an input signal.

If the sum of all inputs to the power of p is zero, the gradient is set to zero as well.

See LPPool2d for details.

#

lp_pool3d

functionFull reference ↗
tensorplay.nn.functional.lp_pool3d(input: TensorBase, norm_type, kernel_size, stride=None, ceil_mode: bool = False) TensorBase[source]

Apply a 3D power-average pooling over an input signal.

See LPPool3d for details.

#

lstm_cell

functionFull reference ↗
tensorplay.nn.functional.lstm_cell(input, hx, cx, w_ih, w_hh, b_ih=None, b_hh=None)[source]

One time step of a long short-term memory cell. Returns the next hidden state and next cell state.

#

margin_ranking_loss

functionFull reference ↗
tensorplay.nn.functional.margin_ranking_loss(input1: TensorBase, input2: TensorBase, target: TensorBase, margin: float = 0, size_average=None, reduce=None, reduction: str = 'mean') TensorBase[source]

Compute the margin ranking loss.

See MarginRankingLoss for details.

#

max_pool1d_with_indices

functionFull reference ↗
tensorplay.nn.functional.max_pool1d_with_indices(input: TensorBase, kernel_size, stride=None, padding=0, dilation=1, ceil_mode: bool = False, return_indices: bool = True)[source]

Applies a 1D max pooling over an input signal, returning (output, indices).

See MaxPool1d for details.

#

max_pool1d

functionFull reference ↗
tensorplay.nn.functional.max_pool1d(input: TensorBase, kernel_size, stride=None, padding=0, dilation=1, ceil_mode: bool = False, return_indices: bool = False)[source]

max_pool1d(input, kernel_size, stride=None, padding=0, dilation=1, ceil_mode=False, return_indices=False) -> Tensor

Applies a 1D max pooling over an input signal composed of several input planes. Input shape (N, C, L) or unbatched (C, L).

#

max_pool2d_with_indices

functionFull reference ↗
tensorplay.nn.functional.max_pool2d_with_indices(input: TensorBase, kernel_size, stride=None, padding=0, dilation=1, ceil_mode: bool = False, return_indices: bool = True)[source]

Applies a 2D max pooling over an input composed of several input planes, returning (output, indices).

See MaxPool2d for details.

#

max_pool2d

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

max_pool3d_with_indices

functionFull reference ↗
tensorplay.nn.functional.max_pool3d_with_indices(input: TensorBase, kernel_size, stride=None, padding=0, dilation=1, ceil_mode: bool = False, return_indices: bool = True)[source]

Applies a 3D max pooling over an input signal, returning (output, indices).

See MaxPool3d for details.

#

max_pool3d

functionFull reference ↗
tensorplay.nn.functional.max_pool3d(input: TensorBase, kernel_size, stride=None, padding=0, dilation=1, ceil_mode: bool = False, return_indices: bool = False) TensorBase[source]

max_pool3d(input, kernel_size, stride=None, padding=0, dilation=1, ceil_mode=False, return_indices=False) -> Tensor

Applies a 3D max pooling over an input signal composed of several input planes. Input shape (N, C, D, H, W) or unbatched (C, D, H, W).

#

max_unpool1d

functionFull reference ↗
tensorplay.nn.functional.max_unpool1d(input: TensorBase, indices: TensorBase, kernel_size, stride=None, padding=0, output_size=None) TensorBase[source]

Compute a partial inverse of MaxPool1d.

See MaxUnpool1d for details.

#

max_unpool2d

functionFull reference ↗
tensorplay.nn.functional.max_unpool2d(input: TensorBase, indices: TensorBase, kernel_size, stride=None, padding=0, output_size=None) TensorBase[source]

Compute a partial inverse of MaxPool2d.

See MaxUnpool2d for details.

#

max_unpool3d

functionFull reference ↗
tensorplay.nn.functional.max_unpool3d(input: TensorBase, indices: TensorBase, kernel_size, stride=None, padding=0, output_size=None) TensorBase[source]

Compute a partial inverse of MaxPool3d.

See MaxUnpool3d for details.

#

multi_head_attention_forward

functionFull reference ↗
tensorplay.nn.functional.multi_head_attention_forward(query: TensorBase, key: TensorBase, value: TensorBase, embed_dim_to_check: int, num_heads: int, in_proj_weight: TensorBase = None, in_proj_bias: TensorBase = None, bias_k=None, bias_v=None, add_zero_attn: bool = False, dropout_p: float = 0.0, out_proj_weight: TensorBase = None, out_proj_bias: TensorBase = None, training: bool = True, key_padding_mask=None, need_weights: bool = True, attn_mask=None, use_separate_proj_weight: bool = False, q_proj_weight=None, k_proj_weight=None, v_proj_weight=None, static_k=None, static_v=None, average_attn_weights: bool = True, is_causal: bool = False)[source]

multi_head_attention_forward(query, key, value, embed_dim_to_check, num_heads, in_proj_weight, in_proj_bias=None, bias_k=None, bias_v=None, add_zero_attn=False, dropout_p=0.0, out_proj_weight=None, out_proj_bias=None, training=True, key_padding_mask=None, need_weights=True, attn_mask=None, use_separate_proj_weight=False, q_proj_weight=None, k_proj_weight=None, v_proj_weight=None, static_k=None, static_v=None, average_attn_weights=True, is_causal=False) -> (Tensor, Optional[Tensor])

Computes multi-head attention on (L, N, E) inputs (2D unbatched inputs are promoted internally and the batch dim is squeezed on return). Returns the projected output of shape (L, N, E) and, when need_weights is true, the attention weights of shape (N, L, S) — or (num_heads, L, S) with average_attn_weights=False.

#

multi_margin_loss

functionFull reference ↗
tensorplay.nn.functional.multi_margin_loss(input: TensorBase, target: TensorBase, p: int = 1, margin: float = 1.0, weight: TensorBase | None = None, size_average=None, reduce=None, reduction: str = 'mean') TensorBase[source]

Compute the multi margin loss, with optional weighting.

sum_d max(0, margin - x_y + x_d)^p * w_y / C over non-target classes. See MultiMarginLoss for details.

#

multilabel_margin_loss

functionFull reference ↗
tensorplay.nn.functional.multilabel_margin_loss(input: TensorBase, target: TensorBase, size_average=None, reduce=None, reduction: str = 'mean') TensorBase[source]

Compute the multilabel margin loss.

for each positive label y (targets are active until the first -1), add max(0, 1 - x[y] + x[d]) over non-target labels d; divide by C. See MultiLabelMarginLoss for details.

#

multilabel_soft_margin_loss

functionFull reference ↗
tensorplay.nn.functional.multilabel_soft_margin_loss(input: TensorBase, target: TensorBase, weight: TensorBase | None = None, size_average=None, reduce=None, reduction: str = 'mean') TensorBase[source]

Compute the multilabel soft margin loss.

See MultiLabelSoftMarginLoss for details.

#

native_channel_shuffle

functionFull reference ↗
tensorplay.nn.functional.native_channel_shuffle(input: TensorBase, groups: int) TensorBase[source]
#

nll_loss

functionFull reference ↗
tensorplay.nn.functional.nll_loss(input, target, weight=None, size_average=None, ignore_index=-100, reduce=None, reduction='mean')[source]

The negative log likelihood loss.

input with a scalar target, 2D (N, C), and N-d target.

See NLLLoss for details.

#

normalize

functionFull reference ↗
tensorplay.nn.functional.normalize(input, p=2, dim=1, eps=1e-12) Tensor[source]

Performs LpL_p normalization over the specified dimension —

#

one_hot

functionFull reference ↗
tensorplay.nn.functional.one_hot(tensor, num_classes=-1) LongTensor[source]

Returns long tensor shaped tensor.shape + (num_classes,) with a 1 at

#

pad

functionFull reference ↗
tensorplay.nn.functional.pad(input, pad, mode='constant', value=0)[source]

Pads tensor. pad values are described starting from the last dimension and may cover any suffix of the input dimensions.

#

pairwise_distance

functionFull reference ↗
tensorplay.nn.functional.pairwise_distance(x1: TensorBase, x2: TensorBase, p: float = 2.0, eps: float = 1e-06, keepdim: bool = False) TensorBase[source]

Computes the pairwise distance between input vectors.

dimension.

#

pdist

functionFull reference ↗
tensorplay.nn.functional.pdist(input: TensorBase, p: float = 2.0) TensorBase[source]

Computes the pairwise distance between rows of input.

Returns the flattened upper triangle of the N x N distance matrix —

#

pixel_shuffle

functionFull reference ↗
tensorplay.nn.functional.pixel_shuffle(input: TensorBase, upscale_factor: int) TensorBase[source]

Rearranges elements in a tensor of shape (*, C x r^2, H, W) to a tensor of shape (*, C, H x r, W x r).

input[n, c*r^2 + i*r + j, h, w]``.

#

pixel_unshuffle

functionFull reference ↗
tensorplay.nn.functional.pixel_unshuffle(input: TensorBase, downscale_factor: int) TensorBase[source]

Reverses the pixel_shuffle() transformation: (*, C, H x r, W x r) -> (*, C x r^2, H, W).

#

poisson_nll_loss

functionFull reference ↗
tensorplay.nn.functional.poisson_nll_loss(input: TensorBase, target: TensorBase, log_input: bool = True, full: bool = False, size_average=None, eps: float = 1e-08, reduce=None, reduction: str = 'mean') TensorBase[source]

Compute the Poisson negative log likelihood loss.

See PoissonNLLLoss for details.

#

relu_

functionFull reference ↗
tensorplay.nn.functional.relu_(Tensor(a!) self) -> Tensor(a!)
#

rms_norm

functionFull reference ↗
tensorplay.nn.functional.rms_norm(input: TensorBase, normalized_shape, weight: TensorBase | None = None, eps: float | None = None) TensorBase[source]

Apply Root Mean Square Layer Normalization.

Dispatches to the native fused kernel (single dispatch, CPU vectorized rows / CUDA block-per-row); falls back to the composite below under CompositeImplicitAutograd rms_norm.

#

rnn_relu_cell

functionFull reference ↗
tensorplay.nn.functional.rnn_relu_cell(input, hx, w_ih, w_hh, b_ih=None, b_hh=None) Tensor[source]

One time step of an Elman RNN cell with ReLU nonlinearity.

#

rnn_tanh_cell

functionFull reference ↗
tensorplay.nn.functional.rnn_tanh_cell(input, hx, w_ih, w_hh, b_ih=None, b_hh=None) Tensor[source]

One time step of an Elman RNN cell with tanh nonlinearity.

#

rrelu

functionFull reference ↗
tensorplay.nn.functional.rrelu(input, lower=1. / 8, upper=1. / 3, training=False, inplace=False) Tensor[source]

Randomized leaky ReLU.

See RReLU for more details.

#

scaled_dot_product_attention

functionFull reference ↗
tensorplay.nn.functional.scaled_dot_product_attention(query: TensorBase, key: TensorBase, value: TensorBase, attn_mask=None, dropout_p: float = 0.0, is_causal: bool = False, scale=None, enable_gqa: bool = False, backend: str | None = None) TensorBase[source]

scaled_dot_product_attention(query, key, value, attn_mask=None, dropout_p=0.0, is_causal=False, scale=None, enable_gqa=False, backend=None) -> Tensor

Computes scaled dot product attention on query, key and value. Routes to reference:

Attention(Q,K,V)=softmax(QKTE)V\text{Attention}(Q, K, V) = \text{softmax}(\frac{Q K^T}{\sqrt{E}}) V
Parameters:

backend (str, optional) – 'flash' | 'mem_efficient', 'math', or None to pick automatically. 'flash' selects the fused flash-attention kernel, 'math' forces the composed reference path. When None, the routing candidate order is governed by tensorplay.nn.attention.sdpa_kernel().

#

selu_

functionFull reference ↗
tensorplay.nn.functional.selu_(Tensor(a!) self) -> Tensor(a!)
#

sigmoid

functionFull reference ↗
tensorplay.nn.functional.sigmoid(input) Tensor[source]

Applies the element-wise function Sigmoid(x)=11+exp(x)\text{Sigmoid}(x) = \frac{1}{1 + \exp(-x)}

#

silu

functionFull reference ↗
tensorplay.nn.functional.silu(input: TensorBase, inplace: bool = False) TensorBase[source]

Apply the Sigmoid Linear Unit (SiLU) function, element-wise.

The SiLU function is also known as the swish function.

silu(x)=xσ(x),where σ(x) is the logistic sigmoid.\text{silu}(x) = x * \sigma(x), \text{where } \sigma(x) \text{ is the logistic sigmoid.}

Note

See Gaussian Error Linear Units (GELUs) where the SiLU (Sigmoid Linear Unit) was originally coined, and see Sigmoid-Weighted Linear Units for Neural Network Function Approximation in Reinforcement Learning and Swish: a Self-Gated Activation Function where the SiLU was experimented with later.

See SiLU for more details.

#

smooth_l1_loss

functionFull reference ↗
tensorplay.nn.functional.smooth_l1_loss(input: TensorBase, target: TensorBase, size_average=None, reduce=None, reduction: str = 'mean', beta: float = 1.0) TensorBase[source]

Compute the Smooth L1 loss.

Function uses a squared term if the absolute element-wise error falls below beta and an L1 term otherwise. See SmoothL1Loss for details.

#

soft_margin_loss

functionFull reference ↗
tensorplay.nn.functional.soft_margin_loss(input: TensorBase, target: TensorBase, size_average=None, reduce=None, reduction: str = 'mean') TensorBase[source]

Compute the soft margin loss.

See SoftMarginLoss for details.

#

softmin

functionFull reference ↗
tensorplay.nn.functional.softmin(input: TensorBase, dim: int | None = None, dtype=None) TensorBase[source]

Apply a softmin function.

Note that Softmin(x)=Softmax(x)\text{Softmin}(x) = \text{Softmax}(-x).

See Softmin for more details.

#

softshrink

functionFull reference ↗
tensorplay.nn.functional.softshrink(input, lambd=0.5) Tensor[source]

Applies the soft shrinkage function element-wise.

See Softshrink for more details.

#

softsign

functionFull reference ↗
tensorplay.nn.functional.softsign(input) Tensor[source]

Applies element-wise, the function SoftSign(x)=x1+x\text{SoftSign}(x) = \frac{x}{1 + |x|}

See Softsign for more details.

#

tanh

functionFull reference ↗
tensorplay.nn.functional.tanh(input) Tensor[source]

Applies element-wise Tanh(x)=exp(x)exp(x)exp(x)+exp(x)\text{Tanh}(x) = \frac{\exp(x) - \exp(-x)}{\exp(x) + \exp(-x)}

#

tanhshrink

functionFull reference ↗
tensorplay.nn.functional.tanhshrink(input) Tensor[source]

Applies element-wise, Tanhshrink(x)=xTanh(x)\text{Tanhshrink}(x) = x - \text{Tanh}(x)

See Tanhshrink for more details.

#

threshold_

functionFull reference ↗
tensorplay.nn.functional.threshold_(Tensor(a!) self, Scalar threshold, Scalar value) -> Tensor(a!)
#

threshold

functionFull reference ↗
tensorplay.nn.functional.threshold(input: TensorBase, threshold: float, value: float, inplace: bool = False) TensorBase[source]

Apply a threshold to each element of the input Tensor.

See Threshold for more details.

#

triplet_margin_loss

functionFull reference ↗
tensorplay.nn.functional.triplet_margin_loss(anchor: TensorBase, positive: TensorBase, negative: TensorBase, margin: float = 1.0, p: float = 2, eps: float = 1e-06, swap: bool = False, size_average=None, reduce=None, reduction: str = 'mean') TensorBase[source]

Compute the triplet loss between given input tensors and a margin greater than 0.

See TripletMarginLoss for details.

#

triplet_margin_with_distance_loss

functionFull reference ↗
tensorplay.nn.functional.triplet_margin_with_distance_loss(anchor: TensorBase, positive: TensorBase, negative: TensorBase, *, distance_function=None, margin: float = 1.0, swap: bool = False, reduction: str = 'mean') TensorBase[source]

Compute the triplet margin loss using a custom distance function.

See TripletMarginWithDistanceLoss for details.

Search documentation

Search all 1,743 documentation pages.

Keyboard shortcuts

Global

  • /Focus search
  • ?This dialog
  • ,Open settings
  • jAI assistant

Search

  • Navigate results
  • Open result
  • escClose

Package

  • mMain information
  • dDocs
  • .Code
  • -Changelog
  • tTimeline
  • sStats
  • vVersions