Understanding Model Adapters: The Magic Behind the Scenes 🎭
Ever wondered how Dataloop seamlessly integrates with your ML models? Let's peek behind the curtain and explore the Model Adapter's inner workings!
The Two Types of Functions 🎭
Think of the Model Adapter as a theater production with two types of actors:
🎬 Wrapper Functions - The stage managers who handle all the behind-the-scenes work
- Part of the
BaseModelAdapterclass - Handle data movement, file management, and coordination
- Make your life easier by managing the complex stuff
- Part of the
🎭 User Functions - The star performers you get to direct
- Functions you implement in your
ModelAdapter - Contain your model's specific logic
- Turn your ML model into a Dataloop-ready superstar
- Functions you implement in your
Let's meet our cast of characters!
The Stage Managers: Wrapper Functions 🎬
load_from_model: The Setup Crew 📦

What happens:
- 📥 Downloads your model's artifacts
- 📂 Creates a cozy home at
~/.dataloop/models/{model.name} - 🎯 Calls your
loadfunction to bring the model to life
Your files will be organized like this:
DATALOOP_PATH/
└── models/
└── model.name/
└── artifacts/save_to_model: The Preservation Expert 💾
What happens:
- 💾 Calls your
savefunction to package up the model - ☁️ Uploads everything to Dataloop's cloud
- ✨ Keeps your model safe and sound
predict_items: The Performance Director 🎯

The show must go on! Here's how:
- 🎬 Creates batches of items
- 🎨 Prepares each batch using your
prepare_item_func - 🎯 Makes predictions using your
predictfunction - 📝 Saves the results as annotations
- 🔄 Repeats until all items are processed
train_model: The Training Coach 🏋️♂️

Your model's training journey:
- 📥 Loads the current model state
- 🎯 Prepares training data
- 🏋️♂️ Trains using your
trainfunction - 💾 Saves the improved model
- 🧹 Cleans up temporary files
Your training data will be organized like this:
DATALOOP_PATH/
└── models/
└── model.name/
└── artifacts/
└── model_data/
└── model.id_model.name/
└── timestamp/
├── output/
└── datasets/
└── dataset.id/
├── train/
│ ├── items/
│ └── json/
└── validation/
├── items/
└── json/evaluate_model: The Performance Reviewer 📊

How your model gets its report card:
- 📥 Loads the latest model version
- 🎯 Makes predictions on test data
- 📊 Compares with ground truth
- 📈 Generates performance metrics
embed_items: The Feature Vector Transformer 🎆

The embedding process:
- 🎬 Creates batches of items
- 🎨 Prepares each batch using your
prepare_item_func - 🔢 Generates embeddings using your
embedfunction - 💾 Stores the vectors in a feature set
- 🔄 Repeats until all items are processed
Your Star Performers: User Functions 🌟
Required Functions for Different Use Cases:
For Prediction Only:
load📥 - Brings your model to lifepredict🎯 - Makes predictions on data
For Training:
- Everything above, plus:
train🏋️♂️ - Teaches your model new trickssave💾 - Preserves your model's knowledge
For Embedding:
load📥 - Brings your model to lifeembed🔢 - Converts items to feature vectorsprepare_item_func🎨 - Prepares items for embedding
Function Details
load 📥
def load(self, local_path, **kwargs):
"""Load your model from files"""
self.model = YourModel.load(local_path)save 💾
def save(self, local_path, **kwargs):
"""Save your model's state"""
torch.save(self.model.state_dict(), f'{local_path}/weights.pth')train 🏋️♂️
def train(self, data_path, **kwargs):
"""Train your model on new data"""
# Your training logic here
passpredict 🎯
def predict(self, batch, **kwargs):
"""Make predictions and return Dataloop annotations"""
predictions = self.model(batch)
return convert_to_annotations(predictions)prepare_item_func 🎨
def prepare_item_func(self, item):
"""Prepare items for prediction"""
return preprocess_for_model(item)embed 🔢
def embed(self, batch, **kwargs):
"""Convert a batch of items into embedding vectors"""
embeddings = self.model.encode(item)
return embeddingsPro Tips for Model Adapter Success 💡
Error Handling 🛡️
- Add proper logging in each function
- Handle edge cases gracefully
- Validate inputs and outputs
Performance ⚡
- Optimize batch processing
- Use efficient data loading
- Clean up temporary files
Best Practices 📋
- Document your functions clearly
- Follow the function signatures
- Test each component thoroughly
Need more help? Check out our example implementations🚀