Skip to content

Reference LSM

Raul Montoya Cardenas edited this page Jul 29, 2026 · 2 revisions

Reference LSM (reference_lsm.jl)

Wiki hero

Generated with Grok Build: Grok 4.5 · xAI Imagine (/imagine)

A 2,048-neuron dense CUDA reservoir for rapid prototyping. Not exported on the public API surface (call via LiquidCortex.run_lsm_step / module-qualified internals). Prefer SparseBrain / EnsembleBrain for production capacity.

Constants

Constant Value
REF_N 2048
REF_IN_DEFAULT 16
REF_OUT_DEFAULT 16

Lazy GPU State

Globals start as nothing / defaults so using LiquidCortex works without a GPU:

Ref Content
_ref_W CuMatrix{Float32} recurrent weights
_ref_Win CuMatrix{Float32} input weights
_ref_Wout CuMatrix{Float32} readout
_ref_x CuVector{Float32} reservoir state
_ref_n_in / _ref_n_out Locked dimensions after init
_ref_initialized Boolean gate

Manual init

LiquidCortex._init_ref_lsm!(; n_in=8, n_out=4)
  • Validates positive dimensions.
  • Initializes W ~ N(0, 0.02), Win ~ N(0, 0.5), Wout ~ N(0, 0.1) via cpu_randn_cu.
  • Zeros state vector of length REF_N.

Lazy init

First run_lsm_step without prior init:

  • Errors if !_cuda_available[].
  • Calls _init_ref_lsm!(; n_in=length(inputs_vec), n_out=n_out).

Step API

y = LiquidCortex.run_lsm_step(inputs_vec::Vector{Float32}, inhibit_val::Float32; n_out=16)
# y :: Vector{Float32} on CPU

Dynamics:

u = cu(inputs_vec)
gain = 1 − 0.4 * inhibit_val
x ← tanh(gain * (W x + Win u))
y = Array(Wout * x)

Throws DimensionMismatch if length(inputs_vec) ≠ _ref_n_in after init.

String helper

s = LiquidCortex.run_lsm_step_str(inputs_vec, inhibit_val; n_out=16)
# comma-separated floats for IPC / shell integration

Vs SparseBrain

Aspect Reference LSM SparseBrain
Size 2,048 dense 65,536 sparse
Activation Continuous tanh state LIF spikes + OU noise
Inhibition Recurrent gain shrink Dynamic threshold raise
Plasticity None online STDP traces + W_out Hebb
State model Module-level singleton Instance structs
Export Internal helpers Public API

Testing Notes

test/runtests.jl (main) includes GPU tests that:

  • Snapshot / clear / restore reference globals to avoid cross-test pollution.
  • Cover lazy init, custom dims, ArgumentError / DimensionMismatch, and string output.

See Test Suite.


Last updated: July 28, 2026 Updated by: Grok Build: Grok 4.5 Package tip reference: 4e2698c (main)

Clone this wiki locally