A toolkit for building, visualizing, and controlling gomlx neural network models using the emergent GUI, including the netview for displaying and interacting with the network.
-
egomlx-- the core toolkit package: implements the emerNetwork,Layer, andPathinterfaces on top of gomlx, providing netview visualization, the standard params setting system, looper integration helpers, and weights I/O. -
sims/ra25-- a simple random-associator feedforward network with 2 hidden layers that maps 25 random 5x5 input to output patterns. It serves as the basic template for creating new models, mirroring the axon/v2/sims/ra25 structure.
Supports the following features, wrapped in the emer framework:
-
Feedforward and recurrent networks (
NetworkParams.NCycles> 1) with selectable activation functions, output error statistics, and netview visualization -
Backward learning pass:
Network.Backwardbuilds one compiled graph with forward + loss + autodiff gradients + optimizer weight updates (via gomlx optimizers). The loss function and optimizer settings are global inNetwork.NetworkParams; pathway-specific learning is controlled byPathParams.Learn. DWt (gradient) values are available as a netview synapse variable, read back only when actually being viewed. -
Recurrent settling: with
NetworkParams.NCycles> 1, the network is unrolled for that many cycles, with the weights shared across cycles.Forwardpaths use the sender's current-cycle activity, and the recurrentBackandLateralpaths use the sender's previous-cycle activity (zero on the first cycle). The loss is computed on the final cycle, so learning is backpropagation through time. -
ActParams.Noiseadds Gaussian noise to a layer's net input on every cycle.NetworkParams.Decay< 1 carries over the final activity of the previous trial: the first cycle of the next trial starts from (1 − Decay) times that activity, within each data-parallel stream, with no gradient flowing back into the previous trial.ActParams.Dropoutsets a layer's activity to zero with that probability on each cycle of the training passes only (scaling the rest to keep the mean), with no effect on Forward passes. -
Connectivity:
ConnectLayersaccepts anypaths.Pattern. Each pathway is a dense gomlx layer, and patterns other than full connectivity (e.g.,paths.PoolOneToOne) are implemented by multiplying its weights by a fixed 0/1 connectivity mask (Path.Mask), so the unconnected weights stay zero and get no gradient. The weights are initialized using the actual number of connected senders (Path.FanIn). Note thatpaths.Fullleaves out each unit's connection to itself for a lateral (self) pathway, unless itsSelfConis set.
gomlx runs the compiled graphs on a pluggable backend. compute.MustNew() picks the backend named by the environment variable GOMLX_BACKEND, and uses XLA if it is not set. Network.SetBackend sets one explicitly in code.
GOMLX_BACKEND |
Hardware (macOS) | Notes |
|---|---|---|
xla (default) |
CPU | XLA has no GPU support on macOS. Slowest to compile, fastest per call for small networks. Uses several CPU threads. |
mps |
Apple GPU | Metal Performance Shaders, from go-darwinml. No extra install needed. |
mlx |
Apple GPU | Apple MLX, from go-darwinml. Needs the MLX library: brew install mlx, and then a full rebuild (see below). |
For example:
GOMLX_BACKEND=mlx ./conflict_rnn -noguiNetwork.TimerReport names the backend in use, so check it to confirm that the one you asked for was picked up.
go-darwinml decides whether to include MLX support at compile time, by checking whether the MLX headers exist (__has_include(<mlx/mlx.h>)). Go's build cache does not notice when those headers are installed later. So a binary built before brew install mlx keeps reporting "MLX is not installed", even after rebuilding normally. Force a full rebuild once, which refreshes the cached cgo package:
brew install mlx
go build -a .After that, ordinary builds of any program pick up the MLX-enabled package from the cache. Do the same after upgrading or removing MLX.
Network.CompileTimer, ForwardTimer and BackwardTimer time graph compilation separately from the computation (each Exec call, including reading back the results), and Network.TimerReport reports all three. Changing the network parameters (UpdateParams) or the batch shape rebuilds the graphs, so applying params in bulk (one UpdateParams per sheet) keeps the number of compiles down.
For reference, a 40-epoch run of the small recurrent conflict_rnn network (10 cycles, batch of 16, on an Apple Silicon Mac) gave identical results on all three backends, with these times:
| Backend | Wall | CPU (user) | Compile (9 graphs) | Forward / call | Backward / call |
|---|---|---|---|---|---|
| XLA | 8.2 s | 14.9 s | 2.17 s | 0.58 ms | 2.17 ms |
| MPS | 11.6 s | 7.8 s | 0.44 s | 1.36 ms | 4.48 ms |
| MLX | 10.9 s | 4.9 s | 0.02 s | 1.62 ms | 4.09 ms |
For small networks and batches like this, the per-call overhead of the GPU backends outweighs their compute advantage, so XLA on the CPU is fastest for a single run. MLX compiles almost instantly and uses the least CPU, so it may be the better choice for running many jobs in parallel. Larger networks and batches should favor the GPU backends.
- Go with the Cogent Core GUI framework. See install instructions there.
From sims/ra25:
$ core run [platform]
See the sims/ra25 README for full instructions.
This is coded largely using AI tools, under strong human supervision.