molfeat.store
¶
ModelInfo
¶
Bases: BaseModel
Source code in molfeat/store/modelcard.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 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 |
|
match(new_card, match_only=None)
¶
Compare two model card information and returns True if they are the same
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_card |
Union[ModelInfo, dict]
|
card to search for in the modelstore |
required |
match_only |
Optional[List[str]]
|
list of minimum attribute that should match between the two model information |
None
|
Source code in molfeat/store/modelcard.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
path(root_path)
¶
Generate the folder path where to save this model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root_path |
str
|
path to the root folder |
required |
Source code in molfeat/store/modelcard.py
74 75 76 77 78 79 80 81 |
|
set_usage(usage)
¶
Set the usage of the model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
usage |
str
|
usage of the model |
required |
Source code in molfeat/store/modelcard.py
103 104 105 106 107 108 109 |
|
usage()
¶
Return the usage of the model
Source code in molfeat/store/modelcard.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
get_model_init(card)
¶
Get the model initialization code
Parameters:
Name | Type | Description | Default |
---|---|---|---|
card |
model card to use |
required |
Source code in molfeat/store/modelcard.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
ModelStore
¶
A class for artefact serializing from any url
This class not only allow pretrained model serializing and loading, but also help in listing model availability and registering models.
For simplicity. * There is no versioning. * Only one model should match a given name * Model deletion is not allowed (on the read-only default store) * Only a single store is supported per model store instance
Building a New Model Store
To create a new model store, you will mainly need a model store bucket path. The default model store bucket, located at gs://molfeat-store-prod/artifacts/
, is read-only.
To build your own model store bucket, follow the instructions below:
- Create a local or remote cloud directory that can be accessed by fsspec (and the corresponding filesystem).
- [Optional] Sync the default model store bucket to your new path if you want to access the default models.
- Set the environment variable
MOLFEAT_MODEL_STORE_BUCKET
to your new path. This variable will be used as the default model store bucket when creating a new model store instance without specifying a path. Note that setting up this path is necessary if you want to access models directly by their names, without manually loading them from your custom model store.
Source code in molfeat/store/modelstore.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 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 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
available_models
property
¶
Return a list of all models that have been serialized in molfeat
__len__()
¶
Return the length of the model store
Source code in molfeat/store/modelstore.py
78 79 80 |
|
download(modelcard, output_dir=None, chunk_size=2048, force=False)
¶
Download an artifact locally
Parameters:
Name | Type | Description | Default |
---|---|---|---|
modelcard |
ModelInfo
|
information on the model to download |
required |
output_dir |
Optional[Union[PathLike, Path]]
|
path where to save the downloaded artifact |
None
|
chunk_size |
int
|
chunk size to use for download |
2048
|
force |
bool
|
whether to force download even if the file exists already |
False
|
Source code in molfeat/store/modelstore.py
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 236 237 238 239 240 241 242 243 244 |
|
exists(card=None, check_remote=False, **match_params)
¶
Returns True if a model is registered in the store
Parameters:
Name | Type | Description | Default |
---|---|---|---|
card |
Optional[ModelInfo]
|
card of the model to check |
None
|
check_remote |
bool
|
whether to check if the remote path of the model exists |
False
|
match_params |
parameters for matching as expected by |
{}
|
Source code in molfeat/store/modelstore.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
load(model_name, load_fn=None, load_fn_kwargs=None, download_output_dir=None, chunk_size=2048, force=False)
¶
Load a model by its name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name |
Union[str, dict, ModelInfo]
|
name of the model to load |
required |
load_fn |
Optional[Callable]
|
Custom loading function to load the model |
None
|
load_fn_kwargs |
Optional[dict]
|
Optional dict of additional kwargs to provide to the loading function |
None
|
download_output_dir |
Optional[Union[PathLike, Path]]
|
Argument for download function to specify the download folder |
None
|
chunk_size |
int
|
chunk size for download |
2048
|
force |
bool
|
whether to reforce the download of the file |
False
|
Returns:
Name | Type | Description |
---|---|---|
model |
Optional model, if the model requires download or loading weights |
|
model_info |
model information card |
Source code in molfeat/store/modelstore.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
register(modelcard, model=None, chunk_size=2048, save_fn=None, save_fn_kwargs=None, force=True)
¶
Register a new model to the store
!!! note save_fn
You can pass additional kwargs for your save_fn
through the save_fn_kwargs
argument.
It's expected that save_fn
will be called as : save_fn(model, <model_upload_path>, **save_fn_wargs)
,
with <model_upload_path>
being provided by the model store, and that it will return the path to the serialized model.
If not provided, joblib.dump
is used by default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
modelcard |
Union[ModelInfo, dict]
|
Model information |
required |
model |
Optional[Any]
|
A path to the model artifact or any object that needs to be saved |
None
|
chunk_size |
int
|
the chunk size for the upload |
2048
|
save_fn |
Optional[Callable]
|
any custom function for serializing the model, that takes the model, the upload path and parameters |
None
|
save_fn_kwargs |
Optional[dict]
|
any additional kwargs to pass to save_fn |
None
|
force |
bool
|
whether to force upload to the bucket |
True
|
Source code in molfeat/store/modelstore.py
82 83 84 85 86 87 88 89 90 91 92 93 94 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 |
|
search(modelcard=None, **search_kwargs)
¶
"Return all model card that match the required search parameters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
modelcard |
Optional[ModelInfo]
|
model card to search for |
None
|
search_kwargs |
search parameters to use |
{}
|
Source code in molfeat/store/modelstore.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
PretrainedModel
¶
Bases: ABC
Base class for loading pretrained models
Source code in molfeat/store/loader.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
load()
abstractmethod
¶
Load the model
Source code in molfeat/store/loader.py
40 41 42 43 |
|
PretrainedStoreModel
¶
Bases: PretrainedModel
Class for loading pretrained models from the model zoo
Source code in molfeat/store/loader.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
__init__(name, cache_path=None, store=None)
¶
Interface for pretrained model from the default modelstore
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the pretrained transformer in the model store |
required |
cache_path |
Optional[PathLike]
|
optional local cache path. |
None
|
store |
Optional[ModelStore]
|
ModelStore to use for loading the pretrained model |
None
|
Source code in molfeat/store/loader.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
load()
¶
Load the model
Source code in molfeat/store/loader.py
106 107 108 |
|