Skip to content

Commit

Permalink
added support for PyTorch model cfg in universal python loadgen harness
Browse files Browse the repository at this point in the history
  • Loading branch information
gfursin committed Apr 8, 2024
1 parent 0f47e10 commit 292bfcf
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
7 changes: 5 additions & 2 deletions cm-mlops/script/app-loadgen-generic-python/_cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ default_env:
input_mapping:
modelpath: CM_ML_MODEL_FILE_WITH_PATH
modelcodepath: CM_ML_MODEL_CODE_WITH_PATH
modelcfgpath: CM_ML_MODEL_CFG_WITH_PATH
modelsamplepath: CM_ML_MODEL_SAMPLE_WITH_PATH
output_dir: CM_MLPERF_OUTPUT_DIR
scenario: CM_MLPERF_LOADGEN_SCENARIO
Expand Down Expand Up @@ -255,9 +256,11 @@ input_description:
modelpath:
desc: Full path to file with model weights
modelcodepath:
desc: (for python models) Full path to file with model code
desc: (for PyTorch models) Full path to file with model code and cm.py
modelcfgpath:
desc: (for PyTorch models) Full path to JSON file with model cfg
modelsamplepath:
desc: (for python models) Full path to file with model sample in pickle format
desc: (for PyTorch models) Full path to file with model sample in pickle format
ep:
desc: ONNX Execution provider
scenario:
Expand Down
5 changes: 5 additions & 0 deletions cm-mlops/script/app-loadgen-generic-python/customize.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Developer: Grigori Fursin

from cmind import utils
import os
import shutil
Expand Down Expand Up @@ -49,6 +51,9 @@ def preprocess(i):
if env.get('CM_ML_MODEL_CODE_WITH_PATH', '') != '':
run_opts +=" --model_code "+env['CM_ML_MODEL_CODE_WITH_PATH']

if env.get('CM_ML_MODEL_CFG_WITH_PATH', '') != '':
run_opts +=" --model_cfg "+env['CM_ML_MODEL_CFG_WITH_PATH']

if env.get('CM_ML_MODEL_SAMPLE_WITH_PATH', '') != '':
run_opts +=" --model_sample_pickle "+env['CM_ML_MODEL_SAMPLE_WITH_PATH']

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(
intra_op_threads=0,
inter_op_threads=0,
model_code='', # Not used here
model_cfg={}, # Not used here
model_sample_pickle='' # Not used here
):
self.model_path = model_path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Developer: Grigori Fursin

import typing
import importlib
import os
Expand Down Expand Up @@ -42,11 +44,13 @@ def __init__(
intra_op_threads=0,
inter_op_threads=0,
model_code='',
model_cfg={},
model_sample_pickle=''
):

self.model_path = model_path
self.model_code = model_code
self.model_cfg = model_cfg
self.model_sample_pickle = model_sample_pickle
self.execution_provider = execution_provider

Expand Down Expand Up @@ -80,7 +84,10 @@ def create(self) -> Model:
del(sys.path[0])

# Init model
model = model_module.model_init(checkpoint, 'model_state_dict')
if len(self.model_cfg)>0:
print ('Model cfg: {}'.format(self.model_cfg))

model = model_module.model_init(checkpoint, self.model_cfg)
model.eval()

return XModel(model)
Expand Down
12 changes: 12 additions & 0 deletions cm-mlops/script/app-loadgen-generic-python/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def main(
backend: str,
model_path: str,
model_code: str,
model_cfg: str,
model_sample_pickle: str,
output_path: typing.Optional[str],
runner_name: str,
Expand All @@ -48,13 +49,22 @@ def main(
else:
raise Exception("Error: backend is not recognized.")

# Load model cfg
model_cfg_dict = {}
if model_cfg!='':
import json

with open(model_cfg) as mc:
model_cfg_dict = json.load(mc)

model_factory = XModelFactory(
model_path,
execution_provider,
execution_mode,
interop_threads,
intraop_threads,
model_code,
model_cfg_dict,
model_sample_pickle
)

Expand Down Expand Up @@ -205,13 +215,15 @@ def main(
parser.add_argument("--loadgen_expected_qps", help="Expected QPS", default=1, type=float)
parser.add_argument("--loadgen_duration_sec", help="Expected duration in sec.", default=1, type=float)
parser.add_argument("--model_code", help="(for PyTorch models) path to model code with cm.py", default="")
parser.add_argument("--model_cfg", help="(for PyTorch models) path to model's configuration in JSON file", default="")
parser.add_argument("--model_sample_pickle", help="(for PyTorch models) path to a model sample in pickle format", default="")

args = parser.parse_args()
main(
args.backend,
args.model_path,
args.model_code,
args.model_cfg,
args.model_sample_pickle,
args.output,
args.runner,
Expand Down
2 changes: 2 additions & 0 deletions cm-mlops/script/app-loadgen-generic-python/src/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Developer: Grigori Fursin

import os
import psutil

Expand Down

0 comments on commit 292bfcf

Please sign in to comment.