To prepare a model version to be served in ⚗️ Instill Model, please follow these steps on your local system:
- Install the latest Python 📦 Instill SDK:
pip install instill-sdk
- Create an empty folder for your custom model and run the
init
command to generate required files, with sample codes and comments that describe their function
instill init
- Modify the model config file (
instill.yaml
) to describe your model's dependencies. - Modify the
model.py
file which defines the model class that will be decorated into a servable model with the Python 📦 Instill SDK. - Organize the repository files into a valid model layout.
#Model Configuration
Model configuration is handled within the instill.yaml
file that accompanies
the model. It describes the models necessary dependency information and is
crucial for reproducibility, sharing and discoverability.
In the instill.yaml
file, you are can specify the following details:
- build:
- gpu:
- Required:
boolean
- Description: Specifies if the model needs GPU support.
- Required:
- python_version:
- Required:
string
- Supported Versions:
3.11
- Required:
- cuda_version:
- Optional:
string
- Supported Versions:
11.5
,11.6
,11.7
,11.8
,12.1
- Default: Defaults to
11.8
if not specified or empty.
- Optional:
- python_packages:
- Optional:
list
- Description: Lists packages to be installed with
pip
.
- Optional:
- system_packages:
- Optional:
list
- Description: Lists packages to be installed from the
apt
package manager. The model image is based onUbuntu 22.04 LTS
.
- Optional:
- gpu:
Below is an example instill.yaml
for the
TinyLlama model:
#Model Layout
To deploy a model in ⚗️ Instill Model, we suggest you prepare the model files similar to the following layout:
.├── instill.yaml├── model.py├── <additional_modules>└── <weights> ├── <weight_file_1> ├── <weight_file_2> ├── ... └── <weight_file_n>
The above layout displays a typical model in ⚗️ Instill Model consisting of
instill.yaml
- model config file that describe the model dependenciesmodel.py
- a decorated model class that contains custom inference logic<additional_modules>
- a directory that holds supporting python modules if necessary<weights>
- a directory that holds the weight files if necessary
You can name the <weights>
and <additional_modules>
folders freely provided
that they can be properly loaded and used by the model.py
file.
#Prepare Model Code
To implement a custom model that can be deployed and served in ⚗️
Instill Model, you only need to construct a simple model class within the
model.py
file.
The custom model class is required to contain two methods:
__init__
This is where the model loading process is defined, allowing the weights to be stored in memory and yielding faster auto-scaling behavior.__call__
This is the inference request entrypoint, and is where you implement your model inference logic.
Also you will need to determine which AI task spec your model will be following. By using the
parse_task_***_to_***_input
, it will convert the request input into easy-to-use dataclassconstruct_task_xxx_output
, it will convert various standard type output into response format
Below is a simple example implementation of the TinyLlama model with explanations:
Once all the required model files are prepared, please refer to the Build Model Image and Push Model Image pages for further information about creating and pushing your custom model image to ⚗️ Instill Model in 🔮 Instil Core or on ☁️ Instill Cloud.