Skip to content

Commit 154d5a5

Browse files
committed
Fixes mlcommons#925, llvm src install, support --docker_host_mlc_repos
1 parent c43c927 commit 154d5a5

8 files changed

Lines changed: 113 additions & 5 deletions

File tree

.github/workflows/test-mlc-script-features.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,60 @@ jobs:
103103
run: |
104104
mlcr run,docker,container --adr.compiler.tags=gcc --docker_mlc_repo=mlcommons@mlperf-automations --docker_mlc_repo_branch=dev --image_name=mlc-script-app-image-classification-onnx-py --env.MLC_DOCKER_RUN_SCRIPT_TAGS=app,image-classification,onnx,python --env.MLC_DOCKER_IMAGE_BASE=ubuntu:22.04 --env.MLC_DOCKER_IMAGE_REPO=local --quiet
105105
106+
- name: Test docker process_mounts input_mapping fallback (src_path fix)
107+
shell: bash
108+
run: |
109+
python3 << 'PYTEST'
110+
import subprocess, re, sys, os
111+
112+
# Find the automation/script directory via mlc
113+
out = subprocess.run(['mlc', 'find', 'script', '--tags=detect,os', '--quiet'],
114+
capture_output=True, text=True)
115+
match = re.search(r'Item path:\s*(.+)', out.stdout + out.stderr)
116+
if not match:
117+
print("ERROR: Could not locate MLC repo via 'mlc find script'")
118+
sys.exit(1)
119+
repo_root = os.path.dirname(os.path.dirname(match.group(1).strip()))
120+
sys.path.insert(0, os.path.join(repo_root, 'automation'))
121+
122+
from script.docker_utils import process_mounts
123+
124+
# Test 1: input_mapping in run_state is used as fallback for docker path remapping
125+
docker_settings = {'user': 'mlcuser'}
126+
mounts = ['${{ MLC_SRC_REPO_PATH }}:${{ MLC_SRC_REPO_PATH }}']
127+
env = {'MLC_SRC_REPO_PATH': '/home/user/repos/my-project'}
128+
run_state = {
129+
'input_mapping': {'src_path': 'MLC_SRC_REPO_PATH'},
130+
'file_path_env_keys': [],
131+
'folder_path_env_keys': []
132+
}
133+
f_run_cmd = {'src_path': '/home/user/repos/my-project'}
134+
135+
result = process_mounts(mounts, env, docker_settings, f_run_cmd, run_state)
136+
assert result['return'] == 0, f"process_mounts failed: {result}"
137+
assert f_run_cmd['src_path'] != '/home/user/repos/my-project', \
138+
f"FAIL: src_path was not remapped to container path! Got: {f_run_cmd['src_path']}"
139+
assert '/mlc-mount/' in f_run_cmd['src_path'], \
140+
f"FAIL: Expected /mlc-mount/ in remapped path, got: {f_run_cmd['src_path']}"
141+
print(f"PASS: src_path correctly remapped to {f_run_cmd['src_path']}")
142+
143+
# Test 2: without input_mapping, f_run_cmd should not be modified
144+
f_run_cmd2 = {'src_path': '/home/user/repos/my-project'}
145+
run_state2 = {
146+
'input_mapping': {},
147+
'file_path_env_keys': [],
148+
'folder_path_env_keys': []
149+
}
150+
mounts2 = ['${{ MLC_SRC_REPO_PATH }}:${{ MLC_SRC_REPO_PATH }}']
151+
result2 = process_mounts(mounts2, env, docker_settings, f_run_cmd2, run_state2)
152+
assert result2['return'] == 0
153+
assert f_run_cmd2['src_path'] == '/home/user/repos/my-project', \
154+
f"FAIL: Without input_mapping, src_path should be unchanged, got: {f_run_cmd2['src_path']}"
155+
print("PASS: Without input_mapping, src_path stays as host path")
156+
157+
print("\nAll process_mounts tests passed!")
158+
PYTEST
159+
106160
test_experiment:
107161
runs-on: ${{ matrix.os }}
108162
strategy:

automation/script/docker.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def dockerfile(self_module, input_params):
156156
state = {}
157157
state['dockerfile_env'] = dockerfile_env
158158
state['dockerfile_build_env'] = dockerfile_build_env
159+
159160
# Generate Dockerfile
160161
mlc_docker_input = {
161162
'action': 'run', 'automation': 'script', 'tags': 'build,dockerfile',
@@ -170,6 +171,9 @@ def dockerfile(self_module, input_params):
170171
if docker_inputs.get('mlc_repo_path', '') != '':
171172
mlc_docker_input['mlc_repo_path'] = docker_inputs['mlc_repo_path']
172173

174+
if is_true(input_params.get('docker_host_mlc_repos', '')):
175+
mlc_docker_input['host_mlc_repos'] = 'yes'
176+
173177
docker_v = False
174178
docker_s = False
175179
if is_true(input_params.get(

automation/script/docker_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def process_mounts(mounts, env, docker_settings, f_run_cmd, run_state):
4545
if "${{ " + key + " }}:${{ " + key + " }}" not in mounts:
4646
mounts.append("${{ " + key + " }}:${{ " + key + " }}")
4747

48-
docker_input_mapping = docker_settings.get("input_mapping", {})
48+
docker_input_mapping = docker_settings.get("input_mapping", run_state.get("input_mapping", {}))
4949
container_env_string = ""
5050

5151
for index in range(len(mounts)):

automation/script/module.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5872,6 +5872,7 @@ def update_state_from_meta(meta, env, state, const, const_state, run_state, i):
58725872

58735873
input_mapping = meta.get('input_mapping', {})
58745874
if input_mapping:
5875+
run_state['input_mapping'] = input_mapping
58755876
update_env_from_input_mapping(
58765877
env,
58775878
input_update_env,

script/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MLCommons Automation Scripts
22

3-
*Last updated: 2026-04-21 04:32:01*
3+
*Last updated: 2026-04-22 06:04:04*
44

55
This directory contains automation scripts for MLPerf benchmarks, AI/ML workflows, and development operations.
66

script/build-dockerfile/customize.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,50 @@ def preprocess(i):
343343
f.write(EOL + '# Download MLC repo for scripts' + EOL)
344344
pat = env.get('MLC_GH_TOKEN', '')
345345

346-
if use_copy_repo:
346+
if is_true(env.get('MLC_DOCKER_HOST_MLC_REPOS', '')):
347+
# Copy all host MLC repos into the Docker image
348+
host_repos_path = i['automation'].action_object.repos_path
349+
if host_repos_path and os.path.isdir(host_repos_path):
350+
build_context_dir = os.path.dirname(
351+
env.get('MLC_DOCKERFILE_WITH_PATH',
352+
os.path.join(os.getcwd(), "Dockerfile")))
353+
host_repos_context = os.path.join(build_context_dir, "mlc_host_repos")
354+
if os.path.exists(host_repos_context):
355+
shutil.rmtree(host_repos_context)
356+
os.makedirs(host_repos_context, exist_ok=True)
357+
358+
copied_repos = []
359+
for item in os.listdir(host_repos_path):
360+
item_path = os.path.join(host_repos_path, item)
361+
if not os.path.isdir(item_path):
362+
continue
363+
# Skip local cache, index files, etc.
364+
if item in ['local']:
365+
continue
366+
dest = os.path.join(host_repos_context, item)
367+
logger.info(f"Copying host repo {item} to build context")
368+
shutil.copytree(item_path, dest)
369+
copied_repos.append(item)
370+
371+
if copied_repos:
372+
docker_repos_dest = "$HOME/MLC/repos"
373+
for repo_name in copied_repos:
374+
relative_path = os.path.relpath(
375+
os.path.join(host_repos_context, repo_name),
376+
build_context_dir)
377+
f.write(
378+
f'COPY --chown={docker_user}:{docker_group} {relative_path} {docker_repos_dest}/{repo_name}' +
379+
EOL)
380+
f.write(EOL + '# Register host MLC repositories' + EOL)
381+
for repo_name in copied_repos:
382+
f.write(
383+
f'RUN mlc add repo {docker_repos_dest}/{repo_name} --quiet' +
384+
EOL)
385+
f.write(EOL)
386+
else:
387+
logger.warning(f"MLC_DOCKER_HOST_MLC_REPOS_PATH not found: {host_repos_path}")
388+
389+
elif use_copy_repo:
347390
repo_name = os.path.basename(relative_repo_path)
348391
docker_repo_dest = f"$HOME/MLC/repos/{repo_name}"
349392
f.write(

script/build-dockerfile/meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ input_mapping:
4747
mlc_repo_flags: MLC_DOCKER_ADD_FLAG_TO_MLC_MLOPS_REPO
4848
mlc_repo_path: MLC_REPO_PATH
4949
mlc_repos: MLC_DOCKER_EXTRA_MLC_REPOS
50+
host_mlc_repos: MLC_DOCKER_HOST_MLC_REPOS
5051
os: MLC_DOCKER_OS
5152
os_version: MLC_DOCKER_OS_VERSION
5253
package_manager_update_cmd: MLC_PACKAGE_MANAGER_UPDATE_CMD

script/install-llvm-src/meta.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ input_mapping:
3333
pull_changes: MLC_LLVM_REPO_PULL_CHANGES
3434
target_triple: MLC_LLVM_TARGET_TRIPLE
3535
targets: MLC_LLVM_TARGETS_TO_BUILD
36+
src_path: MLC_LLVM_SRC_REPO_PATH
3637

3738
# Dependencies
3839
deps:
@@ -54,9 +55,11 @@ deps:
5455
names:
5556
- llvm-src-repo
5657
tags: get,git,repo
57-
skip_if_env:
58+
skip_if_any_env:
5859
MLC_LLVM_INSTALLED_PATH:
5960
- true
61+
MLC_LLVM_SRC_REPO_PATH:
62+
- on
6063
update_tags_from_env_with_prefix:
6164
_branch.:
6265
- MLC_GIT_CHECKOUT
@@ -146,7 +149,7 @@ variations:
146149
openmp:
147150
default: true
148151
env:
149-
+MLC_LLVM_ENABLE_PROJECTS:
152+
+MLC_LLVM_ENABLE_RUNTIMES:
150153
- openmp
151154
group: openmp
152155
no-openmp-rt:
@@ -341,6 +344,8 @@ docker:
341344
skip_run_cmd: true
342345
pre_run_cmds:
343346
- mlc pull repo
347+
mounts:
348+
- ${{ MLC_LLVM_SRC_REPO_PATH }}:${{ MLC_LLVM_SRC_REPO_PATH }}
344349

345350
# Output / debugging
346351
sort: 1000

0 commit comments

Comments
 (0)