This repository implements a 3-tiered Docker image architecture for deploying ML models with KServe.
┌────────────────────┐
│ │
│ Model Layer │ (e.g., GLiNER, BERT, etc.)
│ (Level 3) │ Model-specific implementation
│ │
├────────────────────┤
│ │
│ Framework Layer │ (e.g., PyTorch, TensorFlow)
│ (Level 2) │ Framework-specific base classes
│ │
├────────────────────┤
│ │
│ Base Layer │ (CPU or GPU)
│ (Level 1) │ Common dependencies and utilities
│ │
└────────────────────┘
The foundation of our image stack provides:
Location: common/base/{cpu,gpu}/
Built on top of the base layer, specialized for specific ML frameworks:
Location: common/kserve/{torch,tensorflow}/{cpu,gpu}/
The application-specific layer that implements:
Location: models/{model_name}/
docker volume create model-volume
download.py script in the OCI directory to download the model/oci directory):
# Run a temp container with the volume attached
docker run -d --name temp-container -v model-volume:/model-volume alpine tail -f /dev/null
# Copy the files
docker cp florence-2-large temp-container:/model-volume/
# Stop and remove the temp container
docker stop temp-container
docker rm temp-container
Images should be built in order from base to model layer:
# 1. Build the base layer
docker build -f common/base/gpu/Dockerfile.gpu -t cfg-ms-base-gpu .
# OR
docker build -f common/base/cpu/Dockerfile.cpu -t cfg-ms-base-cpu .
# 2. Build the framework layer
docker build -f common/kserve/torch/gpu/Dockerfile.torch.gpu -t torch-gpu:latest .
# OR
docker build -f common/kserve/torch/cpu/Dockerfile.torch.cpu -t cfg-ms-torch-cpu .
# 3. Build the model layer
docker build -f models/gliner/Dockerfile --build-arg MODE=gpu -t gliner-predictor:gpu .
# OR
docker build -f models/gliner/Dockerfile --build-arg MODE=cpu -t gliner-predictor:cpu .
To create a new model implementation:
Create a new directory under models/
Implement a class that inherits from the appropriate framework base class
Implement the required load() and process_request() methods
Add a simple entry point using the base class's serve() method
Create a Dockerfile that builds upon the appropriate framework image
Add a readme file with the following info:
The kserve_torch package (and similar framework packages) provides base classes to standardize model implementations:
# Example model implementation
from kserve_torch import BaseTorchModel # This is imported as a pip packaged installed in the layer 2 image
class MyModel(BaseTorchModel):
def load(self):
# Model-specific loading code
async def process_request(self, request):
# Model-specific inference code
if __name__ == "__main__":
BaseTorchModel.serve(model_class=MyModel)
Docker images are built and pushed when changes are detected at any of the image levels on merges into the main branch.
See the OCI_README.md for instructions on how to build and run OCI images for the models.
Local development should be done using Docker due to the dependency architecture.
47 commits
Python
90.2%
Dockerfile
7.4%
Batchfile
2.4%
This repository implements a 3-tiered Docker image architecture for deploying ML models with KServe.
┌────────────────────┐
│ │
│ Model Layer │ (e.g., GLiNER, BERT, etc.)
│ (Level 3) │ Model-specific implementation
│ │
├────────────────────┤
│ │
│ Framework Layer │ (e.g., PyTorch, TensorFlow)
│ (Level 2) │ Framework-specific base classes
│ │
├────────────────────┤
│ │
│ Base Layer │ (CPU or GPU)
│ (Level 1) │ Common dependencies and utilities
│ │
└────────────────────┘
The foundation of our image stack provides:
Location: common/base/{cpu,gpu}/
Built on top of the base layer, specialized for specific ML frameworks:
Location: common/kserve/{torch,tensorflow}/{cpu,gpu}/
The application-specific layer that implements:
Location: models/{model_name}/
docker volume create model-volume
download.py script in the OCI directory to download the model/oci directory):
# Run a temp container with the volume attached
docker run -d --name temp-container -v model-volume:/model-volume alpine tail -f /dev/null
# Copy the files
docker cp florence-2-large temp-container:/model-volume/
# Stop and remove the temp container
docker stop temp-container
docker rm temp-container
Images should be built in order from base to model layer:
# 1. Build the base layer
docker build -f common/base/gpu/Dockerfile.gpu -t cfg-ms-base-gpu .
# OR
docker build -f common/base/cpu/Dockerfile.cpu -t cfg-ms-base-cpu .
# 2. Build the framework layer
docker build -f common/kserve/torch/gpu/Dockerfile.torch.gpu -t torch-gpu:latest .
# OR
docker build -f common/kserve/torch/cpu/Dockerfile.torch.cpu -t cfg-ms-torch-cpu .
# 3. Build the model layer
docker build -f models/gliner/Dockerfile --build-arg MODE=gpu -t gliner-predictor:gpu .
# OR
docker build -f models/gliner/Dockerfile --build-arg MODE=cpu -t gliner-predictor:cpu .
To create a new model implementation:
Create a new directory under models/
Implement a class that inherits from the appropriate framework base class
Implement the required load() and process_request() methods
Add a simple entry point using the base class's serve() method
Create a Dockerfile that builds upon the appropriate framework image
Add a readme file with the following info:
The kserve_torch package (and similar framework packages) provides base classes to standardize model implementations:
# Example model implementation
from kserve_torch import BaseTorchModel # This is imported as a pip packaged installed in the layer 2 image
class MyModel(BaseTorchModel):
def load(self):
# Model-specific loading code
async def process_request(self, request):
# Model-specific inference code
if __name__ == "__main__":
BaseTorchModel.serve(model_class=MyModel)
Docker images are built and pushed when changes are detected at any of the image levels on merges into the main branch.
See the OCI_README.md for instructions on how to build and run OCI images for the models.
Local development should be done using Docker due to the dependency architecture.
47 commits
Python
90.2%
Dockerfile
7.4%
Batchfile
2.4%