~/bend-docscommunity

src/autograd/tensor_backward.bend checks

raw source on the hub · import bendtorch-core@0.1.0.0/src/autograd/tensor_backward.bend as Tensor_backward

18 imports
import Base
import ../shape/core.bend as Shape
import ../tensor/core.bend as Core
import ../tensor/elementwise.bend as Elementwise
import ../tensor/layout.bend as Layout
import ../tensor/matmul.bend as Matrix
import ../tensor/batched_matmul.bend as Batched
import ../tensor/reduction.bend as Reduction
import ../tensor/transforms.bend as Transforms
import ../tensor/signed.bend as Signed
import ../tensor/slice.bend as Slice
import ../tensor/gather.bend as Gather
import ./broadcast.bend as Broadcast
import ./reduce.bend as Reduce
import ./sum_to_size.bend as SumToSize
import ./sum_dims.bend as SumDims
import ./gradient.bend as Gradient
import ./loss.bend as Loss

Types

type Error source · line 69 · raw

Data

type Node source · line 82 · raw

Data

type Saved source · line 101 · raw

Type

The operand values a product saves at record time.

type Entry source · line 105 · raw

Type

type Tape source · line 108 · raw

Type

type Contribution source · line 111 · raw

Type

type Pass source · line 116 · raw

Type

What one entry's VJP hands back: its saved values and its gradient, unchanged, and the contributions for its operands in operand order.

type Binary source · line 119 · raw

Data

type Slicing source · line 1447 · raw

Data

Which of the three a slice step is: PyTorch's a[..., start:stop:step, ...] at axis dim, a.narrow(dim, start, length) and a.select(dim, index). The axis and the positions along it are PyTorch's signed ints (signed.bend).

type Indexing source · line 1537 · raw

Data

Which of the two an indexing step is: PyTorch's a.index_select(dim, index) with a vector of entries, and a.gather(dim, index) with an index tensor.

Definitions

def empty source · line 128 · raw

Tape

def at_head source · line 132 · raw

@+count:Nat -> @+id:Nat -> Bool

Whether the head of a newest-first list of count elements has id id.

def entry_listed source · line 139 · raw

@entry:Entry -> @pair:Pair(List<&1, Entry>, List<&2, Node>) -> Pair(List<&1, Entry>, List<&2, Node>)

def listed source · line 145 · raw

@entries:List<&1, Entry> -> Pair(List<&1, Entry>, List<&2, Node>)

The nodes of a list of entries, newest first, next to the entries.

def prepend source · line 152 · raw

@-A:Type -> @head:A -> @result:Result<&2, &1, Error, List<&1, A>> -> Result<&2, &1, Error, List<&1, A>>

def unsets source · line 159 · raw

@count:Nat -> List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot>

def both source · line 168 · raw

@first:Result<&2, &1, Error, Contribution> -> @second:Result<&2, &1, Error, Contribution> -> Result<&2, &1, Error, List<&1, Contribution>>

def delivered_as source · line 178 · raw

@+target:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/reduce.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>)

def reduced source · line 189 · raw

@+target:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>)

A contribution for operand target: g reduced to the operand's shape. g comes back unchanged.

def contribution_of source · line 192 · raw

@pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>) -> Result<&2, &1, Error, Contribution>

def product_reduced source · line 196 · raw

@+target:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic> -> Result<&2, &1, Error, Contribution>

def added_second source · line 204 · raw

@first:Result<&2, &1, Error, Contribution> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>) -> Pass

def added_first source · line 208 · raw

@+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>) -> Pass

def vjp_add source · line 213 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d(a+b)/da and d(a+b)/db: g, each reduced to its operand's shape.

def negated_pair source · line 216 · raw

@pair:Pair(Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic), Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)

def negated source · line 223 · raw

@g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @zero:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Tensor<0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/reduction.scalar_shape>> -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)

-g, word by word: F32.neg flips the sign bit, as PyTorch's neg does.

def negate source · line 231 · raw

@g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)

def subtracted_second source · line 234 · raw

@first:Result<&2, &1, Error, Contribution> -> @+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pass

def subtracted_first source · line 239 · raw

@+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>) -> Pass

def vjp_sub source · line 244 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d(a-b)/da: g; d(a-b)/db: -g, negated before it is reduced, as in PyTorch.

def multiplied_second source · line 247 · raw

@+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @first:Result<&2, &1, Error, Contribution> -> @y:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic), Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pass

def multiplied_first source · line 253 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @x:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic), Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pass

def vjp_mul source · line 261 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @saved:Saved -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d(a*b)/da: g * right; d(a*b)/db: g * left, with the operand values saved at record time, each product reduced to its operand's shape.

def expanded source · line 268 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/broadcast.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pass

def vjp_sum source · line 277 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d(sum a)/da: g broadcast to a's shape, as PyTorch's g.expand(a.shape).

def relabel_decided source · line 280 · raw

@+held:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @tensor:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Tensor<held> -> @decision:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BoolCase<Nat.is_eq(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.elements(held), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.elements(shape))> -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic

def relabeled source · line 290 · raw

@+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @gradient:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic

g with the dimensions of shape, which has as many elements: a reshape, which moves no word. A g with another element count keeps its own.

def restored source · line 295 · raw

@+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @pass:Pass -> Pass

The pass with g back in its own shape.

def unsqueezed source · line 299 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+kept:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @tensor:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Tensor<shape> -> @decision:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BoolCase<Nat.is_eq(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.elements(shape), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.elements(kept))> -> Pass

def vjp_sum_dims source · line 310 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+kept:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d(sum of a over some axes)/da: g read with the kept shape, the reduced axes put back as 1 (PyTorch's unsqueeze when keepdim is False), then broadcast to a's shape, as the Sum VJP does.

def multiplied source · line 314 · raw

@+target:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.Error, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic))> -> Result<&2, &1, Error, Contribution>

def left_product source · line 325 · raw

@+target:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @copy:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/transforms.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>)

g @ right^T for the left operand. g and right are copied first, so a failure loses neither.

def right_product source · line 335 · raw

@+target:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @copy:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/transforms.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>)

left^T @ g for the right operand.

def matmul_fourth source · line 344 · raw

@first:Result<&2, &1, Error, Contribution> -> @y:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>) -> Pass

def matmul_third source · line 349 · raw

@+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @first:Result<&2, &1, Error, Contribution> -> @y:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @x:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic) -> Pass

def matmul_second source · line 354 · raw

@+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @x:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>) -> Pass

def matmul_first source · line 359 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @x:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @y:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic) -> Pass

def vjp_matmul source · line 366 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @saved:Saved -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d(a@b)/da: g @ b^T; d(a@b)/db: a^T @ g, with the operand values saved at record time.

def nt_left source · line 375 · raw

@+target:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @copy:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic) -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>)

g @ W for the left operand of x @ W^T: g and W are copied first, so a failure loses neither.

def weight_product source · line 383 · raw

@copy:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @flipped:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.Error, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic))>

g^T @ x, g read in place. It has its own name so that the proofs of where the contribution goes name it without restating the product; the value laws read what it computes.

def nt_right source · line 387 · raw

@+target:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @copy:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic) -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>)

g^T @ x for the right operand.

def nt_fourth source · line 392 · raw

@first:Result<&2, &1, Error, Contribution> -> @y:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>) -> Pass

def nt_third source · line 397 · raw

@+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @first:Result<&2, &1, Error, Contribution> -> @y:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @x:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic) -> Pass

def nt_second source · line 402 · raw

@+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @x:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>) -> Pass

def nt_first source · line 407 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @x:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @y:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic) -> Pass

def alone source · line 412 · raw

@result:Result<&2, &1, Error, Contribution> -> Result<&2, &1, Error, List<&1, Contribution>>

def nt_alone_second source · line 419 · raw

@y:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>) -> Pass

def nt_alone_first source · line 423 · raw

@+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @x:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @y:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic) -> Pass

def vjp_matmul_nt_right source · line 430 · raw

@+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @saved:Saved -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d(x @ W^T)/dW alone, g^T @ x, for a product whose input x takes no gradient: the second contribution of vjp_matmul_nt, computed the same way, without g @ W.

def vjp_matmul_nt source · line 441 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @saved:Saved -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d(x @ W^T)/dx: g @ W; d(x @ W^T)/dW: g^T @ x, with the operand values saved at record time. Neither product builds a transpose: g @ W is matmul, and g^T @ x is matmul_tn, which reads g in place. Each product already has its operand's shape.

def relu_passed source · line 448 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @zero:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic), Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pass

def vjp_relu source · line 457 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @saved:Saved -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d relu(a)/da: the pointwise ReluBackward of the saved input x and g, g's own word where x is above zero or NaN and +0.0 where x is at most zero, reduced to the input's shape.

def mse_second source · line 464 · raw

@+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @first:Result<&2, &1, Error, Contribution> -> @d:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic), Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pass

def mse_first source · line 470 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+scale:F32 -> @e:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic), Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pass

def mse_shaped source · line 476 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @e:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape) -> Pass

def vjp_mse source · line 486 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @saved:Saved -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d mse_loss(a, b)/da: (2 / N * d) * g, and d/db: (2 / N * e) * g, PyTorch's mse_loss_backward, with the differences e = right - left and d = left - right saved at record time over the broadcast shape of N cells; each is reduced to its operand's shape. The steps are the Mul VJP's, with MseGrad for Mul.

def entropy_second source · line 493 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @first:Result<&2, &1, Error, Contribution> -> @onehot:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic), Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pass

def entropy_first source · line 499 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+count:F32 -> @+single:Bool -> @lp:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic), Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pass

def vjp_cross_entropy source · line 514 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @saved:Saved -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d cross_entropy(a)/da, as two contributions to a that its slot adds in order. The first is PyTorch's nll_loss backward, OneHotGrad of g and the saved one-hot rows: -(g / N) at each row's target and +0.0 elsewhere, for the N rows. The second is the rest of PyTorch's log_softmax backward, SoftmaxGrad of g and the saved lp: -(exp(lp) * r) with r the row sum of the first, -(g / N) + 0.0, or -(g / N) itself when the logits have one column (PyTorch's sum of one word keeps -0.0). Added into an empty slot, first + second is PyTorch's first - exp(lp) * r word for word. The steps are the Mul VJP's, with OneHotGrad and SoftmaxGrad for Mul and both contributions to a.

def kept_one source · line 522 · raw

@+target:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @gradient:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @mine:Bool -> @rest:List<&1, Contribution> -> List<&1, Contribution>

def kept_others source · line 531 · raw

@+id:Nat -> @items:List<&1, Contribution> -> List<&1, Contribution>

The contributions to every node but id, in order.

def without source · line 538 · raw

@+id:Nat -> @contributions:Result<&2, &1, Error, List<&1, Contribution>> -> Result<&2, &1, Error, List<&1, Contribution>>

def unsent source · line 546 · raw

@+id:Nat -> @pass:Pass -> Pass

A VJP's pass without its contributions to id.

def skips source · line 552 · raw

@+id:Nat -> @node:Node -> Bool

Whether the VJP of Frozen{id, node} skips a product instead of dropping it: node is x @ W^T and id is x and not W.

def nt_frozen source · line 559 · raw

@+id:Nat -> @+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @saved:Saved -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @skip:Bool -> Pass

def batched_reduced source · line 569 · raw

@+target:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic))> -> Result<&2, &1, Error, Contribution>

A contribution for operand target from a product over the output's batch: the product reduced to the operand's shape, as a broadcast operand of an elementwise operation is.

def batched_fourth source · line 578 · raw

@first:Result<&2, &1, Error, Contribution> -> @y:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>) -> Pass

def batched_right source · line 585 · raw

@+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/batched_matmul.Plan -> @copy:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic) -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>)

left^T @ g for the right operand, from copies of g and of the saved left operand.

def batched_third source · line 590 · raw

@+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/batched_matmul.Plan -> @first:Result<&2, &1, Error, Contribution> -> @y:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @x:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic) -> Pass

def batched_second source · line 595 · raw

@+b:Nat -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/batched_matmul.Plan -> @x:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>) -> Pass

def batched_left source · line 602 · raw

@+a:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/batched_matmul.Plan -> @copy:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic) -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, Error, Contribution>)

g @ right^T for the left operand, from copies of g and of the saved right operand, so a failure loses neither.

def batched_first source · line 607 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/batched_matmul.Plan -> @x:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @y:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic) -> Pass

def batched_planned source · line 612 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @x:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @y:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @result:Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/batched_matmul.Plan> -> Pass

def vjp_batched source · line 626 · raw

@+a:Nat -> @+b:Nat -> @+left:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @saved:Saved -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d(a@b)/da and d(a@b)/db of torch.matmul: g @ b^T and a^T @ g over the output's batch (Batched.left_gradient and Batched.right_gradient), each then summed to its operand's shape with sum_to_size, which sums the batch dimensions the operand was broadcast along and keeps a product that already has the operand's shape. A 1-D operand's product already drops its row or column.

def scatter_sent source · line 633 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pass

def slice_unsqueezed source · line 641 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+kept:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Plan -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @tensor:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Tensor<shape> -> @decision:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.BoolCase<Nat.is_eq(0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.elements(shape), 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.elements(kept))> -> Pass

def vjp_slice source · line 654 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+kept:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Plan -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d(a slice of a)/da: g read with the kept shape, the slice's output with the axis kept (PyTorch's unsqueeze for select), then scattered into +0.0 words of a's shape (PyTorch's slice_backward): each input cell the slice read gets the gradient word of the output cell it went to.

def gather_sent source · line 658 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pass

def vjp_gather source · line 670 · raw

@+a:Nat -> @+input:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+plan:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Plan -> @+entries:List<&2, U32> -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

d(an index_select or a gather of a)/da: g, of the output's shape, added into +0.0 words of a's shape at the entries (PyTorch's index_add and scatter_add): each input cell gets the sum of the gradient words of the output cells that read it, in output order.

def vjp source · line 677 · raw

@node:Node -> @saved:Saved -> @g:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pass

The vector-Jacobian product of one node with gradient g: the contribution each operand receives, in operand order, already reduced to its shape. A constant sends nothing, and Frozen{id, node} sends node's contributions without the ones to id.

def placed source · line 718 · raw

@rest:List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot> -> @outcome:0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Outcome -> Result<&2, &1, Error, List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot>>

def bump source · line 728 · raw

@slots:List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot> -> @+count:Nat -> @+target:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @gradient:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @same:Bool -> Result<&2, &1, Error, List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot>>

Accumulates a contribution into the slot of node target, in a newest-first list of count slots; same says whether the head is that node. A target the list does not hold changes nothing.

def deliver source · line 740 · raw

@contributions:List<&1, Contribution> -> @+count:Nat -> @state:Result<&2, &1, Error, List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot>> -> Result<&2, &1, Error, List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot>>

def sent source · line 750 · raw

@contributions:Result<&2, &1, Error, List<&1, Contribution>> -> @+count:Nat -> @slots:List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot> -> Result<&2, &1, Error, List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot>>

def Swept source · line 760 · raw

Type

def finished source · line 763 · raw

@entry:Entry -> @slot:0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot -> @pair:Swept -> Swept

def passed source · line 767 · raw

@node:Node -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @value:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @slot:0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot -> @+below:Nat -> @pending:List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot> -> @rec:(@_:Result<&2, &1, Error, List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot>> -> Swept) -> @pass:Pass -> Swept

def visited source · line 772 · raw

@+node:Node -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @value:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @saved:Saved -> @slot:0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot -> @gradient:0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot -> @+below:Nat -> @pending:List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot> -> @rec:(@_:Result<&2, &1, Error, List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot>> -> Swept) -> Swept

def sweep source · line 782 · raw

@entries:List<&1, Entry> -> @state:Result<&2, &1, Error, List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot>> -> @+count:Nat -> Swept

Visits entries newest first with their working gradients. Once a step fails, the remaining entries pass through unchanged.

def seeded source · line 795 · raw

@node:Node -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @value:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @saved:Saved -> @slot:0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot -> @rest:List<&1, Entry> -> @+below:Nat -> @ones:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Tensor<shape>> -> Swept

def seeded_entry source · line 805 · raw

@entry:Entry -> @rest:List<&1, Entry> -> @+below:Nat -> Swept

The seed: ones of the output's shape.

def pass source · line 812 · raw

@entries:List<&1, Entry> -> @+count:Nat -> @+output:Nat -> @selected:Bool -> Swept

The working gradient of every entry, newest first: Unset for the entries newer than output and for every entry output does not reach, ones of the output's shape at output, and the sweep's totals below it.

def operands_below source · line 823 · raw

@node:Node -> @+bound:Nat -> Bool

def wired source · line 858 · raw

@nodes:List<&2, Node> -> @+count:Nat -> Bool

def merged_entry source · line 869 · raw

@node:Node -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @value:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @saved:Saved -> @outcome:0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Outcome -> @pair:Pair(List<&1, Entry>, Result<&2, &2, Error, Unit>) -> Pair(List<&1, Entry>, Result<&2, &2, Error, Unit>)

Accumulates each working gradient into its entry's slot. A refusal keeps the slot and is reported after the walk.

def merge source · line 879 · raw

@entries:List<&1, Entry> -> @gradients:List<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot> -> Pair(List<&1, Entry>, Result<&2, &2, Error, Unit>)

def merged_tape source · line 890 · raw

@pair:Pair(List<&1, Entry>, Result<&2, &2, Error, Unit>) -> Pair(Tape, Result<&2, &2, Error, Unit>)

def ran source · line 894 · raw

@pair:Swept -> Pair(Tape, Result<&2, &2, Error, Unit>)

def checked source · line 902 · raw

@entries:List<&1, Entry> -> @+count:Nat -> @+output:Nat -> @known:Bool -> @sound:Bool -> Pair(Tape, Result<&2, &2, Error, Unit>)

def planned source · line 911 · raw

@+output:Nat -> @pair:Pair(List<&1, Entry>, List<&2, Node>) -> Pair(Tape, Result<&2, &2, Error, Unit>)

def backward source · line 920 · raw

@tape:Tape -> @+output:Nat -> Pair(Tape, Result<&2, &2, Error, Unit>)

Runs one backward of output and accumulates its gradients into the slots. An output the tape does not hold is refused with UnknownNode; a tape with a node that refers to itself or to a newer or missing node is refused with DanglingOperand. Both refusals leave the tape unchanged.

def cleared source · line 924 · raw

@entries:List<&1, Entry> -> List<&1, Entry>

def zero_grad source · line 932 · raw

@tape:Tape -> Tape

Empties every gradient slot, like PyTorch's zero_grad(set_to_none=True).

def Found source · line 938 · raw

Type

def cloned_value source · line 941 · raw

@node:Node -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @saved:Saved -> @slot:0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot -> @rest:List<&1, Entry> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic) -> Found

def found_value source · line 946 · raw

@entry:Entry -> @rest:List<&1, Entry> -> Found

def prepend_found source · line 950 · raw

@entry:Entry -> @pair:Found -> Found

def value_at source · line 955 · raw

@entries:List<&1, Entry> -> @+count:Nat -> @+id:Nat -> @same:Bool -> Found

A copy of the value of node id, in a newest-first list of count entries.

def counted_entry source · line 966 · raw

@entry:Entry -> @pair:Pair(List<&1, Entry>, Nat) -> Pair(List<&1, Entry>, Nat)

def counted source · line 971 · raw

@entries:List<&1, Entry> -> Pair(List<&1, Entry>, Nat)

The number of entries, next to the entries.

def value_counted source · line 978 · raw

@+id:Nat -> @pair:Pair(List<&1, Entry>, Nat) -> Found

def found_tape source · line 982 · raw

@pair:Found -> Pair(Tape, Result<&2, &1, Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)

def value source · line 987 · raw

@tape:Tape -> @+id:Nat -> Pair(Tape, Result<&2, &1, Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)

A copy of the forward value of node id.

def Graded source · line 991 · raw

Type

def held_copy source · line 994 · raw

@pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic) -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot, Maybe<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)

def copied_grad source · line 998 · raw

@read:Maybe<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic> -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot, Maybe<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)

def graded_entry source · line 1005 · raw

@node:Node -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @value:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @saved:Saved -> @rest:List<&1, Entry> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/gradient.Slot, Maybe<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Graded

def found_grad source · line 1010 · raw

@entry:Entry -> @rest:List<&1, Entry> -> Graded

def prepend_graded source · line 1014 · raw

@entry:Entry -> @pair:Graded -> Graded

def grad_at source · line 1018 · raw

@entries:List<&1, Entry> -> @+count:Nat -> @+id:Nat -> @same:Bool -> Graded

def grad_counted source · line 1029 · raw

@+id:Nat -> @pair:Pair(List<&1, Entry>, Nat) -> Graded

def graded_tape source · line 1033 · raw

@pair:Graded -> Pair(Tape, Result<&2, &1, Error, Maybe<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>>)

def grad source · line 1038 · raw

@tape:Tape -> @+id:Nat -> Pair(Tape, Result<&2, &1, Error, Maybe<&1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>>)

A copy of the gradient slot of node id: None until a backward reaches it.

def pushed source · line 1044 · raw

@node:Node -> @value:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @saved:Saved -> @pair:Pair(List<&1, Entry>, Nat) -> Pair(Tape, Nat)

def done_id source · line 1049 · raw

@pair:Pair(Tape, Nat) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def is_constant source · line 1053 · raw

@node:Node -> Bool

def constant_at source · line 1061 · raw

@nodes:List<&2, Node> -> @+count:Nat -> @+id:Nat -> @same:Bool -> Bool

Whether node id of a newest-first list of count nodes is a constant.

def operand_ids source · line 1073 · raw

@node:Node -> List<&2, Nat>

The operand ids of a node, in operand order.

def frozen_if source · line 1108 · raw

@+id:Nat -> @node:Node -> @constant:Bool -> Node

def freeze source · line 1117 · raw

@ids:List<&2, Nat> -> @+nodes:List<&2, Node> -> @+count:Nat -> @node:Node -> Node

node wrapped in Frozen{id, .} for each operand id that is a constant of the newest-first list of count nodes, the first operand outermost.

def all_constant source · line 1126 · raw

@ids:List<&2, Nat> -> @+nodes:List<&2, Node> -> @+count:Nat -> Bool

Whether every id of a list is a constant of the newest-first list of count nodes.

def settled source · line 1136 · raw

@+node:Node -> @+ids:List<&2, Nat> -> @+nodes:List<&2, Node> -> @+count:Nat -> @constant:Bool -> Node

A node whose operands are all constants is a constant itself, as in PyTorch an operation on tensors that do not require grad gives one that does not; any other node is frozen at each operand that is a constant.

def marked source · line 1143 · raw

@+node:Node -> @value:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @saved:Saved -> @pair:Pair(List<&1, Entry>, List<&2, Node>) -> Pair(Tape, Nat)

def push source · line 1152 · raw

@node:Node -> @value:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @saved:Saved -> @entries:List<&1, Entry> -> Pair(Tape, Result<&2, &2, Error, Nat>)

The new entry's id is the number of entries before it. A recording has at least one operand; when they are all constants it records a constant, and otherwise each operand that is a constant freezes the node.

def leaf source · line 1156 · raw

@tape:Tape -> @value:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pair(Tape, Nat)

Records a leaf.

def constant source · line 1164 · raw

@tape:Tape -> @value:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pair(Tape, Nat)

Records a constant: a leaf that takes no gradient, PyTorch's tensor with requires_grad=False. No VJP sends it a contribution, so its slot reads None after any backward that does not start at it; Sgd.step takes it as a leaf and keeps it.

def recorded source · line 1168 · raw

@node:Node -> @saved:Saved -> @entries:List<&1, Entry> -> @result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic> -> Pair(Tape, Result<&2, &2, Error, Nat>)

def multiplied_record source · line 1176 · raw

@node:Node -> @entries:List<&1, Entry> -> @result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/matmul.Error, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic))> -> Pair(Tape, Result<&2, &2, Error, Nat>)

def dropped source · line 1185 · raw

@node:Node -> @entries:List<&1, Entry> -> @pair:Pair(Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic), Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def kept source · line 1190 · raw

@node:Node -> @entries:List<&1, Entry> -> @pair:Pair(Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic), Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def loss_recorded source · line 1196 · raw

@node:Node -> @entries:List<&1, Entry> -> @result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/loss.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/loss.Recorded> -> Pair(Tape, Result<&2, &2, Error, Nat>)

def loss_dropped source · line 1204 · raw

@node:Node -> @entries:List<&1, Entry> -> @pair:Pair(Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic), Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/loss.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/loss.Recorded>) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def loss_kept source · line 1209 · raw

@node:Node -> @entries:List<&1, Entry> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/loss.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/loss.Recorded>) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def batched_record source · line 1216 · raw

@+a:Nat -> @+b:Nat -> @+left_shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right_shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @entries:List<&1, Entry> -> @left:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @right:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @matrices:Bool -> Pair(Tape, Result<&2, &2, Error, Nat>)

torch.matmul on the tape: two rank-2 operands record Matmul, the product matmul records, and every other pair records BatchedMatmul.

def operated source · line 1224 · raw

@kind:Binary -> @+a:Nat -> @+b:Nat -> @+left_shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+right_shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @entries:List<&1, Entry> -> @left:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @right:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> Pair(Tape, Result<&2, &2, Error, Nat>)

def computed source · line 1243 · raw

@kind:Binary -> @+a:Nat -> @+b:Nat -> @entries:List<&1, Entry> -> @left:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape) -> @right:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def right_found source · line 1249 · raw

@kind:Binary -> @+a:Nat -> @+b:Nat -> @left:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @pair:Found -> Pair(Tape, Result<&2, &2, Error, Nat>)

def left_found source · line 1257 · raw

@kind:Binary -> @+a:Nat -> @+b:Nat -> @pair:Found -> Pair(Tape, Result<&2, &2, Error, Nat>)

def binary source · line 1269 · raw

@tape:Tape -> @kind:Binary -> @+a:Nat -> @+b:Nat -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records a op b from copies of the operands' values. An operand id the tape does not hold is refused with UnknownNode, and an operation the tensor layer refuses (shapes that do not broadcast, or a matmul of the wrong ranks or inner dimensions) with its error; the tape comes back unchanged.

def add source · line 1273 · raw

@tape:Tape -> @+a:Nat -> @+b:Nat -> Pair(Tape, Result<&2, &2, Error, Nat>)

def sub source · line 1276 · raw

@tape:Tape -> @+a:Nat -> @+b:Nat -> Pair(Tape, Result<&2, &2, Error, Nat>)

def mul source · line 1279 · raw

@tape:Tape -> @+a:Nat -> @+b:Nat -> Pair(Tape, Result<&2, &2, Error, Nat>)

def matmul source · line 1282 · raw

@tape:Tape -> @+a:Nat -> @+b:Nat -> Pair(Tape, Result<&2, &2, Error, Nat>)

def batched_matmul source · line 1290 · raw

@tape:Tape -> @+a:Nat -> @+b:Nat -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records torch.matmul(a, b): batched products and 1-D promotion (Batched.matmul). Two rank-2 operands record exactly what matmul records. A rank-0 operand is refused with RankMismatch (105), unequal inner extents with InnerDimensionMismatch (106), batch dimensions that do not broadcast with IncompatibleBroadcast (6); the tape comes back unchanged.

def matmul_nt source · line 1295 · raw

@tape:Tape -> @+a:Nat -> @+b:Nat -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records a @ b^T, with b read in place: PyTorch's linear(a, b) without a bias.

def popped source · line 1299 · raw

@tape:Tape -> Tape

The tape without its newest entry.

def unrecorded source · line 1309 · raw

@pair:Pair(Tape, Result<&2, &2, Error, Nat>) -> Pair(Tape, Result<&2, &2, Error, Nat>)

A refused sum drops the product, the newest entry, so the tape comes back as it was before the product was recorded.

def biased source · line 1317 · raw

@+bias:Nat -> @pair:Pair(Tape, Result<&2, &2, Error, Nat>) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def linear_checked source · line 1325 · raw

@+x:Nat -> @+w:Nat -> @+bias:Nat -> @entries:List<&1, Entry> -> @known:Bool -> Pair(Tape, Result<&2, &2, Error, Nat>)

def linear_counted source · line 1332 · raw

@+x:Nat -> @+w:Nat -> @+bias:Nat -> @pair:Pair(List<&1, Entry>, Nat) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def linear source · line 1343 · raw

@tape:Tape -> @+x:Nat -> @+w:Nat -> @+bias:Nat -> Pair(Tape, Result<&2, &2, Error, Nat>)

Linear: records x @ W^T with W of [out, in], PyTorch's layout, then adds the bias b of [out] to every row. The id is the sum's; the product is the entry before it. The bias id is checked against the tape the call receives, before the product is recorded, so the product's own id never stands in for a missing bias. A refusal of any step (an unknown id, a product or a sum the tensor layer refuses) comes back with its error and the tape as it was.

def summed source · line 1347 · raw

@+a:Nat -> @entries:List<&1, Entry> -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic)> -> Pair(Tape, Result<&2, &2, Error, Nat>)

def sum_shaped source · line 1356 · raw

@+a:Nat -> @entries:List<&1, Entry> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def sum_found source · line 1360 · raw

@+a:Nat -> @pair:Found -> Pair(Tape, Result<&2, &2, Error, Nat>)

def sum source · line 1369 · raw

@tape:Tape -> @+a:Nat -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records the sum of every element of a, a rank-0 tensor.

def dims_error source · line 1373 · raw

@error:0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/sum_dims.Error -> Error

def dims_summed source · line 1380 · raw

@node:Node -> @entries:List<&1, Entry> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/sum_dims.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def dims_planned source · line 1389 · raw

@+a:Nat -> @entries:List<&1, Entry> -> @input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @keepdim:Bool -> @planned:Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/sum_dims.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/autograd/sum_dims.Plan> -> Pair(Tape, Result<&2, &2, Error, Nat>)

def dims_shaped source · line 1399 · raw

@+a:Nat -> @+axes:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position> -> @keepdim:Bool -> @entries:List<&1, Entry> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape) -> Pair(Tape, Result<&2, &2, Error, Nat>)

The signed axes, each wrapped among the operand's axes (its rank, or 1 at rank 0), as PyTorch wraps them, before the plan checks them.

def dims_found source · line 1404 · raw

@+a:Nat -> @+axes:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position> -> @keepdim:Bool -> @pair:Found -> Pair(Tape, Result<&2, &2, Error, Nat>)

def sum_dims source · line 1419 · raw

@tape:Tape -> @+a:Nat -> @+axes:List<&2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position> -> @keepdim:Bool -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records PyTorch's a.sum(dim=axes, keepdim=keepdim), SumDims.sum_dims of a copy of a's value: the kept shape when keepdim is True, else the dropped one. The axes are PyTorch's signed ones: Last{0} is -1, a's last axis. An empty axis list sums every axis. An axis outside -limit..limit-1, where limit is max(rank, 1), so a rank-0 a takes -1 and 0, is refused with AxisOutOfBounds (13), two axes that name one axis with DuplicateAxis (14), an unknown id with UnknownNode; the tape comes back unchanged.

def slice_kept source · line 1423 · raw

@node:Node -> @entries:List<&1, Entry> -> @result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic> -> Pair(Tape, Result<&2, &2, Error, Nat>)

def slice_planned source · line 1431 · raw

@+a:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @entries:List<&1, Entry> -> @result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic> -> @planned:Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Planned> -> Pair(Tape, Result<&2, &2, Error, Nat>)

def slice_taken source · line 1439 · raw

@+a:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @entries:List<&1, Entry> -> @planned:Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Planned> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def slice_extent source · line 1452 · raw

@+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+axis:U32 -> U32

def slice_axis_plan source · line 1455 · raw

@+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+axis:U32 -> @+slicing:Slicing -> Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Planned>

def slice_dim source · line 1466 · raw

@+slicing:Slicing -> 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position

def slice_plan source · line 1479 · raw

@+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+slicing:Slicing -> Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Planned>

The slice each one records: its plan, at the axis and positions the value takes (Signed.slice, narrow and select), and the value it computes. The value is checked first, so a narrow whose start lies before -extent, which only the value refuses, records nothing.

def slice_value source · line 1482 · raw

@input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @+slicing:Slicing -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/slice.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)

def slice_shaped source · line 1491 · raw

@+a:Nat -> @+slicing:Slicing -> @entries:List<&1, Entry> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def slice_found source · line 1495 · raw

@+a:Nat -> @+slicing:Slicing -> @pair:Found -> Pair(Tape, Result<&2, &2, Error, Nat>)

def sliced source · line 1510 · raw

@tape:Tape -> @+a:Nat -> @+slicing:Slicing -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records a slice of a copy of a's value (Signed.slice, narrow or select) as a Slice node with a's shape, the slice's shape with the axis kept and its plan. The value is checked first, so a refusal is the value's: an axis outside -rank..rank-1 is AxisOutOfBounds (13), a step of 0 StepNotPositive (19), a narrow past the extent or with a start before -extent, or a select index outside -extent..extent-1, OutOfRange (20), an unknown id UnknownNode; the tape comes back unchanged.

def slice source · line 1515 · raw

@tape:Tape -> @+a:Nat -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+start:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+stop:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+step:U32 -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records a[..., start:stop:step, ...] with the slice at axis dim.

def narrow source · line 1520 · raw

@tape:Tape -> @+a:Nat -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+start:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+length:U32 -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records a.narrow(dim, start, length).

def select source · line 1524 · raw

@tape:Tape -> @+a:Nat -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+index:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records a.select(dim, index), which drops the axis.

def gather_kept source · line 1527 · raw

@node:Node -> @entries:List<&1, Entry> -> @result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic> -> Pair(Tape, Result<&2, &2, Error, Nat>)

def indexing_plan source · line 1541 · raw

@+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+indexing:Indexing -> Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned>

def indexing_value source · line 1548 · raw

@input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @+indexing:Indexing -> Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>)

def indexing_entries source · line 1555 · raw

@+indexing:Indexing -> List<&2, U32>

def gather_planned source · line 1562 · raw

@+a:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+indexing:Indexing -> @entries:List<&1, Entry> -> @result:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic> -> @planned:Result<&2, &2, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Planned> -> Pair(Tape, Result<&2, &2, Error, Nat>)

def gather_taken source · line 1571 · raw

@+a:Nat -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @+indexing:Indexing -> @entries:List<&1, Entry> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic>) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def gather_shaped source · line 1576 · raw

@+a:Nat -> @+indexing:Indexing -> @entries:List<&1, Entry> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def gather_found source · line 1581 · raw

@+a:Nat -> @+indexing:Indexing -> @pair:Found -> Pair(Tape, Result<&2, &2, Error, Nat>)

def indexed source · line 1597 · raw

@tape:Tape -> @+a:Nat -> @+indexing:Indexing -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records an index_select or a gather of a copy of a's value as a Gathered node with a's shape, the plan and the entries. The value is checked first, so a refusal is the value's: an axis outside -rank..rank-1 is AxisOutOfBounds (13), an entry at or past the extent OutOfRange (20), a gather index of another rank IndexRankMismatch (21), with another extent at another axis IndexShapeMismatch (22), whose entry count is not the product of its dimensions ValueCountMismatch (10), an unknown id UnknownNode; the tape comes back unchanged.

def index_select source · line 1602 · raw

@tape:Tape -> @+a:Nat -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+entries:List<&2, U32> -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records a.index_select(dim, index).

def gather source · line 1606 · raw

@tape:Tape -> @+a:Nat -> @+dim:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/signed.Position -> @+index:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/gather.Index -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records a.gather(dim, index).

def relu_zeroed source · line 1609 · raw

@+a:Nat -> @entries:List<&1, Entry> -> @+shape:0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape -> @input:0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic -> @zero:Result<&2, &1, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Error, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Tensor<0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/reduction.scalar_shape>> -> Pair(Tape, Result<&2, &2, Error, Nat>)

def relu_shaped source · line 1618 · raw

@+a:Nat -> @entries:List<&1, Entry> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def relu_found source · line 1622 · raw

@+a:Nat -> @pair:Found -> Pair(Tape, Result<&2, &2, Error, Nat>)

def relu source · line 1633 · raw

@tape:Tape -> @+a:Nat -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records relu(a), PyTorch's relu, of a's shape: the pointwise product of a copy of a's value with ReluLeft against a rank-0 +0.0, on the parallel elementwise build. The copy is saved for the VJP.

def mse_loss source · line 1642 · raw

@tape:Tape -> @+a:Nat -> @+b:Nat -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records mse_loss(a, b), PyTorch's mse_loss(input, target) with mean reduction, a rank-0 tensor, from copies of the operands' values. The differences a - b and b - a, over the shapes' broadcast, are saved for the VJP. Shapes that do not broadcast are refused with IncompatibleBroadcast (6); an unknown id with UnknownNode; the tape comes back unchanged.

def entropy_shaped source · line 1645 · raw

@+a:Nat -> @+targets:List<&2, U32> -> @entries:List<&1, Entry> -> @pair:Pair(0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/core.Dynamic, 0x1689e5deb278c16abd3bd45eac101ef3/src/shape/core.Shape) -> Pair(Tape, Result<&2, &2, Error, Nat>)

def entropy_found source · line 1650 · raw

@+a:Nat -> @+targets:List<&2, U32> -> @pair:Found -> Pair(Tape, Result<&2, &2, Error, Nat>)

def cross_entropy source · line 1665 · raw

@tape:Tape -> @+a:Nat -> @+targets:List<&2, U32> -> Pair(Tape, Result<&2, &2, Error, Nat>)

Records cross_entropy(a, targets), PyTorch's cross_entropy with class indices and mean reduction, a rank-0 tensor, from a copy of a's value: a must be [rows, columns] logits and targets one class below columns per row. The log_softmax lp and the one-hot rows of the targets are saved for the VJP. Logits of another rank are refused with NotLogits (107), targets that do not fit with TargetOutOfRange (108), an unknown id with UnknownNode; the tape comes back unchanged.

def error_code source · line 1669 · raw

@error:Error -> U32