Skip to content

Commit 34c7054

Browse files
Fix tlt_mlperf test issue (#1112)
1 parent c6a1049 commit 34c7054

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

examples/tensorflow/nlp/transformer_lt_mlperf/quantization/ptq/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ Where (Default values are shown in the square brackets):
7676
* $CONFIG_FILE ["./transformer_lt_mlperf.yaml"]-- The path to quantization configuration .yaml file to load for tuning
7777
* $BATCH_SIZE [64]-- The batch size for model inference
7878
* $ITERATIONS [-1]-- The user-defined total inference iterations in benchmark mode. If it is -1, it means to run the entire dataset
79-
* $WARMUPS [5]-- The number of warmup steps before benchmarking the model
79+
* $WARMUPS [10]-- The number of warmup steps before benchmarking the model
8080
* $VARIANT ["uncased"]-- The case sensitive type to compute BLEU score, which is one of two options: 'uncased'/'cased'
8181
* $INTER_THREADS [2]-- The number of inter op parallelism thread to use, which can be set to the number of sockets
82-
* $INTRA_THREADS [56]-- The number of intra op parallelism thread to use, which can be set to the number of cores
82+
* $INTRA_THREADS [28]-- The number of intra op parallelism thread to use, which can be set to the number of physical core per socket
8383

8484

8585
Details of enabling Intel® Neural Compressor on Transformer_LT_mlperf for Tensorflow.

examples/tensorflow/nlp/transformer_lt_mlperf/quantization/ptq/run_benchmark.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ function init_params {
1919
mode="accuracy"
2020
batch_size=64
2121
iters=-1
22-
warmup_steps=5
22+
warmup_steps=10
2323
bleu_variant="uncased"
2424
num_inter=2
25-
num_intra=56
25+
num_intra=28
2626

2727
for var in "$@"
2828
do

examples/tensorflow/nlp/transformer_lt_mlperf/quantization/ptq/run_inference.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from neural_compressor.experimental import Quantization, common
3535
from neural_compressor.data import DATALOADERS
3636
from neural_compressor.utils.utility import dump_elapsed_time
37+
from neural_compressor.utils import logger
3738

3839

3940
INPUT_TENSOR_NAMES = ['input_tokens:0']
@@ -70,10 +71,10 @@
7071
"num_inter", 2,
7172
"""Number of inter op parallelism thread to use.""")
7273
flags.DEFINE_integer(
73-
"num_intra", 56,
74+
"num_intra", 28,
7475
"""Number of intra op parallelism thread to use.""")
7576
flags.DEFINE_integer(
76-
"warmup_steps", 5,
77+
"warmup_steps", 10,
7778
"""Number of warmup steps before benchmarking the model.""")
7879
flags.DEFINE_integer(
7980
"iters", -1,
@@ -94,7 +95,7 @@ def load_graph(file_name):
9495
text_format.Merge(f.read(), graph_def)
9596
with tf.Graph().as_default() as graph:
9697
tf.import_graph_def(graph_def, name='')
97-
tf.compat.v1.logging.info('Loaded graph from: ' + file_name)
98+
logger.info('Loaded graph from: ' + file_name)
9899
return graph
99100

100101
def _trim_and_decode(ids, subtokenizer):
@@ -227,25 +228,20 @@ def eval_func(infer_graph):
227228
assert iteration <= len(dataloader), \
228229
"'iteration' must be less than or equal to len(dataloader)."
229230
if FLAGS.mode == "benchmark":
230-
tf.compat.v1.logging.info \
231-
('******** Start to get performance of the model ********')
231+
logger.info('******** Start to get performance of the model ********')
232232
else:
233-
tf.compat.v1.logging.info \
234-
('******** Start to get accuracy and performance of the model ********')
233+
logger.info('******** Start to get accuracy and performance of the model ********')
235234
if warmup > 0:
236-
tf.compat.v1.logging.info \
237-
('Start to do warm-up with {}/{} (steps/total_iterations) before getting performance.' \
238-
.format(warmup, iteration))
235+
logger.info('Start to do warm-up with {}/{} (steps/total_iterations) before getting performance.' \
236+
.format(warmup, iteration))
239237
else:
240-
tf.compat.v1.logging.info \
241-
('Start to get performance with {} iterations.'.format(iteration))
238+
logger.info('Start to get performance with {} iterations.'.format(iteration))
242239
for idx, (input_data, _) in enumerate(dataloader):
243240
if idx < iteration:
244241
if idx == warmup and warmup > 0:
245-
tf.compat.v1.logging.info('The warm-up is over.')
246-
tf.compat.v1.logging.info \
247-
('Start to get performance with {}/{} (steps/total_iterations).' \
248-
.format(iteration - warmup, iteration))
242+
logger.info('The warm-up is over.')
243+
logger.info('Start to get performance with {}/{} (steps/total_iterations).' \
244+
.format(iteration - warmup, iteration))
249245
feed_dict = {input_tensors[0]: input_data}
250246
time_start = time.time()
251247
dec_tensor = sess.run(output_tensors, feed_dict)
@@ -255,9 +251,9 @@ def eval_func(infer_graph):
255251
else:
256252
break
257253
latency = np.array(time_list[warmup:]).mean() / FLAGS.batch_size
258-
tf.compat.v1.logging.info('Batch-size = {}'.format(FLAGS.batch_size))
259-
tf.compat.v1.logging.info('Latency: {:.3f} ms'.format(latency * 1000))
260-
tf.compat.v1.logging.info('Throughput: {:.3f} items/sec'.format(1./ latency))
254+
logger.info('Batch-size = {}'.format(FLAGS.batch_size))
255+
logger.info('Latency: {:.3f} ms'.format(latency * 1000))
256+
logger.info('Throughput: {:.3f} items/sec'.format(1./ latency))
261257

262258
if FLAGS.mode != "benchmark":
263259
"""Write translations to file and calculate BLEU score."""
@@ -269,8 +265,7 @@ def eval_func(infer_graph):
269265
for k,otr in enumerate(itr):
270266
translation_count += 1
271267
decoded_translations.append(_trim_and_decode(otr, subtokenizer))
272-
tf.compat.v1.logging.info \
273-
('Total number of sentences translated:%d' % (translation_count))
268+
logger.info('Total number of sentences translated:%d' % (translation_count))
274269
tf.io.gfile.makedirs(os.path.dirname(FLAGS.file_out))
275270
with tf.io.gfile.GFile(FLAGS.file_out, "w") as f:
276271
for i in sorted_keys:
@@ -279,14 +274,16 @@ def eval_func(infer_graph):
279274
global uregex
280275
uregex = UnicodeRegex()
281276
score_uncased = bleu_wrapper(FLAGS.reference_file, FLAGS.file_out, False)
282-
tf.compat.v1.logging.info("Case-insensitive results: {:.8f}".format(score_uncased))
277+
logger.info("Case-insensitive results: {:.8f}".format(score_uncased))
283278
score_cased = bleu_wrapper(FLAGS.reference_file, FLAGS.file_out, True)
284-
tf.compat.v1.logging.info("Case-sensitive results: {:.8f}".format(score_cased))
279+
logger.info("Case-sensitive results: {:.8f}".format(score_cased))
285280
assert FLAGS.bleu_variant in ["uncased", "cased"], \
286281
"'bleu_variant' must be one of two options: 'uncased'/'cased'."
287282
if FLAGS.bleu_variant == "uncased":
283+
logger.info("Accuracy: {:.8f}".format(score_uncased))
288284
return score_uncased
289285
else:
286+
logger.info("Accuracy: {:.8f}".format(score_cased))
290287
return score_cased
291288

292289
def main(unused_args):

examples/tensorflow/nlp/transformer_lt_mlperf/quantization/ptq/run_tuning.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ function init_params {
1919
file_out="./output_translation_result.txt"
2020
config="./transformer_lt_mlperf.yaml"
2121
batch_size=64
22-
warmup_steps=5
22+
warmup_steps=10
2323
bleu_variant="uncased"
2424
num_inter=2
25-
num_intra=56
25+
num_intra=28
2626

2727
for var in "$@"
2828
do

0 commit comments

Comments
 (0)