Indexing Operators¶
Every op on this page is used the same way: construct it once, then call it. The
constructor takes what the kernel is compiled with; the call takes the tensors.
Both are documented under each op — __init__ and forward, where forward is
what runs when you call op(...).
Gather¶
tileops.indexing.EmbeddingFwdOp
¶
Gather the weight rows input names; max_norm would rescale them in place.
The lookup is torch.nn.functional.embedding's forward. padding_idx,
scale_grad_by_freq and sparse change only the gradient, so a call with them is the
plain lookup. The in-tree kernels do not renormalize by max_norm: on the builtin
target a call with it raises OpNotAvailableError and leaves weight unchanged.
The caller guarantees every index lies in [0, V), or passes validate_inputs=True.
__init__
¶
__init__(
padding_idx=None,
max_norm=None,
norm_type=2.0,
scale_grad_by_freq=False,
sparse=False,
*,
validate_inputs=False,
target=None
)
Build the op. The table shape and dtypes are taken from each call.
Parameters:
-
padding_idx(int | None, default:None) –The row whose gradient is not accumulated; the forward reads it.
-
max_norm(float | None, default:None) –The norm each looked-up row is rescaled to at most, in place.
-
norm_type(float, default:2.0) –The p of the norm
max_normbounds. -
scale_grad_by_freq(bool, default:False) –Scale the gradient by index frequency; no effect forward.
-
sparse(bool, default:False) –Return a sparse gradient; no effect forward.
-
validate_inputs(bool, default:False) –Check on every call that each index lies in
[0, V), at the cost of a device synchronization; not allowed during CUDA Graph capture. -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Gather a row of weight per index.
Parameters:
-
input(Tensor) –int32 or int64 indices of any shape
[*S]. -
weight(Tensor) –The table
[V, D], float16, bfloat16, float32, int32 or int64.
Returns:
-
Tensor–A new tensor
[*S, D]inweight's dtype.
Join¶
tileops.indexing.ConcatFwdOp
¶
Tensors joined along one axis: torch.cat(tensors, dim).
The elements have one rank and are equal in every axis but dim. The output takes the
dtype the elements' dtypes promote to, as torch.cat does; each element converts to it
exactly.
__init__
¶
Build the op. The shapes and dtypes are taken from each call.
Parameters:
-
dim(int, default:0) –The axis to join along; negative counts from the last.
-
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
Join tensors along dim.
Parameters:
-
tensors(list[Tensor]) –One or more float16, bfloat16 or float32 tensors of one rank, equal in every axis but
dim.
Returns:
-
Tensor–A new contiguous tensor in the promoted dtype.
Scatter¶
tileops.indexing.MaskedScatterFwdOp
¶
Fill the true positions of mask with consecutive elements of source.
The out-of-place forward of torch.Tensor.masked_scatter: input and mask
broadcast together, and the k-th true position in row-major order takes
source.flatten()[k]. The other positions keep input.
The caller guarantees that source holds at least as many elements as the broadcast
mask has true positions; the op does not count them.
__init__
¶
Build the op; shapes and dtypes arrive with each call. A subclass with manifest parameters assigns them first and then calls this.
It selects and builds no kernel and reads no device property: an op constructs wherever it is imported, and a device it cannot run on is refused at the first call.
Parameters:
-
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
Raises:
-
ValueError–A manifest parameter is outside its signature, or an implementation breaks its kernel interface's contract.
-
TypeError–An implementation breaks its kernel interface's contract.
forward
¶
Scatter source into the true positions of mask.
Parameters:
-
input(Tensor) –Any shape
[*A], float16, bfloat16 or float32. -
mask(Tensor) –bool
[*M], broadcastable withinput. -
source(Tensor) –Any shape
[*R]ininput's dtype.
Returns:
-
Tensor–A new tensor of shape
broadcast(A, M)ininput's dtype.