Skip to content

Commit de26510

Browse files
Sid9993github-actions[bot]arjunsuresh
authored
Cleaned the boolean usage in MLCFlow (#246)
* Cleaned the boolean usage in MLCFlow * Made the remaining script changes * Update module.py | fix boolean usage in script module --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Arjun Suresh <arjun@gateoverflow.com>
1 parent 86f7e11 commit de26510

File tree

8 files changed

+31
-36
lines changed

8 files changed

+31
-36
lines changed

automation/script/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def docker_run(self_module, i):
246246
for t in i.get('tags', '').split(",") if t.startswith("_")]
247247

248248
docker_cache = i.get('docker_cache', "yes")
249-
if docker_cache.lower() in ["no", "false"]:
249+
if is_false(docker_cache):
250250
env.setdefault('MLC_DOCKER_CACHE', docker_cache)
251251

252252
image_repo = i.get('docker_image_repo', '')

automation/script/module.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ def _run(self, i):
358358
if fake_deps:
359359
env['MLC_TMP_FAKE_DEPS'] = 'yes'
360360

361-
if str(i.get('skip_sys_utils', '')).lower() in ['true', 'yes']:
361+
if is_true(i.get('skip_sys_utils', '')):
362362
env['MLC_SKIP_SYS_UTILS'] = 'yes'
363-
if str(i.get('skip_sudo', '')).lower() in ['true', 'yes']:
363+
if is_true(i.get('skip_sudo', '')):
364364
env['MLC_TMP_SKIP_SUDO'] = 'yes'
365365

366366
run_state = i.get('run_state', self.run_state)
@@ -374,12 +374,10 @@ def _run(self, i):
374374
# Check verbose and silent
375375
verbose = False
376376

377-
silent = True if str(i.get('silent', '')).lower() in [
378-
'true', 'yes', 'on'] else False
377+
silent = True if is_true(i.get('silent', '')) else False
379378

380379
if not silent:
381-
silent = True if str(i.get('s', '')).lower() in [
382-
'true', 'yes', 'on'] else False
380+
silent = True if is_true(i.get('s', '')) else False
383381

384382
if silent:
385383
if 'verbose' in i:
@@ -1020,11 +1018,9 @@ def _run(self, i):
10201018
if r['return'] > 0:
10211019
return r
10221020

1023-
if str(env.get('MLC_RUN_STATE_DOCKER', False)
1024-
).lower() in ['true', '1', 'yes']:
1021+
if is_true(env.get('MLC_RUN_STATE_DOCKER', False)):
10251022
if state.get('docker'):
1026-
if str(state['docker'].get('run', True)
1027-
).lower() in ['false', '0', 'no']:
1023+
if is_false(state['docker'].get('run', True)):
10281024
logger.info(
10291025
recursion_spaces +
10301026
' - Skipping script::{} run as we are inside docker'.format(found_script_item))
@@ -1047,7 +1043,7 @@ def _run(self, i):
10471043
'deps': []}
10481044
return rr
10491045

1050-
elif str(state['docker'].get('real_run', True)).lower() in ['false', '0', 'no']:
1046+
elif is_false(state['docker'].get('real_run', True)):
10511047
logger.info(
10521048
recursion_spaces +
10531049
' - Doing fake run for script::{} as we are inside docker'.format(found_script_item))
@@ -1576,7 +1572,7 @@ def _run(self, i):
15761572
}
15771573

15781574
# Check and run predeps in customize.py
1579-
if str(meta.get('predeps', 'True')).lower() not in ["0", "false", "no"] and os.path.isfile(
1575+
if not is_false(meta.get('predeps', 'True')) and os.path.isfile(
15801576
path_to_customize_py): # possible duplicate execution - needs fix
15811577
r = utils.load_python_module(
15821578
{'path': path, 'name': 'customize'})
@@ -2962,13 +2958,10 @@ def test(self, i):
29622958
run_variations = [
29632959
f"_{v}" for v in variations if variations[v].get(
29642960
'group',
2965-
'') == '' and str(
2961+
'') == '' and not is_true(
29662962
variations[v].get(
29672963
'exclude-in-test',
2968-
'')).lower() not in [
2969-
"1",
2970-
"true",
2971-
"yes"]]
2964+
''))]
29722965
else:
29732966
given_variations = run_input.get(
29742967
'variations_list', [])
@@ -5029,7 +5022,7 @@ def enable_or_skip_script(meta, env):
50295022
"""
50305023

50315024
if not isinstance(meta, dict):
5032-
logger.info(
5025+
logger.warn(
50335026
"The meta entry is not a dictionary for skip/enable if_env: %s",
50345027
meta)
50355028

@@ -5039,10 +5032,10 @@ def enable_or_skip_script(meta, env):
50395032
value = str(env[key]).lower().strip()
50405033
if set(meta_key) & set(["yes", "on", "true", "1"]):
50415034
# Any set value other than false is taken as set
5042-
if value not in ["no", "off", "false", "0", ""]:
5035+
if not is_false(value) and value != '':
50435036
continue
50445037
elif set(meta_key) & set(["no", "off", "false", "0"]):
5045-
if value in ["no", "off", "false", "0", ""]:
5038+
if is_false(value) or value == "":
50465039
continue
50475040
elif value in meta_key:
50485041
continue
@@ -5072,10 +5065,10 @@ def any_enable_or_skip_script(meta, env):
50725065
meta_key = [str(v).lower() for v in meta[key]]
50735066

50745067
if set(meta_key) & set(["yes", "on", "true", "1"]):
5075-
if value not in ["no", "off", "false", "0", ""]:
5068+
if not is_false(value) and value != "":
50765069
found = True
50775070
elif set(meta_key) & set(["no", "off", "false", "0", ""]):
5078-
if value in ["no", "off", "false", "0", ""]:
5071+
if is_false(value) or value == "":
50795072
found = True
50805073
elif value in meta_key:
50815074
found = True

script/app-mlperf-inference-nvidia/customize.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from mlc import utils
22
import os
33
import shutil
4+
from utils import *
45

56

67
def preprocess(i):
@@ -590,8 +591,8 @@ def preprocess(i):
590591

591592
run_infer_on_copy_streams = str(
592593
env.get('MLC_MLPERF_NVIDIA_HARNESS_RUN_INFER_ON_COPY_STREAMS', ''))
593-
if run_infer_on_copy_streams and run_infer_on_copy_streams.lower() not in [
594-
"no", "false", "0", ""]:
594+
if run_infer_on_copy_streams and not is_false(
595+
run_infer_on_copy_streams):
595596
run_config += " --run_infer_on_copy_streams"
596597

597598
start_from_device = str(

script/app-mlperf-inference/customize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import mlperf_utils
1111
import re
1212
from datetime import datetime, timezone
13+
from utils import *
1314

1415

1516
def preprocess(i):
@@ -286,8 +287,7 @@ def postprocess(i):
286287
state['app_mlperf_inference_log_summary'][y[0].strip().lower()
287288
] = y[1].strip()
288289

289-
if env.get("MLC_MLPERF_PRINT_SUMMARY", "").lower() not in [
290-
"no", "0", "false"]:
290+
if not is_false(env.get("MLC_MLPERF_PRINT_SUMMARY", "")):
291291
print("\n")
292292
print(mlperf_log_summary)
293293

script/benchmark-program/customize.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mlc import utils
22
import os
3+
from utils import *
34

45

56
def preprocess(i):
@@ -20,7 +21,7 @@ def preprocess(i):
2021
env['MLC_RUN_CMD'] += ' ' + env['MLC_RUN_SUFFIX']
2122

2223
else:
23-
if env['MLC_ENABLE_NUMACTL'].lower() in ["on", "1", "true", "yes"]:
24+
if is_true(env['MLC_ENABLE_NUMACTL']):
2425
env['MLC_ENABLE_NUMACTL'] = "1"
2526
MLC_RUN_PREFIX = "numactl " + env['MLC_NUMACTL_MEMBIND'] + ' '
2627
else:
@@ -49,8 +50,8 @@ def preprocess(i):
4950
if x != '':
5051
env['MLC_RUN_CMD'] = x + ' ' + env.get('MLC_RUN_CMD', '')
5152

52-
if os_info['platform'] != 'windows' and str(
53-
env.get('MLC_SAVE_CONSOLE_LOG', True)).lower() not in ["no", "false", "0"]:
53+
if os_info['platform'] != 'windows' and not is_false(
54+
env.get('MLC_SAVE_CONSOLE_LOG', True)):
5455
logs_dir = env.get('MLC_LOGS_DIR', env['MLC_RUN_DIR'])
5556
env['MLC_RUN_CMD'] += r" 2>&1 | tee " + q + os.path.join(
5657
logs_dir, "console.out") + q + r"; echo \${PIPESTATUS[0]} > exitstatus"

script/download-file/customize.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ def preprocess(i):
8585
extra_download_options = env.get('MLC_DOWNLOAD_EXTRA_OPTIONS', '')
8686

8787
verify_ssl = env.get('MLC_VERIFY_SSL', "True")
88-
if str(verify_ssl).lower() in [
89-
"no", "false"] or os_info['platform'] == 'windows':
88+
if is_false(verify_ssl) or os_info['platform'] == 'windows':
9089
verify_ssl = False
9190
else:
9291
verify_ssl = True

script/generate-mlperf-inference-user-conf/customize.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import shutil
55
import subprocess
66
import sys
7+
from utils import *
78

89

910
def preprocess(i):
@@ -112,8 +113,8 @@ def preprocess(i):
112113
env['MLC_MLPERF_USE_MAX_DURATION'] = 'no'
113114
elif scenario == "MultiStream" and (1000 / float(value) * 660 < 662):
114115
env['MLC_MLPERF_USE_MAX_DURATION'] = 'no'
115-
if env.get('MLC_MLPERF_MODEL_EQUAL_ISSUE_MODE', 'no').lower() not in ["yes", "1", "true"] and env.get(
116-
'MLC_MLPERF_USE_MAX_DURATION', "yes").lower() not in ["no", "false", "0"]:
116+
if not is_true(env.get('MLC_MLPERF_MODEL_EQUAL_ISSUE_MODE', 'no')) and not is_false(env.get(
117+
'MLC_MLPERF_USE_MAX_DURATION', "yes")):
117118
tolerance = 0.4 # much lower because we have max_duration
118119
else:
119120
tolerance = 0.9

script/run-docker-container/customize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ def postprocess(i):
185185
if is_true(env.get('MLC_DOCKER_USE_GOOGLE_DNS', '')):
186186
run_opts += ' --dns 8.8.8.8 --dns 8.8.4.4 '
187187

188-
if env.get('MLC_CONTAINER_TOOL', '') == 'podman' and env.get(
189-
'MLC_PODMAN_MAP_USER_ID', '').lower() not in ["no", "0", "false"]:
188+
if env.get('MLC_CONTAINER_TOOL', '') == 'podman' and not is_false(env.get(
189+
'MLC_PODMAN_MAP_USER_ID', '')):
190190
run_opts += " --userns=keep-id"
191191

192192
if env.get('MLC_DOCKER_PORT_MAPS', []):

0 commit comments

Comments
 (0)