Skip to content

Commit 0079132

Browse files
committed
Improvements to remote-run
1 parent 63864d7 commit 0079132

5 files changed

Lines changed: 129 additions & 2 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Test remote run features
2+
3+
on:
4+
pull_request:
5+
branches: [ "main", "dev" ]
6+
paths:
7+
- '.github/workflows/test-remote-run.yml'
8+
- 'automation/script/remote_run.py'
9+
- 'script/remote-run-commands/**'
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
test_remote_run:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v3
23+
with:
24+
python-version: "3.12"
25+
26+
- name: Install mlcflow and pull repo
27+
env:
28+
REPO: ${{ github.event.pull_request.head.repo.html_url }}
29+
BRANCH: ${{ github.event.pull_request.head.ref }}
30+
run: |
31+
pip install mlcflow
32+
mlc pull repo "$REPO" --branch="$BRANCH"
33+
34+
- name: Set up SSH to localhost
35+
run: |
36+
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""
37+
cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
38+
chmod 600 ~/.ssh/authorized_keys
39+
ssh-keyscan -H localhost >> ~/.ssh/known_hosts
40+
# Verify SSH to localhost works
41+
ssh -o BatchMode=yes localhost "echo SSH_OK"
42+
43+
- name: Test remote pre_run_cmds and post_run_cmds
44+
run: |
45+
mlcr remote,run,cmds,ssh \
46+
--host=localhost \
47+
--ssh_key_file=~/.ssh/id_ed25519 \
48+
--run_cmds,="echo MAIN_CMD_RAN" \
49+
--pre_run_cmds,="echo PRE_RUN_EXECUTED > /tmp/pre_run_test.txt" \
50+
--post_run_cmds,="echo POST_RUN_EXECUTED > /tmp/post_run_test.txt"
51+
52+
# Verify pre_run_cmds executed
53+
test -f /tmp/pre_run_test.txt
54+
grep -q "PRE_RUN_EXECUTED" /tmp/pre_run_test.txt
55+
echo "pre_run_cmds: PASSED"
56+
57+
# Verify post_run_cmds executed
58+
test -f /tmp/post_run_test.txt
59+
grep -q "POST_RUN_EXECUTED" /tmp/post_run_test.txt
60+
echo "post_run_cmds: PASSED"
61+
62+
- name: Test remote_pre_run_cmds via remote_run
63+
run: |
64+
mlcr detect,os \
65+
--remote_host=localhost \
66+
--remote_ssh_key_file=~/.ssh/id_ed25519 \
67+
--remote_pre_run_cmds,="echo REMOTE_PRE_RAN > /tmp/remote_pre_test.txt" \
68+
--remote_post_run_cmds,="echo REMOTE_POST_RAN > /tmp/remote_post_test.txt"
69+
70+
test -f /tmp/remote_pre_test.txt
71+
grep -q "REMOTE_PRE_RAN" /tmp/remote_pre_test.txt
72+
echo "remote_pre_run_cmds via remote_run: PASSED"
73+
74+
test -f /tmp/remote_post_test.txt
75+
grep -q "REMOTE_POST_RAN" /tmp/remote_post_test.txt
76+
echo "remote_post_run_cmds via remote_run: PASSED"
77+
78+
- name: Test remote_copy_mlc_repos with custom MLC_REPOS path
79+
run: |
80+
# Use a random-ish path for MLC_REPOS on the "remote"
81+
export CUSTOM_REPOS_PATH="/tmp/custom-mlc-repos-$(date +%s)"
82+
mkdir -p "$CUSTOM_REPOS_PATH"
83+
84+
# Create a dummy repo to copy
85+
mkdir -p ~/MLC/repos/test-dummy-repo
86+
echo "DUMMY_CONTENT" > ~/MLC/repos/test-dummy-repo/marker.txt
87+
88+
mlcr detect,os \
89+
--remote_host=localhost \
90+
--remote_ssh_key_file=~/.ssh/id_ed25519 \
91+
--remote_copy_mlc_repos,=test-dummy-repo
92+
93+
# Verify the repo was copied to MLC/repos (default rsync target)
94+
test -f ~/MLC/repos/test-dummy-repo/marker.txt
95+
echo "remote_copy_mlc_repos: PASSED"

automation/script/remote_run.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def remote_run(self_module, i):
140140
script_run_cmd += f" --env.{key}={remote_env[key]}"
141141

142142
remote_pre_run_cmds = i.get('remote_pre_run_cmds', [])
143+
remote_post_run_cmds = i.get('remote_post_run_cmds', [])
143144

144145
run_cmds.append(f"{script_run_cmd}")
145146

@@ -157,6 +158,33 @@ def remote_run(self_module, i):
157158
remote_inputs['files_to_copy'] = files_to_copy
158159
remote_inputs['copy_directory'] = remote_copy_directory
159160

161+
# For repo copying, add a separate copy with MLC/repos target
162+
if i.get('remote_copy_mlc_repos', False):
163+
local_repos_path = os.path.join(os.path.expanduser("~"), "MLC", "repos")
164+
repos_to_copy = i.get('remote_copy_mlc_repos', [])
165+
if isinstance(repos_to_copy, bool) or repos_to_copy is True:
166+
repos_to_copy = [
167+
d for d in os.listdir(local_repos_path)
168+
if os.path.isdir(os.path.join(local_repos_path, d))
169+
]
170+
repo_files = [
171+
os.path.join(local_repos_path, repo)
172+
for repo in repos_to_copy
173+
if os.path.isdir(os.path.join(local_repos_path, repo))
174+
]
175+
if repo_files:
176+
remote_inputs['files_to_copy'] = remote_inputs.get(
177+
'files_to_copy', []) + repo_files
178+
remote_mlc_repos_path = i.get("remote_mlc_repos_path", "MLC/repos")
179+
remote_inputs['copy_directory'] = remote_mlc_repos_path
180+
# On the remote, if MLC_REPOS is set and differs, symlink so
181+
# mlcflow finds the copied repos
182+
run_cmds.insert(0,
183+
f'if [ -n "$MLC_REPOS" ] && [ "$MLC_REPOS" != "{remote_mlc_repos_path}" ]; then '
184+
f'mkdir -p "{remote_mlc_repos_path}" && '
185+
f'ln -sfn "$(realpath {remote_mlc_repos_path})"/* "$MLC_REPOS/"; '
186+
f'fi')
187+
160188
if files_to_copy_back:
161189
remote_inputs['files_to_copy_back'] = files_to_copy_back
162190

@@ -171,6 +199,7 @@ def remote_run(self_module, i):
171199
'action': 'run', 'target': 'script', 'tags': 'remote,run,cmds,ssh',
172200
'script_tags': i.get('tags'), 'run_cmds': run_cmds,
173201
'pre_run_cmds': remote_pre_run_cmds,
202+
'post_run_cmds': remote_post_run_cmds,
174203
**remote_inputs
175204
}
176205

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-05-22 05:08:04*
3+
*Last updated: 2026-05-23 04:34:02*
44

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

script/remote-run-commands/customize.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def preprocess(i):
7777

7878
run_cmds = env.get('MLC_SSH_RUN_COMMANDS', [])
7979

80-
run_cmds = pre_run_cmds + run_cmds
80+
post_run_cmds = env.get('MLC_SSH_POST_RUN_CMDS', [])
81+
82+
run_cmds = pre_run_cmds + run_cmds + post_run_cmds
8183

8284
for i, cmd in enumerate(run_cmds):
8385
if 'cm ' in cmd:

script/remote-run-commands/meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ input_mapping:
2929
files_to_copy: MLC_SSH_FILES_TO_COPY
3030
files_to_copy_back: MLC_SSH_FILES_TO_COPY_BACK
3131
host: MLC_SSH_HOST
32+
post_run_cmds: MLC_SSH_POST_RUN_CMDS
3233
pre_run_cmds: MLC_SSH_PRE_RUN_CMDS
3334
password: MLC_SSH_PASSWORD
3435
path_to_copy_back_files: MLC_SSH_PATH_TO_COPY_BACK_FILES

0 commit comments

Comments
 (0)