Skip to content

Commit

Permalink
Cleanups for intel gptj int4
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunsuresh committed Mar 14, 2024
1 parent 171dcbc commit 6d2b1c3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
5 changes: 5 additions & 0 deletions cm-mlops/script/app-mlperf-inference-intel/_cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,18 @@ variations:
CM_LOCAL_MLPERF_INFERENCE_INTEL_RUN_MODE: calibration
new_env_keys:
- CM_ML_MODEL_*
- INT4_CALIBRATION_DIR

calibration,gptj_:
deps:
- tags: get,generic-python-lib,_package.texttable
names:
- pip-package
- texttable
- tags: get,generic-python-lib,_package.transformers
names:
- pip-package
version: "4.21.2"

build-harness,bert_:
deps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ export CALIBRATION_DATA_JSON=${WORKLOAD_DATA}/calibration-data/cnn_dailymail_cal
export VALIDATION_DATA_JSON=${WORKLOAD_DATA}/validation-data/cnn_dailymail_validation.json
export INT4_CALIBRATION_DIR=${WORKLOAD_DATA}/quantized-int4-model
#sudo -E bash run_quantization.sh
bash run_quantization.sh
#bash run_quantization.sh
echo "${RUN_QUANTIZATION_CMD}"
eval "${RUN_QUANTIZATION_CMD}"
test $? -eq 0 || exit $?
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/bin/bash

export PATH=${CM_CONDA_BIN_PATH}:$PATH

cd ${CM_MLPERF_INFERENCE_INTEL_CALIBRATION_PATH}
CUR_DIR=$(pwd)
export WORKLOAD_DATA=${CUR_DIR}/data
mkdir -p ${WORKLOAD_DATA}

echo $PATH
python download-calibration-dataset.py --calibration-list-file calibration-list.txt --output-dir ${WORKLOAD_DATA}/calibration-data
test $? -eq 0 || exit $?

export CALIBRATION_DATA_JSON=${WORKLOAD_DATA}/calibration-data/cnn_dailymail_calibration.json

Expand All @@ -20,4 +22,3 @@ export QUANTIZED_MODEL_DIR=${WORKLOAD_DATA}/quantized-int4-model
mkdir -p ${QUANTIZED_MODEL_DIR}
bash run_calibration_int4.sh
test $? -eq 0 || exit $?
exit 0
34 changes: 22 additions & 12 deletions cm-mlops/script/app-mlperf-inference-intel/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ def preprocess(i):
i['run_script_input']['script_name'] = "calibrate_gptj_int4_model"
calibration_path = os.path.join(calibration_root, "INT4")
env['CM_MLPERF_INFERENCE_INTEL_CALIBRATION_PATH'] = calibration_path
'''env['CALIBRATION_DATA_JSON'] =
env['CHECKPOINT_DIR'] =
env['QUANTIZED_MODEL_DIR'] =
'''
env['INT4_CALIBRATION_DIR'] = os.path.join(calibration_path, "data", "quantized-int4-model")


elif env['CM_LOCAL_MLPERF_INFERENCE_INTEL_RUN_MODE'] == "build_harness":
Expand All @@ -80,13 +77,22 @@ def preprocess(i):
env['CM_MLPERF_INFERENCE_INTEL_HARNESS_PATH'] = os.path.join(os.getcwd(), "harness", "build", "gptj_inference")
env['DATA_PATH'] = os.path.join(os.getcwd(), "harness", "gptj")
env['MLPERF_INFERENCE_ROOT'] = env['CM_MLPERF_INFERENCE_SOURCE']
final_model_path = os.path.join(harness_root, "data", "gpt-j-int8-model", "best_model.pt")
env['INT8_MODEL_DIR'] = os.path.dirname(final_model_path)
if not os.path.exists(env['INT8_MODEL_DIR']):
os.makedirs(env['INT8_MODEL_DIR'])
env['CM_ML_MODEL_PATH'] = env['INT8_MODEL_DIR']
if env.get('CM_MLPERF_INFERENCE_INTEL_GPTJ_INT8_MODEL_PATH', '') != '':
shutil.copy(env['CM_MLPERF_INFERENCE_INTEL_GPTJ_INT8_MODEL_PATH'], env['INT8_MODEL_DIR'])
if env.get('INTEL_GPTJ_INT4', '') == 'yes':
model_precision = "int4"
env['RUN_QUANTIZATION_CMD'] = "bash run_quantization_int4.sh"
else:
model_precision = "int8"
env['RUN_QUANTIZATION_CMD'] = "bash run_quantization.sh"
final_model_path = os.path.join(harness_root, "data", f"gpt-j-{model_precision}-model", "best_model.pt")
model_dir_name = f"{model_precision.upper()}_MODEL_DIR"
env[model_dir_name] = os.path.dirname(final_model_path)
if not os.path.exists(env[model_dir_name]):
os.makedirs(env[model_dir_name])
env['CM_ML_MODEL_PATH'] = env[model_dir_name]
if env.get('CM_MLPERF_INFERENCE_INTEL_GPTJ_INT8_MODEL_PATH', '') != '' and env.get('INT8_MODEL_DIR', '') != '':
shutil.copy(env['CM_MLPERF_INFERENCE_INTEL_GPTJ_INT8_MODEL_PATH'], env[model_dir_name])
if env.get('CM_MLPERF_INFERENCE_INTEL_GPTJ_INT4_MODEL_PATH', '') != '' and env.get('INT4_MODEL_DIR', '') != '':
shutil.copy(env['CM_MLPERF_INFERENCE_INTEL_GPTJ_INT4_MODEL_PATH'], env[model_dir_name])

elif env['CM_LOCAL_MLPERF_INFERENCE_INTEL_RUN_MODE'] == "run_harness":
print(f"Harness Root: {harness_root}")
Expand All @@ -104,7 +110,11 @@ def preprocess(i):
env['LOADGEN_MODE'] = 'Accuracy'
else:
env['LOADGEN_MODE'] = 'Performance'
env['INT8_MODEL_DIR'] = env['CM_ML_MODEL_PATH']
if env.get('INTEL_GPTJ_INT4', '') == 'yes':
model_precision = "int4"
env['INT4_MODEL_DIR'] = env['CM_ML_MODEL_PATH']
else:
env['INT8_MODEL_DIR'] = env['CM_ML_MODEL_PATH']
env['CM_RUN_DIR'] = i['run_script_input']['path']
env['CM_RUN_CMD'] = "bash run_gptj_harness.sh "

Expand Down

0 comments on commit 6d2b1c3

Please sign in to comment.