Skip to content

Commit

Permalink
Fixes for cm docker script
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunsuresh committed Jun 16, 2023
1 parent ddfe31c commit 9f32eed
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 6 deletions.
67 changes: 63 additions & 4 deletions cm-mlops/automation/script/module_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,7 @@ def dockerfile(i):

docker_os = i.get('docker_os', docker_settings.get('docker_os', 'ubuntu'))
docker_os_version = i.get('docker_os_version', docker_settings.get('docker_os_version', '22.04'))
fake_run_deps = i.get('fake_run_deps', docker_settings.get('fake_run_deps', False))

dockerfile_path = os.path.join(script_path,'dockerfiles', docker_os +'_'+docker_os_version +'.Dockerfile')
if i.get('print_deps'):
Expand All @@ -1135,7 +1136,8 @@ def dockerfile(i):
'print_deps': True,
'quiet': True,
'silent': True,
'fake_run': True
'fake_run': True,
'fake_deps': True
}
r = self_module.cmind.access(cm_input)
if r['return'] > 0:
Expand All @@ -1158,6 +1160,7 @@ def dockerfile(i):
'run_cmd': f'{run_cmd} --quiet',
'script_tags': f'{tag_string}',
'quiet': True,
'fake_docker_deps': fake_run_deps,
'print_deps': True,
'real_run': True
}
Expand Down Expand Up @@ -1241,6 +1244,8 @@ def docker(i):
else:
run_cmd = ""

env=i.get('env', {})

for artifact in sorted(lst, key = lambda x: x.meta.get('alias','')):

meta = artifact.meta
Expand All @@ -1249,11 +1254,64 @@ def docker(i):
script_alias = meta.get('alias')
tag_string=",".join(tags)

_os=i.get('docker_os', 'ubuntu')
version=i.get('docker_os_version', '22.04')
run_config_path = os.path.join(script_path,'run_config.yml')
if not os.path.exists(run_config_path):
print("No run_config.yml file present in {}".format(script_path))
continue
import yaml
with open(run_config_path, 'r') as run_config_file:
run_config = yaml.safe_load(run_config_file)
docker_settings = run_config.get('docker')
if not docker_settings or not docker_settings.get('build') or not run_config.get('run_with_default_inputs'):
print("Run config is not configured for docker run in {}".format(run_config_path))
continue

_os = i.get('docker_os', docker_settings.get('docker_os', 'ubuntu'))
version = i.get('docker_os_version', docker_settings.get('docker_os_version', '22.04'))

import re
mounts = docker_settings.get('mounts', [])
input_mapping = meta.get('input_mapping', {})

docker_input_mapping = {}
for c_input in input_mapping:
if c_input in i:
docker_input_mapping[input_mapping[c_input]] = i[c_input]

for index in range(len(mounts)):
mount = mounts[index]
mount_parts = mount.split(":")
if len(mount_parts) != 2:
return {'return': 1, 'error': f'Invalid mount specified in docker settings'}
host_mount = mount_parts[0]
container_mount = mount_parts[1]
tmp_values = re.findall(r'\${{ (.*?) }}', str(host_mount))
if tmp_values:
for tmp_value in tmp_values:
if tmp_value in env:
new_host_mount = env[tmp_value]
elif tmp_value in docker_input_mapping:
new_host_mount = docker_input_mapping[tmp_value]
else:
new_host_mount = host_mount

tmp_values = re.findall(r'\${{ (.*?) }}', str(container_mount))
if tmp_values:
for tmp_value in tmp_values:
if tmp_value in env:
new_container_mount = env[tmp_value]
elif tmp_value in docker_input_mapping:
new_container_mount = docker_input_mapping[tmp_value]
else:
new_container_mount = container_mount
mounts[index] = new_host_mount+":"+new_container_mount

if mounts:
mount_string = ",".join(mounts)
else:
mount_string = ",".join(mounts)

cm_repo=i.get('cm_repo', 'mlcommons@ck')
env=i.get('env', {})

dockerfile_path = os.path.join(script_path,'dockerfiles', _os +'_'+version +'.Dockerfile')

Expand All @@ -1265,6 +1323,7 @@ def docker(i):
'cm_repo': cm_repo,
'env': env,
'image_repo': 'cm',
'mounts': mounts,
'image_tag': script_alias,
'docker_os_version': version,
'detached': 'no',
Expand Down
1 change: 1 addition & 0 deletions cm-mlops/script/build-dockerfile/_cm.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"docker_os_version": "CM_DOCKER_OS_VERSION",
"file_path": "CM_DOCKERFILE_WITH_PATH",
"gh_token": "CM_GH_TOKEN",
"fake_docker_deps": "CM_DOCKER_FAKE_DEPS",
"image_repo": "CM_DOCKER_IMAGE_REPO",
"image_tag": "CM_DOCKER_IMAGE_TAG",
"real_run": "CM_REAL_RUN",
Expand Down
5 changes: 4 additions & 1 deletion cm-mlops/script/build-dockerfile/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,11 @@ def preprocess(i):
env['CM_DOCKER_RUN_CMD']="cm run script --quiet --tags=" + env['CM_DOCKER_RUN_SCRIPT_TAGS']

fake_run = " --fake_run"
fake_run = fake_run + " --fake_deps" if env.get('CM_DOCKER_FAKE_DEPS') else fake_run
f.write('RUN ' + env['CM_DOCKER_RUN_CMD'] + fake_run + run_cmd_extra + EOL)
if not "run" in env['CM_DOCKER_RUN_CMD'] or env.get('CM_REAL_RUN', None):

#fake_run to install the dependent scripts and caching them
if not "run" in env['CM_DOCKER_RUN_CMD'] and env.get('CM_REAL_RUN', None):
fake_run = ""
f.write('RUN ' + env['CM_DOCKER_RUN_CMD'] + fake_run + run_cmd_extra + EOL)

Expand Down
3 changes: 2 additions & 1 deletion cm-mlops/script/download-file/run.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash
require_download="1"
if [ -e ${CM_DOWNLOAD_DOWNLOADED_PATH} ]; then
CMD=${CM_DOWNLOAD_CHECKSUM_CMD}
echo ${CMD}
eval ${CMD}
test $? -eq 0 || require_download="1"
else
require_download="1"
fi

if [[ ${require_download} == "1" ]]; then
Expand Down
3 changes: 3 additions & 0 deletions cm-mlops/script/prepare-training-data-bert/run_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ docker:
build: true
docker_os: ubuntu
docker_os_version: "22.04"
fake_run_deps: true
mounts:
- ${{ CM_DATA_DIR }}:${{ CM_DATA_DIR }}

run_with_default_inputs: true #if false the script won't run automatic tests

Expand Down

0 comments on commit 9f32eed

Please sign in to comment.