diff --git a/automation/script/docker.py b/automation/script/docker.py index 1e762e348..056192898 100644 --- a/automation/script/docker.py +++ b/automation/script/docker.py @@ -246,7 +246,7 @@ def docker_run(self_module, i): for t in i.get('tags', '').split(",") if t.startswith("_")] docker_cache = i.get('docker_cache', "yes") - if docker_cache.lower() in ["no", "false"]: + if is_false(docker_cache): env.setdefault('MLC_DOCKER_CACHE', docker_cache) image_repo = i.get('docker_image_repo', '') diff --git a/automation/script/module.py b/automation/script/module.py index 4c3b7fbb1..cadf35608 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -358,9 +358,9 @@ def _run(self, i): if fake_deps: env['MLC_TMP_FAKE_DEPS'] = 'yes' - if str(i.get('skip_sys_utils', '')).lower() in ['true', 'yes']: + if is_true(i.get('skip_sys_utils', '')): env['MLC_SKIP_SYS_UTILS'] = 'yes' - if str(i.get('skip_sudo', '')).lower() in ['true', 'yes']: + if is_true(i.get('skip_sudo', '')): env['MLC_TMP_SKIP_SUDO'] = 'yes' run_state = i.get('run_state', self.run_state) @@ -374,12 +374,10 @@ def _run(self, i): # Check verbose and silent verbose = False - silent = True if str(i.get('silent', '')).lower() in [ - 'true', 'yes', 'on'] else False + silent = True if is_true(i.get('silent', '')) else False if not silent: - silent = True if str(i.get('s', '')).lower() in [ - 'true', 'yes', 'on'] else False + silent = True if is_true(i.get('s', '')) else False if silent: if 'verbose' in i: @@ -1020,11 +1018,9 @@ def _run(self, i): if r['return'] > 0: return r - if str(env.get('MLC_RUN_STATE_DOCKER', False) - ).lower() in ['true', '1', 'yes']: + if is_true(env.get('MLC_RUN_STATE_DOCKER', False)): if state.get('docker'): - if str(state['docker'].get('run', True) - ).lower() in ['false', '0', 'no']: + if is_false(state['docker'].get('run', True)): logger.info( recursion_spaces + ' - Skipping script::{} run as we are inside docker'.format(found_script_item)) @@ -1047,7 +1043,7 @@ def _run(self, i): 'deps': []} return rr - elif str(state['docker'].get('real_run', True)).lower() in ['false', '0', 'no']: + elif is_false(state['docker'].get('real_run', True)): logger.info( recursion_spaces + ' - Doing fake run for script::{} as we are inside docker'.format(found_script_item)) @@ -1576,7 +1572,7 @@ def _run(self, i): } # Check and run predeps in customize.py - if str(meta.get('predeps', 'True')).lower() not in ["0", "false", "no"] and os.path.isfile( + if not is_false(meta.get('predeps', 'True')) and os.path.isfile( path_to_customize_py): # possible duplicate execution - needs fix r = utils.load_python_module( {'path': path, 'name': 'customize'}) @@ -2962,13 +2958,10 @@ def test(self, i): run_variations = [ f"_{v}" for v in variations if variations[v].get( 'group', - '') == '' and str( + '') == '' and not is_true( variations[v].get( 'exclude-in-test', - '')).lower() not in [ - "1", - "true", - "yes"]] + ''))] else: given_variations = run_input.get( 'variations_list', []) @@ -5029,7 +5022,7 @@ def enable_or_skip_script(meta, env): """ if not isinstance(meta, dict): - logger.info( + logger.warn( "The meta entry is not a dictionary for skip/enable if_env: %s", meta) @@ -5039,10 +5032,10 @@ def enable_or_skip_script(meta, env): value = str(env[key]).lower().strip() if set(meta_key) & set(["yes", "on", "true", "1"]): # Any set value other than false is taken as set - if value not in ["no", "off", "false", "0", ""]: + if not is_false(value) and value != '': continue elif set(meta_key) & set(["no", "off", "false", "0"]): - if value in ["no", "off", "false", "0", ""]: + if is_false(value) or value == "": continue elif value in meta_key: continue @@ -5072,10 +5065,10 @@ def any_enable_or_skip_script(meta, env): meta_key = [str(v).lower() for v in meta[key]] if set(meta_key) & set(["yes", "on", "true", "1"]): - if value not in ["no", "off", "false", "0", ""]: + if not is_false(value) and value != "": found = True elif set(meta_key) & set(["no", "off", "false", "0", ""]): - if value in ["no", "off", "false", "0", ""]: + if is_false(value) or value == "": found = True elif value in meta_key: found = True diff --git a/script/app-mlperf-inference-nvidia/customize.py b/script/app-mlperf-inference-nvidia/customize.py index 550b273fe..70e5d3710 100644 --- a/script/app-mlperf-inference-nvidia/customize.py +++ b/script/app-mlperf-inference-nvidia/customize.py @@ -1,6 +1,7 @@ from mlc import utils import os import shutil +from utils import * def preprocess(i): @@ -590,8 +591,8 @@ def preprocess(i): run_infer_on_copy_streams = str( env.get('MLC_MLPERF_NVIDIA_HARNESS_RUN_INFER_ON_COPY_STREAMS', '')) - if run_infer_on_copy_streams and run_infer_on_copy_streams.lower() not in [ - "no", "false", "0", ""]: + if run_infer_on_copy_streams and not is_false( + run_infer_on_copy_streams): run_config += " --run_infer_on_copy_streams" start_from_device = str( diff --git a/script/app-mlperf-inference/customize.py b/script/app-mlperf-inference/customize.py index ab421f248..5a215d27b 100644 --- a/script/app-mlperf-inference/customize.py +++ b/script/app-mlperf-inference/customize.py @@ -10,6 +10,7 @@ import mlperf_utils import re from datetime import datetime, timezone +from utils import * def preprocess(i): @@ -286,8 +287,7 @@ def postprocess(i): state['app_mlperf_inference_log_summary'][y[0].strip().lower() ] = y[1].strip() - if env.get("MLC_MLPERF_PRINT_SUMMARY", "").lower() not in [ - "no", "0", "false"]: + if not is_false(env.get("MLC_MLPERF_PRINT_SUMMARY", "")): print("\n") print(mlperf_log_summary) diff --git a/script/benchmark-program/customize.py b/script/benchmark-program/customize.py index 25b7a17e3..a355e8248 100644 --- a/script/benchmark-program/customize.py +++ b/script/benchmark-program/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import * def preprocess(i): @@ -20,7 +21,7 @@ def preprocess(i): env['MLC_RUN_CMD'] += ' ' + env['MLC_RUN_SUFFIX'] else: - if env['MLC_ENABLE_NUMACTL'].lower() in ["on", "1", "true", "yes"]: + if is_true(env['MLC_ENABLE_NUMACTL']): env['MLC_ENABLE_NUMACTL'] = "1" MLC_RUN_PREFIX = "numactl " + env['MLC_NUMACTL_MEMBIND'] + ' ' else: @@ -49,8 +50,8 @@ def preprocess(i): if x != '': env['MLC_RUN_CMD'] = x + ' ' + env.get('MLC_RUN_CMD', '') - if os_info['platform'] != 'windows' and str( - env.get('MLC_SAVE_CONSOLE_LOG', True)).lower() not in ["no", "false", "0"]: + if os_info['platform'] != 'windows' and not is_false( + env.get('MLC_SAVE_CONSOLE_LOG', True)): logs_dir = env.get('MLC_LOGS_DIR', env['MLC_RUN_DIR']) env['MLC_RUN_CMD'] += r" 2>&1 | tee " + q + os.path.join( logs_dir, "console.out") + q + r"; echo \${PIPESTATUS[0]} > exitstatus" diff --git a/script/download-file/customize.py b/script/download-file/customize.py index f72034d5f..64066122f 100644 --- a/script/download-file/customize.py +++ b/script/download-file/customize.py @@ -85,8 +85,7 @@ def preprocess(i): extra_download_options = env.get('MLC_DOWNLOAD_EXTRA_OPTIONS', '') verify_ssl = env.get('MLC_VERIFY_SSL', "True") - if str(verify_ssl).lower() in [ - "no", "false"] or os_info['platform'] == 'windows': + if is_false(verify_ssl) or os_info['platform'] == 'windows': verify_ssl = False else: verify_ssl = True diff --git a/script/generate-mlperf-inference-user-conf/customize.py b/script/generate-mlperf-inference-user-conf/customize.py index 4863aa494..ec1a5fab7 100644 --- a/script/generate-mlperf-inference-user-conf/customize.py +++ b/script/generate-mlperf-inference-user-conf/customize.py @@ -4,6 +4,7 @@ import shutil import subprocess import sys +from utils import * def preprocess(i): @@ -112,8 +113,8 @@ def preprocess(i): env['MLC_MLPERF_USE_MAX_DURATION'] = 'no' elif scenario == "MultiStream" and (1000 / float(value) * 660 < 662): env['MLC_MLPERF_USE_MAX_DURATION'] = 'no' - if env.get('MLC_MLPERF_MODEL_EQUAL_ISSUE_MODE', 'no').lower() not in ["yes", "1", "true"] and env.get( - 'MLC_MLPERF_USE_MAX_DURATION', "yes").lower() not in ["no", "false", "0"]: + if not is_true(env.get('MLC_MLPERF_MODEL_EQUAL_ISSUE_MODE', 'no')) and not is_false(env.get( + 'MLC_MLPERF_USE_MAX_DURATION', "yes")): tolerance = 0.4 # much lower because we have max_duration else: tolerance = 0.9 diff --git a/script/run-docker-container/customize.py b/script/run-docker-container/customize.py index a504ffd07..02ef20fd0 100644 --- a/script/run-docker-container/customize.py +++ b/script/run-docker-container/customize.py @@ -185,8 +185,8 @@ def postprocess(i): if is_true(env.get('MLC_DOCKER_USE_GOOGLE_DNS', '')): run_opts += ' --dns 8.8.8.8 --dns 8.8.4.4 ' - if env.get('MLC_CONTAINER_TOOL', '') == 'podman' and env.get( - 'MLC_PODMAN_MAP_USER_ID', '').lower() not in ["no", "0", "false"]: + if env.get('MLC_CONTAINER_TOOL', '') == 'podman' and not is_false(env.get( + 'MLC_PODMAN_MAP_USER_ID', '')): run_opts += " --userns=keep-id" if env.get('MLC_DOCKER_PORT_MAPS', []):