1 min readfrom Machine Learning

H64LM: A 249M-parameter Mixture-of-Experts Transformer built from scratch in PyTorch [P]

Our take

Introducing H64LM, a 249M-parameter Mixture-of-Experts Transformer meticulously built from scratch in PyTorch. This research project offers a unique opportunity to examine the inner workings of modern large language models by implementing core components—attention, MoE routing, and the training loop—directly. Featuring Grouped Query Attention and Sparse Mixture-of-Experts with top-2 routing, H64LM prioritizes accessibility and understanding. For those interested in model diffing techniques, consider "Contrastive Decoding Diffing (CDD)," a related article exploring recovery of finetuning data from logits. Explore the project on GitHub: [https://github.com

The recent emergence of H64LM, a 249M-parameter Mixture-of-Experts Transformer built from scratch in PyTorch, is a significant development worthy of attention. It’s not about achieving state-of-the-art performance – the author explicitly notes the model's overfitting on a WikiText-103 subset – but rather about fostering a deeper understanding of Large Language Model (LLM) architecture and training. This project stands in contrast to the increasingly abstracted and opaque nature of modern LLM development, where reliance on high-level training frameworks often obscures the underlying mechanics. This echoes concerns raised in a recent discussion about the subtle "sameness" creeping into model outputs lately [Does anyone have a name for that subtle "Sameness" creeping into model outputs lately?], suggesting a lack of fundamental architectural diversity and innovation. Furthermore, the ability to recover verbatim finetuning data from logits alone, as demonstrated in Contrastive Decoding Diffing (CDD) [Contrastive Decoding Diffing (CDD): recovering verbatim finetuning data from logits alone, no weight access needed], highlights the importance of understanding the training process itself, a goal directly addressed by H64LM’s implementation-from-scratch approach.

The decision to implement core components like attention, MoE routing, and the training loop manually is a testament to the value of granular control and experimentation. While specialized frameworks offer convenience, they can also restrict exploration and hinder the ability to truly diagnose and optimize performance. H64LM’s inclusion of features like Grouped Query Attention (GQA), sparse MoE with auxiliary routing losses, and SwiGLU activation functions demonstrates a thoughtful consideration of current architectural trends. The author’s explicit documentation of limitations, such as batch-size-1-only generation and the use of DataParallel instead of Distributed Data Parallel (DDP), also contributes to the project's transparency and utility for researchers. It's a pragmatic approach, prioritizing clarity and educational value over immediate scalability.

Beyond its technical merits, H64LM represents a valuable counterpoint to the increasing trend towards monolithic, closed-source LLMs. By openly sharing the code, the author invites feedback and encourages further investigation into the intricacies of these complex systems. This aligns with a broader movement towards democratizing AI research and fostering a community-driven understanding of LLM technology. The fact that the project is built in PyTorch, a widely adopted framework, further enhances its accessibility and potential for adaptation by others. The deliberate choice to eschew “Trainer abstractions” and implement a custom training loop signals a desire to empower users to truly grasp every aspect of the training process, moving beyond simply tweaking hyperparameters within a pre-defined framework.

Ultimately, H64LM isn’t about building the next breakthrough LLM. It’s about fostering a deeper, more accessible understanding of the building blocks that underpin these powerful models. As we continue to rely on increasingly complex AI systems, the ability to dissect, analyze, and potentially rebuild them becomes ever more crucial. The question moving forward is whether this project inspires more researchers to prioritize transparency and implement foundational components from scratch, accelerating our collective understanding of LLMs and paving the way for more innovative and controllable AI architectures.

Hi everyone,

I built H64LM, a research project to better understand modern LLMs by implementing one from scratch in PyTorch.

Instead of relying on high-level training frameworks, I implemented the core components myself attention, MoE routing, normalization, and the training loop.

Features

  • 249M-parameter Transformer
  • Grouped Query Attention (GQA)
  • Sparse Mixture-of-Experts (8 experts, Top-2 routing) with 3 auxiliary routing losses
  • SwiGLU, RoPE, RMSNorm
  • Sliding-window attention
  • Mixed-precision training, gradient accumulation
  • Custom training loop (no Trainer abstractions)
  • Checkpointing and resume support

The included checkpoint was trained on a subset of WikiText-103 to validate the pipeline end-to-end, not to be a strong model it's visibly overfit past epoch 10 (best val PPL ~40.5).

Known limitations are documented in the README, including batch-size-1-only generation and no true DDP (falls back to DataParallel).

GitHub: https://github.com/Haiderkhan64/H64LM

Feedback on the implementation or architecture is very welcome.

submitted by /u/Loose_Literature6090
[link] [comments]

Read on the original site

Open the publisher's page for the full experience

View original article