Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 73 additions & 21 deletions script/generate-mlperf-inference-user-conf/customize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from mlc import utils
import importlib.util
import os
import json
import shutil
Expand All @@ -23,11 +24,14 @@ def preprocess(i):
submission_checker_dir = os.path.join(mlperf_path, "tools", "submission")
# Remove any stale submission_checker.py that would shadow the
# submission_checker package directory in newer inference versions
stale_checker = os.path.join(submission_checker_dir, "submission_checker.py")
stale_checker = os.path.join(
submission_checker_dir,
"submission_checker.py")
if os.path.isfile(stale_checker) and os.path.isdir(
os.path.join(submission_checker_dir, "submission_checker")):
os.remove(stale_checker)
sys.path.append(submission_checker_dir)
if submission_checker_dir not in sys.path:
sys.path.insert(0, submission_checker_dir)

version = env.get('MLC_MLPERF_INFERENCE_VERSION', "4.1")

Expand Down Expand Up @@ -581,22 +585,73 @@ def measure_files_exist(OUTPUT_DIR, run_files):
return True


def get_checker_files(env):
if is_true(env.get('MLC_MLPERF_MODULARISED_INFERENCE_SUBMISSION_CHECKER', '')):
def _get_submission_checker_constants_module(submission_checker_dir=None):
required_attrs = [
"REQUIRED_ACC_FILES",
"REQUIRED_PERF_FILES",
"REQUIRED_POWER_FILES",
"REQUIRED_PERF_POWER_FILES",
"REQUIRED_MEASURE_FILES",
"OFFLINE_MIN_SPQ_SINCE_V4",
]

# Ensure the caller's directory is at the front of sys.path so that
# both submission_checker.py and its log_parser dependency are found
# before any other copy that might be on sys.path.
if submission_checker_dir and submission_checker_dir not in sys.path:
sys.path.insert(0, submission_checker_dir)

try:
import submission_checker.constants as constants
if all(hasattr(constants, attr) for attr in required_attrs):
return constants
except (ImportError, ModuleNotFoundError, AttributeError):
pass

REQUIRED_ACC_FILES = constants.REQUIRED_ACC_FILES
REQUIRED_PERF_FILES = constants.REQUIRED_PERF_FILES
REQUIRED_POWER_FILES = constants.REQUIRED_POWER_FILES
REQUIRED_PERF_POWER_FILES = constants.REQUIRED_PERF_POWER_FILES
REQUIRED_MEASURE_FILES = constants.REQUIRED_MEASURE_FILES
else:
try:
import submission_checker as checker
REQUIRED_ACC_FILES = checker.REQUIRED_ACC_FILES
REQUIRED_PERF_FILES = checker.REQUIRED_PERF_FILES
REQUIRED_POWER_FILES = checker.REQUIRED_POWER_FILES
REQUIRED_PERF_POWER_FILES = checker.REQUIRED_PERF_POWER_FILES
REQUIRED_MEASURE_FILES = checker.REQUIRED_MEASURE_FILES
if all(hasattr(checker, attr) for attr in required_attrs):
return checker
except (ImportError, ModuleNotFoundError, AttributeError):
pass

# importlib fallback: load submission_checker.py directly from the
# provided directory, bypassing sys.modules caching and any sys.path
# ordering issues that could cause the standard imports above to pick up
# the wrong (or no) module.
if submission_checker_dir:
checker_file = os.path.join(
submission_checker_dir,
"submission_checker.py")
if os.path.isfile(checker_file):
try:
spec = importlib.util.spec_from_file_location(
"submission_checker_direct", checker_file)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
if all(hasattr(mod, attr) for attr in required_attrs):
return mod
except (ImportError, ModuleNotFoundError, AttributeError, OSError):
pass

raise AttributeError(
"submission_checker module is missing required constants for file checks"
)


def _get_submission_checker_dir(env):
return os.path.join(
env['MLC_MLPERF_INFERENCE_SOURCE'], "tools", "submission")


def get_checker_files(env):
constants = _get_submission_checker_constants_module(
_get_submission_checker_dir(env))
REQUIRED_ACC_FILES = constants.REQUIRED_ACC_FILES
REQUIRED_PERF_FILES = constants.REQUIRED_PERF_FILES
REQUIRED_POWER_FILES = constants.REQUIRED_POWER_FILES
REQUIRED_PERF_POWER_FILES = constants.REQUIRED_PERF_POWER_FILES
REQUIRED_MEASURE_FILES = constants.REQUIRED_MEASURE_FILES
return REQUIRED_ACC_FILES, REQUIRED_PERF_FILES, REQUIRED_POWER_FILES, REQUIRED_PERF_POWER_FILES, REQUIRED_MEASURE_FILES


Expand All @@ -605,12 +660,9 @@ def get_required_min_queries_offline(model, version, env):
if int(version[0]) < 4:
return 24756

if is_true(env.get('MLC_MLPERF_MODULARISED_INFERENCE_SUBMISSION_CHECKER', '')):
import submission_checker.constants as constants
REQUIRED_MIN_QUERIES = constants.OFFLINE_MIN_SPQ_SINCE_V4
else:
import submission_checker as checker
REQUIRED_MIN_QUERIES = checker.OFFLINE_MIN_SPQ_SINCE_V4
constants = _get_submission_checker_constants_module(
_get_submission_checker_dir(env))
REQUIRED_MIN_QUERIES = constants.OFFLINE_MIN_SPQ_SINCE_V4

mlperf_model = model
mlperf_model = mlperf_model.replace("resnet50", "resnet")
Expand Down
Loading