From 4d2ac5cd684f6012b2fb2cf0c6442716830eda81 Mon Sep 17 00:00:00 2001 From: Arjun Date: Thu, 27 Mar 2025 15:42:00 +0530 Subject: [PATCH 1/4] Fix a bug in script module not updating state in postprocess, modularized parsing of memory info --- automation/script/module.py | 1 + .../customize.py | 27 ++++++++++++------- .../detect_memory.sh | 3 +-- .../meta.yaml | 8 +++++- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/automation/script/module.py b/automation/script/module.py index db32015b4..1325f5197 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -1860,6 +1860,7 @@ def _run(self, i): run_script_input['meta'] = meta run_script_input['env'] = env + run_script_input['state'] = state run_script_input['run_state'] = run_state run_script_input['recursion'] = recursion diff --git a/script/get-mlperf-inference-sut-description/customize.py b/script/get-mlperf-inference-sut-description/customize.py index 93746764e..cdc66473f 100644 --- a/script/get-mlperf-inference-sut-description/customize.py +++ b/script/get-mlperf-inference-sut-description/customize.py @@ -2,7 +2,7 @@ import os import json import shutil - +from utils import * def preprocess(i): env = i['env'] @@ -41,6 +41,8 @@ def preprocess(i): sut_desc_path = env['MLC_MLPERF_INFERENCE_SUT_DESC_PATH'] 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": print(f"Reusing SUT description file {sut}") state['MLC_SUT_META'] = json.load(open(sut_path)) @@ -168,18 +170,11 @@ def preprocess(i): if env.get('MLC_SUDO_USER', '') == "yes" and env.get( 'MLC_HOST_OS_TYPE', 'linux'): + env['MLC_MEMINFO_FILE'] = os.path.join(os.getcwd(), 'meminfo.dump') r = i['automation'].run_native_script( {'run_script_input': i['run_script_input'], 'env': env, 'script_name': 'detect_memory'}) if r['return'] > 0: return r - if env.get('MLC_HOST_MEM_INFO', '') != '': - state['MLC_SUT_META']['host_memory_configuration'] = env['MLC_HOST_MEM_INFO'] - - state['MLC_SUT_META'] = dict(sorted(state['MLC_SUT_META'].items())) - - sut_file = open(sut_path, "w") - json.dump(state['MLC_SUT_META'], sut_file, indent=4) - sut_file.close() return {'return': 0} @@ -187,5 +182,19 @@ def preprocess(i): def postprocess(i): env = i['env'] + state = i['state'] + + if env.get('MLC_MEMINFO_OUTFILE', '') != '' and os.path.exists(env['MLC_MEMINFO_OUTFILE']): + with open(env['MLC_MEMINFO_OUTFILE'], "r") as f: + data = f.read() + state['MLC_SUT_META']['host_memory_configuration'] = data + + state['MLC_SUT_META'] = dict(sorted(state['MLC_SUT_META'].items())) + + sut_path = env['MLC_SUT_PATH'] + sut_file = open(sut_path, "w") + json.dump(state['MLC_SUT_META'], sut_file, indent=4) + sut_file.close() + return {'return': 0} diff --git a/script/get-mlperf-inference-sut-description/detect_memory.sh b/script/get-mlperf-inference-sut-description/detect_memory.sh index 4a21653b9..3d53fba78 100644 --- a/script/get-mlperf-inference-sut-description/detect_memory.sh +++ b/script/get-mlperf-inference-sut-description/detect_memory.sh @@ -1,7 +1,6 @@ #!/bin/bash if [[ ${MLC_SUDO_USER} == "yes" ]]; then - ${MLC_SUDO} dmidecode -t memory > meminfo.out - ${MLC_PYTHON_BIN_WITH_PATH} ${MLC_TMP_CURRENT_SCRIPT_PATH}/get_memory_info.py + ${MLC_SUDO} dmidecode -t memory > ${MLC_MEMINFO_FILE} fi test $? -eq 0 || return $? diff --git a/script/get-mlperf-inference-sut-description/meta.yaml b/script/get-mlperf-inference-sut-description/meta.yaml index c46bf930b..5e935a0dc 100644 --- a/script/get-mlperf-inference-sut-description/meta.yaml +++ b/script/get-mlperf-inference-sut-description/meta.yaml @@ -29,16 +29,22 @@ deps: MLC_HOST_OS_TYPE: - linux tags: detect,sudo -- tags: get,generic-python-lib,_package.dmiparser - env: MLC_CACHE_DIR_ENV_NAME: MLC_MLPERF_INFERENCE_SUT_DESC_PATH extra_cache_tags: mlperf,inference,sut,descriptions tags: get,cache,dir,_name.mlperf-inference-sut-descriptions + +posthook_deps: + - tags: parse,dmidecode,memory,info + enable_if_env: + MLC_MEMINFO_FILE: + - on docker: run: false input_mapping: name: MLC_HW_NAME submitter: MLC_MLPERF_SUBMITTER + memory: MLC_DETERMINE_MEMORY_CONFIGURATION new_env_keys: - MLC_HW_* - MLC_SUT_* From ceff374eda15b5ee5c48dc88799a63ac5310dd83 Mon Sep 17 00:00:00 2001 From: Arjun Date: Thu, 27 Mar 2025 15:43:19 +0530 Subject: [PATCH 2/4] Fix a bug in script module not updating state in postprocess, modularized parsing of memory info --- .../parse-dmidecode-memory-info/customize.py | 33 +++++++++++++++++++ .../get_memory_info.py | 13 ++++++-- script/parse-dmidecode-memory-info/meta.yaml | 21 ++++++++++++ script/parse-dmidecode-memory-info/run.bat | 23 +++++++++++++ script/parse-dmidecode-memory-info/run.sh | 17 ++++++++++ 5 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 script/parse-dmidecode-memory-info/customize.py rename script/{get-mlperf-inference-sut-description => parse-dmidecode-memory-info}/get_memory_info.py (81%) create mode 100644 script/parse-dmidecode-memory-info/meta.yaml create mode 100644 script/parse-dmidecode-memory-info/run.bat create mode 100644 script/parse-dmidecode-memory-info/run.sh diff --git a/script/parse-dmidecode-memory-info/customize.py b/script/parse-dmidecode-memory-info/customize.py new file mode 100644 index 000000000..3a13ec914 --- /dev/null +++ b/script/parse-dmidecode-memory-info/customize.py @@ -0,0 +1,33 @@ +from mlc import utils +import os +import subprocess + + +def preprocess(i): + + env = i['env'] + state = i['state'] + + os_info = i['os_info'] + + input_file = env.get('MLC_MEMINFO_FILE', '') + + if input_file == '': + return {'return': 1, 'error': 'Please provide a valid input file containing the meminfo output from dmidecode -t memory'} + + output_file = env.get('MLC_MEMINFO_OUTFILE', os.path.join(os.getcwd(), 'meminfo.txt')) + + env['MLC_MEMINFO_OUTFILE'] = output_file + + env['MLC_RUN_CMD'] = f"""{env['MLC_PYTHON_BIN_WITH_PATH']} {os.path.join(env['MLC_TMP_CURRENT_SCRIPT_PATH'], "get_memory_info.py")} {input_file} {output_file}""" + return {'return': 0} + + +def postprocess(i): + + env = i['env'] + state = i['state'] + + os_info = i['os_info'] + + return {'return': 0} diff --git a/script/get-mlperf-inference-sut-description/get_memory_info.py b/script/parse-dmidecode-memory-info/get_memory_info.py similarity index 81% rename from script/get-mlperf-inference-sut-description/get_memory_info.py rename to script/parse-dmidecode-memory-info/get_memory_info.py index 220517576..6f7c89ce9 100644 --- a/script/get-mlperf-inference-sut-description/get_memory_info.py +++ b/script/parse-dmidecode-memory-info/get_memory_info.py @@ -1,8 +1,15 @@ import os import json +import argparse from dmiparser import DmiParser -with open("meminfo.out", "r") as f: +# Adding argument parser +parser = argparse.ArgumentParser(description='Process meminfo and output MLC_HOST_MEM_INFO.') +parser.add_argument("input_file", help="Path to the input file (e.g. meminfo.out)") +parser.add_argument("output_file", help="Path to the output file (e.g. tmp-run-env.out)") +args = parser.parse_args() + +with open(args.input_file, "r") as f: text = f.read() parser = DmiParser(text, sort_keys=True, indent=4) @@ -57,5 +64,5 @@ meminfo.append("; ".join(item['info'])) meminfo_string = ", ".join(meminfo) - with open("tmp-run-env.out", "w") as f: - f.write(f"MLC_HOST_MEM_INFO={meminfo_string}") + with open(args.output_file, "w") as f: + f.write(meminfo_string) diff --git a/script/parse-dmidecode-memory-info/meta.yaml b/script/parse-dmidecode-memory-info/meta.yaml new file mode 100644 index 000000000..0f4c1b8e4 --- /dev/null +++ b/script/parse-dmidecode-memory-info/meta.yaml @@ -0,0 +1,21 @@ +alias: parse-dmidecode-memory-info +automation_alias: script +automation_uid: 5b4e0237da074764 +category: MLC Utils +deps: + - tags: get,generic-python-lib,_package.dmiparser +new_env_keys: + - MLC_MEMINFO_OUTFILE +input_mapping: + input: MLC_MEMINFO_FILE + output: MLC_MEMINFO_OUTFILE +new_state_keys: [] +post_deps: [] +posthook_deps: [] +prehook_deps: [] +tags: +- dmidecode +- parse +- memory +- info +uid: 1a6be59b1e564fbf diff --git a/script/parse-dmidecode-memory-info/run.bat b/script/parse-dmidecode-memory-info/run.bat new file mode 100644 index 000000000..12c8a6224 --- /dev/null +++ b/script/parse-dmidecode-memory-info/run.bat @@ -0,0 +1,23 @@ +@echo off +setlocal enabledelayedexpansion + +:: Function to exit if the last command failed +:exit_if_error +if %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL% +exit /b 0 + +:: Function to run a command +:run +echo Running: +echo %1 +echo. + +if /I "%MLC_FAKE_RUN%" NEQ "yes" ( + call %1 + call :exit_if_error +) +exit /b 0 + +:: Add your run commands here... +call :run "%MLC_RUN_CMD%" + diff --git a/script/parse-dmidecode-memory-info/run.sh b/script/parse-dmidecode-memory-info/run.sh new file mode 100644 index 000000000..c4542b8c2 --- /dev/null +++ b/script/parse-dmidecode-memory-info/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 3a206fded0951a9bc7730f66124cd756e054adfa Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 27 Mar 2025 10:14:23 +0000 Subject: [PATCH 3/4] [Automated Commit] Format Codebase [skip ci] --- .../get-mlperf-inference-sut-description/customize.py | 6 ++++-- script/parse-dmidecode-memory-info/customize.py | 8 ++++++-- script/parse-dmidecode-memory-info/get_memory_info.py | 11 ++++++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/script/get-mlperf-inference-sut-description/customize.py b/script/get-mlperf-inference-sut-description/customize.py index cdc66473f..879f98164 100644 --- a/script/get-mlperf-inference-sut-description/customize.py +++ b/script/get-mlperf-inference-sut-description/customize.py @@ -4,6 +4,7 @@ import shutil from utils import * + def preprocess(i): env = i['env'] state = i['state'] @@ -184,7 +185,8 @@ def postprocess(i): env = i['env'] state = i['state'] - if env.get('MLC_MEMINFO_OUTFILE', '') != '' and os.path.exists(env['MLC_MEMINFO_OUTFILE']): + if env.get('MLC_MEMINFO_OUTFILE', '') != '' and os.path.exists( + env['MLC_MEMINFO_OUTFILE']): with open(env['MLC_MEMINFO_OUTFILE'], "r") as f: data = f.read() state['MLC_SUT_META']['host_memory_configuration'] = data @@ -196,5 +198,5 @@ def postprocess(i): sut_file = open(sut_path, "w") json.dump(state['MLC_SUT_META'], sut_file, indent=4) sut_file.close() - + return {'return': 0} diff --git a/script/parse-dmidecode-memory-info/customize.py b/script/parse-dmidecode-memory-info/customize.py index 3a13ec914..b5a1805f7 100644 --- a/script/parse-dmidecode-memory-info/customize.py +++ b/script/parse-dmidecode-memory-info/customize.py @@ -15,11 +15,15 @@ def preprocess(i): if input_file == '': return {'return': 1, 'error': 'Please provide a valid input file containing the meminfo output from dmidecode -t memory'} - output_file = env.get('MLC_MEMINFO_OUTFILE', os.path.join(os.getcwd(), 'meminfo.txt')) + output_file = env.get( + 'MLC_MEMINFO_OUTFILE', + os.path.join( + os.getcwd(), + 'meminfo.txt')) env['MLC_MEMINFO_OUTFILE'] = output_file - env['MLC_RUN_CMD'] = f"""{env['MLC_PYTHON_BIN_WITH_PATH']} {os.path.join(env['MLC_TMP_CURRENT_SCRIPT_PATH'], "get_memory_info.py")} {input_file} {output_file}""" + env['MLC_RUN_CMD'] = f"""{env['MLC_PYTHON_BIN_WITH_PATH']} {os.path.join(env['MLC_TMP_CURRENT_SCRIPT_PATH'], "get_memory_info.py")} {input_file} {output_file}""" return {'return': 0} diff --git a/script/parse-dmidecode-memory-info/get_memory_info.py b/script/parse-dmidecode-memory-info/get_memory_info.py index 6f7c89ce9..55c521a60 100644 --- a/script/parse-dmidecode-memory-info/get_memory_info.py +++ b/script/parse-dmidecode-memory-info/get_memory_info.py @@ -4,9 +4,14 @@ from dmiparser import DmiParser # Adding argument parser -parser = argparse.ArgumentParser(description='Process meminfo and output MLC_HOST_MEM_INFO.') -parser.add_argument("input_file", help="Path to the input file (e.g. meminfo.out)") -parser.add_argument("output_file", help="Path to the output file (e.g. tmp-run-env.out)") +parser = argparse.ArgumentParser( + description='Process meminfo and output MLC_HOST_MEM_INFO.') +parser.add_argument( + "input_file", + help="Path to the input file (e.g. meminfo.out)") +parser.add_argument( + "output_file", + help="Path to the output file (e.g. tmp-run-env.out)") args = parser.parse_args() with open(args.input_file, "r") as f: From 03a5599f1f8079310d38c3cbc41efe89b5af7ca2 Mon Sep 17 00:00:00 2001 From: Arjun Suresh Date: Thu, 27 Mar 2025 10:43:52 +0000 Subject: [PATCH 4/4] Update build_wheel.yml --- .github/workflows/build_wheel.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build_wheel.yml b/.github/workflows/build_wheel.yml index 5467a7cc9..3b7919325 100644 --- a/.github/workflows/build_wheel.yml +++ b/.github/workflows/build_wheel.yml @@ -8,7 +8,6 @@ on: - VERSION jobs: - build_wheels: if: github.repository_owner == 'mlcommons' name: Build wheel