molfeat.store
¶
ModelInfo
¶
Bases: BaseModel
Source code in molfeat/store/modelcard.py
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 |
|
authors: Optional[List[str]]
class-attribute
¶
created_at: datetime = Field(default_factory=datetime.now)
class-attribute
¶
description: str
class-attribute
¶
group: Optional[str] = 'all'
class-attribute
¶
inputs: str = 'smiles'
class-attribute
¶
name: str
class-attribute
¶
reference: Optional[str]
class-attribute
¶
representation: Literal[graph, line-notation, vector, tensor, other]
class-attribute
¶
require_3D: Optional[bool] = False
class-attribute
¶
sha256sum: Optional[str]
class-attribute
¶
submitter: str
class-attribute
¶
tags: Optional[List[str]]
class-attribute
¶
type: Literal[pretrained, hand-crafted, hashed, count]
class-attribute
¶
version: int = 0
class-attribute
¶
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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
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
59 60 61 62 63 64 65 66 |
|
usage()
¶
Return the usage of the model
Source code in molfeat/store/modelcard.py
88 89 90 91 92 93 94 95 96 97 98 99 |
|
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
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 |
|
ModelStore
¶
A class emulating artefact serializing from any url
This class should not only allow pretrained model serializing and loading, but should also help in listing model availability and registering models
For simplicity. * There is no versioning. * Only one model per model name is permitted * Model deletion is not allowed * Only a single Cloud storage is supported
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 |
|
METADATA_PATH_NAME = 'metadata.json'
class-attribute
¶
MODEL_PATH_NAME = 'model.save'
class-attribute
¶
MODEL_STORE_BUCKET = 'gs://molfeat-store-prod/artifacts/'
class-attribute
¶
available_models
property
¶
Return a list of all models that have been serialized in MolFeat
model_store_bucket = model_store_bucket
instance-attribute
¶
__contains__(card=None)
¶
Source code in molfeat/store/modelstore.py
270 271 |
|
__init__(model_store_bucket=None)
¶
Source code in molfeat/store/modelstore.py
45 46 47 48 49 50 |
|
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[os.PathLike, pathlib.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
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 |
|
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
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
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[os.PathLike, pathlib.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
|
Source code in molfeat/store/modelstore.py
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 |
|
register(modelcard, model=None, chunk_size=2048, save_fn=None, save_fn_kwargs=None, force=True)
¶
Register a new model to the store
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 as inputs |
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
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 |
|
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
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
ModelStoreError
¶
Bases: Exception
Source code in molfeat/store/modelstore.py
21 22 |
|
PretrainedModel
¶
Bases: abc.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 |
|
cache_path = cache_path
instance-attribute
¶
name = name
instance-attribute
¶
store = store
instance-attribute
¶
__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[os.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 |
|