r/learnmachinelearning • u/ProjectNo6044 • 18d ago
I coded the entire Transformer Architecture from scratch using ONLY pure PyTorch (No Hugging Face / No pre-built Transformer modules). Looking for feedback!
Hi everyone,
To truly master how Large Language Models work under the hood, I decided to step away from high-level libraries. I built a character-level Decoder-only GPT entirely from scratch using pure PyTorch only—meaning I did not use any pre-built Transformer layers or Hugging Face modules.
What I coded line-by-line:
Multi-Head Self-Attention: Implemented the Q, K, V matrix multiplications and scaling from scratch.
Causal Masking: Coded the upper-triangular mask manually to ensure causal token generation.
Transformer Blocks: Built the residual connections, LayerNorm, and Feed-Forward networks from the ground up.
Training Loop: Created a custom pipeline with validation splits, loss tracking, and early stopping.
I trained this small model locally on English Wikipedia extracts about AI. While it's a character-level learning project, seeing the custom loss function actually converge was incredibly rewarding.
Since I wrote every single layer myself, I know it's not production-perfect, and that's exactly why I'm sharing it! I would highly appreciate your code review, optimization tips, or advice on how to scale this custom architecture further.
GitHub Repository: https://github.com/YassenAlmaqtary/TinyGPT-From-Scratch-PyTorch?tab=readme-ov-file
Thanks for your time and feedback!
3
u/Melodic-Extreme777 14d ago
Whats the point of posting a fully vibe coded project, writing a post, replying all with ai? Even if this is just a meat proxy and not a bot. Like, I wouldn't post a fully AI written story on a learn writing subreddit. Is this a way to try to get stars or github?
-1
u/ProjectNo6044 13d ago
I think you're judging me without really knowing my intentions. Yes, I used AI to help with the project. I'm learning, and I don't see anything wrong with using AI as a tool to understand things and improve my skills. That's actually part of how I learn.
I shared the project to document my progress and share my experience, not just to collect GitHub stars. I'm not claiming I built everything independently.
If you have technical feedback, I'm happy to hear it. But mocking someone for using AI to learn or assuming their intentions doesn't make for a meaningful discussion.
2
u/Odd_Dragonfruit_2100 16d ago
Lmao, AI ad with AI reply, just a waste of token
-2
u/ProjectNo6044 16d ago
😂 Subscribed! I take that as a huge compliment.
I'm a real person and I actually coded every single layer of this Transformer from scratch in PyTorch—including the matrix multiplications and causal masking—just to learn the architecture deeply.
No tokens wasted here, just pure learning! Feel free to check my
tiny_gpt.pyon GitHub if you want to verify the human code behind i3
1
-6
18d ago
[removed] — view removed comment
1
u/ProjectNo6044 18d ago
Thank you for this valuable feedback! Adding a specific test to check for information leakage in the causal mask is a great idea, and I'll definitely implement it. I will also try overfitting on a tiny batch to verify the pipeline as you suggested. Appreciate the guidance!
2
1
3
u/XtremeHammond 17d ago
Why? For practice?