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

enhance(job): refactor sw-docker-entrypiont with split swmp and swrt workdir #1293

Merged
merged 1 commit into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions client/scripts/sw-docker-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ fi
ulimit -n 65535 || true

CONDA_BIN="/opt/miniconda3/bin"
WORKDIR=${SW_SWMP_WORKDIR:=/opt/starwhale/swmp}
SWMP_DIR=${SW_SWMP_WORKDIR:=/opt/starwhale/swmp}
SWRT_DIR=${SW_SWRT_WORKDIR:=/opt/starwhale/swrt}
PIP_CACHE_DIR=${SW_PIP_CACHE_DIR:=/root/.cache/pip}
_MANIFEST_RUNTIME=$(yq -r .environment.python ${WORKDIR}/_manifest.yaml) || true
VERBOSE="-vvvv"
STEP=${SW_TASK_STEP:-""}
TASK_INDEX=${SW_TASK_INDEX:-0}
Expand Down Expand Up @@ -59,15 +59,25 @@ set_pip_cache() {

pre_check() {
echo "--> run pre check for swmp model dir ..."
cd ${WORKDIR}
if [ ! -f "${SWMP_DIR}/model.yaml" ] || [ ! -d "${SWMP_DIR}/src" ]; then
echo "${SWMP_DIR} is not starwhale swmp target dir, will exit"
exit 1
fi

echo "--> run pre check for swrt runtime dir ..."
if [ ! -f "${SWRT_DIR}/_manifest.yaml" ] || [ ! -d "${SWRT_DIR}/dependencies" ]; then
echo "${SWRT_DIR} is not starwhale swrt target dir, will exit"
exit 1
fi

if [ ! -f "_manifest.yaml" ] || [ ! -f "model.yaml" ]; then
echo "${WORKDIR} is not starwhale target dir, will exit"
if [ "${SWRT_DIR}" = "${SWMP_DIR}" ]; then
echo "swmp and swrt use the same dir, will exit"
exit 1
fi
}

set_python() {
_MANIFEST_RUNTIME=$(yq -r .environment.python ${SWRT_DIR}/_manifest.yaml) || exit 1
_RUNTIME="python${_MANIFEST_RUNTIME}"

echo "**** DETECT RUNTIME: ${_RUNTIME}"
Expand All @@ -78,20 +88,21 @@ set_python() {
_update_python_alter "python3.8"
fi
}

# TODO:restore when processing evaluation(eval run use param: 'runtime URI', and it can be uri or dir path )
restore_activate_runtime() {
echo '--> restore python env ...'
export PYTHONWARNINGS="ignore:Unverified HTTPS request"
swcli ${VERBOSE} runtime restore .
swcli ${VERBOSE} runtime restore ${SWRT_DIR} || exit 1
unset PYTHONWARNINGS

echo '--> source activate ...'
eval "$(./activate.sw)"
eval "$(${SWRT_DIR}/activate.sw)" || exit 1
}

run() {
echo "--> start to run swmp ${STEP}, use $(which swcli) cli..."
swcli ${VERBOSE} model eval "${WORKDIR}"/src --dataset=${SW_DATASET_URI} --step=${STEP} --task-index=${TASK_INDEX} --version=${SW_EVALUATION_VERSION}
echo "--> start to run swmp ${STEP}, use $(which swcli) cli @ ${SWMP_DIR} ..."
swcli ${VERBOSE} model eval "${SWMP_DIR}"/src --dataset=${SW_DATASET_URI} --step=${STEP} --task-index=${TASK_INDEX} --version=${SW_EVALUATION_VERSION} || exit 1
}

welcome() {
Expand All @@ -100,7 +111,9 @@ welcome() {
echo "Date: `date -u +%Y-%m-%dT%H:%M:%SZ`"
echo "Version: `swcli --version`"
echo "Run: $1 "
echo "Model: ${SW_SWMP_NAME}@${SW_SWMP_VERSION}"
echo "Model Version: ${SW_SWMP_NAME}@${SW_SWMP_VERSION}"
echo "Model Workdir: ${SWMP_DIR}"
echo "Runtime Workdir: ${SWRT_DIR}"
echo "===================================="
}

Expand Down
1 change: 1 addition & 0 deletions client/starwhale/base/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class RunSubDirType:
RUNLOG = "runlog"
LOG = "log"
SWMP = "swmp"
SWRT = "swrt"


class JobOperationType:
Expand Down
2 changes: 1 addition & 1 deletion client/starwhale/core/eval/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def _gen_run_container_cmd(self, typ: str, step: str, task_index: int) -> str:
"-v",
f"{self._model_dir}/{DefaultYAMLName.MODEL}:{_CNTR_WORKDIR}/{RunSubDirType.SWMP}/{DefaultYAMLName.MODEL}",
"-v",
f"{self._runtime_dir}:{_CNTR_WORKDIR}/{RunSubDirType.SWMP}",
f"{self._runtime_dir}:{_CNTR_WORKDIR}/{RunSubDirType.SWRT}",
]

if typ == EvalTaskType.SINGLE:
Expand Down
2 changes: 1 addition & 1 deletion client/tests/core/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_run(self, m_scheduler: MagicMock, m_call: MagicMock) -> None:
f"-v {sw.object_store_dir}:{sw.object_store_dir}",
f"-v {project_dir}/workdir/model/mnist/gn/gnstmntggi4t111111111111/src:/opt/starwhale/swmp/src",
f"-v {project_dir}/workdir/model/mnist/gn/gnstmntggi4t111111111111/src/model.yaml:/opt/starwhale/swmp/model.yaml",
f"-v {project_dir}/workdir/runtime/mnist/ga/ga4doztfg4yw11111111111111:/opt/starwhale/swmp",
f"-v {project_dir}/workdir/runtime/mnist/ga/ga4doztfg4yw11111111111111:/opt/starwhale/swrt",
"-e SW_PROJECT=self",
f"-e SW_EVALUATION_VERSION={build_version}",
"-e SW_INSTANCE_URI=local",
Expand Down