ML in a Box: Analyzing Containerization Practices in Open Source ML Projects
This paper presents the first large-scale empirical study of 1,993 open-source ML Dockerfiles, revealing that while containers serve distinct roles in ML workflows, they are often large and inefficient due to frequent rebuilds triggered by experimentation, prompting the identification of seven specific refactoring patterns to improve build efficiency and reduce footprint.
Original paper dedicated to the public domain under CC0 1.0 (http://creativecommons.org/publicdomain/zero/1.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you're a chef running a massive, high-tech kitchen. In the world of Machine Learning (ML), your "recipes" are code, your "ingredients" are data and models, and your "kitchen" is a container. A container is like a self-contained, portable kitchen box that holds everything you need to cook a specific dish, ensuring it tastes the same whether you're cooking in New York, Tokyo, or on a spaceship.
For a long time, people knew these kitchen boxes were useful. But nobody really knew how big they were, how long they took to pack, or how often the chefs had to throw the whole box away and start over just because they moved a single spice jar.
A team of researchers decided to peek inside 1,993 of these ML kitchen boxes from 392 different projects to see what was really going on. Here is what they found, served up with a side of reality.
The "Kitchen Box" Sizes: It's a Big Deal
First, they weighed the boxes. You might think a container is light and snappy, but these ML boxes are giants.
- On average, a container weighs 10.27 GB. That's like carrying a whole library of encyclopedias in your backpack just to make a sandwich.
- The "Training" boxes (where the AI learns) are the heaviest, averaging 17.25 GB. Some of these monsters even hit 125 GB!
- The "Inference" boxes (where the AI just does the work) are smaller, around 1.72 GB, but still not exactly pocket-sized.
And packing these boxes? It takes time. The average "cold build" (packing a box from scratch) takes 8.84 minutes. For the big training boxes, it can take over 14 minutes. That's a long time to wait just to see if your code works.
The "Oops" Moment: Why We Throw Boxes Away
Here is the tricky part. In a normal kitchen, if you change a recipe, you just tweak the instructions. But in the ML world, the kitchen works on a strict "layer" system. Imagine building a tower of blocks. If you change the color of the third block, you have to take apart the third, fourth, fifth, and all the way to the top, even if the top blocks didn't change at all.
The researchers found that 44.4% of all the changes developers made to their projects triggered a total rebuild of the container. That means nearly half the time, they were throwing away all that hard work and starting over.
What caused the throw-away?
It wasn't usually the recipe itself (the Dockerfile). It was the ingredients!
- 96.4% of the rebuilds happened because someone changed a file that got copied inside the box (like a dataset or a code file).
- Only 1.1% of rebuilds were because someone changed the actual instructions on how to build the box.
The Waste: 70% of the Work is for Nothing
This is the saddest part of the story. When the "layer tower" breaks, the kitchen tries to reuse the blocks it already built. But the researchers found that 71% of the work was wasted.
- Think of it like this: You spend 10 minutes building a tower of blocks. You knock over the third block. You try to reuse the first two blocks, but then you have to rebuild the rest. In the end, you only reused about 30% of your effort. The other 70% was just re-doing work you already did.
Why does this happen?
It depends on what you are changing.
- If you are tweaking the experiment (changing the AI's brain or data), you are the most likely to break the tower. This happens 46% of the time for training boxes.
- If you are updating the infrastructure (like the kitchen's plumbing or electricity), you almost always break the tower, and you lose almost all your progress.
The Good News: Smart Chefs Found Shortcuts
Despite the mess, the researchers found that some smart chefs were already fixing these problems. They looked at the "best" kitchens (those that wasted the least time) and found 7 specific tricks they used to stop the waste. These aren't just guesses; they are real changes developers made that actually worked.
Here are the 7 tricks:
- Don't pack the groceries: Instead of copying huge datasets into the box, just tell the box where to find them when it starts cooking.
- Don't pack the model: Same for the AI model itself. Don't bake it into the box; load it from the outside when needed.
- Move the heavy lifting: If you have to download a big model, do it early in the recipe. That way, if you change a small file later, the big download stays cached (saved).
- Split the kitchen: If you need a box for both CPUs and GPUs, don't make one giant box with everything. Make two smaller, specialized boxes.
- Pick the right tools: Don't install the "GPU version" of a tool if you only need the "CPU version." It saves a ton of space.
- Move the volatile stuff: If you change your config files often, put them after the big installations in the recipe so they don't break the heavy layers.
- Don't download the whole history: When grabbing code from the internet, don't download the entire history of the project. Just grab the latest snapshot.
The Bottom Line
The paper doesn't say these problems are "solved." It says that right now, ML containers are huge, slow, and fragile. Developers are wasting a massive amount of time (about 70% of their rebuild effort) because they are packing too much stuff into the box and breaking the cache too early.
But, the good news is that we know how to fix it. By using these 7 tricks, teams can make their containers smaller and their builds faster. It's not magic; it's just better organization. The researchers measured all of this by actually building the boxes and counting the minutes, so we know these numbers are real. The next time you see a machine learning project, remember: it's not just about the code; it's about how you pack the kitchen.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.