Born - Production-Ready ML for Go "Models are born production-ready" Born is a modern deep learning framework for Go, inspired by Burn (Rust). Build ML models in pure Go and deploy as single binaries - no Python runtime, no complex dependencies. Pure Go ML with GPU acceleration - no CGO required! Why Born? The Problem Deploying ML models is hard: Python runtime required Complex dependency management Large Docker…
Born is a modern deep learning framework for Go, inspired by Burn (Rust). Build ML models in pure Go and deploy as single binaries - no Python runtime, no complex dependencies.
Pure Go ML with GPU acceleration - no CGO required!
Why Born?
The Problem
Deploying ML models is hard:
Python runtime required
Complex dependency management
Large Docker images
Slow startup times
Integration friction with Go backends
The Born Solution
import "github.com/born-ml/born"
// Models "born" ready for production
model := born.Load("resnet50.born")
prediction := model.Predict(image)
// That's it. No Python. No containers. Just Go.
Benefits:
Single binary deployment
Fast startup (< 100ms)
Small memory footprint
Native Go integration
Cross-platform out of the box
Features
Core
Pure Go - No CGO dependencies, trivial cross-compilation
Type Safe - Generics-powered API for compile-time guarantees
Autodiff - Automatic differentiation via decorator pattern
Production Ready - Single binary deployment, fast startup
WebAssembly - Run inference in browsers natively (core tensor has zero platform-specific code)
ONNX Import - Load PyTorch/TensorFlow models via .onnx (57 operators)
GGUF Import - llama.cpp format with K-quant dequantization (Q4_K, Q5_K, Q6_K, Q8_0); embedded tokenizer support (GPT-2 BPE, SentencePiece)
LLaMA - models/llama.LoadGGUF() for end-to-end LLaMA inference; verified on TinyLlama 1.1B Q8_0 and Q4_K_M; CPU embedding fallback for large-vocab models
Injectable Attention - swap attention implementation at model load time for research experiments
Native Format - .born format with nn.Save() / nn.Load() / nn.SaveTo() / nn.LoadFrom() (file, stream, or []byte)
Checkpoints - Resume training with optimizer state preservation
SafeTensors - HuggingFace compatible; F16/BF16 tensors widened to float32 on load
Reproducibility - nn.SetSeed() for deterministic weight initialization
Quick Start
Installation
# Clone repository
git clone https://github.com/born-ml/born.git
cd born
# Build
make build
# Or install CLI
make install
Development Setup
Requirements:
Go 1.26+ (1.26 required for optional SIMD support via GOEXPERIMENT=simd)
Make (optional, but recommended)
golangci-lint (for linting)
Build:
make build # Build all binaries
make test # Run tests
make lint # Run linter
make bench # Run benchmarks
Example: MNIST Classification
Working example included! See examples/mnist/ for complete implementation.
package main
import (
"github.com/born-ml/born/autodiff"
"github.com/born-ml/born/backend/cpu"
"github.com/born-ml/born/nn"
"github.com/born-ml/born/optim"
)
func main() {
// Create backend with autodiff
backend := autodiff.New(cpu.New())
// Define model (784 → 128 → 10)
model := NewMNISTNet(backend)
// Create loss and optimizer
criterion := nn.NewCrossEntropyLoss(backend)
optimizer := optim.NewAdam(model.Parameters(), optim.AdamConfig{
LR: 0.001,
Betas: [2]float32{0.9, 0.999},
}, backend)
// Training loop
for epoch := range 10 {
// Forward pass
logits := model.Forward(batch.ImagesTensor)
loss := criterion.Forward(logits, batch.LabelsTensor)
// Backward pass
optimizer.ZeroGrad()
grads := backend.Backward(loss.Raw())
optimizer.Step(grads)
// Log progress
acc := nn.Accuracy(logits, batch.LabelsTensor)
fmt.Printf("Epoch %d: Loss=%.4f, Accuracy=%.2f%%\n",
epoch, loss.Raw().AsFloat32()[0], acc*100)
}
}
Run it:cd examples/mnist && go run .
Example: LLM Inference (LLaMA)
package main
import (
"fmt"
"github.com/born-ml/born/backend/cpu"
"github.com/born-ml/born/models/llama"
"github.com/born-ml/born/generate"
"github.com/born-ml/born/tokenizer"
)
func main() {
backend := cpu.New()
// Load LLaMA model from GGUF (Q4_K_M, Q8_0, F16, F32 supported)
model, _ := llama.LoadGGUF("tinyllama-1.1b.Q8_0.gguf", backend)
defer model.Release()
// Load tokenizer
tok, _ := tokenizer.NewTikTokenForModel("gpt-4")
// Create generator with sampling config
gen := generate.NewTextGenerator(model, tok, generate.SamplingConfig{
Temperature: 0.7,
TopP: 0.9,
TopK: 40,
})
// Generate text
result, _ := gen.Generate("Hello, world!", generate.GenerateConfig{
MaxTokens: 100,
})
fmt.Println(result)
// Or use streaming
stream, _ := gen.GenerateStream("Once upon a time", generate.GenerateConfig{
MaxTokens: 50,
Stream: true,
})
for chunk := range stream {
fmt.Print(chunk.Token)
}
}
All operations required for LLM inference (Attention, RoPE, LayerNorm, etc.) are fully supported on GPU.
GPU Backend Setup:
The WebGPU backend uses gogpu/wgpu — a pure Go WebGPU implementation. No shared libraries, no DLLs, no CGO. Just go build and it works.
# That's it. No downloads, no system libraries.
go build ./...
Currently supported on Windows (D3D12). Linux (Vulkan) and macOS (Metal) support coming soon — gogpu/wgpu supports all three backends.
Usage:
import (
"github.com/born-ml/born/autodiff"
"github.com/born-ml/born/backend/cpu"
"github.com/born-ml/born/backend/webgpu"
)
// Automatic GPU/CPU selection with graceful fallback
var backend tensor.Backend
if webgpu.IsAvailable() {
gpu, err := webgpu.New()
if err == nil {
backend = autodiff.New(gpu)
defer gpu.Release() // Don't forget to release GPU resources
}
}
if backend == nil {
backend = autodiff.New(cpu.New())
}
Decorator Pattern
Functionality composed via decorators (inspired by Burn):
// Basic backend
base := cpu.New()
// Add autodiff
withAutodiff := autodiff.New(base)
// Add kernel fusion
optimized := fusion.New(withAutodiff)
// Your code works with any backend!
model := createModel(optimized)
Type Safety with Generics
type Tensor[T DType, B Backend] struct {
raw *RawTensor
backend B
}
// Compile-time type checking
func (t *Tensor[float32, B]) MatMul(other *Tensor[float32, B]) *Tensor[float32, B]
Roadmap
✅ What’s Working
Core Framework
Tensor API with generics, autodiff, NN modules (Linear, Conv2D, ReLU, etc.)
Optimizers (SGD, Adam), losses (CrossEntropyLoss)
MNIST: 97.44% MLP, 98.18% CNN accuracy
GPU Acceleration
WebGPU backend with 38+ operations (123x MatMul speedup)
Models trained anywhere (PyTorch, TensorFlow) are imported and born production-ready:
Training → Birth → Production
(Burn) (Born) (Run)
PyTorch trains → Born imports → Born deploys
TensorFlow trains → Born imports → Born deploys
Born trains → Born ready → Born serves
Production First
Single Binary: Entire model in one executable
No Runtime: No Python, no dependencies
Fast Startup: < 100ms cold start
Small Memory: Minimal footprint
Cloud Native: Natural fit for Go services
Developer Experience
Type Safe: Catch errors at compile time
Clean API: Intuitive and ergonomic
Great Docs: Comprehensive documentation
Easy Deploy: go build and you’re done
Performance
Actual Benchmarks (AMD Ryzen 9 5950X, NVIDIA RTX 3080):
Matrix Operations (WebGPU vs CPU)
Operation
CPU
GPU
Speedup
MatMul 1024x1024
7143ms
58ms
123x
MatMul 512x512
499ms
12ms
41x
MatMul 256x256
56ms
3.7ms
15x
Neural Network Inference
Batch Size
CPU
GPU
Speedup
Throughput
64
48ms
19ms
2.5x
3,357/s
256
182ms
21ms
8.5x
11,883/s
512
348ms
32ms
10.9x
15,973/s
CPU backend includes cache-tiled MatMul (3–5x), AVX2 SIMD micro-kernel (3.5x), and SIMD element-wise ops (up to 5.4x). Build with GOEXPERIMENT=simd to enable.
WebGPU WGSL Shaders
Born includes 30+ optimized WGSL compute shaders:
Shader
Workgroup
Description
addShader
256
Element-wise addition
subShader
256
Element-wise subtraction
mulShader
256
Element-wise multiplication
divShader
256
Element-wise division
matmulShader
16x16
Matrix multiplication (2D)
batchMatMulShader
8x8x1
Batched matmul (3D/4D)
conv2dShader
8x8x1
2D convolution with padding
maxPool2dShader
8x8x1
2D max pooling
transposeShader
16x16
Matrix transpose
reluShader
256
ReLU activation
sigmoidShader
256
Sigmoid activation
tanhShader
256
Tanh activation
softmaxShader
256
Softmax (numerically stable)
expShader
256
Element-wise exp
sqrtShader
256
Element-wise sqrt
rsqrtShader
256
Reciprocal sqrt (1/√x)
cosShader
256
Element-wise cosine
sinShader
256
Element-wise sine
greaterShader
256
Greater-than comparison
lowerShader
256
Less-than comparison
equalShader
256
Equality comparison
andShader
256
Logical AND
orShader
256
Logical OR
notShader
256
Logical NOT
argmaxShader
256
Argmax along dimension
globalSumShader
256
Parallel sum reduction
scalarMulShader
256
Scalar multiplication
scalarAddShader
256
Scalar addition
addShaderInt32
256
Int32 element-wise addition
subShaderInt32
256
Int32 element-wise subtraction
mulShaderInt32
256
Int32 element-wise multiplication
divShaderInt32
256
Int32 element-wise division
All shaders use workgroup shared memory for optimal performance and support bounds checking for safety.
Q: Why not use Gorgonia?
A: Gorgonia is great but uses a different approach. Born focuses on modern Go (generics), pure Go (no CGO), and production-first design inspired by Burn.
Q: Can I run LLMs with Born?
A: Yes. Use models/llama.LoadGGUF() to load LLaMA-compatible GGUF files directly — verified on TinyLlama 1.1B Q8_0 and Q4_K_M. Tokenizers, sampling strategies, KV-cache, and streaming generation are all included.
Q: When will it be ready?
A: Core features are released! CPU/GPU backends, transformers, LLM support, and ONNX import all work. See ROADMAP.md for upcoming features.
Q: Can I use PyTorch models?
A: Yes! Via ONNX import. Train in PyTorch, export to ONNX, deploy with Born. GGUF models are also supported.
Q: WebAssembly support?
A: Yes! Pure Go compiles to WASM natively. Inference in browsers out of the box.
Q: What LLM architectures are supported?
A: LLaMA 2/3, Mistral, DeepSeek, and compatible architectures. GQA, RoPE, SwiGLU are all supported.
Q: How do I enable GPU acceleration?
A: No install required. The WebGPU backend uses gogpu/wgpu — pure Go, zero CGO, zero runtime libraries. Run go build ./... and use webgpu.IsAvailable() to check GPU support at runtime. See Architecture for setup. 38+ GPU operations included — everything needed for LLM inference.
Q: What GPU operations are supported?
A: All operations needed for production ML! Math (Add, Mul, Exp, etc.), Matrix (MatMul, BatchMatMul, Conv2D), Activations (ReLU, Softmax), Comparisons (Greater, Equal), Boolean (And, Or, Not), Reductions (Sum, Argmax), and more. See the WebGPU Operation Table.
评论