Welvet examples
70. CamSync — inter-cameral / cross-mesh weight blend
Part: VII · Apps
Package: github.com/openfluke/welvet/layers/parallel
Status: ok — ✅ CamSync
When
Building or training a net that needs the layers/parallel Op (also usable as a Parallel cam).
Where
import "github.com/openfluke/welvet/layers/parallel"
cd 70-cam-sync && source ../env.sh && go run .
Why
Mix BranchModes and different inits let cams diverge on purpose. Sometimes you want them to share — gently (1% pull) or hard (full average) — within a Parallel, across Stack children, or even between same-shaped stores sitting on wildly different mesh layouts (1×2×1 ↔ 2×4×5). That is CamSync: couple weights without collapsing the graph into one Dense.
What
CamSyncConfig{Alpha, When, Groups, Cross}. BlendStores pulls every store in a clique toward the mean. Empty Groups = all cams; Cross wires SyncEndpoint pairs across layers/cams. Shape rule: Rows×Cols must match. Bidirectional today; one-way teacher→student not yet.
Sample output (captured)
cosine before=-0.0697 after=1.0000
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/70-cam-sync).
main.go
Download source ↓package main
import (
"fmt"
"github.com/openfluke/welvet/core"
"github.com/openfluke/welvet/layers/dense"
"github.com/openfluke/welvet/layers/parallel"
"github.com/openfluke/welvet/quant"
"github.com/openfluke/welvet/stub/seed"
"github.com/openfluke/welvet/weights"
)
func main() {
s, err := parallel.Bicameral(8, 16, 1, core.ActivationLeakyReLU,
core.DTypeFloat32, quant.FormatNone)
if err != nil {
panic(err)
}
hemi := s.Children[1].(*parallel.Layer)
left := hemi.Branches[0].(*dense.Layer).Weights
right := hemi.Branches[1].(*dense.Layer).Weights
_ = seed.InitStoreHe(left, 16, seed.From("cam0"))
_ = seed.InitStoreHe(right, 16, seed.From("cam1"))
hemi.SetCamSync(parallel.CamSyncConfig{
Enabled: true,
Alpha: 1.0,
When: parallel.SyncManual,
})
before, _ := weights.StoreCosine(left, right)
if err := hemi.SyncNow(); err != nil {
panic(err)
}
after, _ := weights.StoreCosine(left, right)
fmt.Printf("cosine before=%.4f after=%.4f\n", before, after)
}