File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 2727from ..configuration import BENTOML_VERSION
2828from ..configuration .containers import BentoMLContainer
2929from ..models import ModelStore
30+ from ..models import copy_model
3031from ..runner import Runner
3132from ..store import Store
3233from ..store import StoreItem
@@ -587,7 +588,16 @@ def save(
587588 if self ._model_store is not None :
588589 # Move models to the global model store, if any
589590 for model in self ._model_store .list ():
590- model .save (model_store )
591+ copied = copy_model (
592+ model .tag ,
593+ src_model_store = self ._model_store ,
594+ target_model_store = model_store ,
595+ )
596+ if not copied :
597+ logger .warning (
598+ "Model %s already exists in the global model store, skipping copy." ,
599+ model .tag ,
600+ )
591601
592602 def ignore_models (src_path : str , names : list [str ]) -> t .Iterable [str ]:
593603 if Path (src_path ) == self ._path and "models" in names :
Original file line number Diff line number Diff line change @@ -700,18 +700,20 @@ def copy_model(
700700 * ,
701701 src_model_store : ModelStore ,
702702 target_model_store : ModelStore ,
703- ):
703+ ) -> bool :
704704 """copy a model from src model store to target modelstore, and do nothing if the
705- model tag already exist in target model store
705+ model tag already exist in target model store.
706+ Returns True if the model is copied, False if the model already exists in target model store.
706707 """
707708 try :
708709 target_model_store .get (model_tag ) # if model tag already found in target
709- return
710+ return False
710711 except NotFound :
711712 pass
712713
713714 model = src_model_store .get (model_tag )
714715 model .save (target_model_store )
716+ return True
715717
716718
717719def _ModelInfo_dumper (dumper : yaml .Dumper , info : ModelInfo ) -> yaml .Node :
You can’t perform that action at this time.
0 commit comments