Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[updater] update models 110 to 130 #1218

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
387f91c
WIP
Sep 7, 2022
278ceaa
WIP
Sep 7, 2022
245a827
Merge branch 'dev' into zzw/dev-update
Sep 8, 2022
864de7b
Merge branch 'dev' into zzw/dev-update
Sep 8, 2022
a2a8108
WIP
Sep 9, 2022
1596d89
update
Sep 9, 2022
f70b8f5
Merge branch 'dev' into zzw/dev-update
Sep 9, 2022
e4c3188
update
Sep 9, 2022
26bd415
move sandbox.py to common utils;
Sep 10, 2022
c184dda
update
Sep 10, 2022
b865b2f
add sandbox state: SANDBOX_STATE_UNKNOWN
Sep 10, 2022
1a221e9
WIP: test cases for invoker_cmd_sandbox_version.py
Sep 10, 2022
6ff5e82
add RequestType.SANDBOX_VERSION
Sep 11, 2022
d82b282
fix invoker_cmd_sandbox_version test case
Sep 11, 2022
b53fdc0
controller: fix flake8 and mypy errors
Sep 11, 2022
71d1a13
update
Sep 11, 2022
1741250
update
Sep 11, 2022
1201e11
Merge branch 'dev' into zzw/dev-update
Sep 11, 2022
c984aa1
update
Sep 11, 2022
b7a4dba
update
Sep 11, 2022
738207d
remove unused imports
Sep 11, 2022
d63ca26
update
Sep 11, 2022
1f09d7f
fix ymir 1.1.0 mir_command files
Sep 11, 2022
3b9f985
update
Sep 11, 2022
167a64a
update
Sep 12, 2022
9e8184f
update
Sep 12, 2022
34f26bf
WIP
Sep 12, 2022
d2168de
get mir_command_pb2 from git
Sep 12, 2022
d965b37
update
Sep 12, 2022
30626a5
Merge branch 'zzw/dev-update' into zzw/dev-update-110-130
Sep 12, 2022
cff3163
update
Sep 12, 2022
097422e
Merge branch 'zzw/dev-update' into zzw/dev-update-110-130
Sep 12, 2022
6c814f5
add env version check
Sep 13, 2022
2fa9a0f
unchange main.py for ymir_app
Sep 13, 2022
304ec2a
Merge branch 'dev' into zzw/dev-update
fenrir-z Sep 13, 2022
8d4b093
Merge branch 'zzw/dev-update' into zzw/dev-update-110-130
Sep 13, 2022
0c6a7ed
Merge branch 'dev' into zzw/dev-update
Sep 13, 2022
ba1e709
Merge branch 'zzw/dev-update' into zzw/dev-update-110-130
Sep 13, 2022
7dc9fcb
Merge branch 'dev' into zzw/dev-update
Sep 13, 2022
c6375ec
Merge branch 'zzw/dev-update' into zzw/dev-update-110-130
Sep 13, 2022
f126aa2
Merge branch 'dev' into zzw/dev-update
fenrir-z Sep 14, 2022
683bd41
Merge branch 'zzw/dev-update' into zzw/dev-update-110-130
Sep 14, 2022
a1bf289
Merge branch 'dev' into zzw/dev-update
fenrir-z Sep 16, 2022
23098a9
update
Sep 16, 2022
f7dc77d
Merge branch 'dev' into zzw/dev-update
Sep 17, 2022
0905167
update
Sep 17, 2022
a0c9eca
app, ctl and cmd use YMIR_VERSION from mir/version.py
Sep 17, 2022
961f269
using YMIR_VERSION from mir.version
Sep 17, 2022
21296a0
update
Sep 17, 2022
3493904
remove SandboxInfo
Sep 17, 2022
436c1ef
update
Sep 17, 2022
4c7df68
update
Sep 17, 2022
99970b0
UpdateErrorCode -> UpdaterErrorCode
Sep 17, 2022
3f517a3
Merge branch 'zzw/dev-update' into zzw/dev-update-110-130
Sep 17, 2022
33b34a9
WIP
Sep 18, 2022
83ee2a6
update test case for controller sandbox version invoker
Sep 18, 2022
6ee84c2
update
Sep 18, 2022
a64e29d
update
Sep 19, 2022
2e56cc6
update
Sep 19, 2022
f2921e8
Merge branch 'zzw/dev-update' into zzw/dev-update-110-130
Sep 19, 2022
4a1e14a
update
Sep 19, 2022
7b6f3ec
update
Sep 19, 2022
2b825d5
Merge branch 'zzw/dev-update' into zzw/dev-update-110-130
Sep 19, 2022
3b91a6f
update
Sep 19, 2022
1c2a809
update
Sep 19, 2022
8601751
update
Sep 19, 2022
958e996
update
Sep 19, 2022
732eb65
Merge branch 'dev' into zzw/dev-update
fenrir-z Sep 20, 2022
209697d
revert deps.py
Sep 20, 2022
4756455
update
Sep 20, 2022
01a6902
update
Sep 20, 2022
a66f404
update
Sep 20, 2022
018add6
labels.py: add validator for ymir_version
Sep 20, 2022
6c108e9
remove update_errors
Sep 20, 2022
7f6007e
remove some unused error codes
Sep 20, 2022
4bd8f0f
update doc
Sep 20, 2022
20cf049
Merge branch 'zzw/dev-update' into zzw/dev-update-110-130
Sep 20, 2022
713420f
update
Sep 20, 2022
739a49c
labels.py: change validator
Sep 20, 2022
698b412
remove EXPECTED_YMIR_VERSION
Sep 20, 2022
4b515ac
update
Sep 20, 2022
c2d8f4f
update
Sep 20, 2022
8ea7ac6
update
Sep 20, 2022
15287d7
Merge branch 'dev' into zzw/dev-update
fenrir-z Sep 20, 2022
39f1024
split sandbox.py into sandbox_util.py and sandbox_updater.py
Sep 20, 2022
3efb596
update
Sep 20, 2022
8a8e289
Merge branch 'dev' into zzw/dev-update
Sep 20, 2022
6e1be1d
update
Sep 20, 2022
e48b745
Merge branch 'dev' into zzw/dev-update
fenrir-z Sep 21, 2022
ed59371
update
Sep 21, 2022
98fd1b5
SANDBOX_VERSION -> CMD_VERSION_GET
Sep 21, 2022
2e2a778
update
Sep 21, 2022
dfa3898
update
Sep 21, 2022
f33c889
update
Sep 21, 2022
1098fd5
Merge branch 'zzw/dev-update' into zzw/dev-update-110-130
Sep 21, 2022
19596ce
Merge branch 'dev' into zzw/dev-update-110-130
Sep 21, 2022
f78d639
Merge branch 'dev' into zzw/dev-update-110-130
Sep 23, 2022
c8a9d05
update ignore files; add some logging to sandbox_util
Sep 23, 2022
b2fc173
Merge branch 'dev' into zzw/dev-update-110-130
Sep 24, 2022
ca4dd53
update
Sep 24, 2022
02c9d41
WIP
Sep 24, 2022
9c6d618
fix dependency of step updater 110 to 130
Sep 24, 2022
029393c
update mirpb for 130
Sep 24, 2022
6eb69f9
add mso110 as reader
Sep 25, 2022
e0e3103
WIP: step updater
Sep 25, 2022
e28a066
Merge branch 'dev' into zzw/dev-update-110-130
fenrir-z Sep 26, 2022
6c9bb8a
WIP
Sep 27, 2022
1e04c85
move some functions from mir_storage to mir_storage_ops
Sep 27, 2022
1fbdba9
Merge branch 'zzw/ref-mir-storage' into zzw/dev-update-110-130
Sep 27, 2022
b5641b6
update
Sep 27, 2022
50cebad
Merge branch 'zzw/ref-mir-storage' into zzw/dev-update-110-130
Sep 27, 2022
99a9eb5
update
Sep 27, 2022
1f34755
WIP
Sep 27, 2022
7a1051c
110 -> 130 update dev done
Sep 27, 2022
aa5935f
add user labels updater
Sep 27, 2022
d897c51
remove git config file mode false from dockerfile backend (moved into…
Sep 27, 2022
66cf741
add step updater doc;
Sep 27, 2022
643db5b
Merge branch 'dev' into zzw/dev-update-110-130
Sep 27, 2022
585f36c
add class_names when training finished
Sep 27, 2022
95c0935
Merge branch 'dev' into zzw/ref-mir-storage
fenrir-z Sep 27, 2022
99a06b4
Merge branch 'zzw/ref-mir-storage' into zzw/dev-update-110-130
Sep 27, 2022
bf953e6
update
Sep 27, 2022
e359f50
revert changes
Sep 27, 2022
8b8b0aa
Merge branch 'zzw/ref-mir-storage' into zzw/dev-update-110-130
Sep 27, 2022
d0c7395
revert changes to mir storage ops in ymir-cmd
Sep 27, 2022
e4315ff
remove unused code
Sep 27, 2022
f7a8257
Merge branch 'dev' into zzw/dev-update-110-130
Sep 28, 2022
8e57dde
update
Sep 28, 2022
4794034
Merge branch 'dev' into zzw/dev-update-110-130
fenrir-z Sep 28, 2022
0dec7d8
add update sub command to ymir.sh
Sep 28, 2022
1de643c
Merge branch 'dev' into zzw/dev-update-110-130
fenrir-z Sep 28, 2022
ee0076b
Merge branch 'dev' into zzw/dev-update-110-130
Sep 28, 2022
31bced2
update
Sep 28, 2022
19c047f
update
Sep 28, 2022
4b1757e
Merge branch 'dev' into zzw/dev-update-110-130
fenrir-z Sep 28, 2022
f8cb1d7
update
Sep 28, 2022
9424b6d
rename variables
Sep 28, 2022
11eb7bb
update
Sep 28, 2022
67cce62
add update_proto_py in step updater 110->130
Sep 29, 2022
98a8f1a
ignore all pyi files in ymir updater
Sep 29, 2022
ab0fb00
remove pyi files
Sep 29, 2022
4bfa26e
update ignore
Sep 29, 2022
7491746
Merge branch 'dev' into zzw/dev-update-110-130
fenrir-z Sep 29, 2022
eb265f1
WIP: updating models
Sep 29, 2022
7af58b0
Merge branch 'dev' into zzw/dev-update-110-130
Sep 29, 2022
86f29f9
Merge branch 'zzw/dev-update-110-130' into zzw/dev-update-110-130-models
Sep 29, 2022
85de2ff
add a smaller pydantic module;
Sep 30, 2022
c60799e
Merge branch 'dev' into zzw/dev-update-110-130
fenrir-z Sep 30, 2022
7acf271
WIP
Sep 30, 2022
b0c7905
stop service before update
Sep 30, 2022
c3c0cd4
Merge branch 'zzw/dev-update-110-130' into zzw/dev-update-110-130-models
Sep 30, 2022
5447b79
update model structure
Sep 30, 2022
2ba56d9
Merge branch 'dev' into zzw/dev-update-110-130
fenrir-z Sep 30, 2022
14cb96d
update
Sep 30, 2022
6c78d25
Merge branch 'zzw/dev-update-110-130' into zzw/dev-update-110-130-models
Sep 30, 2022
3fb6345
update
Sep 30, 2022
5ad7247
Merge branch 'dev' into zzw/dev-update-110-130-models
fenrir-z Sep 30, 2022
eaf9587
update
Sep 30, 2022
ed29bba
Merge branch 'dev' into zzw/dev-update-110-130-models
Sep 30, 2022
c993e18
Merge branch 'dev' into zzw/dev-update-110-130-models
fenrir-z Sep 30, 2022
8e3853e
update
Sep 30, 2022
5e3f2cc
Merge branch 'dev' into zzw/dev-update-110-130-models
Oct 9, 2022
b17313e
add ymir version to model package
Oct 9, 2022
8b247e3
update
Oct 9, 2022
6e2d679
Merge branch 'dev' into zzw/dev-update-110-130-models
fenrir-z Oct 9, 2022
0aafc11
update
Oct 9, 2022
e62b02b
update
Oct 9, 2022
fcca059
update
Oct 9, 2022
36011eb
update
Oct 9, 2022
2583bb0
update
Oct 9, 2022
6a460a2
in ymir-info.yaml: ymir_version -> package_version
Oct 9, 2022
e1f9073
set backup dir to sandbox/ymir-models-bk and sandbox/sandbox-bk
Oct 9, 2022
247e4bd
update
Oct 9, 2022
0002e27
update
Oct 9, 2022
f577e3c
update
Oct 9, 2022
b599668
update
Oct 9, 2022
7a9c44e
in ModelStorage: package_version is a required field
Oct 9, 2022
65b95e7
check model structure before update
Oct 9, 2022
77b2f8b
update
Oct 9, 2022
629db58
update
Oct 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
76 changes: 48 additions & 28 deletions ymir/backend/src/common/common_utils/sandbox_updater.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import logging
import os
import shutil
from typing import Callable, List
from typing import Callable, List, Optional, Tuple

import yaml

from common_utils.sandbox_util import detect_users_and_repos, SandboxError
from common_utils.sandbox_util import detect_users_and_repos
from common_utils.version import ymir_salient_version
from id_definition.error_codes import UpdaterErrorCode

from update_1_1_0_to_1_3_0.step_updater import update_all as update_110_130
from update_1_1_0_to_1_3_0.step_updater import update_models as update_models_110_130
from update_1_1_0_to_1_3_0.step_updater import update_repo as update_repo_110_130


_RepoUpdaterType = Callable[[str, str, str], None]
_ModelsUpdaterType = Callable[[str], None]
_StepUpdaterType = Tuple[Optional[_RepoUpdaterType], Optional[_ModelsUpdaterType]]


def update(sandbox_root: str, assets_root: str, models_root: str, src_ver: str, dst_ver: str) -> None:
Expand All @@ -21,56 +23,74 @@ def update(sandbox_root: str, assets_root: str, models_root: str, src_ver: str,
logging.info(f"nothing to update {src_ver} -> {dst_ver}")
return

_backup(sandbox_root)
_backup(sandbox_root=sandbox_root, models_root=models_root)

# update
user_to_repos = detect_users_and_repos(sandbox_root)
try:
for repo_func in steps:
for user_id, repo_ids in user_to_repos.items():
for repo_id in repo_ids:
repo_func(os.path.join(sandbox_root, user_id, repo_id), assets_root, models_root)
for repo_func, models_func in steps:
# update user repos
if repo_func:
for user_id, repo_ids in user_to_repos.items():
for repo_id in repo_ids:
repo_func(os.path.join(sandbox_root, user_id, repo_id), assets_root, models_root)
# update models
if models_func:
models_func(models_root)

for user_id in user_to_repos:
_update_user_labels(label_path=os.path.join(sandbox_root, user_id, 'labels.yaml'), dst_ver=dst_ver)
except Exception as e:
_roll_back(sandbox_root)
_roll_back(sandbox_root=sandbox_root, models_root=models_root)
raise e

# cleanup
shutil.rmtree(os.path.join(sandbox_root, 'backup'))
shutil.rmtree(os.path.join(sandbox_root, 'sandbox-bk'))
shutil.rmtree(os.path.join(sandbox_root, 'ymir-models-bk'))


def _backup(sandbox_root: str) -> None:
backup_dir = os.path.join(sandbox_root, 'backup')
os.makedirs(backup_dir, exist_ok=True)
if os.listdir(backup_dir):
raise SandboxError(error_code=UpdaterErrorCode.BACKUP_DIR_NOT_EMPTY,
error_message=f"Backup directory not empty: {backup_dir}")

def _backup(sandbox_root: str, models_root: str) -> None:
# user dirs in sandbox_root
sandbox_backup_dir = os.path.join(sandbox_root, 'sandbox-bk')
os.makedirs(sandbox_backup_dir, exist_ok=False)
for user_id in detect_users_and_repos(sandbox_root):
shutil.copytree(src=os.path.join(sandbox_root, user_id), dst=os.path.join(backup_dir, user_id), symlinks=True)
shutil.copytree(src=os.path.join(sandbox_root, user_id),
dst=os.path.join(sandbox_backup_dir, user_id),
symlinks=True)

models_backup_dir = os.path.join(sandbox_root, 'ymir-models-bk')
shutil.copytree(src=models_root, dst=models_backup_dir)


def _roll_back(sandbox_root: str) -> None:
backup_dir = os.path.join(sandbox_root, 'backup')
def _roll_back(sandbox_root: str, models_root: str) -> None:
sandbox_backup_dir = os.path.join(sandbox_root, 'sandbox-bk')
for user_id in detect_users_and_repos(sandbox_root):
src_user_dir = os.path.join(backup_dir, user_id)
src_user_dir = os.path.join(sandbox_backup_dir, user_id)
dst_user_dir = os.path.join(sandbox_root, user_id)
shutil.rmtree(dst_user_dir)
shutil.copytree(src=src_user_dir, dst=dst_user_dir, symlinks=True)

shutil.rmtree(os.path.join(sandbox_root, 'backup'))

shutil.move(src=src_user_dir, dst=dst_user_dir)

# models_root
models_backup_dir = os.path.join(sandbox_root, 'ymir-models-bk')
for model_hash in os.listdir(models_backup_dir):
phoenix-xhuang marked this conversation as resolved.
Show resolved Hide resolved
src_model_path = os.path.join(models_backup_dir, model_hash)
if not os.path.isfile(src_model_path):
continue
dst_model_path = os.path.join(models_root, model_hash)
os.remove(dst_model_path)
shutil.move(src=src_model_path, dst=dst_model_path)

shutil.rmtree(sandbox_backup_dir)
shutil.rmtree(models_backup_dir)
logging.info('roll back done')


def _get_update_steps(src_ver: str, dst_ver: str) -> List[_RepoUpdaterType]:
def _get_update_steps(src_ver: str, dst_ver: str) -> List[_StepUpdaterType]:
eq_src_ver = ymir_salient_version(src_ver)
eq_dst_ver = ymir_salient_version(dst_ver)

_UPDATE_NODES: List[str] = ['1.1.0', '1.3.0']
_UPDATE_FUNCS: List[_RepoUpdaterType] = [update_110_130]
_UPDATE_FUNCS: List[_StepUpdaterType] = [(update_repo_110_130, update_models_110_130)]
return _UPDATE_FUNCS[_UPDATE_NODES.index(eq_src_ver):_UPDATE_NODES.index(eq_dst_ver)]


Expand Down
3 changes: 1 addition & 2 deletions ymir/backend/src/common/id_definition/error_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,4 @@ class APIErrorCode(IntEnum):

class UpdaterErrorCode(IntEnum):
INVALID_USER_LABEL_FILE = 170001
BACKUP_DIR_NOT_EMPTY = 170002
SANDBOX_VERSION_NOT_SUPPORTED = 170003
SANDBOX_VERSION_NOT_SUPPORTED = 170002
6 changes: 6 additions & 0 deletions ymir/command/mir/commands/import_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import shutil
import tarfile
from mir.version import DEFAULT_YMIR_SRC_VERSION, YMIR_VERSION, ymir_model_salient_version

import yaml

Expand Down Expand Up @@ -54,6 +55,11 @@ def run_with_args(mir_root: str, dst_rev: str, src_revs: str, work_dir: str, pac

with open(os.path.join(extract_model_dir_path, 'ymir-info.yaml'), 'r') as f:
ymir_info_dict = yaml.safe_load(f.read())

package_version = ymir_info_dict.get('package_version', DEFAULT_YMIR_SRC_VERSION)
if ymir_model_salient_version(package_version) != ymir_model_salient_version(YMIR_VERSION):
raise MirRuntimeError(error_code=MirCode.RC_CMD_INVALID_MODEL_PACKAGE_VERSION,
error_message=f"Invalid model package version: {package_version}")
model_storage = models.ModelStorage.parse_obj(ymir_info_dict)

logging.info(f"importing model with storage: {model_storage}")
Expand Down
4 changes: 3 additions & 1 deletion ymir/command/mir/commands/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
from subprocess import CalledProcessError
from typing import Any, Dict, List, Optional, Tuple
from mir.version import ymir_model_salient_version, YMIR_VERSION

from tensorboardX import SummaryWriter
import yaml
Expand Down Expand Up @@ -35,7 +36,8 @@ def _find_and_save_model(out_root: str, model_upload_location: str, executor_con
type=mirpb.TaskType.TaskTypeTraining),
stages=model_stages,
best_stage_name=best_stage_name,
attachments=attachments)
attachments=attachments,
package_version=ymir_model_salient_version(YMIR_VERSION))
models.pack_and_copy_models(model_storage=model_storage,
model_dir_path=out_model_dir,
model_location=model_upload_location)
Expand Down
1 change: 1 addition & 0 deletions ymir/command/mir/tools/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MirCode(IntEnum):
RC_CMD_OPENPAI_ERROR = 160012
RC_CMD_NO_ANNOTATIONS = 160013
RC_CMD_CAN_NOT_CALC_CONFUSION_MATRIX = 160014
RC_CMD_INVALID_MODEL_PACKAGE_VERSION = 160015 # invalid model package version
RC_CMD_ERROR_UNKNOWN = 169999


Expand Down
1 change: 1 addition & 0 deletions ymir/command/mir/tools/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ModelStorage(BaseModel):
model_hash: str = ''
stage_name: str = ''
attachments: Dict[str, List[str]] = {}
package_version: str = Field(..., min_length=1)

@property
def class_names(self) -> List[str]:
Expand Down
11 changes: 11 additions & 0 deletions ymir/command/mir/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ def ymir_salient_version(ver: str) -> str:
'1.3.0': '1.3.0',
}
return _SALIENT_VERSIONS[ver]


def ymir_model_salient_version(ver: str) -> str:
"""
get model package version from ymir version
"""
_PACKAGE_VERSIONS = {
DEFAULT_YMIR_SRC_VERSION: DEFAULT_YMIR_SRC_VERSION,
'1.3.0': '1.3.0',
}
return _PACKAGE_VERSIONS[ver]
4 changes: 3 additions & 1 deletion ymir/command/tests/unit/test_cmd_import_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from mir.protos import mir_command_pb2 as mirpb
from mir.tools import mir_storage_ops, models, settings as mir_settings
from mir.tools.code import MirCode
from mir.version import YMIR_VERSION
from tests import utils as test_utils


Expand Down Expand Up @@ -64,7 +65,8 @@ def _prepare_model(self):
'mAP': 0.5
},
stages={mss.stage_name: mss},
best_stage_name=mss.stage_name)
best_stage_name=mss.stage_name,
package_version=YMIR_VERSION)
with open(os.path.join(self._src_model_root, 'ymir-info.yaml'), 'w') as f:
yaml.safe_dump(model_storage.dict(), f)
with tarfile.open(self._src_model_package_path, 'w:gz') as tar_gz_f:
Expand Down
4 changes: 3 additions & 1 deletion ymir/command/tests/unit/test_cmd_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
import unittest
from unittest import mock
from mir.version import YMIR_VERSION

import yaml

Expand Down Expand Up @@ -90,7 +91,8 @@ def _prepare_model(self):
'dst_rev': 'a'
},
stages={model_stage.stage_name: model_stage},
best_stage_name=model_stage.stage_name)
best_stage_name=model_stage.stage_name,
package_version=YMIR_VERSION)

with open(os.path.join(self._models_location, 'ymir-info.yaml'), 'w') as f:
yaml.dump(model_storage.dict(), f)
Expand Down
4 changes: 3 additions & 1 deletion ymir/command/tests/unit/test_cmd_mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from unittest import mock

from google.protobuf.json_format import ParseDict
from mir.version import YMIR_VERSION, ymir_model_salient_version
import yaml

from mir.commands.mining import CmdMining
Expand Down Expand Up @@ -89,7 +90,8 @@ def _mock_prepare_model(*args, **kwargs):
stages={mss.stage_name: mss},
best_stage_name=mss.stage_name,
model_hash='xyz',
stage_name=mss.stage_name)
stage_name=mss.stage_name,
package_version=ymir_model_salient_version(YMIR_VERSION))
return ms

# protected: custom: env prepare
Expand Down
7 changes: 4 additions & 3 deletions ymir/command/tests/unit/test_cmd_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

from mir.commands import training
from mir.protos import mir_command_pb2 as mirpb
from mir.tools import mir_repo_utils, mir_storage_ops, models, settings as mir_settings, mir_storage
from mir.tools import mir_storage_ops, models, settings as mir_settings, mir_storage
from mir.tools.code import MirCode
from mir.tools.errors import MirRuntimeError
from mir.tools.mir_storage import sha1sum_for_file
from mir.version import ymir_model_salient_version, YMIR_VERSION
from tests import utils as test_utils


Expand Down Expand Up @@ -235,7 +235,8 @@ def __mock_process_model_storage(*args, **kwargs):
},
stages={mss.stage_name: mss},
best_stage_name=mss.stage_name,
model_hash='xyz')
model_hash='xyz',
package_version=ymir_model_salient_version(YMIR_VERSION))
return ms

# public: test cases
Expand Down
3 changes: 3 additions & 0 deletions ymir/updater/app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
fasteners==0.16.3
protobuf==3.18.1
pyyaml==5.4.1
pydantic==1.9.0
phoenix-xhuang marked this conversation as resolved.
Show resolved Hide resolved

--no-binary=pydantic
11 changes: 11 additions & 0 deletions ymir/updater/app/tools.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

import os
import re
from typing import List

from mir.scm.cmd import CmdScm


# repo funcs
def get_repo_tags(mir_root: str) -> List[str]:
git_cmd = CmdScm(working_dir=mir_root, scm_executable='git')
tags: str = git_cmd.tag()
Expand All @@ -13,3 +16,11 @@ def get_repo_tags(mir_root: str) -> List[str]:
def remove_old_tag(mir_root: str, tag: str) -> None:
git_cmd = CmdScm(working_dir=mir_root, scm_executable='git')
git_cmd.tag(['-d', tag])


# detect models
def get_model_hashes(models_root: str) -> List[str]:
return [
h for h in os.listdir(models_root)
if re.match(pattern=r'^.{40}$', string=h) and os.path.isfile(os.path.join(models_root, h))
]