Documentation
¶
Overview ¶
Package nn runs neural networks published as PyTorch checkpoints: their weights read from the .pth file as it is, and the layers they are made of (linear, convolutions, attention, normalisations, resizing) on float32 tensors, laid out as PyTorch lays them out (row major, the last dimension fastest).
Index ¶
- Constants
- func EyesSize(w, h int) int
- func LoadPTH(file string) (map[string]*Tensor, error)
- func Numel(shape []int) int
- func Parallel(n int, f func(i int))
- func TemporalAttentionBackward(q, peQ, peK, peV *Tensor, ks, vs []*Tensor, heads int, scale float32, ...) (dq, dpeQ, dpeK, dpeV *Tensor, dks, dvs []*Tensor)
- type Backend
- type GPU
- func (g *GPU) Add(a, b *Tensor) *Tensor
- func (g *GPU) AddScaled(x, y, s *Tensor) *Tensor
- func (g *GPU) AddScaledBackward(y, s, dy *Tensor) (dyIn, ds *Tensor)
- func (g *GPU) Attention(q, k, v *Tensor, heads int, scale float32) *Tensor
- func (g *GPU) AttentionBackward(q, k, v *Tensor, heads int, scale float32, dy *Tensor) (dq, dk, dv *Tensor)
- func (g *GPU) Bilinear(x *Tensor, oh, ow int) *Tensor
- func (g *GPU) BilinearBackward(dy *Tensor, h, w int) *Tensor
- func (g *GPU) Clone(x *Tensor) *Tensor
- func (g *GPU) Close()
- func (g *GPU) Conv2d(x, w, b *Tensor, stride, pad int) *Tensor
- func (g *GPU) Conv2dBackward(x, w, dy *Tensor, stride, pad int) (dx, dw, db *Tensor)
- func (g *GPU) ConvTranspose2dK(x, w, b *Tensor) *Tensor
- func (g *GPU) ConvTranspose2dKBackward(x, w, dy *Tensor) (dx, dw, db *Tensor)
- func (g *GPU) Disparity(up *Tensor, w, h, top, bottom int, ...) *Tensor
- func (g *GPU) Download(t *Tensor) (*Tensor, error)
- func (g *GPU) DownloadBytes(dst []byte, t *Tensor) error
- func (g *GPU) DownloadPlanes(dst []byte, p *Planes) error
- func (g *GPU) Eyes(p *Picture, d *Tensor, gap float32) *Tensor
- func (g *GPU) EyesMask(p *Picture, d *Tensor, gap float32, withMask bool) (eyes, mask *Tensor)
- func (g *GPU) Free(t *Tensor)
- func (g *GPU) GEGLU(x *Tensor) *Tensor
- func (g *GPU) GEGLUBackward(x, dy *Tensor) *Tensor
- func (g *GPU) GELU(x *Tensor) *Tensor
- func (g *GPU) GELUBackward(x, dy *Tensor) *Tensor
- func (g *GPU) GroupNorm(x *Tensor, groups int, w, b *Tensor, eps float32) *Tensor
- func (g *GPU) GroupNormBackward(x *Tensor, groups int, w, dy *Tensor, eps float32) (dx, dw, db *Tensor)
- func (g *GPU) InpaintApply(eyes, mask *Tensor, eye, w, h, top, bottom int, d *Tensor)
- func (g *GPU) InpaintInput(eyes, mask *Tensor, eye, w, h, top, bottom int) *Tensor
- func (g *GPU) Keep(t *Tensor)
- func (g *GPU) LayerNorm(x, w, b *Tensor, eps float32) *Tensor
- func (g *GPU) LayerNormBackward(x, w, dy *Tensor, eps float32) (dx, dw, db *Tensor)
- func (g *GPU) Linear(x, w, b *Tensor) *Tensor
- func (g *GPU) LinearBackward(x, w, dy *Tensor) (dx, dw, db *Tensor)
- func (g *GPU) MatchBoth(l, r *Picture, tex float64) (dl, dr []float32, vl, vr []byte, err error)
- func (g *GPU) Moments(x *Tensor, rows, cols, stride int) *Tensor
- func (g *GPU) Name() string
- func (g *GPU) NetInput(p *Picture, top, ah, nw, nh int) *Tensor
- func (g *GPU) ReLU(x *Tensor) *Tensor
- func (g *GPU) ReLUBackward(y, dy *Tensor) *Tensor
- func (g *GPU) RefineInput(p *Picture, top int, d, mom *Tensor, w, h, pw, ph int) *Tensor
- func (g *GPU) Release()
- func (g *GPU) Renorm(out *Tensor, w, h, pw int, want, got *Tensor) *Tensor
- func (g *GPU) Rows(x *Tensor, from int) *Tensor
- func (g *GPU) Samples(d *Tensor, w, h, top, bottom, edge int) *Tensor
- func (g *GPU) Scale(p *Planes, ow, oh int, lx, ly, cx, cy *Taps) *Planes
- func (g *GPU) Split3(x *Tensor) (*Tensor, *Tensor, *Tensor)
- func (g *GPU) TemporalAttention(q, peQ, peK, peV *Tensor, ks, vs []*Tensor, heads int, scale float32) *Tensor
- func (g *GPU) TemporalAttentionBackward(q, peQ, peK, peV *Tensor, ks, vs []*Tensor, heads int, scale float32, ...) (dq, dpeQ, dpeK, dpeV *Tensor, dks, dvs []*Tensor)
- func (g *GPU) Tokens(patches, cls, pos *Tensor) *Tensor
- func (g *GPU) ToneMap(p *Planes, luts []float32, scale float32, full, hlg bool) *Planes
- func (g *GPU) Transpose(x *Tensor) *Tensor
- func (g *GPU) Upload(t *Tensor) *Tensor
- func (g *GPU) UploadPicture(y, cb, cr []byte, w, h, strideY, strideC int) *Picture
- func (g *GPU) UploadPlanes(y, uv []byte, w, h, pitch, depth int) *Planes
- func (g *GPU) UploadTaps(first []int, w []int32, n int) *Taps
- func (g *GPU) Zeros(shape ...int) *Tensor
- type Picture
- type Planes
- type Tape
- func (tp *Tape) Add(a, b *Tensor) *Tensor
- func (tp *Tape) AddScaled(x, y, s *Tensor) *Tensor
- func (tp *Tape) Attention(q, k, v *Tensor, heads int, scale float32) *Tensor
- func (tp *Tape) Backward(out, dy *Tensor)
- func (tp *Tape) Bilinear(x *Tensor, oh, ow int) *Tensor
- func (tp *Tape) Clone(x *Tensor) *Tensor
- func (tp *Tape) Conv2d(x, w, b *Tensor, stride, pad int) *Tensor
- func (tp *Tape) ConvTranspose2dK(x, w, b *Tensor) *Tensor
- func (tp *Tape) GEGLU(x *Tensor) *Tensor
- func (tp *Tape) GELU(x *Tensor) *Tensor
- func (tp *Tape) Grad(t *Tensor) *Tensor
- func (tp *Tape) Grads() map[string]*Tensor
- func (tp *Tape) GroupNorm(x *Tensor, groups int, w, b *Tensor, eps float32) *Tensor
- func (tp *Tape) LayerNorm(x, w, b *Tensor, eps float32) *Tensor
- func (tp *Tape) Linear(x, w, b *Tensor) *Tensor
- func (tp *Tape) Param(name string, w *Tensor) *Tensor
- func (tp *Tape) ReLU(x *Tensor) *Tensor
- func (tp *Tape) Rows(x *Tensor, from int) *Tensor
- func (tp *Tape) Split3(x *Tensor) (q, k, v *Tensor)
- func (tp *Tape) TemporalAttention(q, peQ, peK, peV *Tensor, ks, vs []*Tensor, heads int, scale float32) *Tensor
- func (tp *Tape) Tokens(patches, cls, pos *Tensor) *Tensor
- func (tp *Tape) Transpose(x *Tensor) *Tensor
- func (tp *Tape) Watch(t *Tensor) *Tensor
- type Taps
- type Tensor
- func Add(a, b *Tensor) *Tensor
- func AddScaledBackward(y, s, dy *Tensor) (dyIn, ds *Tensor)
- func Attention(q, k, v *Tensor, heads int, scale float32) *Tensor
- func AttentionBackward(q, k, v *Tensor, heads int, scale float32, dy *Tensor) (dq, dk, dv *Tensor)
- func BicubicScale(x *Tensor, sy, sx float64) *Tensor
- func Bilinear(x *Tensor, oh, ow int) *Tensor
- func Conv2d(x, w, b *Tensor, stride, pad int) *Tensor
- func Conv2dBackward(x, w, dy *Tensor, stride, pad int) (dx, dw, db *Tensor)
- func ConvTranspose2dK(x, w, b *Tensor) *Tensor
- func ConvTranspose2dKBackward(x, w, dy *Tensor) (dx, dw, db *Tensor)
- func GEGLUBackward(x, dy *Tensor) *Tensor
- func GELU(x *Tensor) *Tensor
- func GELUBackward(x, dy *Tensor) *Tensor
- func GroupNorm(x *Tensor, groups int, w, b *Tensor, eps float32) *Tensor
- func GroupNormBackward(x *Tensor, groups int, w, dy *Tensor, eps float32) (dx, dw, db *Tensor)
- func LayerNorm(x, w, b *Tensor, eps float32) *Tensor
- func LayerNormBackward(x, w, dy *Tensor, eps float32) (dx, dw, db *Tensor)
- func Linear(x, w, b *Tensor) *Tensor
- func LinearBackward(x, w, dy *Tensor) (dx, dw, db *Tensor)
- func New(shape ...int) *Tensor
- func ReLU(x *Tensor) *Tensor
- func ReLUBackward(y, dy *Tensor) *Tensor
Constants ¶
const SGMDisparities = 64
SGMDisparities is the most a match searches each way (half resolution pixels): stereo's matchRange, which kernels.cu's SGM_R must equal.
Variables ¶
This section is empty.
Functions ¶
func LoadPTH ¶
LoadPTH reads the tensors of a checkpoint's state dict, by name. A checkpoint whose state dict is under a key ("state_dict", "model") gives that one's.
func TemporalAttentionBackward ¶ added in v0.19.0
func TemporalAttentionBackward(q, peQ, peK, peV *Tensor, ks, vs []*Tensor, heads int, scale float32, dy *Tensor) (dq, dpeQ, dpeK, dpeV *Tensor, dks, dvs []*Tensor)
TemporalAttentionBackward is the gradients of the CPU's TemporalAttention(q, peQ, peK, peV, ks, vs, heads, scale) given dy: at q and peQ, at peK and peV, and at every frame's keys and values.
Types ¶
type Backend ¶
type Backend interface {
// Upload is t as the backend's tensor (the CPU's: t itself).
Upload(t *Tensor) *Tensor
// Download is the backend's tensor in memory (waiting for the ops
// before to have run).
Download(t *Tensor) (*Tensor, error)
Linear(x, w, b *Tensor) *Tensor
Conv2d(x, w, b *Tensor, stride, pad int) *Tensor
ConvTranspose2dK(x, w, b *Tensor) *Tensor
LayerNorm(x, w, b *Tensor, eps float32) *Tensor
GroupNorm(x *Tensor, groups int, w, b *Tensor, eps float32) *Tensor
GELU(x *Tensor) *Tensor // in place
ReLU(x *Tensor) *Tensor // in place
Add(a, b *Tensor) *Tensor // in place
Clone(x *Tensor) *Tensor
Attention(q, k, v *Tensor, heads int, scale float32) *Tensor
Bilinear(x *Tensor, oh, ow int) *Tensor
// Tokens is a vision transformer's tokens: a class token cls [D]
// first, then the patches [D, N] (channels first) as rows, plus the
// position embedding pos [1+N, D].
Tokens(patches, cls, pos *Tensor) *Tensor
// Split3 splits [N, 3D] rows into their three [N, D] thirds.
Split3(x *Tensor) (q, k, v *Tensor)
// AddScaled adds y times a per-channel g [D] to x [N, D], in place.
AddScaled(x, y, g *Tensor) *Tensor
// Transpose is x [R, C] as [C, R].
Transpose(x *Tensor) *Tensor
// GEGLU is a GEGLU's activation: x [N, 2D]'s first half of each row
// times the GELU of its second ([N, D]).
GEGLU(x *Tensor) *Tensor
// Rows is x's rows from the from-th on ([N-from, D]).
Rows(x *Tensor, from int) *Tensor
// TemporalAttention attends, at each of D positions, from the query
// q [D, C] plus peQ [C] over T frames' keys ks[f] [D, C] plus peK[f]
// and values vs[f] plus peV[f] (peK, peV [T, C]), the C channels in
// heads.
TemporalAttention(q, peQ, peK, peV *Tensor, ks, vs []*Tensor, heads int, scale float32) *Tensor
// Keep keeps a tensor past Release (the GPU's are otherwise reused).
Keep(t *Tensor)
// Free frees a kept tensor.
Free(t *Tensor)
// Release gives back every tensor made since the last Release that is
// not kept: a network's intermediates, once its output is downloaded.
Release()
}
Backend runs the layers somewhere: on the CPU (CPU, the package's functions) or on a GPU (NewGPU). A backend's ops take and give its own tensors: Upload makes one of a tensor in memory, Download the reverse. The ops that say "in place" change their first operand and give it back.
var CPU Backend = cpu{}
CPU is the CPU backend: the package's functions.
type GPU ¶
type GPU struct {
// Half rounds the matrix products' inputs to half precision, for the
// tensor cores (their sums stay single precision).
Half bool
// contains filtered or unexported fields
}
GPU is the CUDA backend: tensors in the GPU's memory, the ops its kernels (kernels.cu). Memory is reused: what an op allocates is given back at Release unless kept, to be handed out again to the next op asking for as many bytes (a network's frames ask for the same each time); what no op asked for again between two Releases is freed (the sizes change with the picture's). An op's failure is kept and reported by the next Download.
func (*GPU) AddScaledBackward ¶ added in v0.19.0
AddScaledBackward is the gradients of AddScaled(x, y, s) = x + y s (s a channel's) given dy: at y and at s (at x it is dy itself).
func (*GPU) AttentionBackward ¶ added in v0.19.0
func (g *GPU) AttentionBackward(q, k, v *Tensor, heads int, scale float32, dy *Tensor) (dq, dk, dv *Tensor)
AttentionBackward is the gradients of Attention(q, k, v, heads, scale) given dy: at q, at k and at v. The scores are made again (never kept by the forward pass).
func (*GPU) BilinearBackward ¶
BilinearBackward is the gradient of Bilinear(x, oh, ow) at x ([c, h, w]) given dy, the gradient at its output.
func (*GPU) Conv2dBackward ¶
Conv2dBackward is the gradients of Conv2d(x, w, b, stride, pad) given dy, the gradient at its output: at x, at w and at b. The input's patches as columns, dw is dy times them, the columns' gradient w's transpose times dy, summed back into the input's.
func (*GPU) ConvTranspose2dK ¶
func (*GPU) ConvTranspose2dKBackward ¶
ConvTranspose2dKBackward is the gradients of ConvTranspose2dK(x, w, b) given dy, the gradient at its output: at x, at w and at b.
func (*GPU) Disparity ¶
func (g *GPU) Disparity(up *Tensor, w, h, top, bottom int, a, b, far, knee, lim, clo, cspan, curve float32) *Tensor
Disparity is the disparity of a w x h picture from the depth up of its rows [top, bottom) (w a row): a times the depth plus b, kept within lim either way; the other rows 0. [h, w]. With curve above 0 the depth is first bent within the shot's range, clo its farthest and cspan its span, as stereo.Curved does (stereo.Shaper.CurveArgs's).
func (*GPU) DownloadBytes ¶
DownloadBytes copies the start of the GPU's tensor t to dst (waiting for the ops before to have run).
func (*GPU) DownloadPlanes ¶ added in v0.15.1
DownloadPlanes copies p's planes into dst (Size bytes: Y's rows, then the chroma's), waiting for the ops before to have run.
func (*GPU) Eyes ¶
Eyes renders the picture's two eyes for its disparity d [h, w], as stereo.Pair does (gap its stereo.gapPixels): EyesSize bytes, the left eye's Y, Cb and Cr planes then the right's, their rows w and (w+1)/2 apart.
func (*GPU) EyesMask ¶ added in v0.21.0
EyesMask is Eyes and, when asked, the eyes' holes (what the eye saw nothing of, filled from the side): 2*w*h bytes, the left eye's luma rows then the right's, 1 in a hole.
func (*GPU) GEGLUBackward ¶ added in v0.19.0
GEGLUBackward is the gradient of GEGLU(x) at x given dy.
func (*GPU) GELUBackward ¶ added in v0.19.0
GELUBackward is the gradient of GELU at its input x given dy.
func (*GPU) GroupNormBackward ¶ added in v0.19.0
func (g *GPU) GroupNormBackward(x *Tensor, groups int, w, dy *Tensor, eps float32) (dx, dw, db *Tensor)
GroupNormBackward is the gradients of GroupNorm(x, groups, w, b, eps) given dy: at x, at w and at b.
func (*GPU) InpaintApply ¶ added in v0.21.0
InpaintApply takes the filler's corrections d ([3, ph, pw], InpaintInput's padding) into an eye of Eyes' output, in place, where the mask says hole.
func (*GPU) InpaintInput ¶ added in v0.21.0
InpaintInput is the hole filler's input for an eye (0 the left, 1 the right) of Eyes' output of a w x h picture and EyesMask's mask, its rows [top, bottom): [4, ph, pw] (pw, ph the sides padded to a multiple of 8), as stereo.InpaintInput makes it.
func (*GPU) LayerNormBackward ¶ added in v0.19.0
LayerNormBackward is the gradients of LayerNorm(x, w, b, eps) given dy: at x, at w and at b.
func (*GPU) LinearBackward ¶ added in v0.19.0
LinearBackward is the gradients of Linear(x, w, b) given dy, the gradient at its output: at x (x's shape), at w and at b.
func (*GPU) MatchBoth ¶
MatchBoth is stereo.MatchBoth on the GPU (kernels.cu's sgm_*: the same integers and doubles, so the same disparities) for two w x h pictures: at half their size, the left eye's disparity and the right's (full resolution pixels), and which of each are sure (tex the texture they need: stereo's matchTexture).
func (*GPU) Moments ¶
Moments is the sum of x's values and that of their squares (two float64s, in a tensor of four float32s): x's rows rows of cols values, stride apart.
func (*GPU) NetInput ¶
NetInput is the picture's rows [top, top+ah) as the depth network takes them: RGB (BT.709, limited range), resized bilinearly to nw x nh, normalised by ImageNet's mean and deviation, [3, nh, nw].
func (*GPU) ReLUBackward ¶
ReLUBackward zeroes dy, in place, where ReLU's output y is zero.
func (*GPU) RefineInput ¶
RefineInput is the refinement's input, [4, ph, pw], for the picture's active rows from top at half size (w x h): their Y (2x2 averages), Cb and Cr, and the depth d [w x h] standardised by its moments mom (Moments'); the sides padded to pw x ph by repeating the last row and column.
func (*GPU) Renorm ¶
Renorm is out (w x h of rows pw apart, its moments got) put back to the mean and deviation of the moments want: [1, h, w].
func (*GPU) Samples ¶
Samples gathers what of a w x h disparity d (whose active rows are [top, bottom)) the floating window and the subtitles read: its side strips edge wide on every other active row, the left's then the right's, then every fourth row and column of its lower half.
func (*GPU) Scale ¶ added in v0.15.1
Scale resamples p to ow x oh: lx and ly the luma's filters, cx and cy the chroma's (on chroma samples).
func (*GPU) TemporalAttention ¶
func (*GPU) TemporalAttentionBackward ¶ added in v0.19.0
func (g *GPU) TemporalAttentionBackward(q, peQ, peK, peV *Tensor, ks, vs []*Tensor, heads int, scale float32, dy *Tensor, want []bool) (dq, dpeQ, dpeK, dpeV *Tensor, dks, dvs []*Tensor)
TemporalAttentionBackward is the gradients of TemporalAttention(q, peQ, peK, peV, ks, vs, heads, scale) given dy: at q and peQ, at peK and peV, and at the keys and values of the frames want says (nil for the others).
func (*GPU) ToneMap ¶ added in v0.15.1
ToneMap is convert's tone mapping of p: luts its toLight, curve and gamma tables (4097 values each), scale the code values' over 8 bits', full whether p is full range, hlg whether it is HLG (else PQ).
func (*GPU) UploadPicture ¶
UploadPicture puts a w x h picture's planes on the GPU (until Release): y's rows strideY apart, cb's and cr's strideC.
func (*GPU) UploadPlanes ¶ added in v0.15.1
UploadPlanes puts a w x h picture's planes on the GPU (until Release): y's rows and uv's pitch bytes apart, from their slices' starts.
func (*GPU) UploadTaps ¶ added in v0.15.1
UploadTaps puts a filter on the GPU, kept until Close.
type Picture ¶
type Picture struct {
// contains filtered or unexported fields
}
Picture is an 8-bit 4:2:0 picture's planes on the GPU.
type Planes ¶ added in v0.15.1
Planes is a decoded picture on the GPU as the decoders give it: NV12, or P010 when Depth is over 8, Y's H rows then the interleaved chroma's H/2, Pitch bytes apart.
type Tape ¶ added in v0.19.0
type Tape struct {
*GPU
// contains filtered or unexported fields
}
A Tape records a forward pass on a GPU, op by op, to run it backwards for the gradients at the weights it is told are learnt (Param). Its ops are the GPU's, recorded, so a network written against an interface they satisfy runs on the GPU as it is for inference and on a Tape for learning. Two differences: the ops that are in place on a backend (ReLU, Add) give new tensors here and leave their operands as they were, so a network must use what they give; and the gradients are single precision whatever the GPU's Half says. An op none of whose inputs is on a path from a learnt weight is not recorded. The tensors are the GPU's: released at its Release, with the gradients.
func (*Tape) AddScaled ¶ added in v0.19.0
AddScaled is the GPU's on a copy of x: x + y s, x as it was.
func (*Tape) Backward ¶ added in v0.19.0
Backward runs the pass backwards from out, dy the loss's gradient there (the GPU's tensor, out's shape).
func (*Tape) ConvTranspose2dK ¶ added in v0.19.0
ConvTranspose2dK is the GPU's, recorded.
func (*Tape) Grad ¶ added in v0.19.0
Grad is the gradient at a tensor of the pass after Backward (nil when none reached it), in the tensor's shape.
func (*Tape) Grads ¶ added in v0.19.0
Grads are the learnt weights' gradients, by name, after Backward: one the pass never reached is absent.
func (*Tape) Param ¶ added in v0.19.0
Param uploads a learnt weight: its gradient is gathered under name (Grads).
func (*Tape) Rows ¶ added in v0.19.0
Rows is the GPU's view, recorded: the gradient at the view lands in the rows from on of the gradient at x.
func (*Tape) TemporalAttention ¶ added in v0.19.0
func (tp *Tape) TemporalAttention(q, peQ, peK, peV *Tensor, ks, vs []*Tensor, heads int, scale float32) *Tensor
TemporalAttention is the GPU's, recorded: the gradients reach the query, the position encodings, and the keys and values of the frames on a path from a learnt weight.
func (*Tape) Tokens ¶ added in v0.19.0
Tokens is the GPU's, recorded for the patches (the class token and the position embedding get no gradient: they are not learnt).
type Taps ¶ added in v0.15.1
type Taps struct {
N int
// contains filtered or unexported fields
}
Taps is one dimension of a resampling filter, kept on the GPU: for each output sample, the first input sample it reads and the weights of the N it reads from there.
type Tensor ¶
Tensor is a dense float32 array of a shape: in Data, or on a GPU (a GPU backend's tensors; Data nil).
func AddScaledBackward ¶ added in v0.19.0
AddScaledBackward is the gradients of AddScaled(x, y, s) = x + y s (s a channel's) given dy: at y and at s (at x it is dy itself).
func Attention ¶
Attention is multi-head scaled dot product attention: q [Nq, D], k and v [Nk, D], the D channels in heads of D/heads, each head's softmax(q k^T scale) v; out [Nq, D]. Each head's keys and values are packed once; the jobs are a head's 64 query rows each: their scores, softmax and output.
func AttentionBackward ¶ added in v0.19.0
AttentionBackward is the gradients of Attention(q, k, v, heads, scale) given dy: at q, at k and at v.
func BicubicScale ¶
BicubicScale resizes x [C, H, W] by scale factors (F.interpolate mode "bicubic", align_corners false, a scale factor given): the output floor(H sy) x floor(W sx), each output sampled at (o + 0.5)/s - 0.5 with the cubic convolution kernel (A = -0.75), the edges repeated.
func Bilinear ¶
Bilinear resizes x [C, H, W] to oh x ow, align_corners true (F.interpolate mode "bilinear", align_corners=True).
func Conv2d ¶
Conv2d is nn.Conv2d on x [C, H, W] with w [O, C, kh, kw] and b [O] (nil for none), the stride and padding the same in both directions. A 1x1 convolution is a matrix product as it is; any other is done in bands of output rows, each band's patches gathered as columns ([C kh kw, the band's outputs]) and multiplied by w, so no buffer holds them all.
func Conv2dBackward ¶
Conv2dBackward is the gradients of Conv2d(x, w, b, stride, pad) given dy, the gradient at its output: at x, at w and at b.
func ConvTranspose2dK ¶
ConvTranspose2dK is nn.ConvTranspose2d on x [C, H, W] for a kernel as large as its stride and no padding (each input value spreads to its own k x k outputs): w [C, O, k, k], b [O].
func ConvTranspose2dKBackward ¶
ConvTranspose2dKBackward is the gradients of ConvTranspose2dK(x, w, b) given dy, the gradient at its output: at x, at w and at b.
func GEGLUBackward ¶ added in v0.19.0
GEGLUBackward is the gradient of GEGLU(x) at x given dy.
func GELUBackward ¶ added in v0.19.0
GELUBackward is the gradient of GELU at its input x given dy.
func GroupNorm ¶
GroupNorm is nn.GroupNorm on x [C, ...]: the channels in groups, each normalised over its channels and positions, then w and b per channel.
func GroupNormBackward ¶ added in v0.19.0
GroupNormBackward is the gradients of GroupNorm(x, groups, w, b, eps) given dy: at x, at w and at b.
func LayerNorm ¶
LayerNorm normalises x's last dimension (nn.LayerNorm), w and b its affine parameters.
func LayerNormBackward ¶ added in v0.19.0
LayerNormBackward is the gradients of LayerNorm(x, w, b, eps) given dy: at x, at w and at b.
func Linear ¶
Linear is x [N, in] times w [out, in] transposed, plus b [out] (nil for none): nn.Linear.
func LinearBackward ¶ added in v0.19.0
LinearBackward is the gradients of Linear(x, w, b) given dy, the gradient at its output: at x (x's shape), at w and at b.
func ReLUBackward ¶
ReLUBackward zeroes dy, in place, where ReLU's output y is zero.
func (*Tensor) Clone ¶
Clone is a copy of the tensor (in memory: a GPU tensor's is its backend's Clone).