🇻🇳 Mô hình ngôn ngữ mã nguồn mở Việt Nam • Post-Transformer • Recursive • Emergent
| 🧬 Giới Thiệu | 🏗️ Kiến Trúc | 🚀 Cài Đặt | 🧪 CoT | 📊 Hiệu Năng | 🗺️ Lộ Trình |
Nexus v8 không phải Transformer. Nó là kiến trúc hậu Transformer — mỗi token tự quyết định compute, bộ nhớ vô hạn, weight sinh động từ coordinate.
|
|
┌─────────────────────────────────────────────────────┐
│ INPUT │
│ token_ids: (B, T) │
└─────────────────────┬───────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ EMBEDDING │
│ nn.Embedding(vocab, dim) │
└─────────────────────┬───────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ BLOCK × n_layers │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ ❶ RMSNorm → QUANTUM MIXER │ │
│ │ ┌─────────────────────────────────────────────┐ │ │
│ │ │ Q = wq(x) → q_nope, q_pe │ │ │
│ │ │ K = wk(x) → k_nope + k_pe │ │ │
│ │ │ V = wv(x) │ │ │
│ │ │ │ │ │
│ │ │ attn = Q·Kᵀ × (0.9 + 0.1·cos(Δphase)) │ │ │
│ │ │ out = attn·V │ │ │
│ │ └─────────────────────────────────────────────┘ │ │
│ │ ↳ + residual │ │
│ ├─────────────────────────────────────────────────────┤ │
│ │ ❷ RMSNorm → FFN (SwiGLU) │ │
│ │ out = (SiLU(x·W₁) ⊙ x·W₃)·W₂ │ │ │
│ │ ↳ + residual │ │
│ ├─────────────────────────────────────────────────────┤ │
│ │ ❸ MemoryFabric Read (nếu có) │ │
│ │ top-k retrieval → attention → augment │ │
│ └─────────────────────────────────────────────────────┘ │
└──────────────────────────┬──────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ RMSNorm → LINEAR HEAD │
│ logits: (B, T, vocab) │
└─────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ OUTPUT │
│ Train: (logits, loss) │ Infer: logits │
│ Generate: token_ids │
└─────────────────────────────────────────────────────┘
|
Attention thế hệ mới Phase interference thay Q·Kᵀ. |
Token tự quyết định GRU-style state update. |
Bộ nhớ vô hạn Content-addressable. |
|
Weight động Tham số giảm 80-90%. |
Tự sửa lỗi Tự đánh giá output. |
Suy luận từng bước 28 reasoning chains. |
git clone https://github.com/devtantai-coder/nexus.git
cd nexus
pip install -r requirements.txt |
python inference/build_train.pyKết quả: |
from model import Transformer, ModelArgs
args = ModelArgs(
dim=512, n_layers=8, n_heads=8,
vocab_size=796, dtype="float32"
)
model = Transformer(args)
# Generate
model.generate(["xin chào"], max_new_tokens=40)
#→ "xin chào bạn tôi là nexus..." |
model.generate([
"5 cộng 7 nhân 2 bằng bao nhiêu"
], max_new_tokens=60, temperature=0.7)
#→ "<think> ưu tiên nhân trước
# 7×2=14 → 5+14=19 </think>
# kết quả là 19" |
from model import Transformer, ModelArgs
# Khởi tạo
args = ModelArgs(dim=128, n_layers=2, n_heads=4, vocab_size=2048)
model = Transformer(args)
# Training — unified forward
logits, loss = model(tokens, labels=targets)
loss.backward()
# logits: (B, T, vocab), loss: scalar
# Inference
logits = model(tokens[:, -1:]) # (B, vocab) — next token
logits = model(tokens) # (B, T, vocab) — full seq
# Generation
output = model.generate(
prompt_ids, # list[int] or list[list[int]]
max_new_tokens=100,
temperature=0.7,
top_p=0.9,
repetition_penalty=1.1,
eos_id=0,
) |
|
| Lĩnh vực | Số mẫu | Ví dụ |
|---|---|---|
| 🧮 Toán học | 5 | Số chẵn/lẻ, chu vi, ưu tiên phép tính, dãy số |
| 🔤 Logic | 5 | Tam đoạn luận, modus tollens, suy luận thứ tự |
| 🔬 Giải thích | 3 | Bầu trời xanh, nước biển mặn, lá cây xanh |
| 💻 Lập trình | 3 | Kiểm tra số chẵn, sắp xếp nổi bọt, tìm max |
| 🤖 Khoa học máy tính | 3 | Big Data, ML, Neural Network |
| ⚖️ So sánh | 3 | CPU vs GPU, Internet vs Web, AI vs ML vs DL |
| 🛠️ Giải quyết vấn đề | 6 | Lạc đường, học kỹ năng, bảo vệ môi trường |
Cấu trúc CoT: [question_ids] + [3] + [step_by_step_ids] + [4] + [answer_ids] + [2]
Token đặc biệt: <think>=3, </think>=4, <eos>=2
| Tác vụ | Kết quả | Ghi chú |
|---|---|---|
| Forward (batch=2, seq=16) | 5.89ms | torch.Size([2, 16, 2048]) |
| Generate 1 token | ~27ms | 37 tok/s |
| Generate 8 tokens | 1.07s | 5 generations |
| Train loss (2 epochs) | 5.89 | Label smoothing 0.1 |
| RAM sử dụng | ~200 MB | PyTorch model + data |
| Tác vụ | Kết quả |
|---|---|
| Total params | 31,877,632 |
| Training samples | 9,800 (augmented) |
| Vocab | 796 tokens |
| Seq length | 64 |
| Training | ~10 min / epoch (CPU) |
| Tiêu chí | Transformer | Mamba | Nexus v8 🧠 |
|---|---|---|---|
| Context | 128K (KV cache) | 1M (SSM) | ∞ tokens (Memory Fabric) |
| Compute | O(n²) | O(n) | O(n) × adaptive depth |
| Position encoding | RoPE | None | Phase (built-in) |
| Weight representation | Dense matrix | Dense | Neural Field (lazy) |
| Memory mechanism | KV cache | None | Emergent Fabric |
| Adaptive compute | ❌ | ❌ | ✅ Recursive Program |
| Self-critique | ❌ | ❌ | ✅ Native |
| Chain-of-Thought | ❌ (add-on) | ❌ | ✅ Native tokens |
| VRAM (1B scale) | ~4 GB | ~3 GB | ~1.5 GB |
| CPU inference | ~5 tok/s | ~12 tok/s | 37 tok/s 🏆 |
| 🖥️ Tiny (CPU) | 🏭 Production (32M) | 🚀 Max (32B) | |
|---|---|---|---|
| dim | 128 | 512 | 4096 |
| n_layers | 2 | 8 | 32 |
| n_heads | 4 | 8 | 32 |
| params | 754K | 31.9M | ~32B |
| max_recursion | 0 (tắt) | 0 (tắt) | 4 |
| field_latent_dim | 0 (dense) | 0 (dense) | 128 |
| dtype | float32 | float32 | bf16 |
nexus/
│
├── inference/ # 🧠 Core code
│ ├── model.py # Nexus v8 architecture
│ ├── build_train.py # Training pipeline
│ ├── dataset.py # Vietnamese dataset + CoT
│ ├── chat.py # Chat interface
│ ├── eval.py # Evaluation scripts
│ └── train.py # Training script
│
├── requirements.txt # 📦 Dependencies
├── README.md # 📖 You are here
├── LICENSE # ⚖️ MIT
└── package.json # 📋 Metadata
gantt
title Nexus v8 Development Roadmap
dateFormat YYYY-MM-DD
axisFormat %m/%Y
section Phase 1 ✅ Core Completed
Architecture Design :done, 2026-01-01, 2026-03-01
Python Implementation :done, 2026-03-01, 2026-05-01
Dataset + Training Pipeline :done, 2026-05-01, 2026-06-01
section Phase 2 🚀 In Progress
Triton Kernel Optimization :active, 2026-06-01, 2026-09-01
Flash Attention Integration :2026-07-01, 2026-09-01
FP8 / NF4 Quantization :2026-08-01, 2026-10-01
section Phase 3 🔥 Future
Scale to 1B+ params :2026-10-01, 2027-01-01
HuggingFace Integration :2026-11-01, 2027-01-01
Web UI + Docker :2027-01-01, 2027-03-01
- Quantum Mixer — phase interference attention
- Recursive Program — GRU-style adaptive depth
- Emergent Memory Fabric — content-addressable ∞ context
- Neural Field Programming — weight from coordinate
- Chain-of-Thought — native
<think>tokens - CPU optimized — 37 tok/s on laptop
- Label smoothing + dropout + gradient clipping
- Triton kernels for Field materialize
- Flash attention / memory-efficient attention
- FP8 training + NF4 KV cache
- Multi-GPU data/model parallelism
- Gradient checkpointing
- Pre-trained weights (32M → 1B → 32B)
- HuggingFace model hub
- LoRA / QLoRA fine-tuning
- Gradio chat UI
- Docker + Google Colab
# 1. Fork
# 2. Clone
git clone https://github.com/YOUR_USERNAME/nexus.git
cd nexus
# 3. Branch
git checkout -b feature/ten-cua-ban
# 4. Code
# 5. Commit
git commit -m "Thêm tính năng X"
# 6. Push & PR
git push origin feature/ten-cua-ban
# → GitHub → Open Pull RequestMIT License — xem LICENSE.
|
@devtantai-coder |
Nexus AI Team 🇻🇳 Được xây dựng cho cộng đồng AI Việt Nam. Mọi đóng góp đều được chào đón ❤️ |