Welvet examples

15. layers/layernorm

Open original example ↗Recorded results · not a live execution

Part: III · Layers
Package: github.com/openfluke/welvet/layers/layernorm
Status: ok — ✅

When

Building or training a net that needs the layers/layernorm Op (also usable as a Parallel cam).

Where

import "github.com/openfluke/welvet/layers/layernorm"

cd 15-layernorm && source ../env.sh && go run .

Why

Classic mean+var normalization with γ/β — still required for many HF architectures.

What

WebGPU forward; backward host today. Same dtype×quant axes as other weighted layers.

Sample output (captured)

8 <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/15-layernorm).

main.go

Download source ↓
package main

import (
	"fmt"

	"github.com/openfluke/welvet/core"
	"github.com/openfluke/welvet/layers/layernorm"
)

func main() {
	l, err := layernorm.New(layernorm.Config{Dim: 8})
	if err != nil {
		panic(err)
	}
	x := core.NewTensor[float32](1, 8)
	_, y, err := layernorm.Forward(l, x)
	fmt.Println(len(y.Data), err)
}