Adding Custom Models
Integrate a custom model into a NeMo Curator stage. Package model dependencies in the Python environment or image used by the pipeline.
Before You Start
Before you add a model, prepare your development environment:
- Reviewed the pipeline concepts and diagrams.
- A working NeMo Curator development environment.
- Optionally prepared a container image that includes your model dependencies.
- Optionally created a custom environment to support your new custom model.
How to Add a Custom Model
Implement ModelInterface, then provide the model to a stage that uses it.
Review Model Interface
In NeMo Curator, models inherit from nemo_curator.models.base.ModelInterface and must implement model_id_names and setup:
Create New Model
The following example defines a minimal model for demonstration.
Let’s go through each part of the code piece by piece.
Define the PyTorch Model
Provide a model ID, such as a Hugging Face identifier, to cache or fetch weights. Your model class can download weights before setup() using its model-loading method.
Implement the Model Interface
Your model implements the interface. It defines methods to declare weight identifiers and to initialize the underlying core network.
The setup method initializes the underlying MyCore class that performs the model inference.
The model_id_names property returns a list of weight IDs. These typically correspond to model repository names but do not have to.
Set GPU requirements in the stage’s resources, such as gpu_memory_gb or gpus. The stage manages GPU allocation through Resources.
Manage model weights
Set model_dir to the weights location. Mount the weights into the container or download them before the stage runs.
Next Steps
Use the model in a custom stage.