---
title: "Efficient MultiModal Data Pipeline"
description: "Data loading, not the model or hardware, was the bottleneck in nanoVLM training: naive pad-to-longest batching wasted roughly 60% of each batch on padding tokens."
url: "https://swe.quest/articles/efficient-multimodal-data-pipeline-3f526635f068dafd"
canonical: "https://huggingface.co/blog/mmdp"
source: "Hugging Face"
published: "2025-07-08"
difficulty: "medium"
kind: "How-to"
reading_minutes: 9
tags: ["model-training","data-pipelines","python","algorithms","performance"]
---

# Efficient MultiModal Data Pipeline

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2025-07-08, 9 min read, How-to. Original: [https://huggingface.co/blog/mmdp](https://huggingface.co/blog/mmdp)

## Summary

Data loading, not the model or hardware, was the bottleneck in nanoVLM training: naive pad-to-longest batching wasted roughly 60% of each batch on padding tokens. The pipeline is rebuilt step by step, first with a fixed max length that drops long samples, then by treating batching as a knapsack/bin-packing problem using a PyTorch IterableDataset, worker sharding and a producer-consumer queue. Greedy packing is compared with First Fit Decreasing on toy data. The final ConstantLengthDataset applies a balanced greedy knapsack that respects both token and image budgets, an approach taken from NVIDIA's Eagle 2 paper, and produces dense multimodal batches with minimal padding.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Data pipelines](https://swe.quest/tags/data-pipelines.md) (Data & databases)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- PyTorch DataLoader and datasets
- tokenization and padding
- vision-language model training ([easy posts on Computer vision](https://swe.quest/tags/computer-vision.md?difficulty=easy))

## Keywords

nanoVLM, PyTorch, IterableDataset, First Fit Decreasing, Eagle 2, ConstantLengthDataset

## Related posts

- [Boost your throughput with dynamic batching](https://swe.quest/articles/boost-your-throughput-with-dynamic-batching-c7c722ba8af78c33.md): Modal · 2024-09-16 · Medium · 4 min read · Inference & serving, Performance engineering, Serverless, Python
  Modal added a \`@modal.batched()\` decorator that groups incoming requests into batches flushed when either \`max\_batch\_size\` is reached or \`wait\_ms\` elapses, avoiding the unbounded waits of fixed-size batching.
- [nanoVLM: The simplest repository to train your VLM in pure PyTorch](https://swe.quest/articles/nanovlm-the-simplest-repository-to-train-your-vlm-in-pure-pytorch-58371792838c4fd0.md): Hugging Face · 2025-05-21 · Medium · 9 min read · Model training, Computer vision, LLMs, Python
  nanoVLM is a minimal, readable pure-PyTorch toolkit for training small Vision Language Models, inspired by nanoGPT and runnable on a free Colab notebook.
- [Prefill and Decode for Concurrent Requests - Optimizing LLM Performance](https://swe.quest/articles/prefill-and-decode-for-concurrent-requests-optimizing-llm-performance-66a6db57e54903ca.md): Hugging Face · 2025-04-16 · Medium · 10 min read · Inference & serving, LLMs, Performance engineering, Hardware
  LLM token generation splits into a compute-bound prefill phase, which processes all prompt tokens in parallel to produce the first token, and a memory-bandwidth-bound decode phase, which produces later tokens one at a time.
- [PRX Part 4: Our Data Strategy](https://swe.quest/articles/prx-part-4-our-data-strategy-65ac8355bac33db9.md): Hugging Face · 2026-07-06 · Hard · 20 min read · Model training, Data pipelines, Computer vision, Machine learning
  PRX's pre-training corpus for a 7B text-to-image model is assembled from public and internal datasets, re-captioned with a VLM into long dense paragraphs, curated in Lance and streamed to training as Mosaic Data Shards.
- [Serving MiniMax-M3 for efficient inference: Unlocking 1M-Token Context and Multimodality Without Regrets](https://swe.quest/articles/serving-minimax-m3-for-efficient-inference-unlocking-1m-token-context-and-b95aa870c48b5834.md): Together AI · 2026-06-02 · Hard · 7 min read · Inference & serving, LLMs, Performance engineering, Hardware
  Serving MiniMax M3, a 1M-context multimodal model built on block-sparse MiniMax Sparse Attention (MSA), took several engine and kernel changes that together raised throughput 81–125% across concurrency levels on agentic traffic.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
