Production-Grade 10.16 Billion Parameter Foundation Model for Code Intelligence
Engineered from first principles in PyTorch and DeepSpeed ZeRO-3, featuring FlashAttention-2, Grouped-Query Attention (GQA), Rotary Position Embeddings (RoPE), SwiGLU feed-forward networks, zero-overhead memory-mapped dataset streaming, and a high-performance serving stack.
- 10.16 Billion Parameter Architecture: 46 stacked transformer decoder layers with a 4096 hidden dimension and 14,336 SwiGLU intermediate dimension.
-
Grouped-Query Attention (GQA): 32 Query Heads to 8 Key/Value Heads (
$4:1$ ratio), reducing KV-cache memory bandwidth and inference VRAM consumption by$75%$ . -
FlashAttention-2 Integration:
$O(N)$ SRAM-tiled attention kernel dispatch with exact analytical backward passes and seamless PyTorch SDPA CPU/FP32 fallback. - Rotary Position Embeddings (RoPE): High-precision rotary positional encodings for robust context extrapolation without absolute position table limitations.
- DeepSpeed ZeRO-3 Distributed Engine: Full parameter, gradient, and optimizer state partitioning with activation checkpointing across multi-node GPU clusters (8Γ A100/H100 NVLink).
-
Zero-Waste Sequence Packing: Multi-document sequence concatenation with EOS separators, achieving
$\sim 100%$ active token compute efficiency without padding waste. -
Memory-Mapped Binary Ingestion: Zero-copy
numpy.memmapbinary shard pipeline capable of streaming hundreds of gigabytes of pre-tokenized code at NVMe bus speeds. -
Code-Specialized BPE Tokenizer: 32,000 vocabulary SentencePiece BPE with byte-level fallback (
<0xXX>), preserving Python indentations, tabs, and syntax symbols with zero<unk>tokens. - Production Serving & Evaluation Suite: Built-in FastAPI REST inference server and standard HumanEval / MBPP benchmark evaluation runners.
-
Exhaustively Validated: 29/29 unit and integration tests passing covering gradient backpropagation, numerical stability, KV caching, and causal next-token alignment (
$t \to t+1$ ).
graph TD
A["Raw Code Corpus (The Stack v2 / GitHub)"] --> B["SentencePiece BPE Tokenizer (32k Vocab + Byte Fallback)"]
B --> C["Quality Filtering (Protobuf, Lockfiles, Minified JS, ASCII Stats)"]
C --> D["Sequence Packing (4096-Token Packed Chunks)"]
D --> E["Binary Shards (mmap uint16 .bin + metadata.json)"]
E --> F["Distributed DataLoader (Rank-Offset Sampler & Pinned Memory)"]
subgraph "Transformer Decoder Stack (x46 Layers - 10.16B Params)"
F --> G1["RMSNorm (Pre-Norm with Float32 Stability)"]
G1 --> G2["Q, K, V Projections (32 Q-Heads, 8 KV-Heads)"]
G2 --> G3["RoPE Positional Rotations (theta=10,000)"]
G3 --> G4["FlashAttention-2 (SRAM Tiling & SDPA Fallback)"]
G4 --> G5["Output Projection (Wo) + Residual Connection"]
G5 --> G6["RMSNorm (Pre-FFN)"]
G6 --> G7["SwiGLU FFN (4096 -> 14,336 -> 4096 Dim)"]
G7 --> G8["Residual Connection -> Layer Output"]
end
G8 --> H["Final RMSNorm"]
H --> I["Tied LM Head Projection (4096 -> 32,000 Logits)"]
I --> J["Cross-Entropy Loss (Next-Token Causal Shift)"]
J --> K["DeepSpeed ZeRO-3 Engine (ZeRO Stage 3 + bf16 + Contiguous Gradients)"]
K --> L["AdamW Optimizer (Decoupled Weight Decay + Cosine Warmup)"]
L --> M["DeepSpeed Distributed Checkpoints (step_XXXXXX/)"]
An overview of every component and subsystem across the repository:
| File | Subsystem | Responsibility |
|---|---|---|
config.py |
Configuration |
PrismConfig dataclass, exact analytical parameter counting math, JSON/YAML serialization, and architecture validation. |
normalization.py |
Normalization | Root Mean Square Layer Normalization (RMSNorm) with internal float32 precision for numerical gradient stability. |
attention.py |
Attention Engine | Grouped-Query Attention (GQA), Rotary Position Embeddings (RoPE), KV-cache concatenation, and FlashAttention-2 dispatch. |
feedforward.py |
Feed-Forward Block | SwiGLU gated activation network ( |
transformer.py |
Transformer Block | Full pre-norm transformer decoder block wiring dual RMSNorm layers, attention, SwiGLU FFN, and residual skip routes. |
model.py |
10B Foundation Model |
PrismForCausalLM top-level container, tied embedding table, gradient checkpointing, next-token causal loss, and generation loop. |
| File | Subsystem | Responsibility |
|---|---|---|
tokenizer.py |
BPE Tokenizer | 32k SentencePiece BPE wrapper with byte fallback, digit splitting, whitespace preservation, and trainer interface. |
preprocessing.py |
Heuristic Cleaning | Quality filters for source code: line statistics, character entropy, ASCII ratios, auto-generated code, and file extensions. |
packing.py |
Sequence Packing | Zero-waste sequence packing buffer with EOS delimiters and monotonic binary .bin shard persistence. |
dataset.py |
Dataset Ingestion | Memory-mapped (np.memmap) pre-tokenized binary shard reader and HuggingFace streaming dataset connector. |
dataloader.py |
Distributed Data Loading | PyTorch DataLoader factory with DistributedSampler, pinned host memory, and multi-process worker scheduling. |
| File | Subsystem | Responsibility |
|---|---|---|
trainer.py |
Training Orchestrator | Main DeepSpeed ZeRO-3 training loop, gradient accumulation boundary synchronization, evaluation, and checkpoint triggers. |
optimizer.py |
Optimization & Schedule | AdamW parameter grouping (decoupled decay on weights vs no-decay on norms/biases) and cosine schedule with linear warmup. |
checkpointing.py |
Checkpoint Lifecycle | DeepSpeed distributed model/optimizer checkpoint manager with metadata tracking, rotation, and auto-resume. |
train_logger.py |
Telemetry & Logging | Unified Weights & Biases (WandB) and console dashboard logger with rank-0 filtering and GPU memory telemetry. |
metrics.py |
Performance Metrics | Rolling-window smoothed loss, perplexity, global tokens-per-second throughput (TPS), and remaining time ETA estimator. |
| File | Subsystem | Responsibility |
|---|---|---|
generator.py |
Autoregressive Generator | Autoregressive generation engine with KV caching, greedy search, Top-K, Top-P (nucleus), temperature, and repetition penalty. |
kv_cache.py |
KV-Cache Manager | Pre-allocated tensor cache data structure for efficient static memory inference. |
serving.py |
FastAPI Server | Production REST API with /health and /generate endpoints, CORS middleware, and automatic startup model loading. |
| File | Subsystem | Responsibility |
|---|---|---|
distributed.py |
Distributed Primitives | Rank queries, world size queries, barrier synchronization, and all-reduce scalar aggregation helpers. |
seed.py |
Reproducibility | Rank-offset deterministic pseudo-random number generator seeding across PyTorch, CUDA, NumPy, and Python. |
profiling.py |
Profiling & Profiler | GPU VRAM tracker, model parameter memory footprint calculator, throughput profilers, and benchmark timers. |
| File | Responsibility |
|---|---|
scripts/train.py |
Main distributed training CLI launcher for DeepSpeed multi-GPU execution. |
scripts/train_tokenizer.py |
Streams code samples from HuggingFace, filters text, and trains the SentencePiece BPE tokenizer. |
scripts/preprocess_data.py |
Streams The Stack v2, applies quality filters, tokenizes, packs sequences, and writes binary shards. |
scripts/generate.py |
Interactive multi-line code generation CLI supporting custom sampling parameters. |
scripts/evaluate.py |
Benchmark runner for HumanEval (164 coding tasks) and MBPP evaluation suites. |
scripts/test_pipeline.py |
Exhaustive 29-test unit and integration test suite executing end-to-end on local CPU. |
scripts/validate.py |
Syntax compilation and configuration validation check across all codebase modules. |
requirements.txt |
Complete dependency manifest for PyTorch, DeepSpeed, Tokenizers, FastAPI, and HuggingFace. |
setup.py |
Pip package installer configuring prism-ai library with optional [serve] and [eval] extras. |
| Hyperparameter | Value | Architectural Description |
|---|---|---|
| Model Name | prism-10b |
Decoder-only Autoregressive Transformer |
| Total Parameters |
10.16 Billion ( |
Calibrated 10B profile |
| Hidden Dimension ( |
4096 | Token embedding vector dimension |
| Decoder Layers ( |
46 | Stacked Transformer blocks |
| Query Attention Heads ( |
32 |
|
| KV Attention Heads ( |
8 | Grouped-Query Attention ( |
| SwiGLU Intermediate Dim ( |
14,336 | Feed-forward hidden dimension ( |
| Vocabulary Size ( |
32,000 | Byte-level SentencePiece BPE |
| Context Window ( |
4096 tokens | Standard sequence length (extensible to 64k via RoPE) |
| RoPE Base Theta ( |
10,000.0 | Rotary positional frequency base |
| Normalization | RMSNorm | Pre-normalization ( |
| Weight Tying | Enabled | Embedding table shared with final LM Head |
| Precision | bfloat16 (bf16) | Native mixed-precision training |
Standard Multi-Head Attention stores separate Key/Value states for all
Positional coordinates are encoded via orthogonal 2D rotation matrices in the complex plane:
Inner products naturally preserve relative distance
RMSNorm regularizes input activations based on root-mean-square statistics without mean-centering overhead:
Replaces standard ReLU/GELU activations with a parameterized bilinear gating mechanism:
The training objective optimizes next-token predictive likelihood over all causal positions
# Clone repository
git clone https://github.com/your-username/prism-ai.git
cd prism-ai
# Create and activate Python virtual environment
python -m venv venv
source venv/bin/activate # On Windows: .\venv\Scripts\Activate.ps1
# Install package and core dependencies
pip install -e .# Install FlashAttention-2 with CUDA compilation
pip install flash-attn --no-build-isolationStream code samples from HuggingFace to train a 32,000 vocabulary SentencePiece BPE tokenizer:
python scripts/train_tokenizer.py \
--output_prefix tokenizer/prism_tokenizer \
--vocab_size 32000 \
--num_samples 2000000Stream The Stack v2 (bigcode/the-stack-v2-dedup), filter low-quality code, tokenize, pack into 4096-token sequences, and save binary shards:
python scripts/preprocess_data.py \
--tokenizer_path tokenizer/prism_tokenizer.model \
--output_dir data/tokenized \
--num_tokens 200000000000 \
--shard_size 100000Train the 10.16B model across 8Γ A100/H100 GPUs using DeepSpeed ZeRO-3:
deepspeed scripts/train.py \
--model_config configs/model_10b.yaml \
--train_config configs/training_10b.yaml \
--deepspeed configs/deepspeed/ds_zero3.jsonRun interactive generation using trained model checkpoints:
python scripts/generate.py \
--model_config configs/model_10b.yaml \
--checkpoint checkpoints/step_0100000 \
--tokenizer tokenizer/prism_tokenizer.model \
--temperature 0.7 \
--top_p 0.9Evaluate functional code completion accuracy on OpenAI's HumanEval benchmark:
python scripts/evaluate.py \
--model_config configs/model_10b.yaml \
--checkpoint checkpoints/step_0100000 \
--tokenizer tokenizer/prism_tokenizer.model \
--benchmark humaneval \
--output_file eval_results.jsonlLaunch the production REST API server:
# Set environment variables
export PRISM_CONFIG=configs/model_10b.yaml
export PRISM_CHECKPOINT=checkpoints/step_0100000
export PRISM_TOKENIZER=tokenizer/prism_tokenizer.model
# Start Uvicorn ASGI server
uvicorn prism.inference.serving:app --host 0.0.0.0 --port 8000Run the full local unit and integration test suite (29 tests, CPU-friendly):
python scripts/test_pipeline.py============================================================
Prism AI β Comprehensive Local Pipeline Tests
============================================================
[PASS] Config creation and validation (10.16B default verified)
[PASS] Config YAML loading
[PASS] RMSNorm forward + backward gradient flow
[PASS] RoPE frequency precomputation
[PASS] RoPE apply rotation
[PASS] GQA Attention forward pass
[PASS] GQA Attention with KV cache (prefill + decode)
[PASS] GQA Attention backward pass
[PASS] SwiGLU FFN forward + backward
[PASS] TransformerBlock forward + backward
[PASS] Full model forward pass
[PASS] Full model loss computation
[PASS] Causal target shift exact alignment (t -> t+1)
[PASS] Full model backward pass (100% parameter gradient flow)
[PASS] Full model gradient checkpointing (activation recomputation)
[PASS] Full model KV cache generation
[PASS] Full model weight tying (Embeddings == LM Head)
[PASS] Full model parameter count matches config
[PASS] Optimizer parameter groups (decay vs no-decay)
[PASS] Cosine LR schedule with warmup
[PASS] Sequence packing logic (100% token packing)
[PASS] Pre-tokenized dataset save and memory-mapped load
[PASS] DataLoader creation with dummy data
[PASS] Single training step (forward + backward + optimizer)
[PASS] Metrics tracker (loss, perplexity, TPS, ETA)
[PASS] KV Cache operations (pre-allocated memory management)
[PASS] Text generation with tiny model
[PASS] Data quality filters
[PASS] End-to-end mini pipeline: data -> model -> loss -> backward
============================================================
Results: 29 passed, 0 failed, 29 total
============================================================
Standard Multi-Head Attention requires caching 32 Key and 32 Value heads per layer during inference. At a sequence length of 4,096 in fp16 across 46 layers, standard MHA consumes 30.8 GB of VRAM per batch item solely for KV cache. By grouping 32 query heads to 8 KV heads (
A 10.16B parameter model in mixed precision requires:
- Model Parameters (bf16):
$20.3\text{ GB}$ - Gradients (bf16):
$20.3\text{ GB}$ - Optimizer States (AdamW fp32 master weights, momentum, variance):
$121.9\text{ GB}$ -
Total Static State:
$\sim 162.5\text{ GB}$ (exceeds any single 80GB GPU).
DeepSpeed ZeRO-3 shards parameters, gradients, and optimizer states across all GPUs. On an 8Γ A100-80GB cluster, static memory drops to only
In raw code datasets, file lengths vary drastically (from 50 lines to 5,000 lines). Padding sequences to 4096 tokens with <pad> tokens wastes over <eos> tokens and chunks them into exact 4096-token windows, ensuring
This project is licensed under the Apache 2.0 License. Built for frontier code intelligence research.