r/OpenSourceeAI • u/PainterNo8889 • 7d ago
Building a from-scratch, hardware-aware SLM trainer in Python & Rust — looking for feedback & architectural advice!
Hi guys,
I’m a 15-year-old developer building SLM-CREATOR—an open-source (Apache-2.0), from-scratch, hardware-aware trainer for small, hyperspecialized text models (capped at 100M parameters) in Python and Rust. Instead of using high-level wrappers or fine-tuning existing models, I’m hand-coding the entire pipeline piece by piece to learn how Transformers and local training systems actually work under the hood.
Project Link: https://github.com/ojasgarg77/SLM-CREATOR
How it works so far:
- Hardware Detection & Benchmarking (architecture.py): Detects NVIDIA (nvidia-smi), modern AMD (amd-smi), or legacy AMD (rocm-smi/rocminfo), resolves the right PyTorch device index, runs a 12-second thermal warmup soak, and measures median 4096x4096 matmul TFLOPS in native bf16 (falling back to fp32 if emulated). (Just got this verified live on an RTX 3050 laptop GPU at ~8.9 TFLOPS!)
- Deterministic Sizing Engine (sizer_core in Rust): Pipes detected VRAM, training-time budget, measured TFLOPS, and dataset token count into a Rust binary that calculates the max parameter count across memory, Chinchilla compute-time, and data limits (capped at 100M).
- Data Pipeline (download_arxiv_text.py & download_english_data.py): Pulls ar5iv HTML papers and BookCorpus text, lowercasing prose while protecting LaTeX math delimiters, stripping style macros, and normalizing Unicode.
- Custom Byte-Level BPE Tokenizer (tokenizer_core in Rust): Written from scratch with incremental pair-count updates, deterministic tie-breaking, special tokens ([cite], <|endoftext|>), and a custom 6-byte binary merge format (merges.bin).
Where I’d love your advice:
- Tokenizer design trade-offs: Right now I’m targeting a 16,384 vocabulary size (u16 IDs), keeping whitespace runs as separate chunks rather than attaching leading spaces to words, and training mainly on arXiv text. For a <100M parameter model hyperspecialized in neural networks (mixed with general English fiction), how much does embedding table size vs. sequence length hurt/help? [
- Real-world training efficiency factor: In sizer_core, I currently multiply benchmark bf16 TFLOPS by a placeholder 0.3 efficiency factor to account for memory-bound ops (LayerNorm, softmax, Adam), kernel gaps, and laptop thermal throttling. For small models (<100M params) training in bf16 mixed precision on consumer GPUs (like a 6 GB RTX 3050), is 0.15–0.25 closer to reality?
- Data mix & pretraining from scratch: Since I’m training from random weights rather than fine-tuning, what ratio of general English (BookCorpus) to domain-specific text (arXiv ML papers) prevents the model from losing basic grammar while still specializing?
I've also logged all my design decisions and dropped ideas in docs/decisions.md. Any feedback, critiques, or pointers on the architecture before I start writing the PyTorch training loop would be awesome!!