tensor_optimizer.bend checks
raw source on the hub · import stelliferous@0.0.4.0/tensor_optimizer.bend as Tensor_optimizer
Parameter updates in a fixed FP32 order. The parameter's storage is reused.
2 imports
import Base import ./tensor_f32.bend as F
Types
type Velocity source · line 15 · raw
Type
The velocity of one parameter: none before its first step with momentum. The rest is always Still: a recursive type is one box, so a layer stays narrow however many tensors it holds.
StillVelocity
Moving@tensor:Tensor -> @rest:Velocity -> Velocity
Definitions
def Tensor source · line 5 · raw
Type
def sgd source · line 9 · raw
@parameter:Tensor -> @gradient:Tensor -> @+rate:F32 -> Tensor
parameter - gradient * rate, for a gradient of the parameter's shape.
def decayed_copies source · line 20 · raw
@gradient:Tensor -> @+decay:F32 -> @copies:Pair(Tensor, Tensor) -> Pair(Tensor, Tensor)
gradient + parameter * decay. A decay of zero leaves the gradient as it is.
def decayed source · line 24 · raw
@zero:Bool -> @parameter:Tensor -> @gradient:Tensor -> @+decay:F32 -> Pair(Tensor, Tensor)
def kept_velocity source · line 29 · raw
@copies:Pair(Tensor, Tensor) -> Pair(Tensor, Velocity)
def accumulated source · line 35 · raw
@velocity:Velocity -> @direction:Tensor -> @+momentum:F32 -> Pair(Tensor, Velocity)
velocity * momentum + direction; the first step takes the direction. A momentum of zero takes the direction and keeps no velocity.
def moved source · line 40 · raw
@zero:Bool -> @velocity:Velocity -> @direction:Tensor -> @+momentum:F32 -> Pair(Tensor, Velocity)
def descended source · line 45 · raw
@parameter:Tensor -> @+rate:F32 -> @applied:Pair(Tensor, Velocity) -> Pair(Tensor, Velocity)
def stepped source · line 49 · raw
@velocity:Velocity -> @+rate:F32 -> @+momentum:F32 -> @pair:Pair(Tensor, Tensor) -> Pair(Tensor, Velocity)
def sgd_with source · line 56 · raw
@parameter:Tensor -> @gradient:Tensor -> @velocity:Velocity -> @+rate:F32 -> @+momentum:F32 -> @+decay:F32 -> Pair(Tensor, Velocity)
(parameter - velocity * rate, velocity), as PyTorch's SGD without dampening computes them: direction = gradient + parameter * decay and velocity = velocity * momentum + direction.