Module: model_manager
Model manager for downloading and caching models.
This module provides a class for downloading and caching models from various sources. Currently, it supports downloading models from Huggingface Hub and Arweave.
DownloadedModel
Bases: MlModelId
Represents a downloaded model.
This class extends the MlModelId class and adds a list of file paths to the model.
Attributes:
Name | Type | Description |
---|---|---|
file_paths |
List[Path]
|
A list of file paths to the model files. |
Source code in src/infernet_ml/utils/model_manager.py
from_model(model_id, file_paths)
classmethod
Create a DownloadedModel instance from an MlModelId instance and a list of file paths.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_id |
MlModelId
|
The MlModelId instance. |
required |
file_paths |
List[Path]
|
A list of file paths to the model files. |
required |
Returns:
Type | Description |
---|---|
DownloadedModel
|
A DownloadedModel instance. |
Source code in src/infernet_ml/utils/model_manager.py
serialize_dt(file_paths, _info)
Serialize the file paths to a list of strings. Args: file_paths: A list of file paths. _info: The field information.
Returns:
Type | Description |
---|---|
List[str]
|
A list of strings. |
Source code in src/infernet_ml/utils/model_manager.py
ModelManager
A class for downloading and caching models.
Attributes:
Name | Type | Description |
---|---|---|
cache_dir |
The directory where the models are cached. |
|
default_ml_type |
The default MLType attach to the models when downloading. |
Source code in src/infernet_ml/utils/model_manager.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
__init__(cache_dir=DEFAULT_CACHE_DIR, default_ml_type=None)
Initialize the ModelManager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_dir |
Optional[str | Path]
|
The directory where the models are cached. If None, the default cache directory is used. |
DEFAULT_CACHE_DIR
|
default_ml_type |
Optional[MLType]
|
The default MLType attach to the models when downloading. |
None
|
Returns:
Type | Description |
---|---|
A ModelManager instance. |
Source code in src/infernet_ml/utils/model_manager.py
clear_cache()
download_model(model, ml_type=None, **kwargs)
Download a model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
str | MlModelId
|
The model to download. It can be a unique model ID or an MlModel instance. |
required |
ml_type |
Optional[MLType]
|
The MLType to attach to the model when downloading. |
None
|
**kwargs |
Any
|
Additional keyword arguments to pass to the download function. |
{}
|
Returns:
Type | Description |
---|---|
ModelArtifact
|
The downloaded model. |
Source code in src/infernet_ml/utils/model_manager.py
get_cached_models(default_ml_type=None)
Get a list of cached models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default_ml_type |
Optional[MLType]
|
The default MLType to attach to the models. |
None
|
Returns:
Type | Description |
---|---|
List[BroadcastedArtifact]
|
A list of DownloadedModel instances. |
Source code in src/infernet_ml/utils/model_manager.py
has_model(model_id)
Check if a model is cached.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_id |
str | MlModelId
|
The model ID to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the model is cached, False otherwise. |