From 1b9a32d443b5c7cbd1c41a913c754303e14ef858 Mon Sep 17 00:00:00 2001 From: ANANDHU S <71482562+anandhu-eng@users.noreply.github.com> Date: Mon, 31 Mar 2025 02:11:27 +0530 Subject: [PATCH 01/18] Verify SSL moved to Script Automation (#338) * verify_ssl moved to script automation * code clean --- automation/script/module.py | 3 ++- automation/utils.py | 6 +++--- script/download-and-extract/meta.yaml | 1 - script/download-file/customize.py | 12 ++++++------ script/download-file/meta.yaml | 2 -- script/get-ml-model-gptj/meta.yaml | 3 ++- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/automation/script/module.py b/automation/script/module.py index 1b4875237..e2dafbb95 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -82,7 +82,8 @@ def __init__(self, action_object, automation_file): 'skip_system_deps', 'git_ssh', 'gh_token', - 'hf_token'] + 'hf_token', + 'verify_ssl'] ############################################################ diff --git a/automation/utils.py b/automation/utils.py index 564d06439..986888e87 100644 --- a/automation/utils.py +++ b/automation/utils.py @@ -178,10 +178,10 @@ def download_file(i): text = i.get('text', 'Downloaded: ') - if 'MLC_UTILS_DOWNLOAD_VERIFY_SSL' in os.environ: - verify = os.environ['MLC_UTILS_DOWNLOAD_VERIFY_SSL'] == 'yes' + if 'MLC_VERIFY_SSL' in os.environ: + verify = is_true(os.environ['MLC_VERIFY_SSL']) else: - verify = i.get('verify', True) + verify = is_true(i.get('verify_ssl', True)) try: with requests.get(url, stream=True, allow_redirects=True, verify=verify) as download: diff --git a/script/download-and-extract/meta.yaml b/script/download-and-extract/meta.yaml index 2b8748b2e..04088be27 100644 --- a/script/download-and-extract/meta.yaml +++ b/script/download-and-extract/meta.yaml @@ -15,7 +15,6 @@ input_mapping: store: MLC_DOWNLOAD_PATH to: MLC_EXTRACT_PATH url: MLC_DAE_URL - verify: MLC_VERIFY_SSL new_env_keys: - MLC_DOWNLOAD_DOWNLOADED_PATH* - MLC_EXTRACT_EXTRACTED_PATH diff --git a/script/download-file/customize.py b/script/download-file/customize.py index 1081c31e6..5e162fcf2 100644 --- a/script/download-file/customize.py +++ b/script/download-file/customize.py @@ -84,8 +84,8 @@ def preprocess(i): extra_download_options = env.get('MLC_DOWNLOAD_EXTRA_OPTIONS', '') - verify_ssl = env.get('MLC_VERIFY_SSL', "True") - if is_false(verify_ssl) or os_info['platform'] == 'windows': + verify_ssl = is_true(env.get('MLC_VERIFY_SSL', "True")) + if not verify_ssl or os_info['platform'] == 'windows': verify_ssl = False else: verify_ssl = True @@ -229,17 +229,17 @@ def preprocess(i): rclone_copy_using = env.get('MLC_RCLONE_COPY_USING', 'sync') if rclone_copy_using == "sync": pre_clean = False + if not verify_ssl: + extra_download_options += " --no-check-certificate " if env["MLC_HOST_OS_TYPE"] == "windows": # have to modify the variable from url to temp_url if it is # going to be used anywhere after this point url = url.replace("%", "%%") temp_download_file = env['MLC_DOWNLOAD_FILENAME'].replace( "%", "%%") - env['MLC_DOWNLOAD_CMD'] = f"rclone {rclone_copy_using} {q}{url}{q} {q}{os.path.join(os.getcwd(), temp_download_file)}{q} -P --error-on-no-transfer" + env['MLC_DOWNLOAD_CMD'] = f"rclone {rclone_copy_using} {q}{url}{q} {q}{os.path.join(os.getcwd(), temp_download_file)}{q} -P --error-on-no-transfer {extra_download_options}" else: - env['MLC_DOWNLOAD_CMD'] = f"rclone {rclone_copy_using} {q}{url}{q} {q}{os.path.join(os.getcwd(), env['MLC_DOWNLOAD_FILENAME'])}{q} -P --error-on-no-transfer" - if not verify_ssl: - env['MLC_DOWNLOAD_CMD'] += f" --no-check-certificate" + env['MLC_DOWNLOAD_CMD'] = f"rclone {rclone_copy_using} {q}{url}{q} {q}{os.path.join(os.getcwd(), env['MLC_DOWNLOAD_FILENAME'])}{q} -P --error-on-no-transfer {extra_download_options}" filename = env['MLC_DOWNLOAD_FILENAME'] env['MLC_DOWNLOAD_DOWNLOADED_FILENAME'] = filename diff --git a/script/download-file/meta.yaml b/script/download-file/meta.yaml index 28ac8e31b..92d11e430 100644 --- a/script/download-file/meta.yaml +++ b/script/download-file/meta.yaml @@ -24,8 +24,6 @@ input_mapping: output_file: MLC_DOWNLOAD_FILENAME store: MLC_DOWNLOAD_PATH url: MLC_DOWNLOAD_URL - verify: MLC_VERIFY_SSL - verify_ssl: MLC_VERIFY_SSL new_env_keys: - MLC_DOWNLOAD_DOWNLOADED_PATH - <<>> diff --git a/script/get-ml-model-gptj/meta.yaml b/script/get-ml-model-gptj/meta.yaml index 9ebaf1524..fb3553c06 100644 --- a/script/get-ml-model-gptj/meta.yaml +++ b/script/get-ml-model-gptj/meta.yaml @@ -95,7 +95,6 @@ variations: pytorch,fp32: env: MLC_DOWNLOAD_CHECKSUM_NOT_USED: e677e28aaf03da84584bb3073b7ee315 - MLC_DOWNLOAD_EXTRA_OPTIONS: ' --output-document checkpoint.zip' MLC_PACKAGE_URL: https://cloud.mlcommons.org/index.php/s/QAZ2oM94MkFtbQx/download MLC_RCLONE_CONFIG_NAME: mlc-inference MLC_RCLONE_URL: mlc-inference:mlcommons-inference-wg-public/gpt-j @@ -105,6 +104,8 @@ variations: add_deps_recursive: dae: tags: _extract + env: + MLC_DOWNLOAD_EXTRA_OPTIONS: ' --output-document checkpoint.zip' pytorch,int4,intel: {} pytorch,int8,intel: {} pytorch,intel: From e2f68793f1ccdb4d88bc7c7602346110488ecf94 Mon Sep 17 00:00:00 2001 From: ANANDHU S <71482562+anandhu-eng@users.noreply.github.com> Date: Mon, 31 Mar 2025 19:59:29 +0530 Subject: [PATCH 02/18] Add dry run + generalise rclone download (#339) * add dry run = generalise rclone download * [Automated Commit] Format Codebase [skip ci] --- script/download-and-extract/customize.py | 4 +++ script/download-and-extract/meta.yaml | 3 ++ script/download-file/customize.py | 3 ++ script/download-file/run.sh | 2 +- .../customize.py | 9 +----- .../get-dataset-waymo-calibration/meta.yaml | 30 +++++++++++++++++++ .../run-rclone.sh | 4 --- script/get-dataset-waymo-calibration/run.sh | 5 ++++ script/get-dataset-waymo/customize.py | 7 ----- script/get-dataset-waymo/meta.yaml | 30 +++++++++++++++++++ script/get-dataset-waymo/run-rclone.sh | 7 ----- script/get-dataset-waymo/run.sh | 6 ++++ script/get-ml-model-llama3/customize.py | 13 +++----- script/get-ml-model-llama3/meta.yaml | 30 +++++++++++++++++++ script/get-ml-model-llama3/run-rclone.sh | 4 --- .../get-preprocessed-dataset-criteo/meta.yaml | 20 +++++++++++-- 16 files changed, 135 insertions(+), 42 deletions(-) delete mode 100644 script/get-dataset-waymo-calibration/run-rclone.sh create mode 100644 script/get-dataset-waymo-calibration/run.sh delete mode 100644 script/get-dataset-waymo/run-rclone.sh delete mode 100644 script/get-ml-model-llama3/run-rclone.sh diff --git a/script/download-and-extract/customize.py b/script/download-and-extract/customize.py index 86f8b1d77..45e2d6fdc 100644 --- a/script/download-and-extract/customize.py +++ b/script/download-and-extract/customize.py @@ -54,6 +54,10 @@ def preprocess(i): def postprocess(i): env = i['env'] + + if env.get('MLC_DOWNLOAD_MODE') == "dry": + return {'return': 0} + filepath = env.get('MLC_EXTRACT_EXTRACTED_PATH', '') if filepath == '': filepath = env.get('MLC_DOWNLOAD_DOWNLOADED_PATH', '') diff --git a/script/download-and-extract/meta.yaml b/script/download-and-extract/meta.yaml index 04088be27..d2137d71c 100644 --- a/script/download-and-extract/meta.yaml +++ b/script/download-and-extract/meta.yaml @@ -30,6 +30,9 @@ posthook_deps: MLC_DAE_EXTRACT_DOWNLOADED: - 'yes' - 'True' + skip_if_env: + MLC_DOWNLOAD_MODE: + - 'dry' names: - extract-script tags: extract,file diff --git a/script/download-file/customize.py b/script/download-file/customize.py index 5e162fcf2..bb97f5467 100644 --- a/script/download-file/customize.py +++ b/script/download-file/customize.py @@ -313,6 +313,9 @@ def postprocess(i): env = i['env'] + if env.get('MLC_DOWNLOAD_MODE') == "dry": + return {'return': 0} + filepath = env['MLC_DOWNLOAD_DOWNLOADED_PATH'] if not os.path.exists(filepath): diff --git a/script/download-file/run.sh b/script/download-file/run.sh index 2664ac52b..b792a9e61 100644 --- a/script/download-file/run.sh +++ b/script/download-file/run.sh @@ -50,7 +50,7 @@ if [[ ${require_download} == 1 ]]; then fi # Verify checksum again if necessary -if [[ ${MLC_DOWNLOAD_TOOL} == "mlcutil" || ${require_download} == 1 ]]; then +if [[ "${MLC_DOWNLOAD_MODE}" != "dry" && ( "${MLC_DOWNLOAD_TOOL}" == "mlcutil" || ${require_download} == 1 ) ]]; then if [[ -n "${MLC_DOWNLOAD_CHECKSUM_CMD}" ]]; then echo -e "\nVerifying checksum after download: ${MLC_DOWNLOAD_CHECKSUM_CMD}" eval "${MLC_DOWNLOAD_CHECKSUM_CMD}" || exit $? diff --git a/script/get-dataset-waymo-calibration/customize.py b/script/get-dataset-waymo-calibration/customize.py index e404aa512..a831e4c3f 100644 --- a/script/get-dataset-waymo-calibration/customize.py +++ b/script/get-dataset-waymo-calibration/customize.py @@ -14,16 +14,9 @@ def preprocess(i): if env.get('MLC_DATASET_WAYMO_CALIBRATION_PATH', '') != '': if not os.path.exists(env['MLC_DATASET_WAYMO_CALIBRATION_PATH']): return { - 'return': 1, 'error': f"Path {env['MLC_DATASET_WAYMO_CALIBRATION_PATH']} does not exists!"} + 'return': 1, 'error': f"Path {env['MLC_DATASET_WAYMO_CALIBRATION_PATH']} does not exist!"} else: env['MLC_TMP_REQUIRE_DOWNLOAD'] = "yes" - if env['MLC_DOWNLOAD_SRC'] == "mlcommons": - i['run_script_input']['script_name'] = 'run-rclone' - if env.get('MLC_OUTDIRNAME', '') != '': - env['MLC_DATASET_WAYMO_CALIBRATION_PATH'] = env['MLC_OUTDIRNAME'] - else: - env['MLC_DATASET_WAYMO_CALIBRATION_PATH'] = os.path.join( - os.getcwd(), "kitti_format", "calibration") return {'return': 0} diff --git a/script/get-dataset-waymo-calibration/meta.yaml b/script/get-dataset-waymo-calibration/meta.yaml index dbc17d494..cf9976fa7 100644 --- a/script/get-dataset-waymo-calibration/meta.yaml +++ b/script/get-dataset-waymo-calibration/meta.yaml @@ -33,3 +33,33 @@ variations: - true force_cache: true tags: get,rclone-config,_waymo + - enable_if_env: + MLC_TMP_REQUIRE_DOWNLOAD: + - 'yes' + env: + MLC_DOWNLOAD_FINAL_ENV_NAME: MLC_DATASET_WAYMO_CALIBRATION_PATH + MLC_EXTRACT_FINAL_ENV_NAME: MLC_DATASET_WAYMO_CALIBRATION_PATH + MLC_DOWNLOAD_URL: mlc-waymo:waymo_preprocessed_dataset/kitti_format/testing + extra_cache_tags: waymo,dataset + force_cache: true + names: + - dae + tags: download-and-extract + force_env_keys: + - MLC_OUTDIRNAME + update_tags_from_env_with_prefix: + _url.: + - MLC_DOWNLOAD_URL + rclone: + group: download-tool + add_deps_recursive: + dae: + tags: _rclone + default: true + dry-run: + group: run-mode + env: + MLC_DOWNLOAD_MODE: dry + dry-run,rclone: + env: + MLC_DOWNLOAD_EXTRA_OPTIONS: --dry-run \ No newline at end of file diff --git a/script/get-dataset-waymo-calibration/run-rclone.sh b/script/get-dataset-waymo-calibration/run-rclone.sh deleted file mode 100644 index fd289eff4..000000000 --- a/script/get-dataset-waymo-calibration/run-rclone.sh +++ /dev/null @@ -1,4 +0,0 @@ -cmd="rclone sync mlc-waymo:waymo_preprocessed_dataset/kitti_format/testing ${MLC_DATASET_WAYMO_CALIBRATION_PATH} -P" -echo $cmd -eval $cmd -test $? -eq 0 || exit $? \ No newline at end of file diff --git a/script/get-dataset-waymo-calibration/run.sh b/script/get-dataset-waymo-calibration/run.sh new file mode 100644 index 000000000..8fdfea598 --- /dev/null +++ b/script/get-dataset-waymo-calibration/run.sh @@ -0,0 +1,5 @@ +if [[ "$MLC_DOWNLOAD_MODE" != "dry" && "$MLC_TMP_REQUIRE_DOWNLOAD" = "true" ]]; then + cd "${MLC_DATASET_WAYMO_CALIBRATION_PATH}/testing" || exit + for f in *.tar.gz; do tar -xzvf "$f"; done + cd - || exit +fi \ No newline at end of file diff --git a/script/get-dataset-waymo/customize.py b/script/get-dataset-waymo/customize.py index cb625f443..833fcbf6c 100644 --- a/script/get-dataset-waymo/customize.py +++ b/script/get-dataset-waymo/customize.py @@ -17,13 +17,6 @@ def preprocess(i): 'return': 1, 'error': f"Path {env['MLC_DATASET_WAYMO_PATH']} does not exists!"} else: env['MLC_TMP_REQUIRE_DOWNLOAD'] = "yes" - if env['MLC_DOWNLOAD_SRC'] == "mlcommons": - i['run_script_input']['script_name'] = 'run-rclone' - if env.get('MLC_OUTDIRNAME', '') != '': - env['MLC_DATASET_WAYMO_PATH'] = env['MLC_OUTDIRNAME'] - else: - env['MLC_DATASET_WAYMO_PATH'] = os.path.join( - os.getcwd(), "kitti_format") return {'return': 0} diff --git a/script/get-dataset-waymo/meta.yaml b/script/get-dataset-waymo/meta.yaml index 63bbf2472..bfeb56a8c 100644 --- a/script/get-dataset-waymo/meta.yaml +++ b/script/get-dataset-waymo/meta.yaml @@ -30,5 +30,35 @@ variations: enable_if_env: MLC_TMP_REQUIRE_DOWNLOAD: - yes + - enable_if_env: + MLC_TMP_REQUIRE_DOWNLOAD: + - 'yes' + env: + MLC_DOWNLOAD_FINAL_ENV_NAME: MLC_DATASET_WAYMO_PATH + MLC_EXTRACT_FINAL_ENV_NAME: MLC_DATASET_WAYMO_PATH + MLC_DOWNLOAD_URL: mlc-waymo:waymo_preprocessed_dataset/kitti_format + extra_cache_tags: waymo,dataset + force_cache: true + names: + - dae + tags: download-and-extract + force_env_keys: + - MLC_OUTDIRNAME + update_tags_from_env_with_prefix: + _url.: + - MLC_DOWNLOAD_URL env: MLC_DOWNLOAD_SRC: mlcommons + rclone: + group: download-tool + add_deps_recursive: + dae: + tags: _rclone + default: true + dry-run: + group: run-mode + env: + MLC_DOWNLOAD_MODE: dry + dry-run,rclone: + env: + MLC_DOWNLOAD_EXTRA_OPTIONS: --dry-run diff --git a/script/get-dataset-waymo/run-rclone.sh b/script/get-dataset-waymo/run-rclone.sh deleted file mode 100644 index 12aac3377..000000000 --- a/script/get-dataset-waymo/run-rclone.sh +++ /dev/null @@ -1,7 +0,0 @@ -cmd="rclone sync mlc-waymo:waymo_preprocessed_dataset/kitti_format ${MLC_DATASET_WAYMO_PATH} -P" -echo $cmd -eval $cmd -test $? -eq 0 || exit $? -cd ${MLC_DATASET_WAYMO_PATH}/kitti_format/training -for f in *.tar.gz; do tar -xzvf "$f"; done -cd - diff --git a/script/get-dataset-waymo/run.sh b/script/get-dataset-waymo/run.sh index 3197bb8ad..ba1412ac9 100644 --- a/script/get-dataset-waymo/run.sh +++ b/script/get-dataset-waymo/run.sh @@ -6,3 +6,9 @@ #echo "VARIABLE_NAME=VARIABLE_VALUE" >>tmp-run-env.out #${MLC_PYTHON_BIN_WITH_PATH} contains the path to python binary if "get,python" is added as a dependency + +if [[ "$MLC_DOWNLOAD_MODE" != "dry" && "$MLC_TMP_REQUIRE_DOWNLOAD" = "true" ]]; then + cd "${MLC_DATASET_WAYMO_PATH}/kitti_format/training" || exit + for f in *.tar.gz; do tar -xzvf "$f"; done + cd - || exit +fi \ No newline at end of file diff --git a/script/get-ml-model-llama3/customize.py b/script/get-ml-model-llama3/customize.py index 17ebedabd..91c22df1b 100644 --- a/script/get-ml-model-llama3/customize.py +++ b/script/get-ml-model-llama3/customize.py @@ -15,17 +15,11 @@ def preprocess(i): path = env.get('MLC_OUTDIRNAME', '').strip() - if path != "": + if path != "" and env.get('MLC_DOWNLOAD_SRC', '') == "huggingface": os.makedirs(path, exist_ok=True) env['MLC_GIT_CHECKOUT_FOLDER'] = os.path.join( path, env['MLC_ML_MODEL_NAME']) - if env['MLC_DOWNLOAD_SRC'] == "mlcommons": - i['run_script_input']['script_name'] = 'run-rclone' - if env.get('MLC_OUTDIRNAME', '') != '': - env['LLAMA3_CHECKPOINT_PATH'] = env['MLC_OUTDIRNAME'] - else: - env['LLAMA3_CHECKPOINT_PATH'] = os.getcwd() env['MLC_TMP_REQUIRE_DOWNLOAD'] = 'yes' return {'return': 0} @@ -35,7 +29,8 @@ def postprocess(i): env = i['env'] - env['MLC_ML_MODEL_LLAMA3_CHECKPOINT_PATH'] = env['LLAMA3_CHECKPOINT_PATH'] - env['MLC_GET_DEPENDENT_CACHED_PATH'] = env['MLC_ML_MODEL_PATH'] + if env.get('MLC_DOWNLOAD_MODE', '') != "dry": + env['MLC_ML_MODEL_LLAMA3_CHECKPOINT_PATH'] = env['LLAMA3_CHECKPOINT_PATH'] + env['MLC_GET_DEPENDENT_CACHED_PATH'] = env['MLC_ML_MODEL_PATH'] return {'return': 0} diff --git a/script/get-ml-model-llama3/meta.yaml b/script/get-ml-model-llama3/meta.yaml index 2ae6ba84e..4d52456cb 100644 --- a/script/get-ml-model-llama3/meta.yaml +++ b/script/get-ml-model-llama3/meta.yaml @@ -61,8 +61,38 @@ variations: enable_if_env: MLC_TMP_REQUIRE_DOWNLOAD: - yes + - enable_if_env: + MLC_TMP_REQUIRE_DOWNLOAD: + - 'yes' + env: + MLC_DOWNLOAD_FINAL_ENV_NAME: LLAMA3_CHECKPOINT_PATH + MLC_EXTRACT_FINAL_ENV_NAME: LLAMA3_CHECKPOINT_PATH + MLC_DOWNLOAD_URL: mlc-llama3-1:inference/<<>> + extra_cache_tags: waymo,dataset + force_cache: true + names: + - dae + tags: download-and-extract + force_env_keys: + - MLC_OUTDIRNAME + update_tags_from_env_with_prefix: + _url.: + - MLC_DOWNLOAD_URL env: MLC_DOWNLOAD_SRC: mlcommons + rclone: + group: download-tool + add_deps_recursive: + dae: + tags: _rclone + default: true + dry-run: + group: run-mode + env: + MLC_DOWNLOAD_MODE: dry + dry-run,rclone: + env: + MLC_DOWNLOAD_EXTRA_OPTIONS: --dry-run hf: group: download-src default_variations: diff --git a/script/get-ml-model-llama3/run-rclone.sh b/script/get-ml-model-llama3/run-rclone.sh deleted file mode 100644 index e1943a00f..000000000 --- a/script/get-ml-model-llama3/run-rclone.sh +++ /dev/null @@ -1,4 +0,0 @@ -cmd="rclone sync mlc-llama3-1:inference/${MLC_ML_MODEL_NAME} ${LLAMA3_CHECKPOINT_PATH}/${MLC_ML_MODEL_NAME} -P" -echo $cmd -eval $cmd -test $? -eq 0 || exit $? diff --git a/script/get-preprocessed-dataset-criteo/meta.yaml b/script/get-preprocessed-dataset-criteo/meta.yaml index b4219c7a6..7455121c2 100644 --- a/script/get-preprocessed-dataset-criteo/meta.yaml +++ b/script/get-preprocessed-dataset-criteo/meta.yaml @@ -142,12 +142,28 @@ variations: MLC_EXTRACT_FINAL_ENV_NAME: MLC_DATASET_PREPROCESSED_PATH MLC_EXTRACT_TO_FOLDER: criteo-preprocessed MLC_RCLONE_CONFIG_NAME: mlc-inference - MLC_RCLONE_URL: mlc-inference:mlcommons-inference-wg-public/dlrm_preprocessed + MLC_DOWNLOAD_URL: mlc-inference:mlcommons-inference-wg-public/dlrm_preprocessed extra_cache_tags: criteo,preprocessed,dataset force_cache: true names: - dae - tags: download-and-extract,_rclone,_url.mlc-inference:mlcommons-inference-wg-public/dlrm_preprocessed + tags: download-and-extract + update_tags_from_env_with_prefix: + _url.: + - MLC_DOWNLOAD_URL + rclone: + group: download-tool + add_deps_recursive: + dae: + tags: _rclone + default: true + dry-run: + group: run-mode + env: + MLC_DOWNLOAD_MODE: dry + dry-run,rclone: + env: + MLC_DOWNLOAD_EXTRA_OPTIONS: --dry-run preprocess: group: src validation: From 5a9ba827000ab7b7f44d78054aec131d2c7e5435 Mon Sep 17 00:00:00 2001 From: ANANDHU S <71482562+anandhu-eng@users.noreply.github.com> Date: Tue, 1 Apr 2025 01:04:48 +0530 Subject: [PATCH 03/18] Change logging levels based on verbose and silent (#305) * change logging levels based on verbose and silent * changed env variable * changes for logger * Update meta.yaml * update logging level logic * fix log levels for docker run * [Automated Commit] Format Codebase [skip ci] * clean code * fix for log leveling inside docker * update docker.py --- automation/script/docker.py | 42 +++- automation/script/docker_utils.py | 5 +- automation/script/module.py | 180 +++++++++--------- .../customize.py | 16 +- script/detect-cpu/meta.yaml | 2 + script/get-generic-python-lib/customize.py | 15 +- script/run-mlperf-inference-app/customize.py | 6 +- 7 files changed, 146 insertions(+), 120 deletions(-) diff --git a/automation/script/docker.py b/automation/script/docker.py index 056192898..8e07417b6 100644 --- a/automation/script/docker.py +++ b/automation/script/docker.py @@ -20,7 +20,6 @@ def dockerfile(self_module, input_params): run_command_arc = prune_result['new_input'] current_directory = os.getcwd() is_quiet_mode = input_params.get('quiet', False) - verbose = input_params.get('v', False) is_console_output = input_params.get('out') == 'con' # Step 2: Search for scripts @@ -88,8 +87,7 @@ def dockerfile(self_module, input_params): new_state_keys_from_meta=[], # Add state keys from meta if needed add_deps_recursive=add_deps_recursive, run_state=run_state, - recursion_spaces='', - verbose=verbose # Set to True or False as needed + recursion_spaces='' ) if update_variations_result['return'] > 0: return update_variations_result @@ -109,7 +107,7 @@ def dockerfile(self_module, input_params): deps = docker_settings.get('build_deps', []) if deps: r = self_module._run_deps( - deps, [], env, {}, {}, {}, {}, '', [], '', False, '', verbose, + deps, [], env, {}, {}, {}, {}, '', [], '', False, '', show_time, ' ', run_state) if r['return'] > 0: return r @@ -180,8 +178,34 @@ def dockerfile(self_module, input_params): 'comments': comments, 'run_cmd': f"{run_command_string} --quiet", 'script_tags': input_params.get('tags'), 'env': env, 'dockerfile_env': dockerfile_env, - 'quiet': True, 'v': input_params.get('v', False), 'real_run': True + 'quiet': True, 'real_run': True } + + docker_v = False + docker_s = False + if is_true(input_params.get( + 'docker_v', input_params.get('docker_verbose', False))): + docker_v = True + if is_true(input_params.get( + 'docker_s', input_params.get('docker_silent', False))): + docker_s = True + + if docker_s and docker_v: + logger.warning( + "Both verbose and silent is set to True. Verbose will take precedence.") + docker_s = False + + if not docker_s and not docker_v: + if logger.level == logging.DEBUG: + docker_v = True + elif logger.level == logging.WARNING: + docker_s = True + + if docker_s: + mlc_docker_input['run_cmd'] += ' -s' + elif docker_v: + mlc_docker_input['run_cmd'] += ' -v' + mlc_docker_input.update(docker_inputs) dockerfile_result = self_module.action_object.access(mlc_docker_input) @@ -209,7 +233,6 @@ def docker_run(self_module, i): # Extract and handle basic inputs quiet = i.get('quiet', False) - verbose = i.get('v', False) show_time = i.get('show_time', False) logger = self_module.logger env = i.get('env', {}) @@ -296,8 +319,7 @@ def docker_run(self_module, i): posthook_deps=[], new_env_keys_from_meta=[], new_state_keys_from_meta=[], - add_deps_recursive=add_deps_recursive, run_state=run_state, recursion_spaces='', - verbose=False) + add_deps_recursive=add_deps_recursive, run_state=run_state, recursion_spaces='') if r['return'] > 0: return r @@ -306,7 +328,7 @@ def docker_run(self_module, i): deps = docker_settings.get('deps', []) if deps: r = self_module._run_deps( - deps, [], env, {}, {}, {}, {}, '', [], '', False, '', verbose, + deps, [], env, {}, {}, {}, {}, '', [], '', False, '', show_time, ' ', run_state) if r['return'] > 0: return r @@ -374,7 +396,7 @@ def docker_run(self_module, i): 'action': 'run', 'target': 'script', 'tags': 'run,docker,container', 'rebuild': rebuild_docker_image, 'env': env, 'mounts': mounts, - 'script_tags': i.get('tags'), 'run_cmd': final_run_cmd, 'v': verbose, + 'script_tags': i.get('tags'), 'run_cmd': final_run_cmd, 'quiet': True, 'real_run': True, 'add_deps_recursive': {'build-docker-image': {'dockerfile': dockerfile_path}}, **docker_inputs } diff --git a/automation/script/docker_utils.py b/automation/script/docker_utils.py index 621db878a..2b509dcf9 100644 --- a/automation/script/docker_utils.py +++ b/automation/script/docker_utils.py @@ -344,7 +344,10 @@ def rebuild_flags( command_line += f" --{full_key},={list_values}" # Process scalar values. else: - command_line += f" --{full_key}={quote}{str(value)}{quote}" + if full_key in ['s', 'v']: + command_line += f" -{full_key}" + else: + command_line += f" --{full_key}={quote}{str(value)}{quote}" return command_line diff --git a/automation/script/module.py b/automation/script/module.py index e2dafbb95..32bfb94b2 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -373,31 +373,48 @@ def _run(self, i): run_state['fake_deps'] = True # Check verbose and silent - verbose = False - silent = True if is_true(i.get('silent', '')) else False + # Get the current log level so that the log levels could be reverted + # after execution of the script and corresponding dependencies + original_logging_level = logger.level - if not silent: + verbose = False + silent = False + if i.get('verbose', '') != '': + verbose = True if is_true(i.get('verbose', '')) else False + elif i.get('v', '') != '': + verbose = True if is_true(i.get('v', '')) else False + elif env.get('MLC_VERBOSE', '') != '': + verbose = True if is_true(env.get('MLC_VERBOSE', '')) else False + + if i.get('silent', '') != '': + silent = True if is_true(i.get('silent', '')) else False + elif i.get('s', '') != '': silent = True if is_true(i.get('s', '')) else False + elif env.get('MLC_SILENT', '') != '': + silent = True if is_true(env.get('MLC_SILENT', '')) else False + + if verbose and silent: + logger.warning( + "Both verbose and silent is set to True. Verbose will take precedence.") + silent = False if silent: - if 'verbose' in i: - del (i['verbose']) - if 'v' in i: - del (i['v']) env['MLC_TMP_SILENT'] = 'yes' + logger.setLevel(logging.WARNING) run_state['tmp_silent'] = True - if 'verbose' in i: - verbose = i['verbose'] - elif 'v' in i: - verbose = i['v'] - if verbose: - env['MLC_VERBOSE'] = 'yes' + env['MLC_TMP_VERBOSE'] = 'yes' run_state['tmp_verbose'] = True logger.setLevel(logging.DEBUG) + if not env.get('MLC_TMP_SILENT') and not env.get('MLC_TMP_VERBOSE'): + if logger.level == logging.DEBUG: + env['MLC_TMP_VERBOSE'] = "yes" + elif logger.level == logging.DEBUG: + env['MLC_TMP_SILENT'] = "yes" + print_deps = i.get('print_deps', False) print_versions = i.get('print_versions', False) print_readme = i.get('print_readme', False) @@ -555,11 +572,7 @@ def _run(self, i): x_variation_tags = ['_' + v for v in variation_tags] mlc_script_info += y.join(x_variation_tags) -# if verbose: -# logger.info('') - - if not run_state.get('tmp_silent', False): - logger.info(recursion_spaces + '* ' + mlc_script_info) + logger.info(recursion_spaces + '* ' + mlc_script_info) ####################################################################### # Report if scripts were not found or there is an ambiguity with UIDs @@ -720,7 +733,6 @@ def _run(self, i): False, script_tags_string, quiet, - verbose, logger) # Remember selection @@ -905,8 +917,7 @@ def _run(self, i): new_state_keys_from_meta, add_deps_recursive, run_state, - recursion_spaces, - verbose) + recursion_spaces) if r['return'] > 0: return r @@ -1171,7 +1182,6 @@ def _run(self, i): 'skip_remembered_selections': skip_remembered_selections, 'remembered_selections': remembered_selections, 'quiet': quiet, - 'verbose': verbose, 'show_time': show_time }) if r['return'] > 0: @@ -1205,7 +1215,6 @@ def _run(self, i): True, script_tags_string, quiet, - verbose, logger) if selection >= 0: @@ -1231,10 +1240,9 @@ def _run(self, i): logger.debug( recursion_spaces + ' - Checking dynamic dependencies on other MLC scripts:') - r = self._call_run_deps(deps, self.local_env_keys, local_env_keys_from_meta, env, state, const, const_state, add_deps_recursive, recursion_spaces + extra_recursion_spaces, - remembered_selections, variation_tags_string, True, debug_script_tags, verbose, show_time, extra_recursion_spaces, run_state) + remembered_selections, variation_tags_string, True, debug_script_tags, show_time, extra_recursion_spaces, run_state) if r['return'] > 0: return r @@ -1254,7 +1262,7 @@ def _run(self, i): r = self._call_run_deps(prehook_deps, self.local_env_keys, local_env_keys_from_meta, env, state, const, const_state, add_deps_recursive, recursion_spaces + extra_recursion_spaces, - remembered_selections, variation_tags_string, True, debug_script_tags, verbose, show_time, extra_recursion_spaces, run_state) + remembered_selections, variation_tags_string, True, debug_script_tags, show_time, extra_recursion_spaces, run_state) if r['return'] > 0: return r @@ -1273,10 +1281,9 @@ def _run(self, i): return r version = r['meta'].get('version') - if not run_state.get('tmp_silent', False): - logger.info( - recursion_spaces + - ' ! load {}'.format(path_to_cached_state_file)) + logger.info( + recursion_spaces + + ' ! load {}'.format(path_to_cached_state_file)) ########################################################### # IF REUSE FROM CACHE - update env and state from cache! @@ -1318,7 +1325,7 @@ def _run(self, i): r = self._call_run_deps(posthook_deps, self.local_env_keys, clean_env_keys_post_deps, env, state, const, const_state, add_deps_recursive, recursion_spaces + extra_recursion_spaces, - remembered_selections, variation_tags_string, True, debug_script_tags, verbose, show_time, extra_recursion_spaces, run_state) + remembered_selections, variation_tags_string, True, debug_script_tags, show_time, extra_recursion_spaces, run_state) if r['return'] > 0: return r @@ -1329,7 +1336,7 @@ def _run(self, i): # Check chain of post dependencies on other MLC scripts r = self._call_run_deps(post_deps, self.local_env_keys, clean_env_keys_post_deps, env, state, const, const_state, add_deps_recursive, recursion_spaces + extra_recursion_spaces, - remembered_selections, variation_tags_string, True, debug_script_tags, verbose, show_time, extra_recursion_spaces, run_state) + remembered_selections, variation_tags_string, True, debug_script_tags, show_time, extra_recursion_spaces, run_state) if r['return'] > 0: return r @@ -1536,7 +1543,7 @@ def _run(self, i): r = self._call_run_deps(docker_deps, self.local_env_keys, local_env_keys_from_meta, env, state, const, const_state, add_deps_recursive, recursion_spaces + extra_recursion_spaces, - remembered_selections, variation_tags_string, False, debug_script_tags, verbose, show_time, extra_recursion_spaces, run_state) + remembered_selections, variation_tags_string, False, debug_script_tags, show_time, extra_recursion_spaces, run_state) if r['return'] > 0: return r @@ -1573,7 +1580,6 @@ def _run(self, i): 'variation_tags_string': variation_tags_string, 'found_cached': False, 'debug_script_tags': debug_script_tags, - 'verbose': verbose, 'meta': meta, 'self': self } @@ -1634,7 +1640,7 @@ def _run(self, i): r = self._call_run_deps(deps, self.local_env_keys, local_env_keys_from_meta, env, state, const, const_state, add_deps_recursive, recursion_spaces + extra_recursion_spaces, - remembered_selections, variation_tags_string, False, debug_script_tags, verbose, show_time, extra_recursion_spaces, run_state) + remembered_selections, variation_tags_string, False, debug_script_tags, show_time, extra_recursion_spaces, run_state) if r['return'] > 0: return r @@ -1677,7 +1683,6 @@ def _run(self, i): 'variation_tags_string': variation_tags_string, 'found_cached': False, 'debug_script_tags': debug_script_tags, - 'verbose': verbose, 'meta': meta, 'self': self } @@ -1850,7 +1855,7 @@ def _run(self, i): r = self._call_run_deps(prehook_deps, self.local_env_keys, local_env_keys_from_meta, env, state, const, const_state, add_deps_recursive, recursion_spaces + extra_recursion_spaces, - remembered_selections, variation_tags_string, found_cached, debug_script_tags, verbose, show_time, extra_recursion_spaces, run_state) + remembered_selections, variation_tags_string, found_cached, debug_script_tags, show_time, extra_recursion_spaces, run_state) if r['return'] > 0: return r @@ -1893,7 +1898,7 @@ def _run(self, i): 'clean_env_keys_post_deps', []) r = self._run_deps(post_deps, clean_env_keys_post_deps, env, state, const, const_state, add_deps_recursive, recursion_spaces, - remembered_selections, variation_tags_string, found_cached, debug_script_tags, verbose, show_time, extra_recursion_spaces, run_state) + remembered_selections, variation_tags_string, found_cached, debug_script_tags, show_time, extra_recursion_spaces, run_state) if r['return'] > 0: return r @@ -2155,7 +2160,7 @@ def _run(self, i): # RETURN elapsed_time = time.time() - start_time - if verbose and cached_uid != '': + if cached_uid != '': logger.info( recursion_spaces + ' - cache UID: {}'.format(cached_uid)) @@ -2172,7 +2177,7 @@ def _run(self, i): f.write(readme) if dump_version_info: - r = self._dump_version_info_for_script(quiet=quiet, silent=silent) + r = self._dump_version_info_for_script(quiet=quiet) if r['return'] > 0: return r @@ -2197,12 +2202,18 @@ def _run(self, i): dump_repro(repro_prefix, rr, run_state) - if verbose or show_time: + if show_time: logger.info( recursion_spaces + ' - running time of script "{}": {:.2f} sec.'.format( ','.join(found_script_tags), elapsed_time)) + else: + logger.debug( + recursion_spaces + + ' - running time of script "{}": {:.2f} sec.'.format( + ','.join(found_script_tags), + elapsed_time)) if not recursion and show_space: stop_disk_stats = shutil.disk_usage("/") @@ -2216,17 +2227,16 @@ def _run(self, i): ' - used disk space: {} MB'.format(used_disk_space_in_mb)) # Check if need to print some final info such as path to model, etc - if not run_state.get('tmp_silent', False): - print_env_at_the_end = meta.get('print_env_at_the_end', {}) - if len(print_env_at_the_end) > 0: - for p in sorted(print_env_at_the_end): - t = print_env_at_the_end[p] - if t == '': - t = 'ENV[{}]'.format(p) + print_env_at_the_end = meta.get('print_env_at_the_end', {}) + if len(print_env_at_the_end) > 0: + for p in sorted(print_env_at_the_end): + t = print_env_at_the_end[p] + if t == '': + t = 'ENV[{}]'.format(p) - v = new_env.get(p, None) + v = new_env.get(p, None) - logger.info('{}: {}'.format(t, str(v))) + logger.info('{}: {}'.format(t, str(v))) # Check if print nice versions if print_versions: @@ -2237,6 +2247,9 @@ def _run(self, i): if i.get('pause', False): input('Press Enter to continue ...') + # set the logger level back to the original + logger.setLevel(original_logging_level) + return rr ########################################################################## @@ -2309,12 +2322,10 @@ def _fix_cache_paths(self, env): ########################################################################## def _dump_version_info_for_script( - self, output_dir=os.getcwd(), quiet=False, silent=False): - - if not quiet and not silent: - pass + self, output_dir=os.getcwd(), quiet=False): + logger = self.action_object.logger for f in ['mlc-run-script-versions.json', 'version_info.json']: - if not quiet and not silent: + if not quiet: logger.info('Dumping versions to {}'.format(f)) r = utils.save_json(f, self.run_state.get('version_info', [])) if r['return'] > 0: @@ -2324,7 +2335,7 @@ def _dump_version_info_for_script( ########################################################################## def _update_state_from_variations(self, i, meta, variation_tags, variations, env, state, const, const_state, deps, post_deps, prehook_deps, - posthook_deps, new_env_keys_from_meta, new_state_keys_from_meta, add_deps_recursive, run_state, recursion_spaces, verbose): + posthook_deps, new_env_keys_from_meta, new_state_keys_from_meta, add_deps_recursive, run_state, recursion_spaces): logger = self.action_object.logger # Save current explicit variations @@ -3286,7 +3297,7 @@ def _process_variation_tags_in_groups( def _call_run_deps(script, deps, local_env_keys, local_env_keys_from_meta, env, state, const, const_state, add_deps_recursive, recursion_spaces, remembered_selections, variation_tags_string, found_cached, debug_script_tags='', - verbose=False, show_time=False, extra_recursion_spaces=' ', run_state={'deps': [], 'fake_deps': [], 'parent': None}): + show_time=False, extra_recursion_spaces=' ', run_state={'deps': [], 'fake_deps': [], 'parent': None}): if len(deps) == 0: return {'return': 0} @@ -3301,7 +3312,7 @@ def _call_run_deps(script, deps, local_env_keys, local_env_keys_from_meta, env, r = script._run_deps(deps, local_env_keys, env, state, const, const_state, add_deps_recursive, recursion_spaces, remembered_selections, variation_tags_string, found_cached, debug_script_tags, - verbose, show_time, extra_recursion_spaces, run_state) + show_time, extra_recursion_spaces, run_state) if r['return'] > 0: return r @@ -3310,7 +3321,7 @@ def _call_run_deps(script, deps, local_env_keys, local_env_keys_from_meta, env, ########################################################################## def _run_deps(self, deps, clean_env_keys_deps, env, state, const, const_state, add_deps_recursive, recursion_spaces, remembered_selections, variation_tags_string='', from_cache=False, debug_script_tags='', - verbose=False, show_time=False, extra_recursion_spaces=' ', run_state={'deps': [], 'fake_deps': [], 'parent': None}): + show_time=False, extra_recursion_spaces=' ', run_state={'deps': [], 'fake_deps': [], 'parent': None}): """ Runs all the enabled dependencies and pass them env minus local env """ @@ -3453,8 +3464,6 @@ def _run_deps(self, deps, clean_env_keys_deps, env, state, const, const_state, a 'const_state': copy.deepcopy(const_state), 'add_deps_recursive': add_deps_recursive, 'debug_script_tags': debug_script_tags, - 'verbose': verbose, - 'silent': run_state.get('tmp_silent', False), 'time': show_time, 'run_state': run_state_copy @@ -3747,10 +3756,6 @@ def find_file_in_paths(self, i): logger = self.action_object.logger hook = i.get('hook', None) - verbose = i.get('verbose', False) - if not verbose: - verbose = i.get('v', False) - file_name = i.get('file_name', '') file_name_re = i.get('file_name_re', '') file_is_re = False @@ -4577,9 +4582,6 @@ def find_cached_script(i): show_time = i.get('show_time', False) search_tags = '' - verbose = i.get('verbose', False) - if not verbose: - verbose = i.get('v', False) logger = self_obj.action_object.logger found_cached_scripts = [] @@ -4759,7 +4761,7 @@ def find_cached_script(i): if deps: r = self_obj._call_run_deps(deps, self_obj.local_env_keys, meta.get('local_env_keys', []), env, state, const, const_state, add_deps_recursive, recursion_spaces + extra_recursion_spaces, - remembered_selections, variation_tags_string, True, '', False, show_time, extra_recursion_spaces, {}) + remembered_selections, variation_tags_string, True, '', show_time, extra_recursion_spaces, {}) if r['return'] > 0: return r @@ -5005,9 +5007,6 @@ def prepare_and_run_script_with_postprocessing(i, postprocess="postprocess"): state = i.get('state', {}) const_state = i.get('const_state', {}) run_state = i.get('run_state', {}) - verbose = i.get('verbose', False) - if not verbose: - verbose = i.get('v', False) show_time = i.get('time', False) logger = i['self'].action_object.logger @@ -5106,13 +5105,13 @@ def prepare_and_run_script_with_postprocessing(i, postprocess="postprocess"): path_to_run_script, run_script, cur_dir)) - if not run_state.get('tmp_silent', False): - logger.info(recursion_spaces + ' ! cd {}'.format(cur_dir)) - logger.info( - recursion_spaces + - ' ! call {} from {}'.format( - path_to_run_script, - run_script)) + + logger.info(recursion_spaces + ' ! cd {}'.format(cur_dir)) + logger.info( + recursion_spaces + + ' ! call {} from {}'.format( + path_to_run_script, + run_script)) # Prepare env variables import copy @@ -5253,26 +5252,25 @@ def prepare_and_run_script_with_postprocessing(i, postprocess="postprocess"): if postprocess != '' and customize_code is not None and postprocess in dir( customize_code): - if not run_state.get('tmp_silent', False): - logger.info( - recursion_spaces + - ' ! call "{}" from {}'.format( - postprocess, - customize_code.__file__)) + logger.info( + recursion_spaces + + ' ! call "{}" from {}'.format( + postprocess, + customize_code.__file__)) if len(posthook_deps) > 0 and (postprocess == "postprocess"): r = script_automation._call_run_deps(posthook_deps, local_env_keys, local_env_keys_from_meta, env, state, const, const_state, - add_deps_recursive, recursion_spaces, remembered_selections, variation_tags_string, found_cached, debug_script_tags, verbose, show_time, ' ', run_state) + add_deps_recursive, recursion_spaces, remembered_selections, variation_tags_string, found_cached, debug_script_tags, show_time, ' ', run_state) if r['return'] > 0: return r if (postprocess == "postprocess") and customize_code is not None and 'postprocess' in dir( customize_code): rr = run_postprocess(customize_code, customize_common_input, recursion_spaces, env, state, const, - const_state, meta, verbose, i) # i as run_script_input + const_state, meta, i) # i as run_script_input elif (postprocess == "detect_version") and customize_code is not None and 'detect_version' in dir(customize_code): rr = run_detect_version(customize_code, customize_common_input, recursion_spaces, env, state, const, - const_state, meta, verbose) + const_state, meta) return rr @@ -5280,7 +5278,7 @@ def prepare_and_run_script_with_postprocessing(i, postprocess="postprocess"): def run_detect_version(customize_code, customize_common_input, - recursion_spaces, env, state, const, const_state, meta, verbose=False): + recursion_spaces, env, state, const, const_state, meta): if customize_code is not None and 'detect_version' in dir(customize_code): import copy @@ -5311,7 +5309,7 @@ def run_detect_version(customize_code, customize_common_input, def run_postprocess(customize_code, customize_common_input, recursion_spaces, - env, state, const, const_state, meta, verbose=False, run_script_input=None): + env, state, const, const_state, meta, run_script_input=None): if customize_code is not None and 'postprocess' in dir(customize_code): import copy @@ -5949,7 +5947,7 @@ def detect_state_diff(env, saved_env, new_env_keys, def select_script_item(lst, text, recursion_spaces, - can_skip, script_tags_string, quiet, verbose, logger=None): + can_skip, script_tags_string, quiet, logger=None): """ Internal: select script """ diff --git a/script/app-image-classification-onnx-py/customize.py b/script/app-image-classification-onnx-py/customize.py index ab145df23..c3c31b17a 100644 --- a/script/app-image-classification-onnx-py/customize.py +++ b/script/app-image-classification-onnx-py/customize.py @@ -20,6 +20,8 @@ def postprocess(i): env = i['env'] state = i['state'] + automation = i['automation'] + logger = automation.action_object.logger # print ('') # print ('Running postprocess function in customize.py ...') @@ -45,22 +47,20 @@ def postprocess(i): with open(fjson, 'w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False, indent=4) except Exception as e: - print('CM warning: {}'.format(e)) + logger.warning('CM warning: {}'.format(e)) try: import yaml with open(fyaml, 'w', encoding='utf-8') as f: yaml.dump(data, f) except Exception as e: - print('CM warning: {}'.format(e)) + logger.warning('{}'.format(e)) top_classification = data.get('top_classification', '') - if env.get('MLC_TMP_SILENT', '') != 'yes': - if top_classification != '': - print('') - x = 'Top classification: {}'.format(top_classification) - print('=' * len(x)) - print(x) + if top_classification != '': + x = 'Top classification: {}'.format(top_classification) + logger.info('=' * len(x)) + logger.info(x) return {'return': 0} diff --git a/script/detect-cpu/meta.yaml b/script/detect-cpu/meta.yaml index 7befa2ece..f2dcacc02 100644 --- a/script/detect-cpu/meta.yaml +++ b/script/detect-cpu/meta.yaml @@ -8,6 +8,8 @@ clean_files: - tmp-wmic-cpu.csv deps: - tags: detect,os + names: + - detect-os new_env_keys: - MLC_HOST_CPU_* - MLC_HOST_MEMORY_CAPACITY diff --git a/script/get-generic-python-lib/customize.py b/script/get-generic-python-lib/customize.py index 85b7326cc..97dbb94c6 100644 --- a/script/get-generic-python-lib/customize.py +++ b/script/get-generic-python-lib/customize.py @@ -11,6 +11,8 @@ def preprocess(i): run_script_input = i['run_script_input'] pip_version = env.get('MLC_PIP_VERSION', '').strip().split('.') + logger = automation.action_object.logger + package_name = env.get('MLC_GENERIC_PYTHON_PACKAGE_NAME', '').strip() if package_name == '': return automation._available_variations({'meta': meta}) @@ -115,9 +117,7 @@ def preprocess(i): True, 'true', 'yes', 'on']: extra += ' -U' - print('') - print(recursion_spaces + ' Extra PIP CMD: ' + extra) - print('') + logger.info(recursion_spaces + ' Extra PIP CMD: ' + extra) env['MLC_GENERIC_PYTHON_PIP_EXTRA'] = extra @@ -133,6 +133,8 @@ def preprocess(i): def detect_version(i): env = i['env'] + automation = i['automation'] + logger = automation.action_object.logger if env.get('MLC_TMP_PYTHON_PACKAGE_NAME_ENV', '') != '': env_version_key = 'MLC_' + \ @@ -150,10 +152,9 @@ def detect_version(i): version = r['version'] current_detected_version = version - if env.get('MLC_TMP_SILENT', '') != 'yes': - print( - i['recursion_spaces'] + - ' Detected version: {}'.format(version)) + logger.info( + i['recursion_spaces'] + + ' Detected version: {}'.format(version)) return {'return': 0, 'version': version} diff --git a/script/run-mlperf-inference-app/customize.py b/script/run-mlperf-inference-app/customize.py index 3d1886e1a..530237ab4 100644 --- a/script/run-mlperf-inference-app/customize.py +++ b/script/run-mlperf-inference-app/customize.py @@ -159,7 +159,7 @@ def preprocess(i): tags = "app,mlperf,inference,generic," + variation_implementation + variation_model + variation_backend + variation_device + \ variation_run_style + variation_reproducibility + \ variation_quantization_string + power_variation + variation_all_models - verbose = inp.get('v', False) + print_env = inp.get('print_env', False) print_deps = inp.get('print_deps', False) add_deps_recursive = inp.get('add_deps_recursive', {}) @@ -273,7 +273,7 @@ def preprocess(i): print(f"\nRunning loadgen scenario: {scenario} and mode: {mode}") ii = {'action': action, 'automation': 'script', 'tags': scenario_tags, 'quiet': 'true', 'env': env_copy, 'const': const_copy, 'input': inp, 'state': state, 'add_deps': copy.deepcopy(add_deps), 'add_deps_recursive': - copy.deepcopy(add_deps_recursive), 'ad': ad, 'adr': copy.deepcopy(adr), 'v': verbose, 'print_env': print_env, 'print_deps': print_deps, 'dump_version_info': dump_version_info} + copy.deepcopy(add_deps_recursive), 'ad': ad, 'adr': copy.deepcopy(adr), 'print_env': print_env, 'print_deps': print_deps, 'dump_version_info': dump_version_info} if action == "docker": for k in docker_extra_input: @@ -311,7 +311,7 @@ def preprocess(i): env['MLC_MLPERF_LOADGEN_MODE'] = "compliance" ii = {'action': action, 'automation': 'script', 'tags': scenario_tags, 'quiet': 'true', 'env': copy.deepcopy(env), 'const': copy.deepcopy(const), 'input': inp, 'state': state, 'add_deps': copy.deepcopy(add_deps), 'add_deps_recursive': - copy.deepcopy(add_deps_recursive), 'adr': copy.deepcopy(adr), 'ad': ad, 'v': verbose, 'print_env': print_env, 'print_deps': print_deps, 'dump_version_info': dump_version_info} + copy.deepcopy(add_deps_recursive), 'adr': copy.deepcopy(adr), 'ad': ad, 'print_env': print_env, 'print_deps': print_deps, 'dump_version_info': dump_version_info} if action == "docker": for k in docker_extra_input: ii[k] = docker_extra_input[k] From be25ecaa7dd972ee9d87817bc3ecc55be7e9417c Mon Sep 17 00:00:00 2001 From: ANANDHU S <71482562+anandhu-eng@users.noreply.github.com> Date: Tue, 1 Apr 2025 01:05:06 +0530 Subject: [PATCH 04/18] link submit-mlperf-results with generate-mlperf-inference-submission (#340) * add submitter id * skip get submission dir if base dir is given --- script/generate-mlperf-inference-submission/meta.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/script/generate-mlperf-inference-submission/meta.yaml b/script/generate-mlperf-inference-submission/meta.yaml index 9448db682..c68bc5a37 100644 --- a/script/generate-mlperf-inference-submission/meta.yaml +++ b/script/generate-mlperf-inference-submission/meta.yaml @@ -27,9 +27,11 @@ deps: tags: get,mlperf,results,dir,local - names: - get-mlperf-submission-dir - skip_if_env: + skip_if_any_env: MLC_MLPERF_INFERENCE_SUBMISSION_DIR: - 'on' + MLC_MLPERF_INFERENCE_SUBMISSION_BASE_DIR: + - 'on' tags: get,mlperf,submission,dir docker: mlc_repo: mlcommons@mlperf-automations @@ -82,6 +84,7 @@ input_mapping: submission_base_dir: MLC_MLPERF_INFERENCE_SUBMISSION_BASE_DIR submission_dir: MLC_MLPERF_INFERENCE_SUBMISSION_DIR submitter: MLC_MLPERF_SUBMITTER + submitter_id: MLC_MLPERF_SUBMITTER_ID sw_notes_extra: MLC_MLPERF_SUT_SW_NOTES_EXTRA tar: MLC_TAR_SUBMISSION_DIR get_platform_details: MLC_GET_PLATFORM_DETAILS From 3b934374c23ab8a6b28da924e1ceacfe02b6c46c Mon Sep 17 00:00:00 2001 From: ANANDHU S <71482562+anandhu-eng@users.noreply.github.com> Date: Tue, 1 Apr 2025 14:16:41 +0530 Subject: [PATCH 05/18] handle submission base directory properly (#342) --- .../customize.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/script/generate-mlperf-inference-submission/customize.py b/script/generate-mlperf-inference-submission/customize.py index a10ce68a5..cbe8b430c 100644 --- a/script/generate-mlperf-inference-submission/customize.py +++ b/script/generate-mlperf-inference-submission/customize.py @@ -72,20 +72,15 @@ def generate_submission(env, state, inp, submission_division): sys.path.append(submission_checker_dir) if env.get('MLC_MLPERF_INFERENCE_SUBMISSION_DIR', '') == '': - user_home = str(Path.home()) - env['MLC_MLPERF_INFERENCE_SUBMISSION_DIR'] = os.path.join( - user_home, "mlperf_submission") + if env.get('MLC_MLPERF_INFERENCE_SUBMISSION_BASE_DIR', '') == '': + user_home = str(Path.home()) + env['MLC_MLPERF_INFERENCE_SUBMISSION_DIR'] = os.path.join( + user_home, "mlperf_submission") + else: + env['MLC_MLPERF_INFERENCE_SUBMISSION_DIR'] = os.path.join( + env['MLC_MLPERF_INFERENCE_SUBMISSION_BASE_DIR'], "mlperf_submission") submission_dir = env.get('MLC_MLPERF_INFERENCE_SUBMISSION_DIR', '') - if submission_dir == '': - submission_base_dir = env.get( - 'MLC_MLPERF_INFERENCE_SUBMISSION_BASE_DIR', '') - if submission_base_dir == '': - return {'return': 1, 'error': f"Both MLC_MLPERF_INFERENCE_SUBMISSION_DIR and MLC_MLPERF_INFERENCE_SUBMISSION_BASE_DIR can not be empty!"} - else: - submission_dir = os.path.join( - submission_base_dir, "mlperf_inference_submission") - env['MLC_MLPERF_INFERENCE_SUBMISSION_DIR'] = submission_dir if env.get('MLC_MLPERF_CLEAN_SUBMISSION_DIR', '') != '': print('=================================================') From 2c455164ff7d00c2a6c1b369471d91f4ba6181b9 Mon Sep 17 00:00:00 2001 From: ANANDHU S <71482562+anandhu-eng@users.noreply.github.com> Date: Tue, 1 Apr 2025 18:55:26 +0530 Subject: [PATCH 06/18] Support relative path in docker run (#343) * support relative path in docker run * remove unused library --- automation/script/docker_utils.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/automation/script/docker_utils.py b/automation/script/docker_utils.py index 2b509dcf9..a99f65324 100644 --- a/automation/script/docker_utils.py +++ b/automation/script/docker_utils.py @@ -6,6 +6,12 @@ import copy +def convert_to_abs_path(path): + if not os.path.isabs(path): + path = os.path.abspath(path) + return path + + def process_mounts(mounts, env, docker_settings, f_run_cmd): """ Processes and updates the Docker mounts based on the provided inputs and environment variables. @@ -63,7 +69,6 @@ def process_mounts(mounts, env, docker_settings, f_run_cmd): else: # Skip mount if variable is missing mounts[index] = None break - # Skip further processing if the mount was invalid if mounts[index] is None: continue @@ -241,7 +246,6 @@ def update_container_paths(path, mounts=None, force_target_path=''): if mounts is not None: if all(mount.lower() != mount_entry.lower() for mount in mounts): mounts.append(mount_entry) - return host_path, container_path @@ -387,9 +391,10 @@ def get_docker_default(key): def get_host_path(value): + # convert relative path to absolute path + value = convert_to_abs_path(value) + path_split = value.split(os.sep) - if len(path_split) == 1: - return value new_value = '' if "cache" in path_split and "local": @@ -413,9 +418,10 @@ def get_container_path_script(i): def get_container_path(value, username="mlcuser"): + # convert relative path to absolute path + value = convert_to_abs_path(value) + path_split = value.split(os.sep) - if len(path_split) == 1: - return value, value new_value = '' if "cache" in path_split and "local" in path_split: From 8be31b5faf75f1966d9b12f2a9336cf5925f62f3 Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Wed, 2 Apr 2025 12:47:11 +0100 Subject: [PATCH 07/18] Added kill process script (#347) * Added kill process MLC script --- script/kill-process/customize.py | 52 ++++++++++++++++++++++++++++++++ script/kill-process/meta.yaml | 22 ++++++++++++++ script/kill-process/run.sh | 17 +++++++++++ 3 files changed, 91 insertions(+) create mode 100644 script/kill-process/customize.py create mode 100644 script/kill-process/meta.yaml create mode 100644 script/kill-process/run.sh diff --git a/script/kill-process/customize.py b/script/kill-process/customize.py new file mode 100644 index 000000000..0c39a62eb --- /dev/null +++ b/script/kill-process/customize.py @@ -0,0 +1,52 @@ +from mlc import utils +import os +import subprocess + + +def generate_kill_command(env): + kill_cmd = "" + + if env.get("MLC_KILL_PROCESS_GROUP"): + if env.get("MLC_KILL_PROCESS_ID"): + process_id = env["MLC_KILL_PROCESS_ID"] + # Find process group and kill all processes in it + kill_cmd = f"pkill -g $(ps -o pgid= -p {process_id} | tr -d ' ')" + + elif env.get("MLC_KILL_PROCESS_NAME"): + process_name = env["MLC_KILL_PROCESS_NAME"] + # Find process group of the first matching process name and kill + # all in that group + kill_cmd = f"pkill -g $(pgrep -o {process_name} | xargs ps -o pgid= -p | tr -d ' ')" + + else: + if env.get("MLC_KILL_PROCESS_ID"): + process_id = env["MLC_KILL_PROCESS_ID"] + kill_cmd = f"kill {process_id}" # Kill a single process by ID + + elif env.get("MLC_KILL_PROCESS_NAME"): + process_name = env["MLC_KILL_PROCESS_NAME"] + # Kill all processes matching the name + kill_cmd = f"pkill {process_name}" + + env["MLC_RUN_CMD"] = kill_cmd if kill_cmd else "echo 'No valid input provided'" + + +def preprocess(i): + + env = i['env'] + state = i['state'] + os_info = i['os_info'] + + generate_kill_command(env) + + return {'return': 0} + + +def postprocess(i): + + env = i['env'] + state = i['state'] + + os_info = i['os_info'] + + return {'return': 0} diff --git a/script/kill-process/meta.yaml b/script/kill-process/meta.yaml new file mode 100644 index 000000000..3c0335c27 --- /dev/null +++ b/script/kill-process/meta.yaml @@ -0,0 +1,22 @@ +alias: kill-process +automation_alias: script +automation_uid: 5b4e0237da074764 +category: MLC Script Template +deps: [] +new_env_keys: [] +new_state_keys: [] +post_deps: [] +posthook_deps: [] +prehook_deps: [] +tags: +- kill +- process +tests: + run_inputs: [] +uid: 27b5651692454cb6 +input_mapping: + group: MLC_KILL_PROCESS_GROUP + pid: MLC_KILL_PROCESS_ID + pname: MLC_KILL_PROCESS_NAME + + diff --git a/script/kill-process/run.sh b/script/kill-process/run.sh new file mode 100644 index 000000000..c4542b8c2 --- /dev/null +++ b/script/kill-process/run.sh @@ -0,0 +1,17 @@ +#!/bin/bash +function exit_if_error() { + test $? -eq 0 || exit $? +} + +function run() { + echo "Running: " + echo "$1" + echo "" + if [[ ${MLC_FAKE_RUN} != 'yes' ]]; then + eval "$1" + exit_if_error + fi +} + +#Add your run commands here... +run "$MLC_RUN_CMD" From a20f1712c4f59ad6a75de710ccdde82007ebb19a Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Thu, 3 Apr 2025 16:39:14 +0100 Subject: [PATCH 08/18] Support base variation inside dynamic variations (#348) * Added kill process MLC script * [Automated Commit] Format Codebase [skip ci] * Support base variation in dynamic variation * [Automated Commit] Format Codebase [skip ci] * Update build_wheels.yml * Support _path.# for get-llvm --- .github/workflows/build_wheels.yml | 1 - automation/script/module.py | 10 +++++++--- script/get-llvm/customize.py | 13 +++++++++++++ script/get-llvm/meta.yaml | 3 +++ script/install-llvm-src/meta.yaml | 8 ++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 708ae35e4..86b93ac06 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -6,7 +6,6 @@ on: workflow_dispatch: {} jobs: - build_wheels: if: github.repository_owner == 'mlcommons' name: Build wheel diff --git a/automation/script/module.py b/automation/script/module.py index 32bfb94b2..28fe3e978 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -3146,7 +3146,7 @@ def _update_variation_meta_with_dynamic_suffix( value = variation_meta[key] if isinstance(value, list): # deps,pre_deps... - for item in value: + for i, item in enumerate(value): if isinstance(item, dict): for item_key in item: item_value = item[item_key] @@ -3163,6 +3163,9 @@ def _update_variation_meta_with_dynamic_suffix( else: item[item_key] = item[item_key].replace( "#", variation_tag_dynamic_suffix) + elif isinstance(item, str): + value[i] = value[i].replace( + "#", variation_tag_dynamic_suffix) elif isinstance(value, dict): # add_deps, env, .. for item in value: @@ -3188,8 +3191,9 @@ def _update_variation_meta_with_dynamic_suffix( value[item] = value[item].replace( "#", variation_tag_dynamic_suffix) - else: # scalar value - pass # no dynamic update for now + else: # scalar value, never used? + variation_meta[key] = variation_meta[key].replace( + "#", variation_tag_dynamic_suffix) ########################################################################## diff --git a/script/get-llvm/customize.py b/script/get-llvm/customize.py index 5e1eb0edf..e53a7719f 100644 --- a/script/get-llvm/customize.py +++ b/script/get-llvm/customize.py @@ -15,6 +15,19 @@ def preprocess(i): env['FILE_NAME_C'] = file_name_c if 'MLC_LLVM_CLANG_BIN_WITH_PATH' not in env: + + if env.get('MLC_LLVM_DIR_PATH', '') != '': + llvm_path = env['MLC_LLVM_DIR_PATH'] + if os.path.exists(os.path.join(llvm_path, 'bin', 'clang')): + env['MLC_TMP_PATH'] = os.path.join(llvm_path, 'bin') + else: + for l in os.listdir(aocc_path): + if os.path.exists(os.path.join( + llvm_path, l, 'bin', 'clang')): + llvm_path = os.path.join(llvm_path, l) + env['MLC_LLVM_DIR_PATH'] = llvm_path + env['MLC_TMP_PATH'] = os.path.join(llvm_path, 'bin') + r = i['automation'].find_artifact({'file_name': file_name_c, 'env': env, 'os_info': os_info, diff --git a/script/get-llvm/meta.yaml b/script/get-llvm/meta.yaml index cd6242287..8193227b7 100644 --- a/script/get-llvm/meta.yaml +++ b/script/get-llvm/meta.yaml @@ -46,3 +46,6 @@ variations: ad: llvm-install: tags: src,_clang + path.#: + env: + MLC_LLVM_DIR_PATH: '#' diff --git a/script/install-llvm-src/meta.yaml b/script/install-llvm-src/meta.yaml index 98456233a..461ca0d5a 100644 --- a/script/install-llvm-src/meta.yaml +++ b/script/install-llvm-src/meta.yaml @@ -56,6 +56,14 @@ tags: - src-llvm uid: 2af16e9a6c5f4702 variations: + version.main: + group: version + base: + - branch.main + version.#: + group: version + base: + - tag.# branch.#: env: MLC_GIT_CHECKOUT: '#' From 5d402c4d857fa866e03e05da4b16bfd7d5c02ca8 Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Thu, 3 Apr 2025 17:39:28 +0100 Subject: [PATCH 09/18] Fix for llvm version handling (#350) Co-authored-by: Arjun --- script/install-llvm-src/meta.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/script/install-llvm-src/meta.yaml b/script/install-llvm-src/meta.yaml index 461ca0d5a..2d22a0446 100644 --- a/script/install-llvm-src/meta.yaml +++ b/script/install-llvm-src/meta.yaml @@ -62,8 +62,11 @@ variations: - branch.main version.#: group: version - base: - - tag.# + ad: + llvm-src-repo: + tags: _full-history + env: + MLC_GIT_CHECKOUT_TAG: '#' branch.#: env: MLC_GIT_CHECKOUT: '#' From e0d1d8b0e5d6ef9d85aca2ec12c9ff6edb166ad1 Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Sat, 5 Apr 2025 21:16:09 +0100 Subject: [PATCH 10/18] Fix for llvm version handling (#351) Co-authored-by: Arjun From a62e4f7b87ed47abe931cb7b14e0056f4cb5e113 Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Mon, 7 Apr 2025 18:41:11 +0100 Subject: [PATCH 11/18] Fixes for Nvidia gptj (#352) * Added version fix for nvidia TRTLLM * Fix nvidia gptj --- script/app-mlperf-inference-nvidia/customize.py | 2 +- script/app-mlperf-inference/meta.yaml | 9 +++++++++ .../meta.yaml | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/script/app-mlperf-inference-nvidia/customize.py b/script/app-mlperf-inference-nvidia/customize.py index 70e5d3710..2cb95e75f 100644 --- a/script/app-mlperf-inference-nvidia/customize.py +++ b/script/app-mlperf-inference-nvidia/customize.py @@ -300,7 +300,7 @@ def preprocess(i): if not os.path.exists(fp32_model_path): # download via prehook_deps env['MLC_REQUIRE_GPTJ_MODEL_DOWNLOAD'] = 'yes' - if make_command == "build_engine": + if make_command in ["build_engine", "preprocess_data"]: cmds.append( f"cp -r $MLC_ML_MODEL_FILE_WITH_PATH {fp32_model_path}") diff --git a/script/app-mlperf-inference/meta.yaml b/script/app-mlperf-inference/meta.yaml index 846936234..6a4b6cf3b 100644 --- a/script/app-mlperf-inference/meta.yaml +++ b/script/app-mlperf-inference/meta.yaml @@ -404,6 +404,15 @@ variations: _tp-size.: - MLC_NVIDIA_TP_SIZE + nvidia-original,r5.0-dev_default,gptj_: + docker: + image_name: mlperf-inference-nvidia-v4.1-dev-llm + deps: + - tags: get,ml-model,gptj,_nvidia,_fp8 + update_tags_from_env_with_prefix: + _tp-size.: + - MLC_NVIDIA_TP_SIZE + nvidia-original,r4.1_default: docker: base_image: nvcr.io/nvidia/mlperf/mlperf-inference:mlpinf-v4.1-cuda12.4-pytorch24.04-ubuntu22.04-x86_64-release diff --git a/script/build-mlperf-inference-server-nvidia/meta.yaml b/script/build-mlperf-inference-server-nvidia/meta.yaml index 3530c9482..e8e49748b 100644 --- a/script/build-mlperf-inference-server-nvidia/meta.yaml +++ b/script/build-mlperf-inference-server-nvidia/meta.yaml @@ -276,6 +276,14 @@ versions: - x86_64 MLC_PYTHON_MINOR_VERSION: - 8 + - tags: get,generic-python-lib,_package.cuda-python + names: + - cuda-python + version_max: '12.6' + version_max_usable: '12.3.0' + - tags: get,generic-python-lib,_package.networkx + version_max: '2.9.99' + version_max_usable: '2.8.8' r4.1-dev: default_env: @@ -283,6 +291,14 @@ versions: deps: - tags: get,generic,sys-util,_nlohmann-json3-dev - tags: get,generic,sys-util,_git-lfs + - tags: get,generic-python-lib,_package.cuda-python + names: + - cuda-python + version_max: '12.6' + version_max_usable: '12.3.0' + - tags: get,generic-python-lib,_package.networkx + version_max: '2.9.99' + version_max_usable: '2.8.8' - tags: install,pytorch,from.src,_for-nvidia-mlperf-inference-v4.0 names: - pytorch From f84dc8085a7dc846c63f357774de6c86fe3f6f51 Mon Sep 17 00:00:00 2001 From: ANANDHU S <71482562+anandhu-eng@users.noreply.github.com> Date: Wed, 9 Apr 2025 19:17:39 +0530 Subject: [PATCH 12/18] Handle situation when cache is not present (#356) --- .../clean-nvidia-mlperf-inference-scratch-space/customize.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/script/clean-nvidia-mlperf-inference-scratch-space/customize.py b/script/clean-nvidia-mlperf-inference-scratch-space/customize.py index ce054e99c..83f1d2ed0 100644 --- a/script/clean-nvidia-mlperf-inference-scratch-space/customize.py +++ b/script/clean-nvidia-mlperf-inference-scratch-space/customize.py @@ -37,7 +37,9 @@ def preprocess(i): r = mlc_cache.access({'action': 'rm', 'target': 'cache', 'tags': cache_rm_tags, 'f': True}) print(r) - if r['return'] != 0 and r['return'] != 16: # ignore missing ones + # Check if return code is 0 (success) + # currently, the warning code is not being checked as the possibility arises only for missing cache entry + if r['return'] != 0: return r if r['return'] == 0: # cache entry found if clean_cmd != '': From 65faf825f1e07fb1d8cd31d75ebfc993bab995d9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 9 Apr 2025 13:48:12 +0000 Subject: [PATCH 13/18] [Automated Commit] Format Codebase [skip ci] --- .../clean-nvidia-mlperf-inference-scratch-space/customize.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/clean-nvidia-mlperf-inference-scratch-space/customize.py b/script/clean-nvidia-mlperf-inference-scratch-space/customize.py index 83f1d2ed0..0629f5e50 100644 --- a/script/clean-nvidia-mlperf-inference-scratch-space/customize.py +++ b/script/clean-nvidia-mlperf-inference-scratch-space/customize.py @@ -38,7 +38,8 @@ def preprocess(i): 'tags': cache_rm_tags, 'f': True}) print(r) # Check if return code is 0 (success) - # currently, the warning code is not being checked as the possibility arises only for missing cache entry + # currently, the warning code is not being checked as the possibility + # arises only for missing cache entry if r['return'] != 0: return r if r['return'] == 0: # cache entry found From 35d8f4b5520804d9ec6ad1846ba1ddc3955ad14c Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Wed, 9 Apr 2025 23:17:52 +0100 Subject: [PATCH 14/18] Avoid pycuda on non Ubuntu distros for get-gptj --- script/get-ml-model-gptj/meta.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/script/get-ml-model-gptj/meta.yaml b/script/get-ml-model-gptj/meta.yaml index fb3553c06..2046cedc9 100644 --- a/script/get-ml-model-gptj/meta.yaml +++ b/script/get-ml-model-gptj/meta.yaml @@ -150,6 +150,13 @@ variations: tags: get,cuda - tags: get,nvidia,scratch,space - tags: get,cuda-devices,_with-pycuda + enable_if_env: + MLC_HOST_OS_FLAVOR: + - ubuntu + - tags: get,cuda-devices + skip_if_env: + MLC_HOST_OS_FLAVOR: + - ubuntu - env: {} force_new_env_keys: - GPTJ_CHECKPOINT_PATH From 4c7023aba4bb13f3db0390b139f9715947e9317b Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Sun, 13 Apr 2025 22:54:32 +0100 Subject: [PATCH 15/18] Support google-dns for nvidia gpt docker (#361) * Add an option to kill the busiest process group * Allow google-dns for nvidia gptj docker --- script/get-ml-model-gptj/customize.py | 5 +++++ script/get-ml-model-gptj/run-nvidia.sh | 3 ++- script/kill-process/customize.py | 3 +++ script/kill-process/meta.yaml | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/script/get-ml-model-gptj/customize.py b/script/get-ml-model-gptj/customize.py index b9c640faf..cb15d7ce1 100644 --- a/script/get-ml-model-gptj/customize.py +++ b/script/get-ml-model-gptj/customize.py @@ -40,6 +40,11 @@ def preprocess(i): env['MLC_CUDA_DEVICE_PROP_GPU_COMPUTE_CAPABILITY']) * 10) env['MLC_GPU_ARCH'] = gpu_arch + env['DOCKER_RUN_ARGS'] = f" -v {env['MLC_NVIDIA_MLPERF_SCRATCH_PATH']}:/mnt" + + if is_true(env.get('MLC_DOCKER_USE_GOOGLE_DNS', '')): + env['DOCKER_RUN_ARGS'] += ' --dns 8.8.8.8 --dns 8.8.4.4 ' + env['MLC_TMP_REQUIRE_DOWNLOAD'] = 'no' else: diff --git a/script/get-ml-model-gptj/run-nvidia.sh b/script/get-ml-model-gptj/run-nvidia.sh index a81d52f7c..458580490 100644 --- a/script/get-ml-model-gptj/run-nvidia.sh +++ b/script/get-ml-model-gptj/run-nvidia.sh @@ -13,7 +13,8 @@ make -C docker build test $? -eq 0 || exit $? export RUN_CMD="bash -c 'python3 scripts/build_wheel.py -a=${MLC_GPU_ARCH} --clean --install --trt_root /usr/local/tensorrt/ && python examples/quantization/quantize.py --dtype=float16 --output_dir=/mnt/models/GPTJ-6B/fp8-quantized-ammo/GPTJ-FP8-quantized --model_dir=/mnt/models/GPTJ-6B/checkpoint-final --qformat=fp8 --kv_cache_dtype=fp8 '" -export DOCKER_RUN_ARGS=" -v ${MLC_NVIDIA_MLPERF_SCRATCH_PATH}:/mnt" + + make -C docker run LOCAL_USER=1 test $? -eq 0 || exit $? diff --git a/script/kill-process/customize.py b/script/kill-process/customize.py index 0c39a62eb..0ee68220d 100644 --- a/script/kill-process/customize.py +++ b/script/kill-process/customize.py @@ -18,6 +18,9 @@ def generate_kill_command(env): # all in that group kill_cmd = f"pkill -g $(pgrep -o {process_name} | xargs ps -o pgid= -p | tr -d ' ')" + elif is_true(env.get("MLC_KILL_BUSIEST_PROCESS_GROUP")): + kill_cmd = r"busy_pgid=\$(ps -eo pgid,pcpu --sort=-pcpu | head -n 2 | tail -n 1 | awk '{print $1}') && kill -- -\$busy_pgid" + else: if env.get("MLC_KILL_PROCESS_ID"): process_id = env["MLC_KILL_PROCESS_ID"] diff --git a/script/kill-process/meta.yaml b/script/kill-process/meta.yaml index 3c0335c27..fda7b82b1 100644 --- a/script/kill-process/meta.yaml +++ b/script/kill-process/meta.yaml @@ -18,5 +18,6 @@ input_mapping: group: MLC_KILL_PROCESS_GROUP pid: MLC_KILL_PROCESS_ID pname: MLC_KILL_PROCESS_NAME + busy_group: MLC_KILL_BUSIEST_PROCESS_GROUP From b8b829a4cf9e38b45858d2aa284ab49e725cac69 Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Mon, 14 Apr 2025 00:37:59 +0100 Subject: [PATCH 16/18] Fixes nvidia gptj model generation (#362) --- .../script/templates/default/customize.py | 24 ------------------- automation/script/templates/default/run.bat | 1 - automation/script/templates/default/run.sh | 17 ------------- script/get-ml-model-gptj/customize.py | 1 + script/get-ml-model-gptj/meta.yaml | 6 +++++ 5 files changed, 7 insertions(+), 42 deletions(-) delete mode 100644 automation/script/templates/default/customize.py delete mode 100644 automation/script/templates/default/run.bat delete mode 100644 automation/script/templates/default/run.sh diff --git a/automation/script/templates/default/customize.py b/automation/script/templates/default/customize.py deleted file mode 100644 index bd7c12dd3..000000000 --- a/automation/script/templates/default/customize.py +++ /dev/null @@ -1,24 +0,0 @@ -from cmind import utils -import os - - -def preprocess(i): - - os_info = i['os_info'] - - env = i['env'] - - meta = i['meta'] - - automation = i['automation'] - - quiet = (env.get('MLC_QUIET', False) == 'yes') - - return {'return': 0} - - -def postprocess(i): - - env = i['env'] - - return {'return': 0} diff --git a/automation/script/templates/default/run.bat b/automation/script/templates/default/run.bat deleted file mode 100644 index 648302ca7..000000000 --- a/automation/script/templates/default/run.bat +++ /dev/null @@ -1 +0,0 @@ -rem native script diff --git a/automation/script/templates/default/run.sh b/automation/script/templates/default/run.sh deleted file mode 100644 index 32cf4d51e..000000000 --- a/automation/script/templates/default/run.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -#CM Script location: ${MLC_TMP_CURRENT_SCRIPT_PATH} - -#To export any variable -#echo "VARIABLE_NAME=VARIABLE_VALUE" >>tmp-run-env.out - -#${MLC_PYTHON_BIN_WITH_PATH} contains the path to python binary if "get,python" is added as a dependency - -echo "Running: " -echo "${MLC_RUN_CMD}" -echo "" - -if [[ ${MLC_FAKE_RUN} != "yes" ]]; then - eval "${MLC_RUN_CMD}" - test $? -eq 0 || exit 1 -fi diff --git a/script/get-ml-model-gptj/customize.py b/script/get-ml-model-gptj/customize.py index cb15d7ce1..6dc97fc18 100644 --- a/script/get-ml-model-gptj/customize.py +++ b/script/get-ml-model-gptj/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import * import os diff --git a/script/get-ml-model-gptj/meta.yaml b/script/get-ml-model-gptj/meta.yaml index 2046cedc9..b54e3adeb 100644 --- a/script/get-ml-model-gptj/meta.yaml +++ b/script/get-ml-model-gptj/meta.yaml @@ -34,6 +34,12 @@ prehook_deps: update_tags_from_env_with_prefix: _url.: - MLC_DOWNLOAD_URL +tests: + run_inputs: + - variations_list: + - fp32 + + print_env_at_the_end: MLC_ML_MODEL_FILE_WITH_PATH: Path to the ML model tags: From a71d59988f78488258a6242d0994a54a756a9d9f Mon Sep 17 00:00:00 2001 From: ANANDHU S <71482562+anandhu-eng@users.noreply.github.com> Date: Tue, 15 Apr 2025 18:26:52 +0530 Subject: [PATCH 17/18] Fix for dmidecode + support mounting filepaths in docker (#344) * fix for dmidecode * support mounting file in docker * handle relative path in get_container_value * handle extraction of parent directory properly * [Automated Commit] Format Codebase [skip ci] * file updated * handle directory extraction using file and folder path env keys * [Automated Commit] Format Codebase [skip ci] * clean code * file_path_env_keys made part of general meta * [Automated Commit] Format Codebase [skip ci] * run gh action --------- Co-authored-by: github-actions[bot] --- automation/script/docker.py | 16 ++++- automation/script/docker_utils.py | 62 ++++++++++++++----- .../detect_memory.sh | 2 +- .../meta.yaml | 4 ++ .../meta.yaml | 33 ++++++++++ 5 files changed, 99 insertions(+), 18 deletions(-) diff --git a/automation/script/docker.py b/automation/script/docker.py index 8e07417b6..c2f65ee5c 100644 --- a/automation/script/docker.py +++ b/automation/script/docker.py @@ -294,12 +294,19 @@ def docker_run(self_module, i): 'docker_mounts', [])) # do we need a copy here? variations = meta.get('variations', {}) + + # take the folder path as well as file path env variables from meta + file_path_env_keys = meta.get('file_path_env_keys', []) + folder_path_env_keys = meta.get('folder_path_env_keys', []) + docker_settings = meta.get('docker', {}) state['docker'] = docker_settings run_state = { 'deps': [], 'fake_deps': [], 'parent': None, 'script_id': f"{script_alias},{script_uid}", - 'script_variation_tags': variation_tags + 'script_variation_tags': variation_tags, + 'file_path_env_keys': file_path_env_keys, + 'folder_path_env_keys': folder_path_env_keys } # Update state and handle variations @@ -371,7 +378,12 @@ def docker_run(self_module, i): for key in docker_input_mapping if key in i}) # Handle environment variable-based mounts - res = process_mounts(mounts, env, docker_settings, f_run_cmd) + res = process_mounts( + mounts, + env, + docker_settings, + f_run_cmd, + run_state) if res['return'] > 0: return res docker_inputs['mounts'] = res['mounts'] diff --git a/automation/script/docker_utils.py b/automation/script/docker_utils.py index a99f65324..a94e1a010 100644 --- a/automation/script/docker_utils.py +++ b/automation/script/docker_utils.py @@ -1,7 +1,7 @@ import os from mlc import utils from utils import * -from pathlib import PureWindowsPath, PurePosixPath +from pathlib import PureWindowsPath, PurePosixPath, Path from script.docker_utils import * import copy @@ -11,8 +11,20 @@ def convert_to_abs_path(path): path = os.path.abspath(path) return path +# gets parent directory if the path is a file. Works even though the file +# is not present and is just a path -def process_mounts(mounts, env, docker_settings, f_run_cmd): + +def get_directory(path_str): + path = Path(path_str).resolve() + # If it has a file extension, assume it's a file and return parent dir + if path.suffix: + return str(path.parent) + else: + return str(path) + + +def process_mounts(mounts, env, docker_settings, f_run_cmd, run_state): """ Processes and updates the Docker mounts based on the provided inputs and environment variables. @@ -32,6 +44,8 @@ def process_mounts(mounts, env, docker_settings, f_run_cmd): container_env_string = "" for index in range(len(mounts)): + extract_parent_folder = False + mount = mounts[index] # Locate the last ':' to separate the mount into host and container @@ -54,7 +68,14 @@ def process_mounts(mounts, env, docker_settings, f_run_cmd): for placeholder in host_placeholders: if placeholder in env: host_env_key = placeholder - new_host_mount = get_host_path(env[placeholder]) + # if the env variable is in the file_path_env_keys, then we + # need to get the parent folder path(set + # extract_parent_folder to True) + if placeholder in run_state['file_path_env_keys']: + # set extract_parent_folder to True + extract_parent_folder = True + new_host_mount = get_host_path( + env[placeholder], extract_parent_folder) else: # Skip mount if variable is missing mounts[index] = None break @@ -64,8 +85,14 @@ def process_mounts(mounts, env, docker_settings, f_run_cmd): if container_placeholders: for placeholder in container_placeholders: if placeholder in env: + # if the env variable is in the folder_path_env_keys, then + # we need to get the parent folder path(set + # extract_parent_folder to True) + if placeholder in run_state['folder_path_env_keys']: + # set extract_parent_folder to True + extract_parent_folder = True new_container_mount, container_env_key = get_container_path( - env[placeholder], docker_settings.get('user', 'mlcuser')) + env[placeholder], docker_settings.get('user', 'mlcuser'), extract_parent_folder) else: # Skip mount if variable is missing mounts[index] = None break @@ -218,8 +245,7 @@ def update_container_paths(path, mounts=None, force_target_path=''): if not path: return '', '' # Return empty paths if no path is provided. - # Normalize and resolve the absolute path. - host_path = os.path.abspath(path) + host_path = path container_path = host_path # Default to the same path for containers. # Handle Windows-specific path conversion for Docker. @@ -235,12 +261,7 @@ def update_container_paths(path, mounts=None, force_target_path=''): container_path = '/mlc-mount' + \ container_path if not force_target_path else force_target_path - # Determine the mount string based on whether the path is a file or - # directory. - if os.path.isfile(host_path) or not os.path.isdir(host_path): - mount_entry = f"""{os.path.dirname(host_path)}: {os.path.dirname(container_path)}""" - else: - mount_entry = f"""{host_path}:{container_path}""" + mount_entry = f"""{host_path}:{container_path}""" # Add the mount entry to the mounts list if it's not already present. if mounts is not None: @@ -390,10 +411,15 @@ def get_docker_default(key): return None -def get_host_path(value): +def get_host_path(value, extract_parent_folder=False): # convert relative path to absolute path value = convert_to_abs_path(value) + # if extract_parent_folder is True, then we need to get the parent folder + # path + if extract_parent_folder: + value = get_directory(value) + path_split = value.split(os.sep) new_value = '' @@ -417,8 +443,9 @@ def get_container_path_script(i): return {'return': 0, 'value_mnt': value_mnt, 'value_env': value_env} -def get_container_path(value, username="mlcuser"): +def get_container_path(value, username="mlcuser", extract_parent_folder=False): # convert relative path to absolute path + # if we are trying to mount a file, mount the parent folder. value = convert_to_abs_path(value) path_split = value.split(os.sep) @@ -434,4 +461,9 @@ def get_container_path(value, username="mlcuser"): return "/".join(new_path_split1), "/".join(new_path_split2) else: orig_path, target_path = update_container_paths(path=value) - return target_path, target_path + # new container path is the parent folder of the target path if + # extract_parent_folder is True + if extract_parent_folder: + return get_directory(target_path), target_path + else: + return target_path, target_path diff --git a/script/get-mlperf-inference-sut-description/detect_memory.sh b/script/get-mlperf-inference-sut-description/detect_memory.sh index 3d53fba78..317fd0283 100644 --- a/script/get-mlperf-inference-sut-description/detect_memory.sh +++ b/script/get-mlperf-inference-sut-description/detect_memory.sh @@ -3,4 +3,4 @@ if [[ ${MLC_SUDO_USER} == "yes" ]]; then ${MLC_SUDO} dmidecode -t memory > ${MLC_MEMINFO_FILE} fi -test $? -eq 0 || return $? +test $? -eq 0 || echo "Warning: Memory info is not recorded" diff --git a/script/get-mlperf-inference-sut-description/meta.yaml b/script/get-mlperf-inference-sut-description/meta.yaml index 5e935a0dc..573a6c842 100644 --- a/script/get-mlperf-inference-sut-description/meta.yaml +++ b/script/get-mlperf-inference-sut-description/meta.yaml @@ -29,6 +29,10 @@ deps: MLC_HOST_OS_TYPE: - linux tags: detect,sudo +- skip_if_env: + MLC_SUDO_USER: + - 'no' + tags: get,sys-util,generic,_dmidecode - env: MLC_CACHE_DIR_ENV_NAME: MLC_MLPERF_INFERENCE_SUT_DESC_PATH extra_cache_tags: mlperf,inference,sut,descriptions diff --git a/script/run-mlperf-inference-submission-checker/meta.yaml b/script/run-mlperf-inference-submission-checker/meta.yaml index 6c5a8d417..8d9667ae6 100644 --- a/script/run-mlperf-inference-submission-checker/meta.yaml +++ b/script/run-mlperf-inference-submission-checker/meta.yaml @@ -6,6 +6,10 @@ category: MLPerf benchmark support clean_files: [] default_env: MLC_MLPERF_SHORT_RUN: 'no' +file_path_env_keys: + - MLPERF_INFERENCE_SUBMISSION_TAR_FILE +folder_path_env_keys: + - MLC_MLPERF_INFERENCE_SUBMISSION_DIR default_version: master deps: - names: @@ -40,6 +44,34 @@ deps: MLC_TMP_MLPERF_INFERENCE_PREPROCESS_SUBMISSION: - 'on' tags: preprocess,mlperf,inference,submission +docker: + mlc_repo: mlcommons@mlperf-automations + mlc_repo_branch: dev + extra_run_args: ' --cap-add SYS_ADMIN' + os: ubuntu + os_version: '22.04' + pre_run_cmds: + - mlc pull repo + real_run: false + use_host_group_id: true + use_host_user_id: true + deps: + - names: + - get-mlperf-submission-dir + skip_if_env: + MLC_MLPERF_INFERENCE_SUBMISSION_DIR: + - 'on' + tags: get,mlperf,submission,dir + - enable_if_env: + MLC_TMP_MLPERF_INFERENCE_PREPROCESS_SUBMISSION: + - 'on' + tags: preprocess,mlperf,inference,submission + input_mapping: + submission_dir: MLC_MLPERF_INFERENCE_SUBMISSION_DIR + submission_tar_file: MLPERF_INFERENCE_SUBMISSION_TAR_FILE + mounts: + - ${{ MLC_MLPERF_INFERENCE_SUBMISSION_DIR }}:${{ MLC_MLPERF_INFERENCE_SUBMISSION_DIR }} + - ${{ MLPERF_INFERENCE_SUBMISSION_TAR_FILE }}:${{ MLPERF_INFERENCE_SUBMISSION_TAR_FILE }} input_mapping: extra_args: MLC_MLPERF_SUBMISSION_CHECKER_EXTRA_ARGS extra_checker_args: MLC_MLPERF_SUBMISSION_CHECKER_EXTRA_ARGS @@ -60,6 +92,7 @@ input_mapping: submission_dir: MLC_MLPERF_INFERENCE_SUBMISSION_DIR submitter: MLC_MLPERF_SUBMITTER submitter_id: MLC_MLPERF_SUBMITTER_ID + submission_tar_file: MLPERF_INFERENCE_SUBMISSION_TAR_FILE tar: MLC_TAR_SUBMISSION_DIR post_deps: - enable_if_env: From 795616d93d19d066a1ee1f98a499b59a1ff697b1 Mon Sep 17 00:00:00 2001 From: ANANDHU S <71482562+anandhu-eng@users.noreply.github.com> Date: Tue, 15 Apr 2025 21:46:40 +0530 Subject: [PATCH 18/18] Replace boolean usage (#357) * replace boolean usage * Update test-mlperf-inference-abtf-poc.yml Co-authored-by: Arjun Suresh --- .../test-mlperf-inference-abtf-poc.yml | 4 +- script/activate-python-venv/customize.py | 3 +- .../customize.py | 7 +- script/app-mlperf-inference-amd/customize.py | 3 +- .../customize.py | 3 +- .../app-mlperf-inference-nvidia/customize.py | 14 +- .../customize.py | 5 +- .../app-mlperf-inference-redhat/customize.py | 3 +- script/app-mlperf-inference/customize.py | 2 +- .../app-mlperf-training-nvidia/customize.py | 7 +- .../customize.py | 7 +- script/authenticate-github-cli/customize.py | 3 +- .../customize.py | 5 +- script/benchmark-program-mlperf/customize.py | 5 +- script/calibrate-model-for.qaic/customize.py | 7 +- .../customize.py | 3 +- script/compile-model-for.qaic/customize.py | 5 +- script/convert-csv-to-md/customize.py | 3 +- .../customize.py | 3 +- .../customize.py | 3 +- script/create-patch/customize.py | 3 +- script/detect-sudo/customize.py | 3 +- script/download-and-extract/customize.py | 6 +- script/download-file/customize.py | 2 +- script/download-torrent/customize.py | 3 +- script/draw-graph-from-json-data/customize.py | 3 +- script/dump-pip-freeze/customize.py | 3 +- script/extract-file/customize.py | 8 +- script/fail/customize.py | 5 +- .../customize.py | 4 +- .../customize.py | 20 +- script/get-aocl/customize.py | 3 +- script/get-aria2/customize.py | 9 +- script/get-blis/customize.py | 3 +- script/get-cache-dir/customize.py | 3 +- script/get-compiler-rust/customize.py | 3 +- script/get-conda/customize.py | 3 +- script/get-cuda-devices/customize.py | 1 + script/get-cuda/customize.py | 12 +- script/get-dataset-cnndm/customize.py | 5 +- script/get-dataset-coco/customize.py | 3 +- script/get-dataset-coco2014/customize.py | 5 +- .../customize.py | 5 +- script/get-dataset-igbh/customize.py | 3 +- script/get-dataset-imagenet-val/customize.py | 3 +- .../customize.py | 3 +- .../customize.py | 5 +- .../customize.py | 5 +- script/get-dataset-openimages/customize.py | 5 +- script/get-dataset-openorca/customize.py | 3 +- .../customize.py | 11 +- script/get-generic-python-lib/customize.py | 16 +- script/get-generic-sys-util/customize.py | 14 +- script/get-gh-actions-runner/customize.py | 3 +- script/get-github-cli/customize.py | 3 +- script/get-google-test/customize.py | 3 +- script/get-huggingface-cli/customize.py | 3 +- script/get-java/customize.py | 3 +- script/get-javac/customize.py | 3 +- script/get-lib-protobuf/customize.py | 3 +- .../customize.py | 3 +- .../customize.py | 3 +- .../customize.py | 6 +- script/get-ml-model-gptj/customize.py | 3 +- .../get-ml-model-huggingface-zoo/customize.py | 3 +- script/get-ml-model-mobilenet/customize.py | 6 +- script/get-ml-model-resnet50/customize.py | 5 +- script/get-ml-model-retinanet/customize.py | 5 +- script/get-ml-model-rnnt/customize.py | 3 +- script/get-ml-model-tiny-resnet/customize.py | 3 +- .../customize.py | 3 +- .../customize.py | 3 +- .../get-mlperf-inference-loadgen/customize.py | 9 +- .../customize.py | 3 +- .../customize.py | 3 +- .../get-mlperf-inference-results/customize.py | 3 +- script/get-mlperf-inference-src/customize.py | 5 +- .../customize.py | 3 +- .../customize.py | 3 +- .../customize.py | 2 +- .../get-mlperf-inference-utils/customize.py | 3 +- .../customize.py | 8 +- .../customize.py | 9 +- script/get-python3/customize.py | 3 +- script/get-qaic-apps-sdk/customize.py | 3 +- script/get-qaic-platform-sdk/customize.py | 3 +- script/get-qaic-software-kit/customize.py | 3 +- script/get-rclone-config/customize.py | 3 +- script/get-rclone/customize.py | 9 +- script/get-rocm-devices/customize.py | 4 +- script/get-sys-utils-cm/customize.py | 3 +- script/get-tensorrt/customize.py | 3 +- script/get-tvm-model/customize.py | 3 +- script/get-tvm/customize.py | 3 +- script/get-xilinx-sdk/customize.py | 3 +- script/get-zendnn/customize.py | 3 +- script/install-cuda-prebuilt/customize.py | 5 +- script/install-ipex-from-src/customize.py | 3 +- script/install-llvm-src/customize.py | 3 +- .../customize.py | 3 +- script/install-nccl-libs/customize.py | 3 +- script/install-onednn-from-src/customize.py | 3 +- .../install-onnxruntime-from-src/customize.py | 3 +- script/install-python-venv/customize.py | 3 +- script/install-pytorch-from-src/customize.py | 3 +- .../customize.py | 3 +- .../plug-prebuilt-cudnn-to-cuda/customize.py | 3 +- .../customize.py | 3 +- .../prepare-training-data-bert/customize.py | 3 +- .../prepare-training-data-resnet/customize.py | 3 +- script/run-all-mlperf-models/customize.py | 5 +- script/run-docker-container/customize.py | 4 +- script/run-mlperf-automotive-app/customize.py | 16 +- script/run-mlperf-inference-app/customize.py | 10 +- .../customize.py | 4 +- .../customize.py | 5 +- script/run-vllm-server/customize.py | 493 +++--------------- .../customize.py | 5 +- script/set-device-settings-qaic/customize.py | 5 +- script/set-performance-mode/customize.py | 3 +- script/set-user-limits/customize.py | 3 +- script/set-venv/customize.py | 3 +- 122 files changed, 400 insertions(+), 642 deletions(-) diff --git a/.github/workflows/test-mlperf-inference-abtf-poc.yml b/.github/workflows/test-mlperf-inference-abtf-poc.yml index fadea97da..ebe29fce5 100644 --- a/.github/workflows/test-mlperf-inference-abtf-poc.yml +++ b/.github/workflows/test-mlperf-inference-abtf-poc.yml @@ -15,14 +15,14 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-22.04, ubuntu-20.04, ubuntu-24.04, macos-latest, macos-13, windows-latest] + os: [ubuntu-22.04, ubuntu-latest, macos-latest, macos-13, windows-latest] python-version: [ "3.8", "3.12" ] backend: [ "pytorch" ] implementation: [ "python" ] docker: [ "", " --docker --docker_mlc_repo=${{ github.event.pull_request.head.repo.html_url }} --docker_mlc_repo_branch=${{ github.event.pull_request.head.ref }} --docker_dt" ] extra-args: [ "--adr.compiler.tags=gcc", "--env.MLC_MLPERF_LOADGEN_BUILD_FROM_SRC=off" ] exclude: - - os: ubuntu-24.04 + - os: ubuntu-latest python-version: "3.8" - os: windows-latest python-version: "3.8" diff --git a/script/activate-python-venv/customize.py b/script/activate-python-venv/customize.py index 20ee8f2cf..6681e85b3 100644 --- a/script/activate-python-venv/customize.py +++ b/script/activate-python-venv/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -13,7 +14,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) name = env.get('MLC_NAME', '') if name != '': diff --git a/script/app-mlperf-automotive-mlcommons-python/customize.py b/script/app-mlperf-automotive-mlcommons-python/customize.py index 7efb03221..6ea96b377 100644 --- a/script/app-mlperf-automotive-mlcommons-python/customize.py +++ b/script/app-mlperf-automotive-mlcommons-python/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import json import shutil @@ -12,13 +13,13 @@ def preprocess(i): state = i['state'] script_path = i['run_script_input']['path'] - if env.get('MLC_MLPERF_SKIP_RUN', '') == "yes": + if is_true(env.get('MLC_MLPERF_SKIP_RUN', '')): return {'return': 0} - if env.get('MLC_RUN_DOCKER_CONTAINER', '') == "yes": + if is_true(env.get('MLC_RUN_DOCKER_CONTAINER', '')): return {'return': 0} - if env.get('MLC_MLPERF_POWER', '') == "yes": + if is_true(env.get('MLC_MLPERF_POWER', '')): power = "yes" else: power = "no" diff --git a/script/app-mlperf-inference-amd/customize.py b/script/app-mlperf-inference-amd/customize.py index c2945f45c..b128d0cd5 100644 --- a/script/app-mlperf-inference-amd/customize.py +++ b/script/app-mlperf-inference-amd/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import shutil @@ -11,7 +12,7 @@ def preprocess(i): return {'return': 1, 'error': 'Windows is not supported in this script yet'} env = i['env'] - if env.get('MLC_MLPERF_SKIP_RUN', '') == "yes": + if is_true(env.get('MLC_MLPERF_SKIP_RUN', '')): return {'return': 0} env['MLC_MLPERF_AMD_SCRIPT_PATH'] = env['MLC_TMP_CURRENT_SCRIPT_PATH'] diff --git a/script/app-mlperf-inference-ctuning-cpp-tflite/customize.py b/script/app-mlperf-inference-ctuning-cpp-tflite/customize.py index 246abfafc..a0753c9b5 100644 --- a/script/app-mlperf-inference-ctuning-cpp-tflite/customize.py +++ b/script/app-mlperf-inference-ctuning-cpp-tflite/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import shutil @@ -11,7 +12,7 @@ def preprocess(i): return {'return': 1, 'error': 'Windows is not supported in this script yet'} env = i['env'] - if env.get('MLC_MLPERF_SKIP_RUN', '') == "yes": + if is_true(env.get('MLC_MLPERF_SKIP_RUN', '')): return {'return': 0} if 'MLC_MODEL' not in env: diff --git a/script/app-mlperf-inference-nvidia/customize.py b/script/app-mlperf-inference-nvidia/customize.py index 2cb95e75f..cc11ce229 100644 --- a/script/app-mlperf-inference-nvidia/customize.py +++ b/script/app-mlperf-inference-nvidia/customize.py @@ -12,8 +12,7 @@ def preprocess(i): return {'return': 1, 'error': 'Windows is not supported in this script yet'} env = i['env'] - if str(env.get('MLC_RUN_STATE_DOCKER', '') - ).lower() in ['1', 'true', 'yes']: + if is_true(env.get('MLC_RUN_STATE_DOCKER', '')): return {'return': 0} if env.get('MLC_MODEL', '') == '': @@ -26,8 +25,8 @@ def preprocess(i): return { 'return': 1, 'error': 'Please select a variation specifying the device to run on'} - if env.get('MLC_MLPERF_SKIP_RUN', - '') == "yes" and make_command == "run_harness": + if is_true(env.get('MLC_MLPERF_SKIP_RUN', '') + ) and make_command == "run_harness": return {'return': 0} env['MLPERF_SCRATCH_PATH'] = env['MLC_NVIDIA_MLPERF_SCRATCH_PATH'] @@ -641,7 +640,7 @@ def preprocess(i): run_config += f" --audio_buffer_num_lines={audio_buffer_num_lines}" use_fp8 = str(env.get('MLC_MLPERF_NVIDIA_HARNESS_USE_FP8', '')) - if use_fp8 and use_fp8.lower() not in ["no", "false", "0", ""]: + if use_fp8 and not is_false(use_fp8): run_config += f" --use_fp8" if "llama2" in env["MLC_MODEL"]: @@ -649,7 +648,7 @@ def preprocess(i): run_config += f" --tensor_parallelism={tmp_tp_size}" enable_sort = env.get('MLC_MLPERF_NVIDIA_HARNESS_ENABLE_SORT') - if enable_sort and enable_sort.lower() not in ["no", "false", "0"]: + if enable_sort and not is_false(enable_sort): run_config += f" --enable_sort" sdxl_server_batcher_time_limit = env.get( @@ -675,8 +674,7 @@ def preprocess(i): env.get( 'MLC_MLPERF_NVIDIA_HARNESS_SKIP_POSTPROCESS', '')) - if skip_postprocess and skip_postprocess.lower() not in [ - "no", "false", "0", ""]: + if skip_postprocess and not is_false(skip_postprocess): run_config += f" --skip_postprocess" if test_mode: diff --git a/script/app-mlperf-inference-qualcomm/customize.py b/script/app-mlperf-inference-qualcomm/customize.py index 7a4ed9596..2ba7db912 100644 --- a/script/app-mlperf-inference-qualcomm/customize.py +++ b/script/app-mlperf-inference-qualcomm/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import shutil @@ -11,7 +12,7 @@ def preprocess(i): return {'return': 1, 'error': 'Windows is not supported in this script yet'} env = i['env'] - if env.get('MLC_MLPERF_SKIP_RUN', '') == "yes": + if is_true(env.get('MLC_MLPERF_SKIP_RUN', '')): return {'return': 0} if 'MLC_MODEL' not in env: @@ -78,7 +79,7 @@ def preprocess(i): keys = ['LOC_OFFSET', 'LOC_SCALE', 'CONF_OFFSET', 'CONF_SCALE'] - if env.get('MLC_RETINANET_USE_MULTIPLE_SCALES_OFFSETS', '') == 'yes': + if is_true(env.get('MLC_RETINANET_USE_MULTIPLE_SCALES_OFFSETS', '')): env['+ CXXFLAGS'].append("-DUSE_MULTIPLE_SCALES_OFFSETS=1") for j in range(0, 4): keys.append(f'LOC_OFFSET{j}') diff --git a/script/app-mlperf-inference-redhat/customize.py b/script/app-mlperf-inference-redhat/customize.py index 7278f89a2..25ff631d1 100644 --- a/script/app-mlperf-inference-redhat/customize.py +++ b/script/app-mlperf-inference-redhat/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import shutil @@ -11,7 +12,7 @@ def preprocess(i): return {'return': 1, 'error': 'Windows is not supported in this script yet'} env = i['env'] - if env.get('MLC_MLPERF_SKIP_RUN', '') == "yes": + if is_true(env.get('MLC_MLPERF_SKIP_RUN', '')): return {'return': 0} if 'MLC_MODEL' not in env: diff --git a/script/app-mlperf-inference/customize.py b/script/app-mlperf-inference/customize.py index 5a215d27b..7c74ebd0a 100644 --- a/script/app-mlperf-inference/customize.py +++ b/script/app-mlperf-inference/customize.py @@ -77,7 +77,7 @@ def postprocess(i): return {'return': 0} # in power mode copy the log files from tmp_power directory - if env.get('MLC_MLPERF_POWER', '') == "yes" and mode == "performance": + if is_true(env.get('MLC_MLPERF_POWER', '')) and mode == "performance": mlperf_power_logs_dir = os.path.join( env['MLC_MLPERF_OUTPUT_DIR'], "..", "power") mlperf_ranging_logs_dir = os.path.join( diff --git a/script/app-mlperf-training-nvidia/customize.py b/script/app-mlperf-training-nvidia/customize.py index 27d4377ab..fd4a42a11 100644 --- a/script/app-mlperf-training-nvidia/customize.py +++ b/script/app-mlperf-training-nvidia/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import json import shutil @@ -12,13 +13,13 @@ def preprocess(i): state = i['state'] script_path = i['run_script_input']['path'] - if env.get('MLC_MLPERF_SKIP_RUN', '') == "yes": + if is_true(env.get('MLC_MLPERF_SKIP_RUN', '')): return {'return': 0} - if env.get('MLC_RUN_DOCKER_CONTAINER', '') == "yes": + if is_true(env.get('MLC_RUN_DOCKER_CONTAINER', '')): return {'return': 0} - if env.get('MLC_MLPERF_POWER', '') == "yes": + if is_true(env.get('MLC_MLPERF_POWER', '')): power = "yes" else: power = "no" diff --git a/script/app-mlperf-training-reference/customize.py b/script/app-mlperf-training-reference/customize.py index f062e8cde..f0095b563 100644 --- a/script/app-mlperf-training-reference/customize.py +++ b/script/app-mlperf-training-reference/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import json import shutil @@ -12,13 +13,13 @@ def preprocess(i): state = i['state'] script_path = i['run_script_input']['path'] - if env.get('MLC_MLPERF_SKIP_RUN', '') == "yes": + if is_true(env.get('MLC_MLPERF_SKIP_RUN', '')): return {'return': 0} - if env.get('MLC_RUN_DOCKER_CONTAINER', '') == "yes": + if is_true(env.get('MLC_RUN_DOCKER_CONTAINER', '')): return {'return': 0} - if env.get('MLC_MLPERF_POWER', '') == "yes": + if is_true(env.get('MLC_MLPERF_POWER', '')): power = "yes" else: power = "no" diff --git a/script/authenticate-github-cli/customize.py b/script/authenticate-github-cli/customize.py index 631b93f58..3541c5acd 100644 --- a/script/authenticate-github-cli/customize.py +++ b/script/authenticate-github-cli/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -22,7 +23,7 @@ def preprocess(i): cmd = f" echo {env['MLC_GH_AUTH_TOKEN']} | {cmd} --with-token" env['MLC_RUN_CMD'] = cmd - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) return {'return': 0} diff --git a/script/benchmark-any-mlperf-inference-implementation/customize.py b/script/benchmark-any-mlperf-inference-implementation/customize.py index 644de05b2..00ce47ea5 100644 --- a/script/benchmark-any-mlperf-inference-implementation/customize.py +++ b/script/benchmark-any-mlperf-inference-implementation/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import * import os @@ -13,7 +14,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) models = env['MODELS'].split(",") @@ -29,7 +30,7 @@ def preprocess(i): power = env.get('POWER', '') - if str(power).lower() in ["yes", "true"]: + if is_true(str(power)): POWER_STRING = " --power=yes --adr.mlperf-power-client.power_server=" + env.get( 'POWER_SERVER', '192.168.0.15') + " --adr.mlperf-power-client.port=" + str( diff --git a/script/benchmark-program-mlperf/customize.py b/script/benchmark-program-mlperf/customize.py index 493505c48..bb74f7f4c 100644 --- a/script/benchmark-program-mlperf/customize.py +++ b/script/benchmark-program-mlperf/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -16,9 +17,9 @@ def postprocess(i): env['MLC_MLPERF_RUN_CMD'] = env.get('MLC_RUN_CMD') - if env.get('MLC_MLPERF_POWER', '') == "yes": + if is_true(env.get('MLC_MLPERF_POWER', '')): - if env.get('MLC_MLPERF_SHORT_RANGING_RUN', '') != 'no': + if not is_false(env.get('MLC_MLPERF_SHORT_RANGING_RUN', '')): # Write '0' to the count.txt file in MLC_RUN_DIR count_file = os.path.join(env.get('MLC_RUN_DIR', ''), 'count.txt') with open(count_file, 'w') as f: diff --git a/script/calibrate-model-for.qaic/customize.py b/script/calibrate-model-for.qaic/customize.py index 6e09b1a2f..706ad1767 100644 --- a/script/calibrate-model-for.qaic/customize.py +++ b/script/calibrate-model-for.qaic/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import sys import yaml @@ -14,9 +15,9 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) - if env.get('MLC_CREATE_INPUT_BATCH', '') == 'yes': + if is_true(env.get('MLC_CREATE_INPUT_BATCH', '')): r = create_batched_inputs(env) if r['return'] > 0: return r @@ -74,7 +75,7 @@ def construct_calibration_cmd(env): compiler_params = env['MLC_QAIC_COMPILER_PARAMS'] batchsize = env.get('MLC_QAIC_MODEL_BATCH_SIZE', "1") cmd = env['MLC_QAIC_EXEC_PATH'] + " " - if env.get('MLC_CREATE_INPUT_BATCH', '') == 'yes': + if is_true(env.get('MLC_CREATE_INPUT_BATCH', '')): cmd += " -input-list-file=batched_input_files -batchsize=" + batchsize + " " cmd += compiler_params + " -dump-profile=profile.yaml -model=" + \ env['MLC_ML_MODEL_FILE_WITH_PATH'] diff --git a/script/clean-nvidia-mlperf-inference-scratch-space/customize.py b/script/clean-nvidia-mlperf-inference-scratch-space/customize.py index 0629f5e50..d1ea84490 100644 --- a/script/clean-nvidia-mlperf-inference-scratch-space/customize.py +++ b/script/clean-nvidia-mlperf-inference-scratch-space/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) clean_cmd = '' cache_rm_tags = '' diff --git a/script/compile-model-for.qaic/customize.py b/script/compile-model-for.qaic/customize.py index c055cfb07..ca2c48d75 100644 --- a/script/compile-model-for.qaic/customize.py +++ b/script/compile-model-for.qaic/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) if env.get('MLC_REGISTER_CACHE', '') == '': @@ -49,7 +50,7 @@ def construct_compilation_cmd(env): ' ' + env.get('MLC_QAIC_MODEL_COMPILER_ARGS_SUT', '') batchsize = env.get('MLC_QAIC_MODEL_BATCH_SIZE') - if env.get('MLC_QAIC_MODEL_QUANTIZATION', '') == 'yes': + if is_true(env.get('MLC_QAIC_MODEL_QUANTIZATION', '')): profile_string = " -load-profile=" + \ env['MLC_QAIC_MODEL_PROFILE_WITH_PATH'] else: diff --git a/script/convert-csv-to-md/customize.py b/script/convert-csv-to-md/customize.py index e547a6219..917a99618 100644 --- a/script/convert-csv-to-md/customize.py +++ b/script/convert-csv-to-md/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) csv_file = env.get('MLC_CSV_FILE', '') md_file = env.get('MLC_MD_FILE', '') diff --git a/script/create-fpgaconvnet-app-tinyml/customize.py b/script/create-fpgaconvnet-app-tinyml/customize.py index ae8668d89..e0dbda342 100644 --- a/script/create-fpgaconvnet-app-tinyml/customize.py +++ b/script/create-fpgaconvnet-app-tinyml/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) network_env_name = env['MLC_TINY_FPGACONVNET_NETWORK_ENV_NAME'] run_dir = env['MLC_TINY_FPGACONVNET_' + network_env_name + '_RUN_DIR'] diff --git a/script/create-fpgaconvnet-config-tinyml/customize.py b/script/create-fpgaconvnet-config-tinyml/customize.py index 853ff007f..84bca1b7a 100644 --- a/script/create-fpgaconvnet-config-tinyml/customize.py +++ b/script/create-fpgaconvnet-config-tinyml/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) code_path = os.path.join( env['MLC_GIT_REPO_CHECKOUT_PATH'], diff --git a/script/create-patch/customize.py b/script/create-patch/customize.py index 573e6735e..a14969634 100644 --- a/script/create-patch/customize.py +++ b/script/create-patch/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) new_dir = env.get('MLC_CREATE_PATCH_NEW', '') if new_dir == '': diff --git a/script/detect-sudo/customize.py b/script/detect-sudo/customize.py index c9d82816e..47812286f 100644 --- a/script/detect-sudo/customize.py +++ b/script/detect-sudo/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import subprocess import select @@ -18,7 +19,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) if os.geteuid() == 0: env['MLC_SUDO'] = '' # root user does not need sudo diff --git a/script/download-and-extract/customize.py b/script/download-and-extract/customize.py index 45e2d6fdc..4a11b4fd5 100644 --- a/script/download-and-extract/customize.py +++ b/script/download-and-extract/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import hashlib @@ -13,7 +14,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) if i['input'].get('force_cache'): extra_cache_tags = i['input'].get('extra_cache_tags', '') @@ -42,8 +43,7 @@ def preprocess(i): env['MLC_EXTRACT_REMOVE_EXTRACTED'] = 'no' - if str(env.get('MLC_DAE_EXTRACT_DOWNLOADED') - ).lower() in ["yes", "1", "true"]: + if is_true(env.get('MLC_DAE_EXTRACT_DOWNLOADED')): if (env.get('MLC_EXTRACT_FINAL_ENV_NAME', '') == '') and ( env.get('MLC_DAE_FINAL_ENV_NAME', '') != ''): env['MLC_EXTRACT_FINAL_ENV_NAME'] = env['MLC_DAE_FINAL_ENV_NAME'] diff --git a/script/download-file/customize.py b/script/download-file/customize.py index bb97f5467..40fc3c276 100644 --- a/script/download-file/customize.py +++ b/script/download-file/customize.py @@ -33,7 +33,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) tool = env.get('MLC_DOWNLOAD_TOOL', '') pre_clean = env.get('MLC_PRE_DOWNLOAD_CLEAN', False) diff --git a/script/download-torrent/customize.py b/script/download-torrent/customize.py index 0006d5680..3c6e09a7b 100644 --- a/script/download-torrent/customize.py +++ b/script/download-torrent/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) if not env.get('MLC_TORRENT_DOWNLOADED_FILE_NAME'): return {'return': 1, 'error': 'MLC_TORRENT_DOWNLOADED_FILE_NAME is not set'} diff --git a/script/draw-graph-from-json-data/customize.py b/script/draw-graph-from-json-data/customize.py index 56c734da3..a54a9cf28 100644 --- a/script/draw-graph-from-json-data/customize.py +++ b/script/draw-graph-from-json-data/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) q = '"' if os_info['platform'] == 'windows' else "'" env['MLC_RUN_CMD'] = f"""{env['MLC_PYTHON_BIN_WITH_PATH']} {q}{os.path.join(env['MLC_TMP_CURRENT_SCRIPT_PATH'],"process-mlc-deps.py")}{q} {q}{env['MLC_JSON_INPUT_FILE']}{q} """ diff --git a/script/dump-pip-freeze/customize.py b/script/dump-pip-freeze/customize.py index 617e387df..cc6d7c19c 100644 --- a/script/dump-pip-freeze/customize.py +++ b/script/dump-pip-freeze/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -16,7 +17,7 @@ def preprocess(i): env['MLC_DUMP_RAW_PIP_FREEZE_FILE_PATH'] = os.path.join( os.getcwd(), "tmp-pip-freeze") - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) return {'return': 0} diff --git a/script/extract-file/customize.py b/script/extract-file/customize.py index 2a0d99c4b..f6f041dbc 100644 --- a/script/extract-file/customize.py +++ b/script/extract-file/customize.py @@ -22,7 +22,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) filename = env.get('MLC_EXTRACT_FILEPATH', '') if filename == '': @@ -91,12 +91,12 @@ def preprocess(i): ' > ' + q + extracted_filename + q + ' < ' env['MLC_EXTRACT_TOOL'] = 'gzip ' - elif env.get('MLC_EXTRACT_UNZIP', '') == 'yes': + elif is_true(env.get('MLC_EXTRACT_UNZIP', '')): env['MLC_EXTRACT_TOOL'] = 'unzip ' - elif env.get('MLC_EXTRACT_UNTAR', '') == 'yes': + elif is_true(env.get('MLC_EXTRACT_UNTAR', '')): env['MLC_EXTRACT_TOOL_OPTIONS'] = ' -xvf' env['MLC_EXTRACT_TOOL'] = 'tar ' - elif env.get('MLC_EXTRACT_GZIP', '') == 'yes': + elif is_true(env.get('MLC_EXTRACT_GZIP', '')): env['MLC_EXTRACT_CMD'] = 'gzip ' env['MLC_EXTRACT_TOOL_OPTIONS'] = ' -d ' + \ ('-k ' if not remove_extracted else '') diff --git a/script/fail/customize.py b/script/fail/customize.py index 3f826ffe2..6d3eda24d 100644 --- a/script/fail/customize.py +++ b/script/fail/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,10 +13,10 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) # Checking conditions - if env.get('MLC_FAIL_WINDOWS', '').lower() == 'true': + if is_true(env.get('MLC_FAIL_WINDOWS', '')): if os_info['platform'] == 'windows': return {'return': 1, 'error': 'CM detected fail condition: running on Windows'} diff --git a/script/generate-mlperf-inference-submission/customize.py b/script/generate-mlperf-inference-submission/customize.py index cbe8b430c..2803fd187 100644 --- a/script/generate-mlperf-inference-submission/customize.py +++ b/script/generate-mlperf-inference-submission/customize.py @@ -6,6 +6,7 @@ from tabulate import tabulate import mlperf_utils from pathlib import Path +from utils import is_true def preprocess(i): @@ -94,8 +95,7 @@ def generate_submission(env, state, inp, submission_division): if not os.path.isdir(submission_dir): os.makedirs(submission_dir) - if str(env.get('MLC_MLPERF_SUBMISSION_DIR_SHARED', '') - ).lower() in ["yes", "true", "1"]: + if is_true(str(env.get('MLC_MLPERF_SUBMISSION_DIR_SHARED', ''))): os.chmod(submission_dir, 0o2775) print('* MLPerf inference submission dir: {}'.format(submission_dir)) diff --git a/script/generate-mlperf-inference-user-conf/customize.py b/script/generate-mlperf-inference-user-conf/customize.py index 70d920ed4..bda488003 100644 --- a/script/generate-mlperf-inference-user-conf/customize.py +++ b/script/generate-mlperf-inference-user-conf/customize.py @@ -139,18 +139,18 @@ def preprocess(i): else: # if env.get("MLC_MLPERF_FIND_PERFORMANCE_MODE", '') == "yes": if metric == "target_qps": - if env.get("MLC_MLPERF_FIND_PERFORMANCE_MODE", '') == "yes": + if is_true(env.get("MLC_MLPERF_FIND_PERFORMANCE_MODE", '')): print("In find performance mode: using 1 as target_qps") else: print("No target_qps specified. Using 1 as target_qps") conf[metric] = 1 if metric == "target_latency": - if env.get("MLC_MLPERF_FIND_PERFORMANCE_MODE", '') == "yes": + if is_true(env.get("MLC_MLPERF_FIND_PERFORMANCE_MODE", '')): print("In find performance mode: using 0.5ms as target_latency") else: print("No target_latency specified. Using default") - if env.get('MLC_MLPERF_USE_MAX_DURATION', 'yes').lower() in ["no", "false", "0"] or env.get( - 'MLC_MLPERF_MODEL_EQUAL_ISSUE_MODE', 'no').lower() in ["yes", "1", "true"]: + if is_false(env.get('MLC_MLPERF_USE_MAX_DURATION', 'yes')) or is_true(env.get( + 'MLC_MLPERF_MODEL_EQUAL_ISSUE_MODE', 'no')): # Total number of queries needed is a multiple of dataset # size. So we dont use max_duration and so we need to be # careful with the input latency @@ -169,7 +169,7 @@ def preprocess(i): # {scenario}. Please input {metric} value"} # Pass the modified performance metrics to the implementation - if env.get("MLC_MLPERF_FIND_PERFORMANCE_MODE", '') == "yes": + if is_true(env.get("MLC_MLPERF_FIND_PERFORMANCE_MODE", '')): if metric == "target_latency" and env.get( 'MLC_MLPERF_LOADGEN_TARGET_LATENCY', '') == '': env['MLC_MLPERF_LOADGEN_TARGET_LATENCY'] = conf[metric] @@ -324,8 +324,7 @@ def preprocess(i): env['MLC_MLPERF_MAX_QUERY_COUNT'] = max_query_count # max_duration is effective for all scenarios except the Offline - if env.get('MLC_MLPERF_USE_MAX_DURATION', 'yes').lower() not in [ - "no", "false", "0"]: + if not is_false(env.get('MLC_MLPERF_USE_MAX_DURATION', 'yes')): if scenario != "Offline": user_conf += ml_model_name + "." + scenario + \ f".max_duration = {max_duration_test}" + "\n" @@ -437,8 +436,7 @@ def preprocess(i): os.makedirs(OUTPUT_DIR, exist_ok=True) - if str(env.get('MLC_MLPERF_RESULTS_DIR_SHARED', '') - ).lower() in ["yes", "true", "1"]: + if is_true(env.get('MLC_MLPERF_RESULTS_DIR_SHARED', '')): os.chmod(OUTPUT_DIR, 0o2775) return {'return': 0} @@ -531,8 +529,8 @@ def run_files_exist(mode, OUTPUT_DIR, run_files, env): return is_valid - if "power" in mode and env.get( - 'MLC_MLPERF_SKIP_POWER_CHECKS', 'no').lower() not in ["yes", "true", "on"]: + if "power" in mode and not is_true( + env.get('MLC_MLPERF_SKIP_POWER_CHECKS', 'no')): from power.power_checker import check as check_power_more try: is_valid = check_power_more(os.path.dirname(OUTPUT_DIR)) == 0 diff --git a/script/get-aocl/customize.py b/script/get-aocl/customize.py index a9ad06398..edfc6c12d 100644 --- a/script/get-aocl/customize.py +++ b/script/get-aocl/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) return {'return': 0} diff --git a/script/get-aria2/customize.py b/script/get-aria2/customize.py index f52b1d3bf..bb9529ec8 100644 --- a/script/get-aria2/customize.py +++ b/script/get-aria2/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -16,7 +17,7 @@ def preprocess(i): file_name = file_name_core + \ '.exe' if os_info['platform'] == 'windows' else file_name_core - force_install = env.get('MLC_FORCE_INSTALL', False) == True + force_install = is_true(env.get('MLC_FORCE_INSTALL', False)) if not force_install: r = i['automation'].find_artifact({'file_name': file_name, @@ -70,8 +71,8 @@ def preprocess(i): if r['return'] > 0: return r - if os_info['platform'] == 'windows' or env.get( - 'MLC_ARIA2_BUILD_FROM_SRC', '').lower() == 'true': + if os_info['platform'] == 'windows' or is_true(env.get( + 'MLC_ARIA2_BUILD_FROM_SRC', '')): install_path = os.path.join(os.getcwd(), archive) path_to_file = os.path.join(install_path, file_name) @@ -129,7 +130,7 @@ def postprocess(i): env['MLC_ARIA2_INSTALLED_PATH'] = found_path - if env.get('MLC_ARIA2_INSTALLED_TO_CACHE', '') == 'yes': + if is_true(env.get('MLC_ARIA2_INSTALLED_TO_CACHE', '')): env['+PATH'] = [env['MLC_ARIA2_INSTALLED_PATH']] return {'return': 0, 'version': version} diff --git a/script/get-blis/customize.py b/script/get-blis/customize.py index 19f524ef8..7e2d33f91 100644 --- a/script/get-blis/customize.py +++ b/script/get-blis/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) env['MLC_BLIS_SRC_PATH'] = env['MLC_GIT_CHECKOUT_PATH'] diff --git a/script/get-cache-dir/customize.py b/script/get-cache-dir/customize.py index 41ac52d30..ff4837a91 100644 --- a/script/get-cache-dir/customize.py +++ b/script/get-cache-dir/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) return {'return': 0} diff --git a/script/get-compiler-rust/customize.py b/script/get-compiler-rust/customize.py index 7481e6527..87c93848e 100644 --- a/script/get-compiler-rust/customize.py +++ b/script/get-compiler-rust/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) return {'return': 0} diff --git a/script/get-conda/customize.py b/script/get-conda/customize.py index d176c0609..beb6aa1fb 100644 --- a/script/get-conda/customize.py +++ b/script/get-conda/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -45,7 +46,7 @@ def preprocess(i): if conda_prefix_name != '' or r['return'] > 0: if conda_prefix_name != '' or r['return'] == 16: if conda_prefix_name == '': - if env.get('MLC_TMP_FAIL_IF_NOT_FOUND', '').lower() == 'yes': + if is_true(env.get('MLC_TMP_FAIL_IF_NOT_FOUND', '')): return r print(recursion_spaces + ' # {}'.format(r['error'])) diff --git a/script/get-cuda-devices/customize.py b/script/get-cuda-devices/customize.py index 0ca09bf5a..af6e377fa 100644 --- a/script/get-cuda-devices/customize.py +++ b/script/get-cuda-devices/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import * import os import subprocess diff --git a/script/get-cuda/customize.py b/script/get-cuda/customize.py index 2c9ae7915..77ac713e9 100644 --- a/script/get-cuda/customize.py +++ b/script/get-cuda/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import json @@ -9,7 +10,7 @@ def preprocess(i): env = i['env'] - if str(env.get('CUDA_SKIP_SUDO', '')).lower() == 'true': + if is_true(env.get('CUDA_SKIP_SUDO', '')): env['MLC_SUDO'] = '' recursion_spaces = i['recursion_spaces'] @@ -52,7 +53,7 @@ def preprocess(i): '/usr/local/cuda/bin:/usr/cuda/bin:/usr/local/cuda-11/bin:/usr/cuda-11/bin:/usr/local/cuda-12/bin:/usr/cuda-12/bin:/usr/local/packages/cuda' env['MLC_TMP_PATH_IGNORE_NON_EXISTANT'] = 'yes' - if env['MLC_CUDA_FULL_TOOLKIT_INSTALL'] == "yes": + if is_true(env['MLC_CUDA_FULL_TOOLKIT_INSTALL']): env_key = 'MLC_NVCC_BIN_WITH_PATH' path_env_key = 'PATH' else: @@ -73,7 +74,8 @@ def preprocess(i): if os_info['platform'] == 'windows': return r - if r['return'] == 16 and env['MLC_CUDA_FULL_TOOLKIT_INSTALL'] == "yes": + if r['return'] == 16 and is_true( + env['MLC_CUDA_FULL_TOOLKIT_INSTALL']): env['MLC_REQUIRE_INSTALL'] = "yes" return {'return': 0} else: @@ -84,7 +86,7 @@ def preprocess(i): def detect_version(i): env = i['env'] - if env['MLC_CUDA_FULL_TOOLKIT_INSTALL'] == "yes": + if is_true(env['MLC_CUDA_FULL_TOOLKIT_INSTALL']): return detect_version_nvcc(i) else: return detect_version_cuda_lib(i) @@ -146,7 +148,7 @@ def postprocess(i): found_file_path = env[env['MLC_TMP_ENV_KEY']] - if env['MLC_CUDA_FULL_TOOLKIT_INSTALL'] == "yes": + if is_true(env['MLC_CUDA_FULL_TOOLKIT_INSTALL']): cuda_path_bin = os.path.dirname(found_file_path) env['MLC_CUDA_PATH_BIN'] = cuda_path_bin diff --git a/script/get-dataset-cnndm/customize.py b/script/get-dataset-cnndm/customize.py index 34726734f..062f3b534 100644 --- a/script/get-dataset-cnndm/customize.py +++ b/script/get-dataset-cnndm/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true, is_false import os import shutil @@ -7,7 +8,7 @@ def preprocess(i): env = i['env'] - if env.get('MLC_CNNDM_INTEL_VARIATION', '') == 'yes': + if is_true(env.get('MLC_CNNDM_INTEL_VARIATION', '')): i['run_script_input']['script_name'] = "run-intel" else: print("Using MLCommons Inference source from '" + @@ -19,7 +20,7 @@ def preprocess(i): def postprocess(i): env = i['env'] - if env.get('MLC_DATASET_CALIBRATION', '') == "no": + if is_false(env.get('MLC_DATASET_CALIBRATION', '')): env['MLC_DATASET_PATH'] = os.path.join(os.getcwd(), 'install') env['MLC_DATASET_EVAL_PATH'] = os.path.join( os.getcwd(), 'install', 'cnn_eval.json') diff --git a/script/get-dataset-coco/customize.py b/script/get-dataset-coco/customize.py index 029967fc4..c4d445ac6 100644 --- a/script/get-dataset-coco/customize.py +++ b/script/get-dataset-coco/customize.py @@ -1,6 +1,7 @@ from mlc import utils import os import shutil +from utils import is_true def preprocess(i): @@ -10,7 +11,7 @@ def preprocess(i): automation = i['automation'] env = i['env'] meta = i['meta'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) # Check if path is there to detect existing data set detected = False diff --git a/script/get-dataset-coco2014/customize.py b/script/get-dataset-coco2014/customize.py index 837539efc..d48db2137 100644 --- a/script/get-dataset-coco2014/customize.py +++ b/script/get-dataset-coco2014/customize.py @@ -1,6 +1,7 @@ from mlc import utils import os import shutil +from utils import is_true, is_false def preprocess(i): @@ -22,11 +23,11 @@ def preprocess(i): def postprocess(i): env = i['env'] - if env.get('MLC_GENERATE_SAMPLE_ID', '') == "yes": + if is_true(env.get('MLC_GENERATE_SAMPLE_ID', '')): env['MLC_COCO2014_SAMPLE_ID_PATH'] = os.path.join( os.getcwd(), 'sample_ids.txt') print(env['MLC_COCO2014_SAMPLE_ID_PATH']) - if env.get('MLC_DATASET_CALIBRATION', '') == "no": + if is_false(env.get('MLC_DATASET_CALIBRATION', '')): env['MLC_DATASET_PATH_ROOT'] = os.getcwd() # env['MLC_DATASET_PATH'] = os.path.join(os.getcwd(), 'install', 'validation', 'data') env['MLC_DATASET_CAPTIONS_DIR_PATH'] = os.path.join( diff --git a/script/get-dataset-cognata-mlcommons/customize.py b/script/get-dataset-cognata-mlcommons/customize.py index c74a15825..937d42de0 100644 --- a/script/get-dataset-cognata-mlcommons/customize.py +++ b/script/get-dataset-cognata-mlcommons/customize.py @@ -1,6 +1,7 @@ from mlc import utils import os import json +from utils import is_true def preprocess(i): @@ -65,7 +66,7 @@ def postprocess(i): cur_dir = os.getcwd() - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) mlc_cache_dataset_path = env.get( 'MLC_CUSTOM_CACHE_ENTRY_DATASET_MLCOMMONS_COGNATA_PATH', '').strip() @@ -106,7 +107,7 @@ def postprocess(i): env['MLC_DATASET_MLCOMMONS_COGNATA_PATH'] = dataset_path # If imported, don't process further - if env.get('MLC_DATASET_MLCOMMONS_COGNATA_IMPORTED', '') == 'yes': + if is_true(env.get('MLC_DATASET_MLCOMMONS_COGNATA_IMPORTED', '')): cfg['imported'] = True else: cfg['imported'] = False diff --git a/script/get-dataset-igbh/customize.py b/script/get-dataset-igbh/customize.py index 70b97a440..f9bc1f979 100644 --- a/script/get-dataset-igbh/customize.py +++ b/script/get-dataset-igbh/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -46,7 +47,7 @@ def preprocess(i): env['MLC_DATASET_IGBH_SIZE']} {env.get('MLC_IGBH_CALIBRATION_FLAG', '')} """ # compress graph(for glt implementation) - if env.get('MLC_IGBH_GRAPH_COMPRESS', '') == "yes": + if is_true(env.get('MLC_IGBH_GRAPH_COMPRESS', '')): run_cmd += x_sep + \ f"""{env['MLC_PYTHON_BIN_WITH_PATH']} tools/compress_graph.py --path {download_loc} --dataset_size {env['MLC_DATASET_IGBH_SIZE']} --layout {env['MLC_IGBH_GRAPH_COMPRESS_LAYOUT']} """ diff --git a/script/get-dataset-imagenet-val/customize.py b/script/get-dataset-imagenet-val/customize.py index 24548f6a2..9b4569d15 100644 --- a/script/get-dataset-imagenet-val/customize.py +++ b/script/get-dataset-imagenet-val/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -13,7 +14,7 @@ def preprocess(i): env['MLC_DATASET_IMAGENET_VAL_REQUIRE_DAE'] = 'no' - full = env.get('MLC_IMAGENET_FULL', '').strip() == 'yes' + full = is_true(env.get('MLC_IMAGENET_FULL', '').strip()) path = env.get( 'MLC_INPUT', diff --git a/script/get-dataset-mlperf-inference-llama3/customize.py b/script/get-dataset-mlperf-inference-llama3/customize.py index c501a6e60..bf44782a7 100644 --- a/script/get-dataset-mlperf-inference-llama3/customize.py +++ b/script/get-dataset-mlperf-inference-llama3/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -24,7 +25,7 @@ def postprocess(i): env = i['env'] - if env.get('MLC_TMP_REQUIRE_DOWNLOAD', '') == "yes": + if is_true(env.get('MLC_TMP_REQUIRE_DOWNLOAD', '')): env['MLC_DATASET_LLAMA3_PATH'] = os.path.join( env['MLC_DATASET_LLAMA3_PATH'], env['MLC_DATASET_FILE_NAME']) diff --git a/script/get-dataset-mlperf-inference-mixtral/customize.py b/script/get-dataset-mlperf-inference-mixtral/customize.py index bcfb39259..5ecfbafdf 100644 --- a/script/get-dataset-mlperf-inference-mixtral/customize.py +++ b/script/get-dataset-mlperf-inference-mixtral/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -8,7 +9,7 @@ def preprocess(i): env = i['env'] - if env.get('MLC_DATASET_MIXTRAL_GENERATE_TEST_DATA', '') == "yes": + if is_true(env.get('MLC_DATASET_MIXTRAL_GENERATE_TEST_DATA', '')): env['MLC_DATASET_MIXTRAL_TEST_DATA_GENERATED_PATH'] = os.path.join( os.getcwd(), "mixtral-test-dataset.pkl") @@ -20,7 +21,7 @@ def postprocess(i): env['MLC_DATASET_MIXTRAL_PREPROCESSED_PATH'] = env['MLC_DATASET_PREPROCESSED_PATH'] - if env.get('MLC_DATASET_MIXTRAL_GENERATE_TEST_DATA', '') == "yes": + if is_true(env.get('MLC_DATASET_MIXTRAL_GENERATE_TEST_DATA', '')): env['MLC_DATASET_MIXTRAL_PREPROCESSED_PATH'] = env['MLC_DATASET_MIXTRAL_TEST_DATA_GENERATED_PATH'] return {'return': 0} diff --git a/script/get-dataset-openimages-calibration/customize.py b/script/get-dataset-openimages-calibration/customize.py index fc8466566..00f9cbb8b 100644 --- a/script/get-dataset-openimages-calibration/customize.py +++ b/script/get-dataset-openimages-calibration/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,9 +13,9 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) - if env.get("MLC_CALIBRATE_FILTER", "") == "yes": + if is_true(env.get("MLC_CALIBRATE_FILTER", "")): i['run_script_input']['script_name'] = "run-filter" env['MLC_MLPERF_OPENIMAGES_CALIBRATION_FILTERED_LIST'] = os.path.join( os.getcwd(), "filtered.txt") diff --git a/script/get-dataset-openimages/customize.py b/script/get-dataset-openimages/customize.py index 6eb686d97..9d4539739 100644 --- a/script/get-dataset-openimages/customize.py +++ b/script/get-dataset-openimages/customize.py @@ -1,6 +1,7 @@ from mlc import utils import os import shutil +from utils import is_true, is_false def preprocess(i): @@ -69,7 +70,7 @@ def postprocess(i): env['MLC_DATASET_ANNOTATIONS_DIR_PATH'] = os.path.join( os.getcwd(), 'install', 'annotations') - if env.get('MLC_DATASET_CALIBRATION', '') == "no": + if is_false(env.get('MLC_DATASET_CALIBRATION', '')): env['MLC_DATASET_PATH_ROOT'] = os.path.join(os.getcwd(), 'install') env['MLC_DATASET_PATH'] = os.path.join( os.getcwd(), 'install', 'validation', 'data') @@ -79,7 +80,7 @@ def postprocess(i): env['MLC_DATASET_VALIDATION_ANNOTATIONS_FILE_PATH'] = annotations_file_path env['MLC_DATASET_ANNOTATIONS_FILE_PATH'] = annotations_file_path env['MLC_DATASET_OPENIMAGES_VALIDATION_ANNOTATIONS_FILE_PATH'] = annotations_file_path - if env.get("MLC_DATASET_OPENIMAGES_CUSTOM_ANNOTATIONS", '') == "yes": + if is_true(env.get("MLC_DATASET_OPENIMAGES_CUSTOM_ANNOTATIONS", '')): annotations_file_src = env['MLC_DATASET_OPENIMAGES_ANNOTATIONS_FILE_PATH'] shutil.copy( annotations_file_src, diff --git a/script/get-dataset-openorca/customize.py b/script/get-dataset-openorca/customize.py index 3bb95817b..c9f3889ec 100644 --- a/script/get-dataset-openorca/customize.py +++ b/script/get-dataset-openorca/customize.py @@ -1,6 +1,7 @@ from mlc import utils import os import shutil +from utils import is_false def preprocess(i): @@ -12,7 +13,7 @@ def preprocess(i): def postprocess(i): env = i['env'] - if env.get('MLC_DATASET_CALIBRATION', '') == "no": + if is_false(env.get('MLC_DATASET_CALIBRATION', '')): env['MLC_DATASET_PATH_ROOT'] = env['MLC_DATASET_OPENORCA_PATH'] env['MLC_DATASET_PATH'] = env['MLC_DATASET_OPENORCA_PATH'] env['MLC_DATASET_OPENORCA_PARQUET'] = os.path.join( diff --git a/script/get-dlrm-data-mlperf-inference/customize.py b/script/get-dlrm-data-mlperf-inference/customize.py index 366a3425d..8f0153094 100644 --- a/script/get-dlrm-data-mlperf-inference/customize.py +++ b/script/get-dlrm-data-mlperf-inference/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -35,7 +36,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) variation = env['MLC_DLRM_DATA_VARIATION'] @@ -84,14 +85,14 @@ def preprocess(i): xsep = ' && ' # addition of run command to download the datasets and model - if env.get('MLC_DLRM_DATASET_DOWNLOAD', False) == True: + if is_true(env.get('MLC_DLRM_DATASET_DOWNLOAD', False)): run_cmd += 'cp -r "$MLC_CRITEO_PREPROCESSED_PATH"/. ' + \ os.path.join(dlrm_data_path, "criteo", "day23", "fp32") + xsep - if env.get('MLC_DLRM_MODEL_DOWNLOAD', False) == True: + if is_true(env.get('MLC_DLRM_MODEL_DOWNLOAD', False)): run_cmd += 'cp -r "$MLC_ML_MODEL_FILE_WITH_PATH"/. ' + \ os.path.join(dlrm_data_path, "model") + xsep - if env.get('MLC_DLRM_DATASET_DOWNLOAD', '') != True: + if not is_true(env.get('MLC_DLRM_DATASET_DOWNLOAD', '')): if not os.path.exists(os.path.join( dlrm_data_path, "criteo", "day23", "fp32", "day_23_sparse_multi_hot_unpacked")): os.system(f"unzip {os.path.join(dlrm_data_path, 'criteo', 'day23', 'fp32', 'day_23_sparse_multi_hot.npz')} -d {os.path.join(dlrm_data_path, 'criteo', 'day23', 'fp32', 'day_23_sparse_multi_hot_unpacked')}") @@ -99,7 +100,7 @@ def preprocess(i): run_cmd += f"unzip {os.path.join(dlrm_data_path, 'criteo', 'day23', 'fp32', 'day_23_sparse_multi_hot.npz')} -d {os.path.join(dlrm_data_path, 'criteo', 'day23', 'fp32', 'day_23_sparse_multi_hot_unpacked')}" + xsep if os.path.exists(os.path.join(dlrm_data_path, "criteo", "day23", "fp32", - "day_23_sparse_multi_hot.npz")) or env['MLC_DLRM_DATASET_DOWNLOAD'] == True: + "day_23_sparse_multi_hot.npz")) or is_true(env['MLC_DLRM_DATASET_DOWNLOAD']): file_path = os.path.join( dlrm_data_path, "criteo", diff --git a/script/get-generic-python-lib/customize.py b/script/get-generic-python-lib/customize.py index 97dbb94c6..02c8071c6 100644 --- a/script/get-generic-python-lib/customize.py +++ b/script/get-generic-python-lib/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true, is_false import os @@ -36,10 +37,10 @@ def preprocess(i): extra += ' --break-system-packages ' env['MLC_PYTHON_PIP_COMMON_EXTRA'] = " --break-system-packages" - if env.get('MLC_GENERIC_PYTHON_PACKAGE_INSTALL_DEPS', '') == "no": + if is_false(env.get('MLC_GENERIC_PYTHON_PACKAGE_INSTALL_DEPS', '')): env['MLC_PYTHON_PIP_COMMON_EXTRA'] = " --no-deps" - if env.get('MLC_PIP_INSTALL_NEEDS_USER', '') == "yes": + if is_true(env.get('MLC_PIP_INSTALL_NEEDS_USER', '')): env['MLC_PYTHON_PIP_COMMON_EXTRA'] = " --user" if env.get('MLC_GENERIC_PYTHON_PIP_UNINSTALL_DEPS', '') != '': @@ -62,13 +63,9 @@ def preprocess(i): 'recursion_spaces': recursion_spaces}) force_install = ( - env.get( + is_true(env.get( 'MLC_TMP_PYTHON_PACKAGE_FORCE_INSTALL', - '') in [ - 'yes', - 'true', - 'True', - True]) + ''))) if r['return'] > 0 or force_install: if r['return'] == 16 or force_install: @@ -113,8 +110,7 @@ def preprocess(i): extra += ' -f ' + find_links_url # Check update - if env.get('MLC_GENERIC_PYTHON_PIP_UPDATE', '') in [ - True, 'true', 'yes', 'on']: + if is_true(env.get('MLC_GENERIC_PYTHON_PIP_UPDATE', '')): extra += ' -U' logger.info(recursion_spaces + ' Extra PIP CMD: ' + extra) diff --git a/script/get-generic-sys-util/customize.py b/script/get-generic-sys-util/customize.py index 0efd666bf..f7c7a37d0 100644 --- a/script/get-generic-sys-util/customize.py +++ b/script/get-generic-sys-util/customize.py @@ -1,6 +1,7 @@ from mlc import utils import os import re +from utils import * def preprocess(i): @@ -17,7 +18,7 @@ def preprocess(i): env['MLC_SYS_UTIL_CHECK_CMD'] = env['MLC_SYS_UTIL_VERSION_CMD'] if env.get('MLC_GENERIC_SYS_UTIL_RUN_MODE', '') == "install": - if env.get('MLC_SYS_UTIL_INSTALL_WITH_RETRY', '') == "yes": + if is_true(env.get('MLC_SYS_UTIL_INSTALL_WITH_RETRY', '')): i['run_script_input']['script_name'] = "install-with-retry" else: i['run_script_input']['script_name'] = "install" @@ -67,8 +68,7 @@ def preprocess(i): 'error': f'No package name specified for {util} in the meta'} if not package_name: - if str(env.get('MLC_GENERIC_SYS_UTIL_IGNORE_MISSING_PACKAGE', '') - ).lower() in ["1", "true", "yes"]: + if is_true(env.get('MLC_GENERIC_SYS_UTIL_IGNORE_MISSING_PACKAGE', False)): print( f"WARNING: No package name specified for {pm} and util name {util}. Ignoring it...") env['MLC_TMP_GENERIC_SYS_UTIL_PACKAGE_INSTALL_IGNORED'] = 'yes' @@ -156,14 +156,14 @@ def postprocess(i): version_env_key = f"MLC_{env['MLC_SYS_UTIL_NAME'].upper()}_VERSION" - if (env.get('MLC_SYS_UTIL_VERSION_CMD', '') != '' or env.get('MLC_SYS_UTIL_VERSION_CMD_OVERRIDE', '') != '') and env.get(version_env_key, '') == '' and str(env.get( - 'MLC_TMP_GENERIC_SYS_UTIL_PACKAGE_INSTALL_IGNORED', '')).lower() not in ["yes", "1", "true"] and env.get('MLC_GET_GENERIC_SYS_UTIL_INSTALL_FAILED', '') != 'yes': + if (env.get('MLC_SYS_UTIL_VERSION_CMD', '') != '' or env.get('MLC_SYS_UTIL_VERSION_CMD_OVERRIDE', '') != '') and env.get(version_env_key, '') == '' and not is_true( + env.get('MLC_TMP_GENERIC_SYS_UTIL_PACKAGE_INSTALL_IGNORED', '')) and not is_true(env.get('MLC_GET_GENERIC_SYS_UTIL_INSTALL_FAILED', '')): automation = i['automation'] r = automation.run_native_script( {'run_script_input': i['run_script_input'], 'env': env, 'script_name': 'detect'}) - if r['return'] > 0 and str(env.get( - 'MLC_GENERIC_SYS_UTIL_IGNORE_VERSION_DETECTION_FAILURE', '')).lower() not in ["1", "yes", "true"]: + if r['return'] > 0 and not is_true( + env.get('MLC_GENERIC_SYS_UTIL_IGNORE_VERSION_DETECTION_FAILURE', False)): return {'return': 1, 'error': 'Version detection failed after installation. Please check the provided version command or use env.MLC_GENERIC_SYS_UTIL_IGNORE_VERSION_DETECTION_FAILURE=yes to ignore the error.'} elif r['return'] == 0: diff --git a/script/get-gh-actions-runner/customize.py b/script/get-gh-actions-runner/customize.py index 360308e91..795c50da6 100644 --- a/script/get-gh-actions-runner/customize.py +++ b/script/get-gh-actions-runner/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -13,7 +14,7 @@ def preprocess(i): automation = i['automation'] mlc = automation.action_object - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) cmd = env.get('MLC_GH_ACTIONS_RUNNER_COMMAND', '') if cmd == "config": diff --git a/script/get-github-cli/customize.py b/script/get-github-cli/customize.py index 33b2c3cac..7993b1e3c 100644 --- a/script/get-github-cli/customize.py +++ b/script/get-github-cli/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -23,7 +24,7 @@ def preprocess(i): 'recursion_spaces': recursion_spaces}) if r['return'] > 0: if r['return'] == 16: - if env.get('MLC_TMP_FAIL_IF_NOT_FOUND', '').lower() == 'yes': + if is_true(env.get('MLC_TMP_FAIL_IF_NOT_FOUND', '')): return r print(recursion_spaces + ' # {}'.format(r['error'])) diff --git a/script/get-google-test/customize.py b/script/get-google-test/customize.py index cb1be8fe5..7e86f048e 100644 --- a/script/get-google-test/customize.py +++ b/script/get-google-test/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -13,7 +14,7 @@ def preprocess(i): automation = i['automation'] env['MLC_GIT_CHECKOUT'] = "v" + env['MLC_VERSION'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) return {'return': 0} diff --git a/script/get-huggingface-cli/customize.py b/script/get-huggingface-cli/customize.py index 03fc5b753..ee0a1ff42 100644 --- a/script/get-huggingface-cli/customize.py +++ b/script/get-huggingface-cli/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -7,7 +8,7 @@ def preprocess(i): if env.get('MLC_HF_TOKEN', '') != '': env['MLC_HF_LOGIN_CMD'] = f"""git config --global credential.helper store && huggingface-cli login --token {env['MLC_HF_TOKEN']} --add-to-git-credential """ - elif str(env.get('MLC_HF_DO_LOGIN')).lower() in ["yes", "1", "true"]: + elif is_true(str(env.get('MLC_HF_DO_LOGIN'))): env['MLC_HF_LOGIN_CMD'] = f"""git config --global credential.helper store && huggingface-cli login """ return {'return': 0} diff --git a/script/get-java/customize.py b/script/get-java/customize.py index 199d1b23d..c646f20b8 100644 --- a/script/get-java/customize.py +++ b/script/get-java/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -21,7 +22,7 @@ def preprocess(i): meta = i['meta'] found = False - install = env.get('MLC_JAVA_PREBUILT_INSTALL', '') in ['on', 'True', True] + install = is_true(env.get('MLC_JAVA_PREBUILT_INSTALL', '')) env_path_key = 'MLC_JAVA_BIN_WITH_PATH' diff --git a/script/get-javac/customize.py b/script/get-javac/customize.py index a8c0995a4..7376a523e 100644 --- a/script/get-javac/customize.py +++ b/script/get-javac/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -21,7 +22,7 @@ def preprocess(i): meta = i['meta'] found = False - install = env.get('MLC_JAVAC_PREBUILT_INSTALL', '') in ['on', 'True', True] + install = is_true(env.get('MLC_JAVAC_PREBUILT_INSTALL', '')) env_path_key = 'MLC_JAVAC_BIN_WITH_PATH' diff --git a/script/get-lib-protobuf/customize.py b/script/get-lib-protobuf/customize.py index 4219223dd..c061c346a 100644 --- a/script/get-lib-protobuf/customize.py +++ b/script/get-lib-protobuf/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -13,7 +14,7 @@ def preprocess(i): automation = i['automation'] env['MLC_GIT_CHECKOUT'] = "v" + env['MLC_VERSION'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) return {'return': 0} diff --git a/script/get-ml-model-abtf-ssd-pytorch/customize.py b/script/get-ml-model-abtf-ssd-pytorch/customize.py index 1e3df4acf..a4fa7f16c 100644 --- a/script/get-ml-model-abtf-ssd-pytorch/customize.py +++ b/script/get-ml-model-abtf-ssd-pytorch/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -8,7 +9,7 @@ def preprocess(i): env = i['env'] - if env.get('MLC_ML_MODEL_LOCAL', '') == 'yes': + if is_true(env.get('MLC_ML_MODEL_LOCAL', '')): ml_model = env.get('MLC_ML_MODEL_FILENAME', '') if ml_model == '': return {'return': 1, 'error': '_local.{model name.pth} is not specified'} diff --git a/script/get-ml-model-bert-large-squad/customize.py b/script/get-ml-model-bert-large-squad/customize.py index 3de4c51d5..aed1f27a2 100644 --- a/script/get-ml-model-bert-large-squad/customize.py +++ b/script/get-ml-model-bert-large-squad/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -7,7 +8,7 @@ def preprocess(i): os_info = i['os_info'] env = i['env'] - if env.get('MLC_ML_MODEL_BERT_PACKED', '') == 'yes': + if is_true(env.get('MLC_ML_MODEL_BERT_PACKED', '')): i['run_script_input']['script_name'] = "run-packed" env['MLC_BERT_CONFIG_PATH'] = os.path.join( env['MLC_MLPERF_INFERENCE_BERT_PATH'], "bert_config.json") diff --git a/script/get-ml-model-efficientnet-lite/customize.py b/script/get-ml-model-efficientnet-lite/customize.py index e15084ce0..b9a547fee 100644 --- a/script/get-ml-model-efficientnet-lite/customize.py +++ b/script/get-ml-model-efficientnet-lite/customize.py @@ -25,10 +25,10 @@ def preprocess(i): filename = r['filename'] - if env.get('MLC_UNZIP') == "yes" or env.get('MLC_UNTAR') == "yes": - if env.get('MLC_UNZIP') == "yes": + if is_true(env.get('MLC_UNZIP')) or is_true(env.get('MLC_UNTAR')): + if is_true(env.get('MLC_UNZIP')): cmd = "unzip " - elif env.get('MLC_UNTAR') == "yes": + elif is_true(env.get('MLC_UNTAR')): cmd = "tar -xvzf " os.system(cmd + filename) diff --git a/script/get-ml-model-gptj/customize.py b/script/get-ml-model-gptj/customize.py index 6dc97fc18..997c133ed 100644 --- a/script/get-ml-model-gptj/customize.py +++ b/script/get-ml-model-gptj/customize.py @@ -33,8 +33,7 @@ def preprocess(i): elif env.get('MLC_TMP_ML_MODEL_PROVIDER', '') == 'nvidia': i['run_script_input']['script_name'] = 'run-nvidia' - if str(env.get('MLC_DOCKER_DETACHED_MODE', '') - ).lower() in ['yes', 'true', "1"]: + if is_true(str(env.get('MLC_DOCKER_DETACHED_MODE', ''))): env['DOCKER_RUN_OPTS'] = "--rm --ipc=host --ulimit memlock=-1 --ulimit stack=67108864" gpu_arch = int( float( diff --git a/script/get-ml-model-huggingface-zoo/customize.py b/script/get-ml-model-huggingface-zoo/customize.py index 4f57cfb8a..305ce1a1f 100644 --- a/script/get-ml-model-huggingface-zoo/customize.py +++ b/script/get-ml-model-huggingface-zoo/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -18,7 +19,7 @@ def preprocess(i): if path == '': path = os.getcwd() - if env.get('MLC_GIT_CLONE_REPO', '') != 'yes': + if not is_true(env.get('MLC_GIT_CLONE_REPO', '')): run_cmd = env.get('MLC_PYTHON_BIN_WITH_PATH') + " " + \ os.path.join(script_path, 'download_model.py') else: diff --git a/script/get-ml-model-mobilenet/customize.py b/script/get-ml-model-mobilenet/customize.py index e15084ce0..b9a547fee 100644 --- a/script/get-ml-model-mobilenet/customize.py +++ b/script/get-ml-model-mobilenet/customize.py @@ -25,10 +25,10 @@ def preprocess(i): filename = r['filename'] - if env.get('MLC_UNZIP') == "yes" or env.get('MLC_UNTAR') == "yes": - if env.get('MLC_UNZIP') == "yes": + if is_true(env.get('MLC_UNZIP')) or is_true(env.get('MLC_UNTAR')): + if is_true(env.get('MLC_UNZIP')): cmd = "unzip " - elif env.get('MLC_UNTAR') == "yes": + elif is_true(env.get('MLC_UNTAR')): cmd = "tar -xvzf " os.system(cmd + filename) diff --git a/script/get-ml-model-resnet50/customize.py b/script/get-ml-model-resnet50/customize.py index a954a3c1d..988960764 100644 --- a/script/get-ml-model-resnet50/customize.py +++ b/script/get-ml-model-resnet50/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -8,7 +9,7 @@ def preprocess(i): env = i['env'] - if env.get('MLC_ML_MODEL_TF_FIX_INPUT_SHAPE', '') == "yes": + if is_true(env.get('MLC_ML_MODEL_TF_FIX_INPUT_SHAPE', '')): i['run_script_input']['script_name'] = "run-fix-input" return {'return': 0} @@ -18,7 +19,7 @@ def postprocess(i): env = i['env'] - if env.get('MLC_ML_MODEL_TF_FIX_INPUT_SHAPE', '') == "yes": + if is_true(env.get('MLC_ML_MODEL_TF_FIX_INPUT_SHAPE', '')): env['MLC_ML_MODEL_STARTING_FILE_PATH'] = env['MLC_ML_MODEL_FILE_WITH_PATH'] env['MLC_ML_MODEL_FILE_WITH_PATH'] = os.path.join( os.getcwd(), "resnet50_v1.pb") diff --git a/script/get-ml-model-retinanet/customize.py b/script/get-ml-model-retinanet/customize.py index 7dd6721fb..ae725714e 100644 --- a/script/get-ml-model-retinanet/customize.py +++ b/script/get-ml-model-retinanet/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -8,7 +9,7 @@ def preprocess(i): env = i['env'] - if env.get('MLC_TMP_ML_MODEL_RETINANET_NO_NMS', '') == 'yes': + if is_true(env.get('MLC_TMP_ML_MODEL_RETINANET_NO_NMS', '')): i['run_script_input']['script_name'] = "run-no-nms" env['MLC_ML_MODEL_FILE_WITH_PATH'] = os.path.join( os.getcwd(), "retinanet.onnx") @@ -26,7 +27,7 @@ def postprocess(i): env[env['MLC_ENV_NAME_ML_MODEL_FILE'] ] = env['MLC_ML_MODEL_FILE_WITH_PATH'] - if env.get("MLC_QAIC_PRINT_NODE_PRECISION_INFO", '') == 'yes': + if is_true(env.get("MLC_QAIC_PRINT_NODE_PRECISION_INFO", '')): env['MLC_ML_MODEL_RETINANET_QAIC_NODE_PRECISION_INFO_FILE_PATH'] = os.path.join( os.getcwd(), 'node-precision-info.yaml') diff --git a/script/get-ml-model-rnnt/customize.py b/script/get-ml-model-rnnt/customize.py index b5218f91d..a63eb152f 100644 --- a/script/get-ml-model-rnnt/customize.py +++ b/script/get-ml-model-rnnt/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -26,7 +27,7 @@ def preprocess(i): filename = r['filename'] - if env.get('MLC_UNZIP') == "yes": + if is_true(env.get('MLC_UNZIP')): os.system("unzip " + filename) filename = env['MLC_ML_MODEL_FILE'] env['MLC_ML_MODEL_FILE_WITH_PATH'] = os.path.join(path, filename) diff --git a/script/get-ml-model-tiny-resnet/customize.py b/script/get-ml-model-tiny-resnet/customize.py index 3fb42da47..6f71c9318 100644 --- a/script/get-ml-model-tiny-resnet/customize.py +++ b/script/get-ml-model-tiny-resnet/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -8,7 +9,7 @@ def preprocess(i): env = i['env'] - if env.get("MLC_TMP_ML_MODEL_TF2ONNX", "") == "yes": + if is_true(env.get("MLC_TMP_ML_MODEL_TF2ONNX", "")): outputfile = env.get('MLC_ML_MODEL_OUTFILE', 'model_quant.onnx') env['MLC_RUN_CMD'] = env['MLC_PYTHON_BIN_WITH_PATH'] + " -m tf2onnx.convert --tflite " + \ env['MLC_ML_MODEL_FILE_WITH_PATH'] + " --output " + \ diff --git a/script/get-mlperf-automotive-scratch-space/customize.py b/script/get-mlperf-automotive-scratch-space/customize.py index 17f6712dd..d56152498 100644 --- a/script/get-mlperf-automotive-scratch-space/customize.py +++ b/script/get-mlperf-automotive-scratch-space/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) if env.get('MLC_ABTF_SCRATCH_PATH', '') == '': env['MLC_ABTF_SCRATCH_PATH'] = os.getcwd() diff --git a/script/get-mlperf-inference-intel-scratch-space/customize.py b/script/get-mlperf-inference-intel-scratch-space/customize.py index 01ea63e3a..978cbbcb2 100644 --- a/script/get-mlperf-inference-intel-scratch-space/customize.py +++ b/script/get-mlperf-inference-intel-scratch-space/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) if env.get('MLC_INTEL_MLPERF_SCRATCH_PATH', '') == '': env['MLC_INTEL_MLPERF_SCRATCH_PATH'] = os.getcwd() diff --git a/script/get-mlperf-inference-loadgen/customize.py b/script/get-mlperf-inference-loadgen/customize.py index 4e9ed3a7a..4ae4b8b73 100644 --- a/script/get-mlperf-inference-loadgen/customize.py +++ b/script/get-mlperf-inference-loadgen/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -7,8 +8,8 @@ def preprocess(i): os_info = i['os_info'] env = i['env'] - if env.get('MLC_TMP_MLPERF_INFERENCE_LOADGEN_INSTALL_FROM_PIP', - '') == 'yes': + if is_true(env.get('MLC_TMP_MLPERF_INFERENCE_LOADGEN_INSTALL_FROM_PIP', + '')): i['run_script_input']['script_name'] = "donotrun" return {'return': 0} @@ -19,8 +20,8 @@ def postprocess(i): os_info = i['os_info'] env = i['env'] - if env.get('MLC_TMP_MLPERF_INFERENCE_LOADGEN_INSTALL_FROM_PIP', - '') == 'yes': + if is_true(env.get('MLC_TMP_MLPERF_INFERENCE_LOADGEN_INSTALL_FROM_PIP', + '')): return {'return': 0} for key in ['+PYTHONPATH', '+C_INCLUDE_PATH', '+CPLUS_INCLUDE_PATH', diff --git a/script/get-mlperf-inference-nvidia-scratch-space/customize.py b/script/get-mlperf-inference-nvidia-scratch-space/customize.py index 5227b9cd3..f2c2f14cc 100644 --- a/script/get-mlperf-inference-nvidia-scratch-space/customize.py +++ b/script/get-mlperf-inference-nvidia-scratch-space/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) if env.get('MLC_NVIDIA_MLPERF_SCRATCH_PATH', '') == '': if env.get('MLPERF_SCRATCH_PATH', '') != '': diff --git a/script/get-mlperf-inference-results-dir/customize.py b/script/get-mlperf-inference-results-dir/customize.py index a49293155..61e5ef042 100644 --- a/script/get-mlperf-inference-results-dir/customize.py +++ b/script/get-mlperf-inference-results-dir/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) if env.get('MLC_MLPERF_INFERENCE_RESULTS_DIR', '') == '': env['MLC_MLPERF_INFERENCE_RESULTS_DIR'] = os.getcwd() diff --git a/script/get-mlperf-inference-results/customize.py b/script/get-mlperf-inference-results/customize.py index f921067e1..285a33f9d 100644 --- a/script/get-mlperf-inference-results/customize.py +++ b/script/get-mlperf-inference-results/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import shutil @@ -13,7 +14,7 @@ def preprocess(i): env = i['env'] meta = i['meta'] - if env.get('NVIDIA_ONLY', '') == 'yes': + if is_true(env.get('NVIDIA_ONLY', '')): env['MLC_GIT_URL'] = "https://github.com/GATEOverflow/nvidia-inference-code.git" if 'GITHUB_REPO_OWNER' in env and '<<>>' in env['MLC_GIT_URL']: diff --git a/script/get-mlperf-inference-src/customize.py b/script/get-mlperf-inference-src/customize.py index 4fb2c0c31..8bbe90622 100644 --- a/script/get-mlperf-inference-src/customize.py +++ b/script/get-mlperf-inference-src/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import shutil @@ -71,7 +72,7 @@ def preprocess(i): } for submodule in possible_submodules: env_name = submodule.upper().replace("-", "_") - if env.get("MLC_SUBMODULE_" + env_name) == "yes": + if is_true(env.get("MLC_SUBMODULE_" + env_name)): submodules.append(possible_submodules[submodule]) env['MLC_GIT_SUBMODULES'] = ",".join(submodules) @@ -132,7 +133,7 @@ def postprocess(i): version_info = f.read().strip() env['MLC_MLPERF_INFERENCE_SOURCE_VERSION'] = version_info - if env.get('MLC_GET_MLPERF_IMPLEMENTATION_ONLY', '') == "yes": + if is_true(env.get('MLC_GET_MLPERF_IMPLEMENTATION_ONLY', '')): return {'return': 0} env['MLC_MLPERF_INFERENCE_CONF_PATH'] = os.path.join( diff --git a/script/get-mlperf-inference-submission-dir/customize.py b/script/get-mlperf-inference-submission-dir/customize.py index da58a8af9..7b5290c47 100644 --- a/script/get-mlperf-inference-submission-dir/customize.py +++ b/script/get-mlperf-inference-submission-dir/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) if env.get('MLC_MLPERF_INFERENCE_SUBMISSION_DIR', '') == '': if not os.path.exists("mlperf-inference-submission"): diff --git a/script/get-mlperf-inference-sut-configs/customize.py b/script/get-mlperf-inference-sut-configs/customize.py index a2f605ae5..3b9a956bd 100644 --- a/script/get-mlperf-inference-sut-configs/customize.py +++ b/script/get-mlperf-inference-sut-configs/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import yaml import shutil @@ -50,7 +51,7 @@ def postprocess(i): if env.get('MLC_SUT_CONFIGS_PATH', '') != '': path = env['MLC_SUT_CONFIGS_PATH'] - elif env.get('MLC_SUT_USE_EXTERNAL_CONFIG_REPO', '') == "yes": + elif is_true(env.get('MLC_SUT_USE_EXTERNAL_CONFIG_REPO', '')): path = env.get('MLC_GIT_CHECKOUT_PATH') else: path = os.path.join(os.getcwd(), "configs") diff --git a/script/get-mlperf-inference-sut-description/customize.py b/script/get-mlperf-inference-sut-description/customize.py index 879f98164..4c35209e9 100644 --- a/script/get-mlperf-inference-sut-description/customize.py +++ b/script/get-mlperf-inference-sut-description/customize.py @@ -44,7 +44,7 @@ def preprocess(i): sut_path = os.path.join(sut_desc_path, "suts", sut + ".json") env['MLC_SUT_PATH'] = sut_path - if os.path.exists(sut_path) and env.get('MLC_SUT_DESC_CACHE', '') == "yes": + if os.path.exists(sut_path) and is_true(env.get('MLC_SUT_DESC_CACHE', '')): print(f"Reusing SUT description file {sut}") state['MLC_SUT_META'] = json.load(open(sut_path)) else: diff --git a/script/get-mlperf-inference-utils/customize.py b/script/get-mlperf-inference-utils/customize.py index dcbe141bb..7ae5d02bd 100644 --- a/script/get-mlperf-inference-utils/customize.py +++ b/script/get-mlperf-inference-utils/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import sys @@ -13,7 +14,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) utils_path = env['MLC_TMP_CURRENT_SCRIPT_PATH'] diff --git a/script/get-preprocessed-dataset-openorca/customize.py b/script/get-preprocessed-dataset-openorca/customize.py index 4317c1e84..18b990e09 100644 --- a/script/get-preprocessed-dataset-openorca/customize.py +++ b/script/get-preprocessed-dataset-openorca/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from mlc.utils import * import os import shutil @@ -7,10 +8,9 @@ def preprocess(i): env = i['env'] - if str(env.get('MLC_DATASET_PREPROCESSED_BY_MLC', '') - ).lower() in ["yes", "1", "true"]: + if is_true(str(env.get('MLC_DATASET_PREPROCESSED_BY_MLC', ''))): run_dir = os.getcwd() - if env.get('MLC_DATASET_CALIBRATION', '') == "yes": + if is_true(env.get('MLC_DATASET_CALIBRATION', '')): env['MLC_DATASET_CALIBRATION_PATH'] = os.path.join( env['MLC_OPENORCA_PREPROCESSED_ROOT'], "open_orca_gpt4_tokenized_llama.calibration_1000.pkl.gz") @@ -28,7 +28,7 @@ def preprocess(i): inference_src = env['MLC_MLPERF_INFERENCE_SOURCE'] run_dir = os.path.join(inference_src, 'language', 'llama2-70b') model_dir = env['MLC_ML_MODEL_PATH'] - if env.get('MLC_DATASET_CALIBRATION', '') == "yes": + if is_true(env.get('MLC_DATASET_CALIBRATION', '')): return {'return': 1, 'error': 'No raw preprocessing information is available for openorca calibration. Please use _mlcommons variation to use the MLCommons shared calibration dataset'} else: env['MLC_DATASET_PREPROCESSED_PATH'] = os.path.join( diff --git a/script/get-preprocessed-dataset-squad/customize.py b/script/get-preprocessed-dataset-squad/customize.py index ba1ecf264..ae081e38f 100644 --- a/script/get-preprocessed-dataset-squad/customize.py +++ b/script/get-preprocessed-dataset-squad/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) if env.get('MLC_DATASET_SQUAD_CALIBRATION_SET', '') == "one": env['DATASET_CALIBRATION_FILE'] = os.path.join( @@ -34,7 +35,7 @@ def preprocess(i): env['CK_ENV_MLPERF_INFERENCE'] = env['MLC_MLPERF_INFERENCE_SOURCE'] - if env.get('MLC_DATASET_SQUAD_PACKED', '') == "yes": + if is_true(env.get('MLC_DATASET_SQUAD_PACKED', '')): i['run_script_input']['script_name'] = "run-packed" if env.get('+PYTHONPATH', '') == '': env['+PYTHONPATH'] = [] @@ -49,9 +50,9 @@ def postprocess(i): env = i['env'] cur = os.getcwd() - if env.get('MLC_DATASET_SQUAD_PACKED', '') != "yes": + if not is_true(env.get('MLC_DATASET_SQUAD_PACKED', '')): env['MLC_DATASET_SQUAD_TOKENIZED_ROOT'] = cur - if env.get('MLC_DATASET_RAW', '') == "yes": + if is_true(env.get('MLC_DATASET_RAW', '')): env['MLC_DATASET_SQUAD_TOKENIZED_INPUT_IDS'] = os.path.join( cur, 'bert_tokenized_squad_v1_1_input_ids.raw') env['MLC_DATASET_SQUAD_TOKENIZED_SEGMENT_IDS'] = os.path.join( diff --git a/script/get-python3/customize.py b/script/get-python3/customize.py index a306f9e14..299dc0b59 100644 --- a/script/get-python3/customize.py +++ b/script/get-python3/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -8,7 +9,7 @@ def preprocess(i): env = i['env'] - if env.get('MLC_PYTHON_CONDA', '') == 'yes' and env.get( + if is_true(env.get('MLC_PYTHON_CONDA', '')) and env.get( 'MLC_CONDA_BIN_PATH', '') != '': env['MLC_PYTHON_BIN_WITH_PATH'] = os.path.join( env['MLC_CONDA_BIN_PATH'], "python") diff --git a/script/get-qaic-apps-sdk/customize.py b/script/get-qaic-apps-sdk/customize.py index 74e5f5533..289c2a70b 100644 --- a/script/get-qaic-apps-sdk/customize.py +++ b/script/get-qaic-apps-sdk/customize.py @@ -1,6 +1,7 @@ from mlc import utils import os import xml.etree.ElementTree as et +from utils import is_true def preprocess(i): @@ -34,7 +35,7 @@ def preprocess(i): env['MLC_QAIC_APPS_SDK_PATH'] = path env['MLC_QAIC_EXEC_PATH'] = os.path.join(path, "exec", "qaic-exec") - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) return {'return': 0} diff --git a/script/get-qaic-platform-sdk/customize.py b/script/get-qaic-platform-sdk/customize.py index b0050427c..da006b802 100644 --- a/script/get-qaic-platform-sdk/customize.py +++ b/script/get-qaic-platform-sdk/customize.py @@ -1,6 +1,7 @@ from mlc import utils import os import xml.etree.ElementTree as et +from utils import is_true def preprocess(i): @@ -35,7 +36,7 @@ def preprocess(i): env['MLC_QAIC_RUNNER_PATH'] = os.path.join(path, "exec", "qaic-runner") env['MLC_QAIC_TOOLS_PATH'] = os.path.join(path, "tools") - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) return {'return': 0} diff --git a/script/get-qaic-software-kit/customize.py b/script/get-qaic-software-kit/customize.py index e94db4245..275572a52 100644 --- a/script/get-qaic-software-kit/customize.py +++ b/script/get-qaic-software-kit/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -14,7 +15,7 @@ def preprocess(i): env['MLC_QAIC_SOFTWARE_KIT_PATH'] = env['MLC_GIT_CHECKOUT_PATH'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) if env.get('+ CXXFLAGS', []) == []: env['+ CXXFLAGS'] = [] diff --git a/script/get-rclone-config/customize.py b/script/get-rclone-config/customize.py index 719bf7856..003d1bf8a 100644 --- a/script/get-rclone-config/customize.py +++ b/script/get-rclone-config/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) run_cmds = [] if env.get('MLC_RCLONE_CONFIG_CMD', '') != '': diff --git a/script/get-rclone/customize.py b/script/get-rclone/customize.py index 25ff0d703..0b3a05065 100644 --- a/script/get-rclone/customize.py +++ b/script/get-rclone/customize.py @@ -1,6 +1,7 @@ from mlc import utils import os import configparser +from utils import is_true def preprocess(i): @@ -31,8 +32,8 @@ def preprocess(i): if r['return'] > 0: if r['return'] == 16: install_script = 'install' - if os_info['platform'] != 'windows' and env.get( - 'MLC_RCLONE_SYSTEM', '') == 'yes': + if os_info['platform'] != 'windows' and is_true(env.get( + 'MLC_RCLONE_SYSTEM', '')): install_script += '-system' else: if os_info['platform'] != 'windows': @@ -135,8 +136,8 @@ def postprocess(i): file_name = 'rclone.exe' if os_info['platform'] == 'windows' else 'rclone' - if os_info['platform'] == 'windows' or env.get( - 'MLC_RCLONE_SYSTEM', '') != 'yes': + if os_info['platform'] == 'windows' or not is_true(env.get( + 'MLC_RCLONE_SYSTEM', '')): cur_dir = os.getcwd() path_bin = os.path.join(cur_dir, file_name) if os.path.isfile(path_bin): diff --git a/script/get-rocm-devices/customize.py b/script/get-rocm-devices/customize.py index 8c2903fb0..60b42d5d2 100644 --- a/script/get-rocm-devices/customize.py +++ b/script/get-rocm-devices/customize.py @@ -1,14 +1,14 @@ from mlc import utils import os import subprocess +from utils import * def preprocess(i): env = i['env'] - if str(env.get('MLC_DETECT_USING_HIP-PYTHON', '') - ).lower() in ["1", "yes", "true"]: + if is_true(str(env.get('MLC_DETECT_USING_HIP-PYTHON', ''))): i['run_script_input']['script_name'] = 'detect' return {'return': 0} diff --git a/script/get-sys-utils-cm/customize.py b/script/get-sys-utils-cm/customize.py index 06887bc3f..dd2672fd8 100644 --- a/script/get-sys-utils-cm/customize.py +++ b/script/get-sys-utils-cm/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -16,7 +17,7 @@ def preprocess(i): i['run_script_input']['script_name'] = "run-rhel" # Test (not needed - will be removed) - if str(env.get('MLC_SKIP_SYS_UTILS', '')).lower() in [True, 'yes', 'on']: + if is_true(str(env.get('MLC_SKIP_SYS_UTILS', ''))): return {'return': 0, 'skip': True} diff --git a/script/get-tensorrt/customize.py b/script/get-tensorrt/customize.py index b84792744..616111509 100644 --- a/script/get-tensorrt/customize.py +++ b/script/get-tensorrt/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import tarfile @@ -89,7 +90,7 @@ def preprocess(i): if env.get('MLC_TENSORRT_TAR_FILE_PATH', '') == '': tags = ["get", "tensorrt"] - if env.get('MLC_TENSORRT_REQUIRE_DEV', '') != 'yes': + if not is_true(env.get('MLC_TENSORRT_REQUIRE_DEV', '')): tags.append("_dev") return {'return': 1, 'error': 'Please envoke mlcr "' + ",".join(tags) + '" --tar_file={full path to the TensorRT tar file}'} diff --git a/script/get-tvm-model/customize.py b/script/get-tvm-model/customize.py index 44f785bb3..f214f570e 100644 --- a/script/get-tvm-model/customize.py +++ b/script/get-tvm-model/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) work_dir = env.get('MLC_TUNE_TVM_MODEL_WORKDIR', '') diff --git a/script/get-tvm/customize.py b/script/get-tvm/customize.py index c4053d618..b97e4ca37 100644 --- a/script/get-tvm/customize.py +++ b/script/get-tvm/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -16,7 +17,7 @@ def postprocess(i): os_info = i['os_info'] env = i['env'] - if env.get('MLC_TVM_PIP_INSTALL', '') == "yes": + if is_true(env.get('MLC_TVM_PIP_INSTALL', '')): return {'return': 0} tvm_home = env['TVM_HOME'] diff --git a/script/get-xilinx-sdk/customize.py b/script/get-xilinx-sdk/customize.py index 07097d60a..239b5c9ce 100644 --- a/script/get-xilinx-sdk/customize.py +++ b/script/get-xilinx-sdk/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) file_path = env.get("MLC_XILINX_SDK_BIN_PATH") if not file_path or not os.path.exists(file_path): diff --git a/script/get-zendnn/customize.py b/script/get-zendnn/customize.py index 97fb859e6..c9944b813 100644 --- a/script/get-zendnn/customize.py +++ b/script/get-zendnn/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) env['ZENDNN_BLIS_PATH'] = env['MLC_BLIS_INSTALL_PATH'] env['ZENDNN_LIBM_PATH'] = env['MLC_AOCL_BUILD_PATH'] diff --git a/script/install-cuda-prebuilt/customize.py b/script/install-cuda-prebuilt/customize.py index efe076217..c5dcdf3d3 100644 --- a/script/install-cuda-prebuilt/customize.py +++ b/script/install-cuda-prebuilt/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -8,7 +9,7 @@ def preprocess(i): env = i['env'] - if str(env.get('CUDA_SKIP_SUDO', '')).lower() == 'true': + if is_true(env.get('CUDA_SKIP_SUDO', '')): env['MLC_SUDO'] = '' meta = i['meta'] @@ -37,7 +38,7 @@ def preprocess(i): env['MLC_CUDA_LINUX_FILENAME'] extra_options = env.get('CUDA_ADDITIONAL_INSTALL_OPTIONS', '') - if env.get('MLC_CUDA_INSTALL_DRIVER', '') == "yes": + if is_true(env.get('MLC_CUDA_INSTALL_DRIVER', '')): extra_options += " --driver" env['CUDA_ADDITIONAL_INSTALL_OPTIONS'] = extra_options diff --git a/script/install-ipex-from-src/customize.py b/script/install-ipex-from-src/customize.py index 73ded3321..cef0340b8 100644 --- a/script/install-ipex-from-src/customize.py +++ b/script/install-ipex-from-src/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -13,7 +14,7 @@ def preprocess(i): env['IPEX_DIR'] = env['MLC_IPEX_SRC_REPO_PATH'] - if env.get('MLC_USE_LLVM_FOR_IPEX', '') == 'yes': + if is_true(env.get('MLC_USE_LLVM_FOR_IPEX', '')): env['DNNL_GRAPH_BUILD_COMPILER_BACKEND'] = 1 env['USE_LLVM'] = env['MLC_LLVM_INSTALLED_PATH'] env['LLVM_DIR'] = os.path.join( diff --git a/script/install-llvm-src/customize.py b/script/install-llvm-src/customize.py index ea6b02c54..66ae5ea87 100644 --- a/script/install-llvm-src/customize.py +++ b/script/install-llvm-src/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -22,7 +23,7 @@ def preprocess(i): install_prefix = env['MLC_CONDA_PREFIX'] extra_cmake_options = f"-DCMAKE_SHARED_LINKER_FLAGS=-L{install_prefix} -Wl,-rpath,{install_prefix}" - if env.get('MLC_LLVM_16_INTEL_MLPERF_INFERENCE', '') == "yes": + if is_true(env.get('MLC_LLVM_16_INTEL_MLPERF_INFERENCE', '')): env['MLC_REQUIRE_INSTALL'] = 'yes' i['run_script_input']['script_name'] = "install-llvm-16-intel-mlperf-inference" clang_file_name = "llvm-link" diff --git a/script/install-mlperf-logging-from-src/customize.py b/script/install-mlperf-logging-from-src/customize.py index d6f5dab44..356852e7c 100644 --- a/script/install-mlperf-logging-from-src/customize.py +++ b/script/install-mlperf-logging-from-src/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) return {'return': 0} diff --git a/script/install-nccl-libs/customize.py b/script/install-nccl-libs/customize.py index d6f5dab44..6aaac5dd6 100644 --- a/script/install-nccl-libs/customize.py +++ b/script/install-nccl-libs/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) return {'return': 0} diff --git a/script/install-onednn-from-src/customize.py b/script/install-onednn-from-src/customize.py index 2bdf25c14..6df7f32da 100644 --- a/script/install-onednn-from-src/customize.py +++ b/script/install-onednn-from-src/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -16,7 +17,7 @@ def preprocess(i): env['MLC_RUN_CMD'] = run_cmd env['MLC_ONEDNN_INSTALLED_PATH'] = os.path.join(os.getcwd(), "onednn") - if env.get('MLC_FOR_INTEL_MLPERF_INFERENCE_BERT', '') == "yes": + if is_true(env.get('MLC_FOR_INTEL_MLPERF_INFERENCE_BERT', '')): i['run_script_input']['script_name'] = "run-intel-mlperf-inference-bert" automation = i['automation'] diff --git a/script/install-onnxruntime-from-src/customize.py b/script/install-onnxruntime-from-src/customize.py index 1ee0e39d9..f93ce1554 100644 --- a/script/install-onnxruntime-from-src/customize.py +++ b/script/install-onnxruntime-from-src/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -13,7 +14,7 @@ def preprocess(i): run_cmd = "./build.sh --config RelWithDebInfo --build_wheel --parallel --allow_running_as_root --skip_tests " - if env.get('MLC_ONNXRUNTIME_GPU', '') == "yes": + if is_true(env.get('MLC_ONNXRUNTIME_GPU', '')): cuda_home = env['CUDA_HOME'] run_cmd += f"--use_cuda --cuda_home {cuda_home} --cudnn_home {cuda_home}" diff --git a/script/install-python-venv/customize.py b/script/install-python-venv/customize.py index 7e3b85454..79dd031f0 100644 --- a/script/install-python-venv/customize.py +++ b/script/install-python-venv/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -10,7 +11,7 @@ def preprocess(i): meta = i['meta'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) automation = i['automation'] diff --git a/script/install-pytorch-from-src/customize.py b/script/install-pytorch-from-src/customize.py index acc104efd..30e8d9610 100644 --- a/script/install-pytorch-from-src/customize.py +++ b/script/install-pytorch-from-src/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -11,7 +12,7 @@ def preprocess(i): env = i['env'] - if env.get('MLC_MLPERF_INFERENCE_INTEL_LANGUAGE_MODEL', '') == "yes": + if is_true(env.get('MLC_MLPERF_INFERENCE_INTEL_LANGUAGE_MODEL', '')): i['run_script_input']['script_name'] = "run-intel-mlperf-inference-v3_1" run_cmd = "CC=clang CXX=clang++ USE_CUDA=OFF python -m pip install -e . " diff --git a/script/install-qaic-compute-sdk-from-src/customize.py b/script/install-qaic-compute-sdk-from-src/customize.py index 30371e4b1..f234017d6 100644 --- a/script/install-qaic-compute-sdk-from-src/customize.py +++ b/script/install-qaic-compute-sdk-from-src/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -23,7 +24,7 @@ def preprocess(i): env['+LD_LIBRARY_PATH'] = [] env['+LD_LIBRARY_PATH'].append(os.path.join(env['MLC_LLVM_INSTALLED_PATH'], "..", "lib")) ''' - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) return {'return': 0} diff --git a/script/plug-prebuilt-cudnn-to-cuda/customize.py b/script/plug-prebuilt-cudnn-to-cuda/customize.py index ec3598416..c37d15b17 100644 --- a/script/plug-prebuilt-cudnn-to-cuda/customize.py +++ b/script/plug-prebuilt-cudnn-to-cuda/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): env = i['env'] - if str(env.get('CUDA_SKIP_SUDO', '')).lower() == 'true': + if is_true(env.get('CUDA_SKIP_SUDO', '')): env['MLC_SUDO'] = '' meta = i['meta'] diff --git a/script/plug-prebuilt-cusparselt-to-cuda/customize.py b/script/plug-prebuilt-cusparselt-to-cuda/customize.py index f26246f09..ec679ac7d 100644 --- a/script/plug-prebuilt-cusparselt-to-cuda/customize.py +++ b/script/plug-prebuilt-cusparselt-to-cuda/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -12,7 +13,7 @@ def preprocess(i): env = i['env'] - if str(env.get('CUDA_SKIP_SUDO', '')).lower() == 'true': + if is_true(env.get('CUDA_SKIP_SUDO', '')): env['MLC_SUDO'] = '' meta = i['meta'] diff --git a/script/prepare-training-data-bert/customize.py b/script/prepare-training-data-bert/customize.py index 63bf5b110..7d4fbdce7 100644 --- a/script/prepare-training-data-bert/customize.py +++ b/script/prepare-training-data-bert/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) datadir = env.get('MLC_DATA_DIR', os.getcwd()) env['MLC_DATA_DIR'] = datadir diff --git a/script/prepare-training-data-resnet/customize.py b/script/prepare-training-data-resnet/customize.py index 3d7e16815..295827b74 100644 --- a/script/prepare-training-data-resnet/customize.py +++ b/script/prepare-training-data-resnet/customize.py @@ -1,5 +1,6 @@ from mlc import utils import os +from utils import is_true def preprocess(i): @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) datadir = env.get('MLC_DATA_DIR', os.getcwd()) env['MLC_DATA_DIR'] = datadir diff --git a/script/run-all-mlperf-models/customize.py b/script/run-all-mlperf-models/customize.py index 3ae4f54dd..9bfdc51f9 100644 --- a/script/run-all-mlperf-models/customize.py +++ b/script/run-all-mlperf-models/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import * import os @@ -13,7 +14,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) models = env['MODELS'].split(",") @@ -30,7 +31,7 @@ def preprocess(i): power = env.get('POWER', '') - if str(power).lower() in ["yes", "true"]: + if is_true(str(power)): POWER_STRING = " --power yes --adr.mlperf-power-client.power_server=" + \ env.get('POWER_SERVER', '192.168.0.15') + " --adr.mlperf-power-client.port=" + \ env.get('POWER_SERVER_PORT', '4950') + " " diff --git a/script/run-docker-container/customize.py b/script/run-docker-container/customize.py index 02ef20fd0..c636f4fa7 100644 --- a/script/run-docker-container/customize.py +++ b/script/run-docker-container/customize.py @@ -168,7 +168,7 @@ def postprocess(i): if env.get('MLC_DOCKER_ADD_DEVICE', '') != '': run_opts += " --device=" + env['MLC_DOCKER_ADD_DEVICE'] - if env.get('MLC_DOCKER_PRIVILEGED_MODE', '') == 'yes': + if is_true(env.get('MLC_DOCKER_PRIVILEGED_MODE', '')): run_opts += " --privileged " if env.get('MLC_DOCKER_ADD_NUM_GPUS', '') != '': @@ -310,7 +310,7 @@ def postprocess(i): x1 = '' x2 = '' run_cmd_prefix = "" - if env.get('MLC_DOCKER_INTERACTIVE_MODE', '') in ['yes', 'True', True]: + if is_true(env.get('MLC_DOCKER_INTERACTIVE_MODE', '')): run_cmd_prefix = "(" x1 = '-it' x2 = " && bash ) || bash" diff --git a/script/run-mlperf-automotive-app/customize.py b/script/run-mlperf-automotive-app/customize.py index 6f8398743..9309390a6 100644 --- a/script/run-mlperf-automotive-app/customize.py +++ b/script/run-mlperf-automotive-app/customize.py @@ -5,6 +5,7 @@ import subprocess import copy from tabulate import tabulate +from utils import * summary_ext = ['.csv', '.json', '.xlsx'] @@ -21,7 +22,7 @@ def preprocess(i): script_path = i['run_script_input']['path'] mlc = i['automation'].action_object - if env.get('MLC_RUN_DOCKER_CONTAINER', '') == "yes": + if is_true(env.get('MLC_RUN_DOCKER_CONTAINER', '')): return {'return': 0} dump_version_info = env.get('MLC_DUMP_VERSION_INFO', True) @@ -65,8 +66,8 @@ def preprocess(i): if 'MLC_RERUN' not in env: env['MLC_RERUN'] = "yes" - if str(env.get('MLC_SYSTEM_POWER', 'no')).lower( - ) != "no" or env.get('MLC_MLPERF_POWER', '') == "yes": + if not is_false(env.get('MLC_SYSTEM_POWER', 'no')) or is_true( + env.get('MLC_MLPERF_POWER', '')): power_variation = ",_power" env['MLC_MLPERF_POWER'] = "yes" else: @@ -92,7 +93,7 @@ def preprocess(i): if 'MLC_MLPERF_LOADGEN_SCENARIO' not in env: env['MLC_MLPERF_LOADGEN_SCENARIO'] = "Offline" - if env.get('MLC_MLPERF_LOADGEN_ALL_SCENARIOS', '') == "yes": + if is_true(env.get('MLC_MLPERF_LOADGEN_ALL_SCENARIOS', '')): env['MLC_MLPERF_LOADGEN_SCENARIOS'] = get_valid_scenarios( env['MLC_MODEL'], system_meta['system_type'], @@ -103,7 +104,7 @@ def preprocess(i): env['MLC_MLPERF_LOADGEN_SCENARIOS'] = [ env['MLC_MLPERF_LOADGEN_SCENARIO']] - if env.get('MLC_MLPERF_LOADGEN_ALL_MODES', '') == "yes": + if is_true(env.get('MLC_MLPERF_LOADGEN_ALL_MODES', '')): env['MLC_MLPERF_LOADGEN_MODES'] = ["performance", "accuracy"] else: env['MLC_MLPERF_LOADGEN_MODES'] = [env['MLC_MLPERF_LOADGEN_MODE']] @@ -197,8 +198,7 @@ def preprocess(i): print('=========================================================') - if str(env.get('MLC_MLPERF_USE_DOCKER', '') - ).lower() in ["1", "true", "yes"]: + if is_true(str(env.get('MLC_MLPERF_USE_DOCKER', ''))): action = "docker" del (env['OUTPUT_BASE_DIR']) state = {} @@ -264,7 +264,7 @@ def preprocess(i): if state.get('docker', {}): del (state['docker']) - if env.get("MLC_MLPERF_LOADGEN_COMPLIANCE", "") == "yes": + if is_true(env.get("MLC_MLPERF_LOADGEN_COMPLIANCE", "")): for test in test_list: env_copy = copy.deepcopy(env) for key in env_copy: diff --git a/script/run-mlperf-inference-app/customize.py b/script/run-mlperf-inference-app/customize.py index 530237ab4..2e9c279d2 100644 --- a/script/run-mlperf-inference-app/customize.py +++ b/script/run-mlperf-inference-app/customize.py @@ -22,7 +22,7 @@ def preprocess(i): state = i['state'] script_path = i['run_script_input']['path'] - if env.get('MLC_RUN_DOCKER_CONTAINER', '') == "yes": + if is_true(env.get('MLC_RUN_DOCKER_CONTAINER', '')): return {'return': 0} if env.get('MLC_DOCKER_IMAGE_NAME', '') == 'scc24': @@ -74,8 +74,8 @@ def preprocess(i): if 'MLC_RERUN' not in env: env['MLC_RERUN'] = "yes" - if str(env.get('MLC_SYSTEM_POWER', 'no')).lower( - ) != "no" or env.get('MLC_MLPERF_POWER', '') == "yes": + if not is_false(env.get('MLC_SYSTEM_POWER', 'no')) or is_true( + env.get('MLC_MLPERF_POWER', '')): power_variation = ",_power" env['MLC_MLPERF_POWER'] = "yes" else: @@ -99,7 +99,7 @@ def preprocess(i): if 'MLC_MLPERF_LOADGEN_SCENARIO' not in env: env['MLC_MLPERF_LOADGEN_SCENARIO'] = "Offline" - if env.get('MLC_MLPERF_LOADGEN_ALL_SCENARIOS', '') == "yes": + if is_true(env.get('MLC_MLPERF_LOADGEN_ALL_SCENARIOS', '')): env['MLC_MLPERF_LOADGEN_SCENARIOS'] = get_valid_scenarios( env['MLC_MODEL'], system_meta.get( @@ -112,7 +112,7 @@ def preprocess(i): env['MLC_MLPERF_LOADGEN_SCENARIOS'] = [ env['MLC_MLPERF_LOADGEN_SCENARIO']] - if env.get('MLC_MLPERF_LOADGEN_ALL_MODES', '') == "yes": + if is_true(env.get('MLC_MLPERF_LOADGEN_ALL_MODES', '')): env['MLC_MLPERF_LOADGEN_MODES'] = ["performance", "accuracy"] else: env['MLC_MLPERF_LOADGEN_MODES'] = [env['MLC_MLPERF_LOADGEN_MODE']] diff --git a/script/run-mlperf-inference-mobilenet-models/customize.py b/script/run-mlperf-inference-mobilenet-models/customize.py index a7e3d5ee0..ee9ba88d8 100644 --- a/script/run-mlperf-inference-mobilenet-models/customize.py +++ b/script/run-mlperf-inference-mobilenet-models/customize.py @@ -23,8 +23,8 @@ def preprocess(i): # cache_action = i['automation'].cache_action cache_action = mlc - quiet = (env.get('MLC_QUIET', False) == 'yes') - verbose = (env.get('MLC_VERBOSE', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) + verbose = is_true(env.get('MLC_VERBOSE', False)) models_all = { "mobilenet": { diff --git a/script/run-mlperf-inference-submission-checker/customize.py b/script/run-mlperf-inference-submission-checker/customize.py index 0ecc0217f..6dcd5e1cf 100644 --- a/script/run-mlperf-inference-submission-checker/customize.py +++ b/script/run-mlperf-inference-submission-checker/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os import subprocess @@ -30,7 +31,7 @@ def preprocess(i): submission_checker_file = os.path.join(env['MLC_MLPERF_INFERENCE_SOURCE'], "tools", "submission", "submission_checker.py") - if env['MLC_MLPERF_SHORT_RUN'] == "yes": + if is_true(env['MLC_MLPERF_SHORT_RUN']): import shutil new_submission_checker_file = os.path.join( os.path.dirname(submission_checker_file), @@ -51,7 +52,7 @@ def preprocess(i): else: extra_map = "" - if env.get('MLC_MLPERF_SKIP_POWER_CHECK', 'no') == "yes": + if is_true(env.get('MLC_MLPERF_SKIP_POWER_CHECK', 'no')): power_check = " --skip-power-check" else: power_check = "" diff --git a/script/run-vllm-server/customize.py b/script/run-vllm-server/customize.py index 6946dd7ac..68eceb84d 100644 --- a/script/run-vllm-server/customize.py +++ b/script/run-vllm-server/customize.py @@ -1,431 +1,96 @@ from mlc import utils +from utils import is_true import os import subprocess def preprocess(i): - os_info = i['os_info'] - env = i['env'] - meta = i['meta'] - automation = i['automation'] - cmd_args = "" - - model_name = env.get("MLC_VLLM_SERVER_MODEL_NAME", False) + # Required parameter check + model_name = env.get("MLC_VLLM_SERVER_MODEL_NAME") if not model_name: return {'return': 1, 'error': 'Model name not specified'} - else: - cmd_args += f" --model {env['MLC_ML_MODEL_PATH']} --served-model-name {model_name}" - - tp_size = env.get("MLC_VLLM_SERVER_TP_SIZE", False) - if tp_size: - cmd_args += f" --tensor-parallel-size {tp_size}" - - pp_size = env.get("MLC_VLLM_SERVER_PP_SIZE", False) - if pp_size: - cmd_args += f" --pipeline-parallel-size {pp_size}" - - api_key = env.get("MLC_VLLM_SERVER_API_KEY", "root") - if pp_size: - cmd_args += f" --api-key {api_key}" - - distributed_executor_backend = env.get( - "MLC_VLLM_SERVER_DIST_EXEC_BACKEND", False) - if distributed_executor_backend: - cmd_args += f" --distributed-executor-backend {distributed_executor_backend}" - - host = env.get("MLC_VLLM_SERVER_HOST", False) - if host: - cmd_args += f" --host {host}" - - port = env.get("MLC_VLLM_SERVER_PORT", False) - if port: - cmd_args += f" --port {port}" - - uvicorn_log_level = env.get("MLC_VLLM_SERVER_UVICORN_LOG_LEVEL", False) - if uvicorn_log_level: - cmd_args += f" --uvicorn-log-level {uvicorn_log_level}" - - allow_credentials = env.get("MLC_VLLM_SERVER_ALLOW_CREDENTIALS", False) - if allow_credentials: - cmd_args += f" --allow-credentials" - - allowed_origins = env.get("MLC_VLLM_SERVER_ALLOWED_ORIGINS", False) - if allowed_origins: - cmd_args += f" --allowed-origins {allowed_origins}" - - allowed_methods = env.get("MLC_VLLM_SERVER_ALLOWED_METHODS", False) - if allowed_methods: - cmd_args += f" --allowed-methods {allowed_methods}" - - allowed_headers = env.get("MLC_VLLM_SERVER_ALLOWED_HEADERS", False) - if allowed_headers: - cmd_args += f" --allowed-headers {allowed_headers}" - - lora_modules = env.get("MLC_VLLM_SERVER_LORA_MODULES", False) - if lora_modules: - cmd_args += f" --lora-modules {lora_modules}" - - prompt_adapters = env.get("MLC_VLLM_SERVER_PROMPT_ADAPTERS", False) - if prompt_adapters: - cmd_args += f" --prompt-adapters {prompt_adapters}" - - chat_template = env.get("MLC_VLLM_SERVER_CHAT_TEMPLATE", False) - if chat_template: - cmd_args += f" --chat-template {chat_template}" - - response_role = env.get("MLC_VLLM_SERVER_RESPONSE_ROLE", False) - if response_role: - cmd_args += f" --response-role {response_role}" - - ssl_keyfile = env.get("MLC_VLLM_SERVER_SSL_KEYFILE", False) - if ssl_keyfile: - cmd_args += f" --ssl-keyfile {ssl_keyfile}" - - ssl_certfile = env.get("MLC_VLLM_SERVER_SSL_CERTFILE", False) - if ssl_certfile: - cmd_args += f" --ssl-certfile {ssl_certfile}" - - ssl_ca_certs = env.get("MLC_VLLM_SERVER_SSL_CA_CERTS", False) - if ssl_ca_certs: - cmd_args += f" --ssl-ca-certs {ssl_ca_certs}" - - ssl_cert_reqs = env.get("MLC_VLLM_SERVER_SSL_CERT_REQS", False) - if ssl_cert_reqs: - cmd_args += f" --ssl-cert-reqs {ssl_cert_reqs}" - - root_path = env.get("MLC_VLLM_SERVER_ROOT_PATH", False) - if root_path: - cmd_args += f" --root-path {root_path}" - - middleware = env.get("MLC_VLLM_SERVER_MIDDLEWARE", False) - if middleware: - cmd_args += f" --middleware {middleware}" - - tokenizer = env.get("MLC_VLLM_SERVER_TOKENIZER", False) - if tokenizer: - cmd_args += f" --tokenizer {tokenizer}" - - skip_tokenizer_init = env.get("MLC_VLLM_SERVER_SKIP_TOKENIZER_INIT", False) - if skip_tokenizer_init: - cmd_args += f" --skip-tokenizer-init" - - revision = env.get("MLC_VLLM_SERVER_REVISION", False) - if revision: - cmd_args += f" --revision {revision}" - - code_revision = env.get("MLC_VLLM_SERVER_CODE_REVISION", False) - if code_revision: - cmd_args += f" --code-revision {code_revision}" - - tokenizer_revision = env.get("MLC_VLLM_SERVER_TOKENIZER_REVISION", False) - if tokenizer_revision: - cmd_args += f" --tokenizer-revision {tokenizer_revision}" - - tokenizer_mode = env.get("MLC_VLLM_SERVER_TOKENIZER_MODE", False) - if tokenizer_mode: - cmd_args += f" --tokenizer-mode {tokenizer_mode}" - - trust_remote_code = env.get("MLC_VLLM_SERVER_TRUST_REMOTE_CODE", False) - if trust_remote_code: - cmd_args += f" --trust-remote-code" - - download_dir = env.get("MLC_VLLM_SERVER_DOWNLOAD_DIR", False) - if download_dir: - cmd_args += f" --download-dir {download_dir}" - - load_format = env.get("MLC_VLLM_SERVER_LOAD_FORMAT", False) - if load_format: - cmd_args += f" --load-format {load_format}" - - dtype = env.get("MLC_VLLM_SERVER_DTYPE", False) - if dtype: - cmd_args += f" --dtype {dtype}" - - kv_cache_dtype = env.get("MLC_VLLM_SERVER_KV_CACHE_DTYPE", False) - if kv_cache_dtype: - cmd_args += f" --kv-cache-dtype {kv_cache_dtype}" - - quantization_param_path = env.get( - "MLC_VLLM_SERVER_QUANTIZATION_PARAM_PATH", False) - if quantization_param_path: - cmd_args += f" --quantization-param-path {quantization_param_path}" - - max_model_len = env.get("MLC_VLLM_SERVER_MAX_MODEL_LEN", False) - if max_model_len: - cmd_args += f" --max-model-len {max_model_len}" - - guided_decoding_backend = env.get( - "MLC_VLLM_SERVER_GUIDED_DECODING_BACKEND", False) - if guided_decoding_backend: - cmd_args += f" --guided-decoding-backend {guided_decoding_backend}" - - worker_use_ray = env.get("MLC_VLLM_SERVER_WORKER_USE_RAY", False) - if worker_use_ray: - cmd_args += f" --worker-use-ray" - - max_parallel_loading_workers = env.get( - "MLC_VLLM_SERVER_MAX_PARALLEL_LOADING_WORKERS", False) - if max_parallel_loading_workers: - cmd_args += f" --max-parallel-loading-workers {max_parallel_loading_workers}" - - ray_workers_use_nsight = env.get( - "MLC_VLLM_SERVER_RAY_WORKERS_USE_NSIGHT", False) - if ray_workers_use_nsight: - cmd_args += f" --ray-workers-use-nsight" - - block_size = env.get("MLC_VLLM_SERVER_BLOCK_SIZE", False) - if block_size: - cmd_args += f" --block-size {block_size}" - - enable_prefix_caching = env.get( - "MLC_VLLM_SERVER_ENABLE_PREFIX_CACHING", False) - if enable_prefix_caching: - cmd_args += f" --enable-prefix-caching" - - disable_sliding_window = env.get( - "MLC_VLLM_SERVER_DISABLE_SLIDING_WINDOW", False) - if disable_sliding_window: - cmd_args += f" --disable-sliding-window" - - use_v2_block_manager = env.get( - "MLC_VLLM_SERVER_USE_V2_BLOCK_MANAGER", False) - if use_v2_block_manager: - cmd_args += f" --use-v2-block-manager" - - num_lookahead_slots = env.get("MLC_VLLM_SERVER_NUM_LOOKAHEAD_SLOTS", False) - if num_lookahead_slots: - cmd_args += f" --num-lookahead-slots {num_lookahead_slots}" - - seed = env.get("MLC_VLLM_SERVER_SEED", False) - if seed: - cmd_args += f" --seed {seed}" - - swap_space = env.get("MLC_VLLM_SERVER_SWAP_SPACE", False) - if swap_space: - cmd_args += f" --swap-space {swap_space}" - - gpu_memory_utilization = env.get( - "MLC_VLLM_SERVER_GPU_MEMORY_UTILIZATION", False) - if gpu_memory_utilization: - cmd_args += f" --gpu-memory-utilization {gpu_memory_utilization}" - - num_gpu_blocks_override = env.get( - "MLC_VLLM_SERVER_NUM_GPU_BLOCKS_OVERRIDE", False) - if num_gpu_blocks_override: - cmd_args += f" --num-gpu-blocks-override {num_gpu_blocks_override}" - - max_num_batched_tokens = env.get( - "MLC_VLLM_SERVER_MAX_NUM_BATCHED_TOKENS", False) - if max_num_batched_tokens: - cmd_args += f" --max-num-batched-tokens {max_num_batched_tokens}" - - max_num_seqs = env.get("MLC_VLLM_SERVER_MAX_NUM_SEQS", False) - if max_num_seqs: - cmd_args += f" --max-num-seqs {max_num_seqs}" - - max_logprobs = env.get("MLC_VLLM_SERVER_MAX_LOGPROBS", False) - if max_logprobs: - cmd_args += f" --max-logprobs {max_logprobs}" - - disable_log_stats = env.get("MLC_VLLM_SERVER_DISABLE_LOG_STATS", False) - if disable_log_stats: - cmd_args += f" --disable-log-stats" - - quantization = env.get("MLC_VLLM_SERVER_QUANTIZATION", False) - if quantization: - cmd_args += f" --quantization {quantization}" - - rope_scaling = env.get("MLC_VLLM_SERVER_ROPE_SCALING", False) - if rope_scaling: - cmd_args += f" --rope-scaling {rope_scaling}" - - rope_theta = env.get("MLC_VLLM_SERVER_ROPE_THETA", False) - if rope_theta: - cmd_args += f" --rope-theta {rope_theta}" - - enforce_eager = env.get("MLC_VLLM_SERVER_ENFORCE_EAGER", False) - if enforce_eager: - cmd_args += f" --enforce-eager" - - max_context_len_to_capture = env.get( - "MLC_VLLM_SERVER_MAX_CONTEXT_LEN_TO_CAPTURE", False) - if max_context_len_to_capture: - cmd_args += f" --max-context-len-to-capture {max_context_len_to_capture}" - - max_seq_len_to_capture = env.get( - "MLC_VLLM_SERVER_MAX_SEQ_LEN_TO_CAPTURE", False) - if max_seq_len_to_capture: - cmd_args += f" --max-seq-len-to-capture {max_seq_len_to_capture}" - - disable_custom_all_reduce = env.get( - "MLC_VLLM_SERVER_DISABLE_CUSTOM_ALL_REDUCE", False) - if disable_custom_all_reduce: - cmd_args += f" --disable-custom-all-reduce" - - tokenizer_pool_size = env.get("MLC_VLLM_SERVER_TOKENIZER_POOL_SIZE", False) - if tokenizer_pool_size: - cmd_args += f" --tokenizer-pool-size {tokenizer_pool_size}" - - tokenizer_pool_type = env.get("MLC_VLLM_SERVER_TOKENIZER_POOL_TYPE", False) - if tokenizer_pool_type: - cmd_args += f" --tokenizer-pool-type {tokenizer_pool_type}" - - tokenizer_pool_extra_config = env.get( - "MLC_VLLM_SERVER_TOKENIZER_POOL_EXTRA_CONFIG", False) - if tokenizer_pool_extra_config: - cmd_args += f" --tokenizer-pool-extra-config {tokenizer_pool_extra_config}" - - enable_lora = env.get("MLC_VLLM_SERVER_ENABLE_LORA", False) - if enable_lora: - cmd_args += f" --enable-lora" - - max_loras = env.get("MLC_VLLM_SERVER_MAX_LORAS", False) - if max_loras: - cmd_args += f" --max-loras {max_loras}" - - max_lora_rank = env.get("MLC_VLLM_SERVER_MAX_LORA_RANK", False) - if max_lora_rank: - cmd_args += f" --max-lora-rank {max_lora_rank}" - - lora_extra_vocab_size = env.get( - "MLC_VLLM_SERVER_LORA_EXTRA_VOCAB_SIZE", False) - if lora_extra_vocab_size: - cmd_args += f" --lora-extra-vocab-size {lora_extra_vocab_size}" - - lora_dtype = env.get("MLC_VLLM_SERVER_LORA_DTYPE", False) - if lora_dtype: - cmd_args += f" --lora-dtype {lora_dtype}" - - long_lora_scaling_factors = env.get( - "MLC_VLLM_SERVER_LONG_LORA_SCALING_FACTORS", False) - if long_lora_scaling_factors: - cmd_args += f" --long-lora-scaling-factors {long_lora_scaling_factors}" - - max_cpu_loras = env.get("MLC_VLLM_SERVER_MAX_CPU_LORAS", False) - if max_cpu_loras: - cmd_args += f" --max-cpu-loras {max_cpu_loras}" - - fully_sharded_loras = env.get("MLC_VLLM_SERVER_FULLY_SHARDED_LORAS", False) - if fully_sharded_loras: - cmd_args += f" --fully-sharded-loras" - - enable_prompt_adapter = env.get( - "MLC_VLLM_SERVER_ENABLE_PROMPT_ADAPTER", False) - if enable_prompt_adapter: - cmd_args += f" --enable-prompt-adapter" - - max_prompt_adapters = env.get("MLC_VLLM_SERVER_MAX_PROMPT_ADAPTERS", False) - if max_prompt_adapters: - cmd_args += f" --max-prompt-adapters {max_prompt_adapters}" - - max_prompt_adapter_token = env.get( - "MLC_VLLM_SERVER_MAX_PROMPT_ADAPTER_TOKEN", False) - if max_prompt_adapter_token: - cmd_args += f" --max-prompt-adapter-token {max_prompt_adapter_token}" - - device = env.get("MLC_VLLM_SERVER_DEVICE", False) - if device: - cmd_args += f" --device {device}" - - scheduler_delay_factor = env.get( - "MLC_VLLM_SERVER_SCHEDULER_DELAY_FACTOR", False) - if scheduler_delay_factor: - cmd_args += f" --scheduler-delay-factor {scheduler_delay_factor}" - - enable_chunked_prefill = env.get( - "MLC_VLLM_SERVER_ENABLE_CHUNKED_PREFILL", False) - if enable_chunked_prefill: - cmd_args += f" --enable-chunked-prefill" - - speculative_model = env.get("MLC_VLLM_SERVER_SPECULATIVE_MODEL", False) - if speculative_model: - cmd_args += f" --speculative-model {speculative_model}" - - num_speculative_tokens = env.get( - "MLC_VLLM_SERVER_NUM_SPECULATIVE_TOKENS", False) - if num_speculative_tokens: - cmd_args += f" --num-speculative-tokens {num_speculative_tokens}" - - speculative_draft_tensor_parallel_size = env.get( - "MLC_VLLM_SERVER_SPECULATIVE_DRAFT_TENSOR_PARALLEL_SIZE", False) - if speculative_draft_tensor_parallel_size: - cmd_args += f" --speculative-draft-tensor-parallel-size {speculative_draft_tensor_parallel_size}" - - speculative_max_model_len = env.get( - "MLC_VLLM_SERVER_SPECULATIVE_MAX_MODEL_LEN", False) - if speculative_max_model_len: - cmd_args += f" --speculative-max-model-len {speculative_max_model_len}" - - speculative_disable_by_batch_size = env.get( - "MLC_VLLM_SERVER_SPECULATIVE_DISABLE_BY_BATCH_SIZE", False) - if speculative_disable_by_batch_size: - cmd_args += f" --speculative-disable-by-batch-size {speculative_disable_by_batch_size}" - - ngram_prompt_lookup_max = env.get( - "MLC_VLLM_SERVER_NGRAM_PROMPT_LOOKUP_MAX", False) - if ngram_prompt_lookup_max: - cmd_args += f" --ngram-prompt-lookup-max {ngram_prompt_lookup_max}" - - ngram_prompt_lookup_min = env.get( - "MLC_VLLM_SERVER_NGRAM_PROMPT_LOOKUP_MIN", False) - if ngram_prompt_lookup_min: - cmd_args += f" --ngram-prompt-lookup-min {ngram_prompt_lookup_min}" - - spec_decoding_acceptance_method = env.get( - "MLC_VLLM_SERVER_SPEC_DECODING_ACCEPTANCE_METHOD", False) - if spec_decoding_acceptance_method: - cmd_args += f" --spec-decoding-acceptance-method {spec_decoding_acceptance_method}" - - typical_acceptance_sampler_posterior_threshold = env.get( - "MLC_VLLM_SERVER_TYPICAL_ACCEPTANCE_SAMPLER_POSTERIOR_THRESHOLD", False) - if typical_acceptance_sampler_posterior_threshold: - cmd_args += f" --typical-acceptance-sampler-posterior-threshold {typical_acceptance_sampler_posterior_threshold}" - - typical_acceptance_sampler_posterior_alpha = env.get( - "MLC_VLLM_SERVER_TYPICAL_ACCEPTANCE_SAMPLER_POSTERIOR_ALPHA", False) - if typical_acceptance_sampler_posterior_alpha: - cmd_args += f" --typical-acceptance-sampler-posterior-alpha {typical_acceptance_sampler_posterior_alpha}" - - model_loader_extra_config = env.get( - "MLC_VLLM_SERVER_MODEL_LOADER_EXTRA_CONFIG", False) - if model_loader_extra_config: - cmd_args += f" --model-loader-extra-config {model_loader_extra_config}" - - preemption_mode = env.get("MLC_VLLM_SERVER_PREEMPTION_MODE", False) - if preemption_mode: - cmd_args += f" --preemption-mode {preemption_mode}" - - served_model_name = env.get("MLC_VLLM_SERVER_SERVED_MODEL_NAME", False) - if served_model_name: - cmd_args += f" --served-model-name {served_model_name}" - - qlora_adapter_name_or_path = env.get( - "MLC_VLLM_SERVER_QLORA_ADAPTER_NAME_OR_PATH", False) - if qlora_adapter_name_or_path: - cmd_args += f" --qlora-adapter-name-or-path {qlora_adapter_name_or_path}" - - otlp_traces_endpoint = env.get( - "MLC_VLLM_SERVER_OTLP_TRACES_ENDPOINT", False) - if otlp_traces_endpoint: - cmd_args += f" --otlp-traces-endpoint {otlp_traces_endpoint}" - - engine_use_ray = env.get("MLC_VLLM_SERVER_ENGINE_USE_RAY", False) - if engine_use_ray: - cmd_args += f" --engine-use-ray" - - disable_log_requests = env.get( - "MLC_VLLM_SERVER_DISABLE_LOG_REQUESTS", False) - if disable_log_requests: - cmd_args += f" --disable-log-requests" - max_log_len = env.get("MLC_VLLM_SERVER_MAX_LOG_LEN", False) - if max_log_len: - cmd_args += f" --max-log-len {max_log_len}" + # Base command with required model argument + cmd_args = f" --model {env['MLC_ML_MODEL_PATH']} --served-model-name {model_name}" + + # Dictionary mapping environment variables to their corresponding command + # line arguments + param_mapping = { + "MLC_VLLM_SERVER_TP_SIZE": "--tensor-parallel-size", + "MLC_VLLM_SERVER_PP_SIZE": "--pipeline-parallel-size", + "MLC_VLLM_SERVER_API_KEY": "--api-key", + "MLC_VLLM_SERVER_DIST_EXEC_BACKEND": "--distributed-executor-backend", + "MLC_VLLM_SERVER_HOST": "--host", + "MLC_VLLM_SERVER_PORT": "--port", + "MLC_VLLM_SERVER_UVICORN_LOG_LEVEL": "--uvicorn-log-level", + "MLC_VLLM_SERVER_ALLOWED_ORIGINS": "--allowed-origins", + "MLC_VLLM_SERVER_ALLOWED_METHODS": "--allowed-methods", + "MLC_VLLM_SERVER_ALLOWED_HEADERS": "--allowed-headers", + "MLC_VLLM_SERVER_LORA_MODULES": "--lora-modules", + "MLC_VLLM_SERVER_PROMPT_ADAPTERS": "--prompt-adapters", + "MLC_VLLM_SERVER_CHAT_TEMPLATE": "--chat-template", + "MLC_VLLM_SERVER_RESPONSE_ROLE": "--response-role", + "MLC_VLLM_SERVER_SSL_KEYFILE": "--ssl-keyfile", + "MLC_VLLM_SERVER_SSL_CERTFILE": "--ssl-certfile", + "MLC_VLLM_SERVER_SSL_CA_CERTS": "--ssl-ca-certs", + "MLC_VLLM_SERVER_SSL_CERT_REQS": "--ssl-cert-reqs", + "MLC_VLLM_SERVER_ROOT_PATH": "--root-path", + "MLC_VLLM_SERVER_MIDDLEWARE": "--middleware", + "MLC_VLLM_SERVER_TOKENIZER": "--tokenizer", + "MLC_VLLM_SERVER_REVISION": "--revision", + "MLC_VLLM_SERVER_CODE_REVISION": "--code-revision", + "MLC_VLLM_SERVER_TOKENIZER_REVISION": "--tokenizer-revision", + "MLC_VLLM_SERVER_TOKENIZER_MODE": "--tokenizer-mode", + "MLC_VLLM_SERVER_DOWNLOAD_DIR": "--download-dir", + "MLC_VLLM_SERVER_LOAD_FORMAT": "--load-format", + "MLC_VLLM_SERVER_DTYPE": "--dtype", + "MLC_VLLM_SERVER_KV_CACHE_DTYPE": "--kv-cache-dtype", + "MLC_VLLM_SERVER_QUANTIZATION_PARAM_PATH": "--quantization-param-path", + "MLC_VLLM_SERVER_MAX_MODEL_LEN": "--max-model-len", + "MLC_VLLM_SERVER_GUIDED_DECODING_BACKEND": "--guided-decoding-backend", + "MLC_VLLM_SERVER_MAX_PARALLEL_LOADING_WORKERS": "--max-parallel-loading-workers", + "MLC_VLLM_SERVER_BLOCK_SIZE": "--block-size", + "MLC_VLLM_SERVER_NUM_LOOKAHEAD_SLOTS": "--num-lookahead-slots", + "MLC_VLLM_SERVER_SEED": "--seed", + "MLC_VLLM_SERVER_SWAP_SPACE": "--swap-space", + "MLC_VLLM_SERVER_GPU_MEMORY_UTILIZATION": "--gpu-memory-utilization", + "MLC_VLLM_SERVER_NUM_GPU_BLOCKS_OVERRIDE": "--num-gpu-blocks-override", + "MLC_VLLM_SERVER_MAX_NUM_BATCHED_TOKENS": "--max-num-batched-tokens", + "MLC_VLLM_SERVER_MAX_NUM_SEQS": "--max-num-seqs", + "MLC_VLLM_SERVER_MAX_LOGPROBS": "--max-logprobs", + "MLC_VLLM_SERVER_QUANTIZATION": "--quantization", + "MLC_VLLM_SERVER_ROPE_SCALING": "--rope-scaling", + "MLC_VLLM_SERVER_ROPE_THETA": "--rope-theta" + } + + # Boolean flags that don't need values + bool_flags = { + "MLC_VLLM_SERVER_ALLOW_CREDENTIALS": "--allow-credentials", + "MLC_VLLM_SERVER_SKIP_TOKENIZER_INIT": "--skip-tokenizer-init", + "MLC_VLLM_SERVER_TRUST_REMOTE_CODE": "--trust-remote-code", + "MLC_VLLM_SERVER_WORKER_USE_RAY": "--worker-use-ray", + "MLC_VLLM_SERVER_RAY_WORKERS_USE_NSIGHT": "--ray-workers-use-nsight", + "MLC_VLLM_SERVER_ENABLE_PREFIX_CACHING": "--enable-prefix-caching", + "MLC_VLLM_SERVER_DISABLE_SLIDING_WINDOW": "--disable-sliding-window", + "MLC_VLLM_SERVER_USE_V2_BLOCK_MANAGER": "--use-v2-block-manager", + "MLC_VLLM_SERVER_DISABLE_LOG_STATS": "--disable-log-stats" + } + + # Add parameters with values + for env_var, arg_name in param_mapping.items(): + value = env.get(env_var) + if value: + cmd_args += f" {arg_name} {value}" + + # Add boolean flags + for env_var, arg_name in bool_flags.items(): + if is_true(env.get(env_var)): + cmd_args += f" {arg_name}" cmd = f"{env['MLC_PYTHON_BIN_WITH_PATH']} -m vllm.entrypoints.openai.api_server {cmd_args}" print(cmd) diff --git a/script/save-mlperf-inference-implementation-state/customize.py b/script/save-mlperf-inference-implementation-state/customize.py index 79b9023c4..ef5a6ae05 100644 --- a/script/save-mlperf-inference-implementation-state/customize.py +++ b/script/save-mlperf-inference-implementation-state/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -13,13 +14,13 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) if not state.get( 'mlperf-inference-implementation'): # No state information. Just returning return {'return': 0} - if env.get('MLC_MLPERF_README', "") == "yes": + if is_true(env.get('MLC_MLPERF_README', "")): import mlc inp = i['input'] diff --git a/script/set-device-settings-qaic/customize.py b/script/set-device-settings-qaic/customize.py index 427dab6df..372a0b142 100644 --- a/script/set-device-settings-qaic/customize.py +++ b/script/set-device-settings-qaic/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,9 +13,9 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) - if env.get('MLC_QAIC_ECC', '') == 'yes': + if is_true(env.get('MLC_QAIC_ECC', '')): import json for device in env['MLC_QAIC_DEVICES'].split(","): ecc_template = {} diff --git a/script/set-performance-mode/customize.py b/script/set-performance-mode/customize.py index 032f29b05..19378c7c8 100644 --- a/script/set-performance-mode/customize.py +++ b/script/set-performance-mode/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -13,7 +14,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) return {'return': 0} diff --git a/script/set-user-limits/customize.py b/script/set-user-limits/customize.py index 8574257b9..3e2f4733c 100644 --- a/script/set-user-limits/customize.py +++ b/script/set-user-limits/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) cmds = [] diff --git a/script/set-venv/customize.py b/script/set-venv/customize.py index c9f5e129c..f1e0f726b 100644 --- a/script/set-venv/customize.py +++ b/script/set-venv/customize.py @@ -1,4 +1,5 @@ from mlc import utils +from utils import is_true import os @@ -12,7 +13,7 @@ def preprocess(i): automation = i['automation'] - quiet = (env.get('MLC_QUIET', False) == 'yes') + quiet = is_true(env.get('MLC_QUIET', False)) ############################################################ cur_dir = os.getcwd()