BRAIDGROUP
RESEARCH & DEV
Platform

ML Runtime.
From Scratch.

A complete machine learning infrastructure written in C. Tensor algebra, automatic differentiation, transformer architecture, RLHF alignment, distributed training, and GPU compute — all implemented without PyTorch or TensorFlow.

270+
Source Files
C implementations
60+
Tensor Ops
Element-wise to attention
27
Autograd Ops
With backward functions
2
GPU Backends
CUDA + Vulkan compute
Tensor Engine

Every Operation, Native C.

Eight data types, SIMD-accelerated arithmetic, and a full set of neural network primitives. No Python wrappers. No foreign function interfaces.

Data Types

float64float32float16bfloat16int8int16int32int64

Arithmetic

add, sub, mul, div, pow, neg, scalar_mul with broadcasting and dtype promotion across all 8 types.

Math

sqrt, rsqrt, log, exp, sum, mean, max, min, var, std — all with axis parameter and keepdim support.

Normalization

LayerNorm, RMSNorm, BatchNorm — the three normalization primitives that cover every modern architecture.

Activations

ReLU, GELU, SiLU, sigmoid, tanh, softmax, log_softmax, leaky_relu — every activation used in production models.

Linear Algebra

matmul, scaled_dot_product_attention with GQA and RoPE. BLAS wrapper for optimized matrix operations.

Automatic Differentiation

27 Backward Functions.

A computation graph recorder that tracks every tensor operation and computes exact gradients via reverse-mode automatic differentiation. Supports higher-order derivatives through nested graph traversal.

addmulmatmulrelugelusigmoidtanhlayer_normrms_normsoftmaxcross_entropysummeanpowexplognegsqrtrsqrtsiluleaky_reludropoutreshapetransposesliceembedding_lookupbatch_norm
Computation Graph
// Forward pass records the graph
let x = tensor([2.0, 3.0]);
let w = tensor([0.5, 1.0]).requires_grad(true);
let y = (x * w).sum();

// Backward pass computes gradients
y.backward();
// w.grad => [2.0, 3.0]  (dy/dw = x)
// x.grad => [0.5, 1.0]  (dy/dx = w)
Transformer Architecture

Full Transformer Stack.

Multi-head attention with GQA, rotary position embeddings, KV caching, and pre-norm blocks. Every component that makes a modern LLM work.

Multi-Head Attention

Grouped-query attention (GQA) with configurable head count. Scaled dot-product attention with optional causal masking.

attention.c

Rotary Position Embedding

RoPE applied to query and key vectors for relative position encoding. No learned positional embeddings.

rope.c

KV Cache

Pre-allocated contiguous tensor for autoregressive generation. Stores key-value pairs across layers for O(1) per-token inference.

kv_cache.c

Transformer Block

Pre-norm architecture with RMSNorm or LayerNorm, attention sublayer, and SwiGLU feed-forward network.

transformer_block.c

Feed-Forward Network

SwiGLU activation with configurable hidden dimension. The standard FFN used in LLaMA and modern open-source models.

ffn.c

Token Sampling

Greedy, top-k, top-p (nucleus), and temperature-controlled sampling for text generation.

sampling.c
Training

Training Infrastructure.

A training loop with checkpointing, gradient accumulation, mixed precision, early stopping, and distributed data parallelism — under active development.

Optimizers

SGD with momentum and Nesterov, Adam, AdamW with decoupled weight decay, Lion.

LR Schedulers

Linear warmup, cosine decay, cosine with warmup, step decay, inverse square root.

Memory Efficiency

Gradient checkpointing, gradient accumulation, mixed precision (FP16/BF16), arena-based tensor allocation.

Checkpointing

Save/load model state, optimizer state, scheduler state, and training metrics. Version tracking with epoch numbers.

Early Stopping

Patience-based early stopping with configurable metric tracking. Prevents overfitting without manual intervention.

Weight Initialization

Zeros, ones, uniform, normal, Xavier (Glorot), Kaiming (He) initialization — matching every initialization scheme used in research.

Alignment

RLHF Built In.

Reinforcement Learning from Human Feedback isn't an add-on — it's part of the core runtime. Four alignment algorithms, a reward model, and a safety filter.

PPO

Proximal Policy Optimization with clipping, KL penalty, and Generalized Advantage Estimation (GAE).

DPO

Direct Preference Optimization — skip the reward model entirely. Train from preference pairs.

GRPO

Group Relative Policy Optimization — compare outputs within a group for relative ranking.

Safety Filter

Keyword, pattern, and topic blocking on both input and output. Configurable safety weighting.

Quantization

Six Methods.

From post-training quantization to quantization-aware training, with FP8, weight-only, dynamic, and KV cache quantization. Run larger models on smaller hardware.

Post-Training Quantization (PTQ)
Quantization-Aware Training (QAT)
FP8 Quantization
Weight-Only Quantization
Dynamic Quantization
KV Cache Quantization
Model Loading
// Load from standard formats
let model = llm.load("model.gguf");
let model = llm.load_safetensors("weights.safetensors");

// Convert between formats
model_converter.convert(
  source: "hf_config.json",
  target: "model.gguf",
  quantization: "q4_0"
);

// HuggingFace integration
let config = hf_config.load("config.json");
GPU Compute

Two GPU Backends.

CU

CUDA Backend

285 lines

Runtime compilation via NVRTC. Device memory management, kernel launch, and dedicated CUDA kernels for activations, elementwise ops, and matrix multiplication.

matmul.cuelementwise.cuactivations.cu
VK

Vulkan Compute

446 lines

Vulkan compute pipelines with descriptor set management. 7 GLSL compute shaders for core operations.

matmul.compsoftmax.complayer_norm.compsigmoid.compactivations.compelementwise_add.compelementwise_mul.comp
Distributed

Scale Across GPUs.

Seven parallelism strategies with NCCL-backed communication. From single-machine data parallelism to multi-node pipeline parallelism.

Data Parallel

Gradient all-reduce across workers

Tensor Parallel

Split matrices across devices

Pipeline Parallel

Micro-batch pipeline scheduling

MoE Routing

Mixture of Experts dispatch

ZeRO Sharding

Optimizer state partitioning

Distributed AMP

Mixed precision across nodes

Dist. Checkpoint

Fault-tolerant saving

See It In Action.

The ML runtime ships as part of the Braid standard library. Import std.tensor, std.nn, and std.train to build and train models natively.