← OpenFluke

Chapter 19

layers/residual

github.com/openfluke/welvet/layers/residual


Why it exists

Skip connections stabilize deep stacks: y = F(x) + x with correct skip grads.

What it is

F is Dense Dim→Dim (Depth≥1). Heterogeneous non-Dense F still open.

Go example

examples/19-residual/main.go

Run:cd welvet/examples/19-residual && source ../env.sh && go run .
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)
}

Output

exit 0 · last run via go run .

16 <nil>