Skip to content
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
1 change: 0 additions & 1 deletion .github/workflows/build_wheel_off.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Build wheel and release into PYPI (off now)


on:
push:
branches:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-mlperf-inference-tvm-resnet50.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
pip install mlcflow
- name: Pull MLOps repository
env:
REPO: ${{ github.event.pull_request.head.repo.html_url }
REPO: ${{ github.event.pull_request.head.repo.html_url }}
BRANCH: ${{ github.event.pull_request.head.ref }}
run: |
mlc pull repo "$REPO" --branch="$BRANCH"
Expand Down
11 changes: 6 additions & 5 deletions automation/script/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ def update_docker_environment(
# Add host group ID if specified in the Docker settings and not on Windows
if not is_false(docker_settings.get('pass_group_id')) and os.name != 'nt':
env['+ MLC_DOCKER_BUILD_ARGS'].append(
f"GID=\\\" $(id -g $USER) \\\""
f"GID=\" $(id -g $USER) \""
)

# Add host user ID if specified in the Docker settings and not on Windows
if not is_false(docker_settings.get(
'use_host_user_id')) and os.name != 'nt':
env['+ MLC_DOCKER_BUILD_ARGS'].append(
f"UID=\\\" $(id -u $USER) \\\""
f"UID=\" $(id -u $USER) \""
)

return {'return': 0}
Expand Down Expand Up @@ -349,7 +349,7 @@ def rebuild_flags(
continue

value = command_dict[key]
quote = '\\"' if full_key in quote_keys else ""
quote = '"' if full_key in quote_keys else ""

# Recursively process nested dictionaries.
if isinstance(value, dict):
Expand All @@ -363,14 +363,15 @@ def rebuild_flags(
# Process lists by concatenating values with commas.
elif isinstance(value, list):
list_values = ",".join(
f"{quote}{str(item)}{quote}" for item in value)
quote_if_needed(
item, quote) for item in value)
command_line += f" --{full_key},={list_values}"
# Process scalar values.
else:
if full_key in ['s', 'v']:
command_line += f" -{full_key}"
else:
command_line += f" --{full_key}={quote}{str(value)}{quote}"
command_line += f" --{full_key}={quote_if_needed(value, quote)}"

return command_line

Expand Down
13 changes: 7 additions & 6 deletions automation/script/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@ def _run(self, i):
cached_meta['dependent_cached_path'] = dependent_cached_path

if run_state.get('cache_expiration'): # convert to seconds
cached_meta['cache_expiration'] = utils.parse_expiration(
cached_meta['cache_expiration'] = parse_expiration(
run_state['cache_expiration'])

ii = {'action': 'update',
Expand Down Expand Up @@ -3154,9 +3154,8 @@ def native_run(self, i):
if os.name == 'nt':
script.append('set ' + k + '=' + v)
else:
if ' ' in v:
v = '"' + v + '"'
script.append('export ' + k + '=' + v)
safe_v = quote_if_needed(v)
script.append('export ' + k + '=' + safe_v)

script.append('')

Expand Down Expand Up @@ -5290,7 +5289,7 @@ def prepare_and_run_script_with_postprocessing(i, postprocess="postprocess"):
if r['return'] > 0:
return r

# Save file to run without CM
# Save file to run without MLC
if debug_script_tags != '' and all(
item in found_script_tags for item in debug_script_tags.split(',')):

Expand Down Expand Up @@ -5596,10 +5595,12 @@ def convert_env_to_script(env, os_info, start_script=None):
os_info['env_var'].replace(
'env_var', key)}"""

env_quote = os_info['env_quote']
# Replace placeholders in the platform-specific environment command
# and escapes any quote in the env value
env_command = os_info['set_env'].replace(
'${key}', key).replace(
'${value}', str(env_value))
'${value}', str(env_value).replace(env_quote, f"""\\{env_quote}"""))
script.append(env_command)

return script
Expand Down
17 changes: 17 additions & 0 deletions automation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def get_host_os_info(i={}):
info['bat_ext'] = '.bat'
info['set_env'] = 'set ${key}=${value}'
info['env_separator'] = ';'
info['env_quote'] = '\''
info['env_var'] = '%env_var%'
info['bat_rem'] = 'rem ${rem}'
info['run_local_bat'] = 'call ${bat_file}'
Expand All @@ -63,6 +64,7 @@ def get_host_os_info(i={}):
info['bat_ext'] = '.sh'
info['set_env'] = 'export ${key}="${value}"'
info['env_separator'] = ':'
info['env_quote'] = '"'
info['env_var'] = '${env_var}'
info['set_exec_file'] = 'chmod 755 "${file_name}"'
info['bat_rem'] = '# ${rem}'
Expand Down Expand Up @@ -1104,6 +1106,7 @@ def print_json(i):


def parse_expiration(user_input: str) -> float:
import time
"""
Parse user input like '10m', '2h', '3d' into a UNIX timestamp.
"""
Expand All @@ -1127,3 +1130,17 @@ def parse_expiration(user_input: str) -> float:

seconds = value * units[unit]
return time.time() + seconds


def quote_if_needed(val: str, quote: str) -> str:
"""
Return the value, quoted with escaped quotes if it contains spaces
or quotes.
"""
s = str(val)

if " " in s or '"' in s or quote == '"':
# Escape all existing double quotes
s = s.replace('"', r'\"')
return f'"{s}"'
return s
2 changes: 2 additions & 0 deletions script/detect-cpu/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ alias: detect-cpu
automation_alias: script
automation_uid: 5b4e0237da074764
category: Platform information
cache: true
cache_expiration: 1h
clean_files:
- tmp-lscpu.out
- tmp-systeminfo.csv
Expand Down
2 changes: 2 additions & 0 deletions script/detect-os/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ alias: detect-os
automation_alias: script
automation_uid: 5b4e0237da074764
category: Platform information
cache: true
cache_expiration: 1h
clean_files:
- tmp-run.out
new_env_keys:
Expand Down
Loading