Skip to content

Commit 01588a4

Browse files
authored
Support Intel SDE Tool, improved individual script tests (#333)
* Support subfolder in extract-file * Enable test for intel sde * Dont restrict mlc test to console * Improved github action for individual script tests
1 parent 9ca1197 commit 01588a4

File tree

14 files changed

+235
-10
lines changed

14 files changed

+235
-10
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import yaml
2+
import sys
3+
import json
4+
5+
6+
def get_num_runs(filepath):
7+
with open(filepath, 'r') as file:
8+
content = yaml.safe_load(file)
9+
tests = content.get('tests', {})
10+
if tests:
11+
num_tests = len(tests.get('run_inputs', []))
12+
else:
13+
num_tests = 0
14+
uid = content['uid']
15+
return uid, num_tests
16+
17+
18+
def process_files(files):
19+
filenames = files.split()
20+
return [
21+
{
22+
"file": file,
23+
"uid": uid,
24+
"num_tests": num_tests
25+
}
26+
for file in filenames
27+
if file.endswith('meta.yaml') and (uid := get_num_runs(file))
28+
for _, num_tests in [uid]
29+
]
30+
31+
32+
if __name__ == "__main__":
33+
changed_files = sys.stdin.read().strip()
34+
processed_files = process_files(changed_files)
35+
json_processed_files = json.dumps(processed_files)
36+
print(f"::set-output name=modified_files::{json_processed_files}")

.github/workflows/build_wheel_off.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
- VERSION
99

1010
jobs:
11-
1211
build_wheels:
1312
if: github.repository_owner == 'mlcommons'
1413
name: Build wheel

.github/workflows/build_wheels.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
workflow_dispatch: {}
77

88
jobs:
9-
109
build_wheels:
1110
if: github.repository_owner == 'mlcommons'
1211
name: Build wheel
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# This workflow will run configured tests for any updated MLC script
2+
name: MLC test script on modified meta
3+
4+
on:
5+
pull_request:
6+
branches: [ "main", "dev" ]
7+
paths:
8+
- 'script/**meta.yaml'
9+
10+
jobs:
11+
get-modified-files:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
modified_files: ${{ steps.modified-files.outputs.modified_files }}
15+
16+
steps:
17+
- name: 'Checkout'
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 2
21+
22+
- name: Setup Python
23+
uses: actions/setup-python@v3
24+
with:
25+
python-version: '3.x'
26+
27+
- name: Get changed files
28+
id: modified-files
29+
run: |
30+
git remote add upstream ${{ github.event.pull_request.base.repo.clone_url }}
31+
git fetch upstream
32+
changed_files=$(git diff upstream/${{ github.event.pull_request.base.ref }} --name-only)
33+
echo "$changed_files" | python3 .github/scripts/list_modified_files.py
34+
35+
36+
37+
process_modified_files:
38+
runs-on: ubuntu-latest
39+
needs: get_modified_files
40+
strategy:
41+
fail_fast: false
42+
matrix:
43+
file_info: ${{ fromJSON(needs.get_modified_files.outputs.modified_files) }}
44+
num_run: ${{ range(1, fromJSON(matrix.file_info.num_tests) + 1) }}
45+
46+
steps:
47+
- name: Checkout repository
48+
uses: actions/checkout@v4
49+
50+
- name: Process meta.yaml file
51+
run: |
52+
echo "Processing ${{ matrix.file_info.file }} with run number ${{ matrix.num_run }}"
53+
54+
pip install mlcflow
55+
mlc pull repo ${{ github.event.pull_request.head.repo.html_url }} --branch=${{ github.event.pull_request.head.ref }}
56+
mlc test script ${{ matrix.file_info.uid}} --test_input_index=${{ matrix.num_run }} --docker_mlc_repo=${{ github.event.pull_request.head.repo.html_url }} --docker_mlc_repo_branch=${{ github.event.pull_request.head.ref }} --quiet
57+

automation/script/module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2929,7 +2929,7 @@ def test(self, i):
29292929

29302930
alias = meta.get('alias', '')
29312931
uid = meta.get('uid', '')
2932-
if console:
2932+
if console or True: # Todo restrict to console only?
29332933
logger.info(path)
29342934
test_config = meta.get('tests', '')
29352935
if test_config:

script/download-and-extract/meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ input_mapping:
1919
new_env_keys:
2020
- MLC_DOWNLOAD_DOWNLOADED_PATH*
2121
- MLC_EXTRACT_EXTRACTED_PATH
22+
- MLC_EXTRACT_EXTRACTED_SUBDIR_PATH
2223
- <<<MLC_DOWNLOAD_FINAL_ENV_NAME>>>
2324
- <<<MLC_EXTRACT_FINAL_ENV_NAME>>>
2425
- <<<MLC_DAE_FINAL_ENV_NAME>>>

script/download-file/customize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def preprocess(i):
138138
shell=True,
139139
env=subprocess_env)
140140
if (env.get('MLC_DOWNLOAD_CHECKSUM_FILE', '') != '' or env.get(
141-
'MLC_DOWNLOAD_CHECKSUM', '') != '') and os.path.isfile(env['MLC_DOWNLOAD_FILENAME']):
141+
'MLC_DOWNLOAD_CHECKSUM', '') != '') and os.path.exists(env['MLC_DOWNLOAD_FILENAME']):
142142
# print(checksum_result) #for debugging
143143
if "checksum did not match" in checksum_result.stderr.lower():
144144
computed_checksum = subprocess.run(

script/extract-file/customize.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ def postprocess(i):
176176

177177
extract_to_folder = env.get('MLC_EXTRACT_TO_FOLDER', '')
178178
extract_path = env.get('MLC_EXTRACT_PATH', '')
179-
179+
folderpath = None
180180
extracted_file = env.get('MLC_EXTRACT_EXTRACTED_FILENAME', '')
181181

182182
# Preparing filepath
183-
# Can be either full extracted filename (such as model) or folder
183+
# Can be either the full extracted filename (such as model file) or folder
184184

185185
if extracted_file != '':
186186
filename = os.path.basename(extracted_file)
@@ -191,8 +191,8 @@ def postprocess(i):
191191

192192
filepath = os.path.join(folderpath, filename)
193193
else:
194-
195194
filepath = os.getcwd() # Extracted to the root cache folder
195+
folderpath = os.getcwd()
196196

197197
if not os.path.exists(filepath):
198198
return {
@@ -215,6 +215,18 @@ def postprocess(i):
215215
if archive_filepath != '' and os.path.isfile(archive_filepath):
216216
os.remove(archive_filepath)
217217

218+
# Check if only a single folder is created and if so, export the folder
219+
# name
220+
if folderpath:
221+
sub_items = os.listdir(folderpath)
222+
sub_folders = [
223+
item for item in sub_items if os.path.isdir(
224+
os.path.join(
225+
folderpath, item))]
226+
if len(sub_folders) == 1:
227+
env['MLC_EXTRACT_EXTRACTED_SUBDIR_PATH'] = os.path.join(
228+
folderpath, sub_folders[0])
229+
218230
# Since may change directory, check if need to clean some temporal files
219231
automation.clean_some_tmp_files({'env': env})
220232

script/extract-file/meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ input_mapping:
2323
to: MLC_EXTRACT_PATH
2424
new_env_keys:
2525
- MLC_EXTRACT_EXTRACTED_PATH
26+
- MLC_EXTRACT_EXTRACTED_SUBDIR_PATH
2627
- <<<MLC_EXTRACT_FINAL_ENV_NAME>>>
2728
- MLC_GET_DEPENDENT_CACHED_PATH
2829
new_state_keys: []

script/get-aocc/customize.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def preprocess(i):
6565
'run_script_input': i['run_script_input'],
6666
'recursion_spaces': i['recursion_spaces']})
6767
if r['return'] > 0:
68-
6968
return r
7069

7170
return {'return': 0}

0 commit comments

Comments
 (0)