From dd4d03c5a59590a0c7a34ef6c9c68e7082feee9c Mon Sep 17 00:00:00 2001 From: Arjun Date: Sat, 13 Jan 2024 23:42:27 +0000 Subject: [PATCH] Changes to run bert for intel-mlperf-inference --- cm-mlops/script/get-conda/_cm.json | 1 + cm-mlops/script/get-conda/customize.py | 1 + .../script/install-onednn-from.src/_cm.json | 102 +------------- .../install-onednn-from.src/customize.py | 4 + .../{run.sh => run-intel-mlperf-inference.sh} | 11 +- .../reproduce-mlperf-inference-intel/_cm.yaml | 131 ++++++++++-------- .../build_harness.sh | 51 +++++++ .../customize.py | 74 +++------- .../reproduce-mlperf-inference-intel/run.sh | 8 -- .../run_harness.sh | 25 ++++ 10 files changed, 178 insertions(+), 230 deletions(-) rename cm-mlops/script/install-onednn-from.src/{run.sh => run-intel-mlperf-inference.sh} (55%) create mode 100644 cm-mlops/script/reproduce-mlperf-inference-intel/build_harness.sh delete mode 100644 cm-mlops/script/reproduce-mlperf-inference-intel/run.sh create mode 100644 cm-mlops/script/reproduce-mlperf-inference-intel/run_harness.sh diff --git a/cm-mlops/script/get-conda/_cm.json b/cm-mlops/script/get-conda/_cm.json index cbacee390c..3c7a35c865 100644 --- a/cm-mlops/script/get-conda/_cm.json +++ b/cm-mlops/script/get-conda/_cm.json @@ -14,6 +14,7 @@ "+PATH", "+LD_LIBRARY_PATH", "CM_CONDA_PREFIX", + "CONDA_PREFIX", "CM_CONDA_BIN_PATH", "CM_CONDA_BIN_WITH_PATH", "CM_CONDA_LIB_PATH" diff --git a/cm-mlops/script/get-conda/customize.py b/cm-mlops/script/get-conda/customize.py index 60584f6997..d5bd0ef439 100644 --- a/cm-mlops/script/get-conda/customize.py +++ b/cm-mlops/script/get-conda/customize.py @@ -72,6 +72,7 @@ def postprocess(i): conda_prefix = os.path.dirname(conda_bin_path) env['CM_CONDA_PREFIX'] = conda_prefix + env['CONDA_PREFIX'] = conda_prefix conda_lib_path = os.path.join(conda_prefix, "lib") diff --git a/cm-mlops/script/install-onednn-from.src/_cm.json b/cm-mlops/script/install-onednn-from.src/_cm.json index 67db5ac71d..18037bb052 100644 --- a/cm-mlops/script/install-onednn-from.src/_cm.json +++ b/cm-mlops/script/install-onednn-from.src/_cm.json @@ -84,107 +84,9 @@ "base": [ "tag.v2.6" ], - "deps": [ - { - "names": [ - "conda" - ], - "tags": "get,conda,_name.bert-pt" - }, - { - "tags": "install,pytorch,from.src,_for-intel-mlperf-inference" - }, - { - "names": [ - "conda-package", - "python3" - ], - "tags": "get,generic,conda-package,_package.python", - "version": "3.8" - }, - { - "names": [ - "conda-package", - "ncurses" - ], - "tags": "get,generic,conda-package,_package.ncurses,_source.conda-forge" - }, - { - "names": [ - "conda-package", - "ninja" - ], - "tags": "get,generic,conda-package,_package.ninja" - }, - { - "names": [ - "conda-package", - "cmake" - ], - "tags": "get,generic,conda-package,_package.cmake" - }, - { - "names": [ - "conda-package", - "mkl" - ], - "tags": "get,generic,conda-package,_package.mkl,_source.intel", - "version": "2023.1.0" - }, - { - "names": [ - "conda-package", - "mkl-include" - ], - "tags": "get,generic,conda-package,_package.mkl-include,_source.intel", - "version": "2023.1.0" - }, - { - "names": [ - "conda-package", - "intel-openmp" - ], - "tags": "get,generic,conda-package,_package.intel-openmp,_source.intel", - "version": "2023.1.0" - }, - { - "names": [ - "conda-package", - "llvm-openmp" - ], - "tags": "get,generic,conda-package,_package.llvm-openmp,_source.conda-forge" - }, - { - "names": [ - "conda-package", - "wheel" - ], - "tags": "get,generic,conda-package,_package.wheel,_source.conda-forge" - }, - { - "names": [ - "conda-package", - "setuptools" - ], - "tags": "get,generic,conda-package,_package.setuptools,_source.conda-forge" - }, - { - "names": [ - "conda-package", - "future" - ], - "tags": "get,generic,conda-package,_package.future,_source.conda-forge" - }, - { - "names": [ - "conda-package", - "libstdcxx-ng" - ], - "tags": "get,generic,conda-package,_package.libstdcxx-ng,_source.conda-forge" - } - ], "env": { - "CM_CONDA_ENV": "yes" + "CM_CONDA_ENV": "yes", + "CM_FOR_INTEL_MLPERF_INFERENCE": "yes" } }, "repo.#": { diff --git a/cm-mlops/script/install-onednn-from.src/customize.py b/cm-mlops/script/install-onednn-from.src/customize.py index 0e58d14fa1..06e5402241 100644 --- a/cm-mlops/script/install-onednn-from.src/customize.py +++ b/cm-mlops/script/install-onednn-from.src/customize.py @@ -13,6 +13,10 @@ def preprocess(i): run_cmd="" env['CM_RUN_CMD'] = run_cmd + env['CM_ONEDNN_INSTALLED_PATH'] = os.path.join(os.getcwd(), "onednn") + + if env.get('CM_FOR_INTEL_MLPERF_INFERENCE', '') == "yes": + i['run_script_input']['script_name'] = "run-intel-mlperf-inference" automation = i['automation'] diff --git a/cm-mlops/script/install-onednn-from.src/run.sh b/cm-mlops/script/install-onednn-from.src/run-intel-mlperf-inference.sh similarity index 55% rename from cm-mlops/script/install-onednn-from.src/run.sh rename to cm-mlops/script/install-onednn-from.src/run-intel-mlperf-inference.sh index 94d5e4299b..77bff6883a 100644 --- a/cm-mlops/script/install-onednn-from.src/run.sh +++ b/cm-mlops/script/install-onednn-from.src/run-intel-mlperf-inference.sh @@ -10,17 +10,8 @@ rm -rf build pwd wget -nc --no-check-certificate https://raw.githubusercontent.com/mlcommons/inference_results_v3.1/main/closed/Intel/code/bert-99/pytorch-cpu/patches/onednnv2_6.patch if [ "${?}" != "0" ]; then exit 1; fi -git apply onednnv2_6.patch -if [ "${?}" != "0" ]; then exit 1; fi -pip install -r requirements.txt - -mkdir build -pushd build -cmake -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DBUILD_TPPS_INTREE=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$(dirname $(python3 -c 'import torch; print(torch.__file__)'));../cmake/Modules" -GNinja -DUSERCP=ON .. -ninja -popd +cmd="git apply onednnv2_6.patch" -#cmd="${CM_RUN_CMD}" echo ${cmd} eval ${cmd} diff --git a/cm-mlops/script/reproduce-mlperf-inference-intel/_cm.yaml b/cm-mlops/script/reproduce-mlperf-inference-intel/_cm.yaml index d991372a0e..4c5a475176 100644 --- a/cm-mlops/script/reproduce-mlperf-inference-intel/_cm.yaml +++ b/cm-mlops/script/reproduce-mlperf-inference-intel/_cm.yaml @@ -2,6 +2,7 @@ alias: reproduce-mlperf-inference-intel uid: c05a90433bb04cc1 cache: false +can_force_cache: true automation_alias: script automation_uid: 5b4e0237da074764 @@ -63,15 +64,6 @@ new_state_keys: - mlperf-inference-implementation - CM_SUT_* -# Env keys which are exposed to higher level scripts -new_env_keys: - - CM_MLPERF_* - - CM_DATASET_* - - CM_HW_NAME - - CM_ML_MODEL_* - - CM_MAX_EXAMPLES - - CM_IMAGENET_ACCURACY_DTYPE - - CM_SQUAD_ACCURACY_DTYPE # Dependencies on other CM scripts @@ -93,11 +85,11 @@ deps: names: - mlperf-logging + - tags: get,conda,_name.bert-pt - tags: get,generic,conda-package,_package.python version: "3.8" - tags: get,generic-sys-util,_numactl - tags: get,generic,conda-package,_package.jemalloc,_source.conda-forge - - tags: get,onednn,from.src,_for-intel-mlperf-inference ######################################################################## # Install ResNet50 model (ONNX) and ImageNet @@ -127,25 +119,6 @@ deps: - ######################################################################## - # Install bert dependencies - - - enable_if_env: - CM_MODEL: - - bert-99 - - bert-99.9 - names: - - bert-vocab - tags: get,squad-vocab - - - enable_if_env: - CM_MODEL: - - bert-99 - - bert-99.9 - names: - - squad-tokenized - tags: get,dataset,tokenized,squad,_raw - ######################################################################## # Install OpenImages @@ -169,33 +142,13 @@ deps: ######################################################################## # Install MLPerf inference dependencies - # Download MLPerf inference source - - tags: get,mlcommons,inference,src - names: - - inference-src - - # Download MLPerf inference loadgen - - tags: get,mlcommons,inference,loadgen - names: - - inference-loadgen - - # Creates user conf for given SUT - - tags: generate,user-conf,mlperf,inference - names: - - user-conf-generator - + - tags: get,mlperf,inference,results + version: v3.1 # Post dependencies to run this app including for power measurement post_deps: - - names: - - compile-program - tags: compile,cpp-program - skip_if_env: - CM_MLPERF_SKIP_RUN: - - yes - - names: - runner - mlperf-runner @@ -224,7 +177,7 @@ variations: CM_MLPERF_BACKEND_LIB_NAMESPEC: pytorch deps: - tags: get,pytorch,from.src,_for-intel-mlperf-inference - - tags: get,onednn,from.src,_for-intel-mlperf-inference + - tags: install,onednn,from.src,_for-intel-mlperf-inference @@ -273,7 +226,6 @@ variations: bert_: deps: - - tags: get,generic-python-lib,_onnx - tags: install,transformers,from.src,_for-intel-mlperf-inference env: CM_BENCHMARK: STANDALONE_BERT @@ -283,20 +235,20 @@ variations: standalone: - group: run-mode + group: network-mode default: true env: - CM_RUN_MODE: standalone + CM_MLPERF_NETWORK_RUN_MODE: standalone network-server: - group: run-mode + group: network-mode env: - CM_RUN_MODE: network-server + CM_MLPERF_NETWORK_RUN_MODE: network-server network-client: - group: run-mode + group: network-run-mode env: - CM_RUN_MODE: network-client + CM_MLPERF_NETWORK_RUN_MODE: network-client bert_,network-server: env: @@ -332,6 +284,67 @@ variations: CM_MODEL_BATCH_SIZE: "#" #CM_MLPERF_SUT_NAME_RUN_CONFIG_SUFFIX1: "activation_count.#" + build_harness: + group: run-mode + deps: + - tags: get,generic-sys-util,_rsync + - tags: install,llvm,from.src,_for-intel-mlperf-inference + env: + CM_LOCAL_MLPERF_INFERENCE_INTEL_RUN_MODE: build_harness + new_env_keys: + - CM_MLPERF_INFERENCE_INTEL_HARNESS_PATH + - DATA_PATH + + build_harness,bert_: + deps: + - tags: get,dataset,original,squad + names: + - squad-original + - tags: get,ml-model,bert-large,_pytorch,_int8 + names: + - bert-large + - ml-model + - tags: get,generic-python-lib,_package.tokenization + + + run_harness: + group: run-mode + default: true + deps: + - tags: reproduce,mlperf,inference,intel,harness,_build_harness + inherit_variation_tags: true + names: + - build-harness + skip_inherit_variation_groups: + - run-mode + - device-info + force_cache: true + + # Download MLPerf inference source + - tags: get,mlcommons,inference,src + names: + - inference-src + + # Creates user conf for given SUT + - tags: generate,user-conf,mlperf,inference + names: + - user-conf-generator + + env: + CM_LOCAL_MLPERF_INFERENCE_INTEL_RUN_MODE: run_harness + + # Env keys which are exposed to higher level scripts + new_env_keys: + - CM_MLPERF_* + - CM_DATASET_* + - CM_HW_NAME + - CM_ML_MODEL_* + - CM_MAX_EXAMPLES + - CM_IMAGENET_ACCURACY_DTYPE + - CM_SQUAD_ACCURACY_DTYPE + + + maxq: group: power-mode env: diff --git a/cm-mlops/script/reproduce-mlperf-inference-intel/build_harness.sh b/cm-mlops/script/reproduce-mlperf-inference-intel/build_harness.sh new file mode 100644 index 0000000000..4a2b957a91 --- /dev/null +++ b/cm-mlops/script/reproduce-mlperf-inference-intel/build_harness.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +export PATH=${CM_CONDA_BIN_PATH}:$PATH +echo $PWD + +if [ ! -d harness ]; then + mkdir -p harness +fi + +rm -rf ${CM_CONDA_LIB_PATH}/cmake/mkl/* + +rsync -avz --exclude=".git" ${CM_HARNESS_CODE_ROOT}/ harness/ +pushd harness +rsync -avz --exclude=".git" ${CM_MLPERF_INFERENCE_SOURCE}/ inference/ +test $? -eq 0 || exit $? +pushd mlperf_plugins +rm -rf onednn +rsync -avz --exclude=".git" ${CM_ONEDNN_INSTALLED_PATH}/ onednn/ +test $? -eq 0 || exit $? +popd + +mkdir build +pushd build +cmake -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DBUILD_TPPS_INTREE=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$(dirname $(python3 -c 'import torch; print(torch.__file__)'));../cmake/Modules" -GNinja -DUSERCP=ON .. +test $? -eq 0 || exit $? +ninja +test $? -eq 0 || exit $? +popd +test $? -eq 0 || exit $? + +mkdir -p bert/dataset +cd bert +ln -sf ${CM_DATASET_SQUAD_VAL_PATH} dataset/dev-v1.1.json +test $? -eq 0 || exit $? +if [ ! -d model ]; then + git clone https://huggingface.co/bert-large-uncased model + cd model + rm pytorch_model.bin + ln -sf ${CM_ML_MODEL_FILE_WITH_PATH} pytorch_model.bin + test $? -eq 0 || exit $? + cd .. +fi + +cd .. +pip install boto3 tokenization +test $? -eq 0 || exit $? +bash convert.sh +test $? -eq 0 || exit $? +popd + + diff --git a/cm-mlops/script/reproduce-mlperf-inference-intel/customize.py b/cm-mlops/script/reproduce-mlperf-inference-intel/customize.py index c36bb7b56b..37c71068dc 100644 --- a/cm-mlops/script/reproduce-mlperf-inference-intel/customize.py +++ b/cm-mlops/script/reproduce-mlperf-inference-intel/customize.py @@ -13,6 +13,7 @@ def preprocess(i): if env.get('CM_MLPERF_SKIP_RUN', '') == "yes": return {'return':0} + import json if 'CM_MODEL' not in env: return {'return': 1, 'error': 'Please select a variation specifying the model to run'} if 'CM_MLPERF_BACKEND' not in env: @@ -20,34 +21,21 @@ def preprocess(i): if 'CM_MLPERF_DEVICE' not in env: return {'return': 1, 'error': 'Please select a variation specifying the device to run on'} + ml_model = env['CM_MODEL'] + backend = env['CM_MLPERF_BACKEND'] + device = env['CM_MLPERF_DEVICE'] + harness_root = os.path.join(env['CM_MLPERF_INFERENCE_RESULTS_PATH'], 'closed', 'Intel', 'code', ml_model, backend+"-"+device) + print(f"Harness Root: {harness_root}") - print(f"Harness Root: {}") - - source_files = [] - env['CM_SOURCE_FOLDER_PATH'] = env['CM_CHECKOUT_PATH'] - - - - if '+ CXXFLAGS' not in env: - env['+ CXXFLAGS'] = [] - - if '+CPLUS_INCLUDE_PATH' not in env: - env['+CPLUS_INCLUDE_PATH'] = [] - + env['CM_HARNESS_CODE_ROOT'] = harness_root if env.get('CM_MODEL') == "resnet50": - env['dataset_imagenet_preprocessed_subset_fof'] = env['CM_DATASET_PREPROCESSED_IMAGENAMES_LIST'] - env['dataset_imagenet_preprocessed_dir'] = env['CM_DATASET_PREPROCESSED_PATH'] + pass elif "bert" in env.get('CM_MODEL'): - env['dataset_squad_tokenized_max_seq_length'] = env['CM_DATASET_SQUAD_TOKENIZED_MAX_SEQ_LENGTH'] - env['dataset_squad_tokenized_root'] = env['CM_DATASET_SQUAD_TOKENIZED_ROOT'] - env['dataset_squad_tokenized_input_ids'] = os.path.basename(env['CM_DATASET_SQUAD_TOKENIZED_INPUT_IDS']) - env['dataset_squad_tokenized_input_mask'] = os.path.basename(env['CM_DATASET_SQUAD_TOKENIZED_INPUT_MASK']) - env['dataset_squad_tokenized_segment_ids'] = os.path.basename(env['CM_DATASET_SQUAD_TOKENIZED_SEGMENT_IDS']) - + pass elif "retinanet" in env.get('CM_MODEL'): - env['+ CXXFLAGS'].append("-DMODEL_RX50") + pass script_path = i['run_script_input']['path'] @@ -55,33 +43,6 @@ def preprocess(i): env['CM_DATASET_LIST'] = env['CM_DATASET_ANNOTATIONS_FILE_PATH'] - for file in os.listdir(env['CM_SOURCE_FOLDER_PATH']): - if file.endswith(".c") or file.endswith(".cpp"): - source_files.append(file) - - - print(f"Compiling the source files: {source_files}") - env['CM_CXX_SOURCE_FILES'] = ";".join(source_files) - - env['+ CXXFLAGS'].append("-std=c++17") - env['+ CXXFLAGS'].append("-fpermissive") - - - if '+ LDCXXFLAGS' not in env: - env['+ LDCXXFLAGS'] = [ ] - - env['+ LDCXXFLAGS'] += [ - "-lmlperf_loadgen", - "-lpthread", - "-ldl" - ] - # e.g. -lonnxruntime - if 'CM_MLPERF_BACKEND_LIB_NAMESPEC' in env: - env['+ LDCXXFLAGS'].append('-l' + env['CM_MLPERF_BACKEND_LIB_NAMESPEC']) - - - env['CM_LINKER_LANG'] = 'CXX' - env['CM_RUN_DIR'] = env.get('CM_MLPERF_OUTPUT_DIR', os.getcwd()) if 'CM_MLPERF_CONF' not in env: env['CM_MLPERF_CONF'] = os.path.join(env['CM_MLPERF_INFERENCE_SOURCE'], "mlperf.conf") @@ -89,11 +50,18 @@ def preprocess(i): env['CM_MLPERF_USER_CONF'] = os.path.join(env['CM_MLPERF_INFERENCE_CLASSIFICATION_AND_DETECTION_PATH'], "user.conf") - env['loadgen_mlperf_conf_path'] = env['CM_MLPERF_CONF']# to LOADGEN_MLPERF_CONF - env['loadgen_user_conf_path'] = env['CM_MLPERF_USER_CONF']# to LOADGEN_USER_CONF - env['loadgen_scenario'] = env['CM_MLPERF_LOADGEN_SCENARIO'] - loadgen_mode = env['CM_MLPERF_LOADGEN_MODE'] + env['CONDA_PREFIX'] = env['CM_CONDA_PREFIX'] + + if env['CM_LOCAL_MLPERF_INFERENCE_INTEL_RUN_MODE'] == "build_harness": + i['run_script_input']['script_name'] = "build_harness" + env['CM_MLPERF_INFERENCE_INTEL_HARNESS_PATH'] = os.path.join(os.getcwd(), "harness", "build", "bert_inference") + env['DATA_PATH'] = os.path.join(os.getcwd(), "harness", "bert") + elif env['CM_LOCAL_MLPERF_INFERENCE_INTEL_RUN_MODE'] == "run_harness": + env['MODEL_PATH'] = os.path.dirname(os.path.dirname(env['CM_MLPERF_INFERENCE_INTEL_HARNESS_PATH'])) + env['DATASET_PATH'] = os.path.dirname(os.path.dirname(env['CM_MLPERF_INFERENCE_INTEL_HARNESS_PATH'])) + env['CM_RUN_DIR'] = os.getcwd() + env['CM_RUN_CMD'] = "bash run_harness.sh" return {'return':0} diff --git a/cm-mlops/script/reproduce-mlperf-inference-intel/run.sh b/cm-mlops/script/reproduce-mlperf-inference-intel/run.sh deleted file mode 100644 index ddcd0b5504..0000000000 --- a/cm-mlops/script/reproduce-mlperf-inference-intel/run.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -if [[ ${CM_CALL_MLPERF_RUNNER} == "no" ]]; then - cd ${CM_RUN_DIR} - cmd=${CM_RUN_CMD} - echo "${cmd}" - eval "${cmd}" - test $? -eq 0 || exit $? -fi diff --git a/cm-mlops/script/reproduce-mlperf-inference-intel/run_harness.sh b/cm-mlops/script/reproduce-mlperf-inference-intel/run_harness.sh new file mode 100644 index 0000000000..a85bb92fe3 --- /dev/null +++ b/cm-mlops/script/reproduce-mlperf-inference-intel/run_harness.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +THREADS_PER_INSTANCE=4 + +export LD_PRELOAD=${CONDA_PREFIX}/lib/libjemalloc.so +export MALLOC_CONF="oversize_threshold:1,background_thread:true,percpu_arena:percpu,metadata_thp:always,dirty_decay_ms:9000000000,muzzy_decay_ms:9000000000"; + +accuracy=$1 + +number_threads=`nproc --all` +export number_cores=`lscpu -b -p=Core,Socket | grep -v '^#' | sort -u | wc -l` +num_numa=$(numactl --hardware|grep available|awk -F' ' '{ print $2 }') +num_instance=$(($number_cores / $THREADS_PER_INSTANCE)) + +sut_dir=${MODEL_PATH} +executable=${CM_MLPERF_INFERENCE_INTEL_HARNESS_PATH} +mode="Offline" +OUTDIR="${CM_MLPERF_OUTPUT_DIR}" + +#python ../../user_config.py +USER_CONF="${CM_MLPERF_USER_CONF}" + +CONFIG="-n ${num_numa} -i ${num_instance} -j ${THREADS_PER_INSTANCE} --test_scenario=${mode} --model_file=${sut_dir}/bert.pt --sample_file=${sut_dir}/squad.pt --mlperf_config=${CM_MLPERF_CONF} --user_config=${USER_CONF} -o ${OUTDIR} -w 1300 --warmup ${accuracy}" + +${executable} ${CONFIG}