Welvet examples
19. layers/residual
Part: III · Layers
Package: github.com/openfluke/welvet/layers/residual
Status: ok — ✅
When
Building or training a net that needs the layers/residual Op (also usable as a Parallel cam).
Where
import "github.com/openfluke/welvet/layers/residual"
cd 19-residual && source ../env.sh && go run .
Why
Skip connections stabilize deep stacks: y = F(x) + x with correct skip grads.
What
F is Dense Dim→Dim, or mixed Ops via NewFromOps (Dense, SwiGLU, RMSNorm, LayerNorm). Parallel as F is parallel.ResidualGraft (y = F(x)+x) — Residual cannot import parallel.
Sample output (captured)
16 <nil>
Live capture from go run ./cmd/runall on local ../../welvet (exit 0).
Source
Copied from the Welvet feature book examples (openfluke.github.io/welvet/examples/19-residual).
main.go
Download source ↓package main
import (
"fmt"
"github.com/openfluke/welvet/core"
"github.com/openfluke/welvet/layers/residual"
)
func main() {
l, err := residual.New(residual.Config{Dim: 16, Depth: 2})
if err != nil {
panic(err)
}
x := core.NewTensor[float32](1, 16)
_, y, err := residual.Forward(l, x)
fmt.Println(len(y.Data), err)
}