Skip to content

Define neural architectures in BASIC with packed tensors - #97

Merged
treeform merged 2 commits into
mainfrom
polyworld-nn-tensors
Oct 5, 2026
Merged

treeform merged 2 commits into
mainfrom
polyworld-nn-tensors

Conversation

@treeform

@treeform treeform commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

GotA neural policies can define their architecture in BASIC using shared packed-tensor operations, so a new supported architecture no longer needs a custom native runner. Per-player weights and recurrent state stay inside the VM. BASIC scalar arithmetic remains deterministic integer/Q16.16; float32 is confined to tensors.

  • Add checked, size-budgeted int32, Q16.16 and float32 tensor kernels, including dense, CSR, activations, elementwise math and gather/scatter.
  • Implement all four current architectures in BASIC: Richard, David, Andre and Fly. Their tensor packages make no calls to the custom runner endpoints.
  • Add ZIP conversion, synthetic runnable examples, API documentation and inference benchmarks. Existing named runners remain available.

Uses the merged Bassy #9, pinned to a02e6dd5889310b13d21725c891bde8d01539f08 in both dependency locks. Its contents match the locally tested dependency exactly.

Validation:

  • Nim checks, full release suite with strict native BASIC compilation, lockstep regressions, converter tests and Bassy tests passed locally.
  • Tensor tests passed with interpreted BASIC, native compilation and WASM. Tests cover recurrent resets, immutable weights, invalid handles/shapes, atomic failures, work and memory limits.
  • Ten-player synthetic matches for all four architectures produced identical commands and simulation hashes against the named runners. WASM verified all 2,509 replay ticks per architecture; replay mismatches are still enforced.

Limits: private trained bot uploads were not tested. David's reference state differs by at most 5.96e-8, with at most one raw Q16.16 output unit of difference. Cross-platform float32 bitwise identity is not promised. Benchmarks are documented: small models pay extra host-call overhead, while the tested large David model was faster and Fly was about 1.55x slower than its specialized runner.

@treeform
treeform merged commit f4dccda into main Oct 5, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant