Experiment with framework
Signed-off-by: András Schmelczer <andras@schmelczer.dev>
This commit is contained in:
parent
ea54cd9c8c
commit
cef2e51c67
1 changed files with 442 additions and 251 deletions
24
good_ai/src/good_ai/models/save_model.py
Normal file
24
good_ai/src/good_ai/models/save_model.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Optional, Union
|
||||
|
||||
from joblib import dump
|
||||
from open_s3 import LargeFile
|
||||
|
||||
logger = logging.getLogger("models")
|
||||
|
||||
|
||||
def save_model(
|
||||
model: Union[Path, str, object], key: str, keep_last_n: Optional[int] = None
|
||||
) -> int:
|
||||
file = LargeFile(name=key, mode="wb", keep_last_n=keep_last_n)
|
||||
|
||||
if isinstance(model, Path) or isinstance(model, str):
|
||||
file.push(model)
|
||||
else:
|
||||
with file as f:
|
||||
dump(model, f)
|
||||
|
||||
logger.info(f"Model {key} uploaded with version {file.version}")
|
||||
|
||||
return file.version
|
||||
Loading…
Reference in a new issue