From f5264a715d18e223f8578f0877cf7625822c66b8 Mon Sep 17 00:00:00 2001 From: sid9993 Date: Wed, 19 Feb 2025 23:59:29 +0530 Subject: [PATCH 01/10] Cleaned the boolean usage in MLCFlow --- script/benchmark-program/customize.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/script/benchmark-program/customize.py b/script/benchmark-program/customize.py index 25b7a17e3..5597e5720 100644 --- a/script/benchmark-program/customize.py +++ b/script/benchmark-program/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from automation.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,7 @@ 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" From 080aa2993a9df39c1211c26411d0cb4637b16314 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 19 Feb 2025 18:29:52 +0000 Subject: [PATCH 02/10] [Automated Commit] Format Codebase [skip ci] --- script/benchmark-program/customize.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/benchmark-program/customize.py b/script/benchmark-program/customize.py index 5597e5720..952bf7aec 100644 --- a/script/benchmark-program/customize.py +++ b/script/benchmark-program/customize.py @@ -50,7 +50,8 @@ def preprocess(i): if x != '': env['MLC_RUN_CMD'] = x + ' ' + env.get('MLC_RUN_CMD', '') - if os_info['platform'] != 'windows' and not is_false(env.get('MLC_SAVE_CONSOLE_LOG', True)): + 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" From 6d2047ab50b5cdd4fd1d46914bb8840d1475a13d Mon Sep 17 00:00:00 2001 From: sid9993 Date: Thu, 20 Feb 2025 00:21:14 +0530 Subject: [PATCH 03/10] Changed the import --- script/benchmark-program/customize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/benchmark-program/customize.py b/script/benchmark-program/customize.py index 952bf7aec..a355e8248 100644 --- a/script/benchmark-program/customize.py +++ b/script/benchmark-program/customize.py @@ -1,6 +1,6 @@ from mlc import utils import os -from automation.utils import * +from utils import * def preprocess(i): From 074ad79f4585d16b99f6ab5261b8a4e23e260baa Mon Sep 17 00:00:00 2001 From: sid9993 Date: Thu, 20 Feb 2025 01:32:03 +0530 Subject: [PATCH 04/10] Made the remaining script changes --- automation/script/docker.py | 2 +- automation/script/module.py | 4 ++-- script/app-mlperf-inference-nvidia/customize.py | 5 ++--- script/app-mlperf-inference/customize.py | 4 ++-- script/download-file/customize.py | 3 +-- script/generate-mlperf-inference-user-conf/customize.py | 6 +++--- script/run-docker-container/customize.py | 4 ++-- 7 files changed, 13 insertions(+), 15 deletions(-) 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..fd48d65ee 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -5039,7 +5039,7 @@ 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): continue elif set(meta_key) & set(["no", "off", "false", "0"]): if value in ["no", "off", "false", "0", ""]: @@ -5072,7 +5072,7 @@ 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 is_false(value): found = True elif set(meta_key) & set(["no", "off", "false", "0", ""]): if value in ["no", "off", "false", "0", ""]: diff --git a/script/app-mlperf-inference-nvidia/customize.py b/script/app-mlperf-inference-nvidia/customize.py index 550b273fe..877f851e4 100644 --- a/script/app-mlperf-inference-nvidia/customize.py +++ b/script/app-mlperf-inference-nvidia/customize.py @@ -1,7 +1,7 @@ from mlc import utils import os import shutil - +from utils import * def preprocess(i): @@ -590,8 +590,7 @@ 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/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..acc1ab623 100644 --- a/script/generate-mlperf-inference-user-conf/customize.py +++ b/script/generate-mlperf-inference-user-conf/customize.py @@ -4,7 +4,7 @@ import shutil import subprocess import sys - +from utils import * def preprocess(i): @@ -112,8 +112,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', []): From 9877f8938c7cbcd36feff9820ae0ab837898342d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 19 Feb 2025 20:02:23 +0000 Subject: [PATCH 05/10] [Automated Commit] Format Codebase [skip ci] --- script/app-mlperf-inference-nvidia/customize.py | 4 +++- script/generate-mlperf-inference-user-conf/customize.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/script/app-mlperf-inference-nvidia/customize.py b/script/app-mlperf-inference-nvidia/customize.py index 877f851e4..70e5d3710 100644 --- a/script/app-mlperf-inference-nvidia/customize.py +++ b/script/app-mlperf-inference-nvidia/customize.py @@ -3,6 +3,7 @@ import shutil from utils import * + def preprocess(i): os_info = i['os_info'] @@ -590,7 +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 not is_false(run_infer_on_copy_streams): + 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/generate-mlperf-inference-user-conf/customize.py b/script/generate-mlperf-inference-user-conf/customize.py index acc1ab623..ec1a5fab7 100644 --- a/script/generate-mlperf-inference-user-conf/customize.py +++ b/script/generate-mlperf-inference-user-conf/customize.py @@ -6,6 +6,7 @@ import sys from utils import * + def preprocess(i): os_info = i['os_info'] From ac6f327a445bdd0404b4f2ed39f44167419aa8be Mon Sep 17 00:00:00 2001 From: sid9993 Date: Thu, 20 Feb 2025 09:31:48 +0530 Subject: [PATCH 06/10] Made changes in module.py --- automation/script/module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automation/script/module.py b/automation/script/module.py index fd48d65ee..01070054d 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -5072,7 +5072,7 @@ 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 is_false(value): + if not is_false(value): found = True elif set(meta_key) & set(["no", "off", "false", "0", ""]): if value in ["no", "off", "false", "0", ""]: From 8cc6874670efd734903e5a4e588eba89b4acf04a Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Thu, 20 Feb 2025 19:15:28 +0000 Subject: [PATCH 07/10] Update module.py --- automation/script/module.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automation/script/module.py b/automation/script/module.py index 01070054d..f921fcdc8 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -5029,7 +5029,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,7 +5039,7 @@ 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 not is_false(value): + if value != '' or not is_false(value): continue elif set(meta_key) & set(["no", "off", "false", "0"]): if value in ["no", "off", "false", "0", ""]: From 95ecdcf2e8f5043fe8aaa0c517ac1de35fb39095 Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Thu, 20 Feb 2025 19:16:20 +0000 Subject: [PATCH 08/10] Update module.py --- automation/script/module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automation/script/module.py b/automation/script/module.py index f921fcdc8..319e403af 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -5072,7 +5072,7 @@ 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 not is_false(value): + if value != '' or not is_false(value): found = True elif set(meta_key) & set(["no", "off", "false", "0", ""]): if value in ["no", "off", "false", "0", ""]: From 96faa8a1f48ccd64a78a09df03e2c6f4387cb734 Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Thu, 20 Feb 2025 19:22:52 +0000 Subject: [PATCH 09/10] Update module.py | fix boolean usage in script module --- automation/script/module.py | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/automation/script/module.py b/automation/script/module.py index 319e403af..f158a7f28 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', []) @@ -5042,7 +5035,7 @@ def enable_or_skip_script(meta, env): if value != '' or not is_false(value): continue elif set(meta_key) & set(["no", "off", "false", "0"]): - if value in ["no", "off", "false", "0", ""]: + if value == "" or is_false(value): continue elif value in meta_key: continue @@ -5075,7 +5068,7 @@ def any_enable_or_skip_script(meta, env): if value != '' or not is_false(value): found = True elif set(meta_key) & set(["no", "off", "false", "0", ""]): - if value in ["no", "off", "false", "0", ""]: + if value == "" or is_false(value): found = True elif value in meta_key: found = True From 75be4f7439b25386a361d6208dfb22f79728667e Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Thu, 20 Feb 2025 19:39:22 +0000 Subject: [PATCH 10/10] Update module.py --- automation/script/module.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/automation/script/module.py b/automation/script/module.py index f158a7f28..cadf35608 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -5032,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 != '' or not is_false(value): + if not is_false(value) and value != '': continue elif set(meta_key) & set(["no", "off", "false", "0"]): - if value == "" or is_false(value): + if is_false(value) or value == "": continue elif value in meta_key: continue @@ -5065,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 != '' or not is_false(value): + if not is_false(value) and value != "": found = True elif set(meta_key) & set(["no", "off", "false", "0", ""]): - if value == "" or is_false(value): + if is_false(value) or value == "": found = True elif value in meta_key: found = True