Skip to content

Commit fa9ef6a

Browse files
kaikaiyaointel-zhangyi
authored andcommitted
Neural Coder enable launcher bench (#260)
* enable auto bench in launcher * debug * debug
1 parent 1f582a4 commit fa9ef6a

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

neural_coder/__main__.py

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def parse_args():
3535
parser.add_argument('--config', type=str, default="",
3636
help='quantization configuration file path')
3737

38+
parser.add_argument('-b', '--bench', default=False, action='store_true',
39+
help='conduct auto_quant benchmark instead of enable')
40+
3841
# positional
3942
parser.add_argument("script", type=str,
4043
help="The full path to the script to be launched. "
@@ -51,34 +54,41 @@ def parse_args():
5154
script_copied = args.script[:-3] + "_optimized.py"
5255
shutil.copy(args.script, script_copied)
5356

54-
# optimize on copied script with Neural Coder
55-
from neural_coder import enable
56-
if args.opt == "":
57-
if args.approach == "static":
58-
features = ["pytorch_inc_static_quant_fx"]
59-
if args.approach == "static_ipex":
60-
features = ["pytorch_inc_static_quant_ipex"]
61-
if args.approach == "dynamic":
62-
features = ["pytorch_inc_dynamic_quant"]
63-
else:
64-
features = args.opt.split(",")
65-
66-
# execute optimization enabling
67-
enable(
68-
code=script_copied,
69-
features=features,
70-
overwrite=True,
71-
)
72-
73-
# execute on copied script, which has already been optimized
74-
cmd = []
75-
76-
cmd.append(sys.executable) # "/xxx/xxx/python"
77-
cmd.append("-u")
78-
cmd.append(script_copied)
79-
cmd.extend(args.script_args)
80-
81-
cmd = " ".join(cmd) # list convert to string
82-
83-
process = subprocess.Popen(cmd, env=os.environ, shell=True) # nosec
84-
process.wait()
57+
if not args.bench: # enable
58+
# optimize on copied script with Neural Coder
59+
from neural_coder import enable
60+
if args.opt == "":
61+
if args.approach == "static":
62+
features = ["pytorch_inc_static_quant_fx"]
63+
if args.approach == "static_ipex":
64+
features = ["pytorch_inc_static_quant_ipex"]
65+
if args.approach == "dynamic":
66+
features = ["pytorch_inc_dynamic_quant"]
67+
else:
68+
features = args.opt.split(",")
69+
70+
# execute optimization enabling
71+
enable(
72+
code=script_copied,
73+
features=features,
74+
overwrite=True,
75+
)
76+
77+
# execute on copied script, which has already been optimized
78+
cmd = []
79+
80+
cmd.append(sys.executable) # "/xxx/xxx/python"
81+
cmd.append("-u")
82+
cmd.append(script_copied)
83+
cmd.extend(args.script_args)
84+
85+
cmd = " ".join(cmd) # list convert to string
86+
87+
process = subprocess.Popen(cmd, env=os.environ, shell=True) # nosec
88+
process.wait()
89+
else: # auto_quant
90+
from neural_coder import auto_quant
91+
auto_quant(
92+
code=script_copied,
93+
args=' '.join(args.script_args), # convert list of strings to a single string
94+
)

0 commit comments

Comments
 (0)