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.
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.
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.
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.
nano4M
Multimodal any-to-any generation
Generalize masked modeling across modalities. Following 4M, you train a single model that maps any subset of modalities to any other (RGB, depth, surface normals, and scene descriptions) on the MultimodalCLEVR dataset.
nanoFlow
Continuous-time generative modeling
Switch from discrete tokens to continuous data with Rectified Flow / Flow Matching and a DiT-style denoiser. Learn the velocity field that transports noise to data on MNIST and CIFAR-10.
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.
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 GitHubCitation
If you find nanoMFM useful, please consider citing it.
@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.



