Omni-LLM provides a transparent, from-scratch implementation of the Meta Llama 3 architecture in PyTorch, showcasing the full inner workings of modern Transformer models without relying on external APIs.
It also includes:
- A custom-built RAG (Retrieval Augmented Generation) engine using cosine similarity (linear algebra), not a hosted vector DB.
- A dynamic LoRA (Low-Rank Adaptation) injection system for runtime adapter swapping.
The dashboard visualizes inference behavior, including token probability distributions and vector retrieval scores.
| Retrieval Augmented Generation (RAG) | Low-Rank Adaptation (LoRA) |
|---|---|
![]() |
![]() |
| Vector search similarity scores | Dynamic adapter injection changing tone |
Implemented the architectural patterns used in modern LLMs:
- RMSNorm (Root Mean Square Normalization): implemented manually to replace LayerNorm for stability.
- RoPE (Rotary Positional Embeddings): complex-number rotation for relative positional encoding.
- SwiGLU Activation: Swish-Gated Linear Unit for improved convergence.
- Grouped Query Attention (GQA): reduces KV-cache memory usage during inference.
- Vector DB from scratch:
numpy.dot()-based cosine similarity without Pinecone/Chroma/etc. - KV-caching: caches Key/Value states for efficient autoregressive decoding.
- LoRA injection: runtime wrapper that injects low-rank matrices (A Γ B) into Linear layers.
The system cleanly decouples the neural network (βbrainβ) from the API server.
graph TD
Client[React Frontend] -->|JSON/HTTP| API[FastAPI Server]
subgraph "Inference Engine"
API -->|1. Vector Search| VectorDB[(TinyVectorStore)]
API -->|2. Inject Weights| Adapter[LoRA Manager]
VectorDB -->|Context Chunks| Prompt[Prompt Builder]
Adapter -->|W + AB| Model[Llama-3-Nano]
Prompt --> Model
Model -->|Logits| Sampler[Sampler]
end
Sampler -->|Token Stream| Client
- Python 3.10+
- Node.js
# Clone and enter repo
git clone https://github.com/aseem-ai/omni-llm.git
cd omni-llm
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Run the server
uvicorn src.app:app --reload --port 8001Open frontend/index.html in your browser. Itβs built to run without a build step for portability.
Instead of using a library, I implemented vector similarity manually to optimize for low-latency CPU retrieval using Cosine Similarity:
- Implementation: See
src/app.py(Line 45) for the numpy-based linear algebra routine.
Low-Rank Adaptation (LoRA) adapts the base weight matrix
-
Constraint:
$B \in \mathbb{R}^{d \times r}$ and$A \in \mathbb{R}^{r \times d}$ , where the rank$r \ll d$ . - Why it matters: This reduces trainable parameters by ~98%, allowing the "Specialist" modes to switch instantly without reloading the 10GB base model.
omni-llm/
βββ assets/ # Documentation screenshots
β βββ dashboard_main.png
β βββ rag_demo.png
β βββ lora_demo.png
βββ frontend/ # React dashboard
β βββ index.html # Single-file UI (zero-build)
βββ src/ # Core logic
β βββ app.py # RAG engine & API server
β βββ model.py # Llama 3 architecture (PyTorch)
βββ Dockerfile # Containerization config
βββ Makefile # Dev automation
βββ requirements.txt # Dependency pinningMIT License β feel free to use this architecture for learning.
- Llama 3 Architecture β AI at Meta (2024). The Llama 3 Flock of Models.
- RoPE β Su, J., et al. (2021). RoFormer: Enhanced Transformer with Rotary Position Embedding.
- LoRA β Hu, E. J., et al. (2021). LoRA: Low-Rank Adaptation of Large Language Models.
- SwiGLU β Shazeer, N. (2020). GLU Variants Improve Transformer.
- GQA β Ainslie, J., et al. (2023). GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints.
If uvicorn fails to start, a previous process might be holding the port:
# Kill process on port 8001 (macOS/Linux)
lsof -ti:8001 | xargs kill -9
# Or run on a different port
uvicorn src.app:app --reload --port 8002Make sure you're in the virtual environment, then install requirements:
source venv/bin/activate
pip install -r requirements.txt

