EPFL ยท VILAB ยท Educational Release

nanoMFM

Learn to build multimodal generative foundation models from scratch.

Minimal, readable implementations of GPT, MaskGIT, 4M, Flow Matching, and a VLM, each built step by step through guided notebooks, trained on toy datasets with modest compute.

Taught in CS-503 Visual Intelligence & COM-304 Intelligent Systems at EPFL.

What is this?

nanoMFM is an educational codebase that teaches the modeling fundamentals behind modern generative and multimodal models. It strips each idea down to its essentials so you can read every line, fill in the gaps, and train a working model yourself, without getting lost in engineering overhead.

โœ๏ธ Exercises & notebooks

Each module ships a Jupyter notebook that walks you through the implementation, training, and inference. You fill in the TODO gaps in the exercise stubs, train your model, and visualize its predictions.

๐Ÿš€ Get started right away

Prefer to tinker? A complete reference implementation is included. Switch between modes with a single environment variable: NANOMFM_EXERCISES=1 for stubs, unset for solutions.

Designed to be minimal. Relatively small datasets (TinyStories, MNIST, CIFAR-10, MultimodalCLEVR, and The Cauldron / MMStar for the VLM) and small models keep compute modest. Everything was tested on 1โ€“4 V100 GPUs. The fundamentals you learn here translate directly when scaled up.

The Modules

Five self-contained modules, building from a single-stream language model up to multimodal any-to-any generation and vision-language understanding.

Suggested order: for the first three, we recommend nanoGPT โ†’ nanoMaskGIT โ†’ nano4M. The last two (nanoFlow and nanoVLM) are more independent. In general you can start wherever you like, since every module is self-contained.

01

nanoGPT

Autoregressive transformer for language & image generation

Start with the foundation: a GPT-style decoder-only transformer trained next-token prediction on TinyStories and MNIST. Implement attention and the transformer trunk.

nanoGPT generating a TinyStories story one token at a time
Generated by nanoGPT trained on TinyStories.
nanoGPT generating MNIST digits 0-9
Generated by nanoGPT trained on MNIST.
02

nanoMaskGIT

Generation via unimodal masked modeling

Move from left-to-right to parallel, iterative decoding. Inspired by MaskGIT, you generate images (and text) by progressively unmasking tokens, the masked-modeling recipe that also powers recent diffusion-style language models like LLaDA.

All 10 MNIST digits being unmasked step by step by nanoMaskGIT
Generated by nanoMaskGIT trained on MNIST.
nanoMaskGIT iteratively unmasking a TinyStories text sequence
Generated by nanoMaskGIT trained on TinyStories.
05

nanoVLM

Vision-language model for image understanding & VQA

Bring it together into a vision-language model. Following LLaVA, you connect a vision encoder to a language model through a lightweight projector and train for captioning and visual question answering on The Cauldron, evaluating on MMStar.

nanoVLM answering a visual question: 'What are the cats doing?' produces 'Sleeping'
Answered by nanoVLM trained on The Cauldron.

Get Started

All exercise scripts and their corresponding notebooks are provided in our GitHub repository. Follow the setup and usage instructions at the link below to get started.

View on GitHub

Citation

If you find nanoMFM useful, please consider citing it.

BibTeX
@misc{bachmann2026nanomfm,
  author    = {Bachmann, Roman and Gao, Zhitong and Khattak, Muhammad Uzair and Ye, Mingqiao and Zamir, Amir},
  title     = {nanoMFM: Educational Multimodal Foundation Models},
  publisher = {GitHub},
  year      = {2026},
  url       = {https://github.com/EPFL-VILAB/nanoMFM}
}

Acknowledgments

nanoMFM was initiated, designed, and organized by Roman Bachmann, Zhitong Gao, Muhammad Uzair Khattak, and Mingqiao Ye, who also developed the core project structure and warm-up materials.

We thank Jason Toskov, Ali Garjani, Wonjun Kim, Efe Tarhan, Vikhyat Agrawal, Ismail Hammami, Naser Kazemi, Alexander Ertl, Kunal Singh, Rishubh Singh, Jess Sun, and Najla Sadek for reviewing and testing the notebooks during development and prior to release.

We are grateful to all members of VILAB and the teaching staff of CS-503 and COM-304, whose feedback, testing, and organizational support helped improve the materials and make this release possible.