From 865a575dc5038963b5249d026e5bbaa46d64aefd Mon Sep 17 00:00:00 2001 From: AnDequan <2429060457@qq.com> Date: Thu, 5 Jan 2023 12:01:19 +0800 Subject: [PATCH] performance tuning --- TensorFlow/contrib/nlp/DeepText-NeuralClassifier/README.md | 7 ++++--- .../nlp/DeepText-NeuralClassifier/data_processor.py | 1 + .../nlp/DeepText-NeuralClassifier/model/text_cnn.py | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/TensorFlow/contrib/nlp/DeepText-NeuralClassifier/README.md b/TensorFlow/contrib/nlp/DeepText-NeuralClassifier/README.md index 4edd305b1..854a41ab8 100644 --- a/TensorFlow/contrib/nlp/DeepText-NeuralClassifier/README.md +++ b/TensorFlow/contrib/nlp/DeepText-NeuralClassifier/README.md @@ -11,7 +11,7 @@ **版本(Version):1.1** -**修改时间(Modified) :2022.12.21** +**修改时间(Modified) :2023.1.5** **框架(Framework):TensorFlow 1.15.0** @@ -158,11 +158,12 @@ precision: 0.839792, recall: 0.806885, f1: 0.823009,standard: 8192 ### NPU/GPU 网络训练性能 | NPU | GPU | |-------|------| -| 110.49sec/epoch| 32.14sec/epoch| +| 22ms/step| 23ms/step| ``` 其中GPU为v100 +训练过程中打印的是100个step的用时 ``` ## 综合评价 NPU上训练后的精度与GPU基本一致。 -NPU在训练性能上与GPU还存在相当大差距。 +就每个step的用时来看,NPU的性能优于GPU。 diff --git a/TensorFlow/contrib/nlp/DeepText-NeuralClassifier/data_processor.py b/TensorFlow/contrib/nlp/DeepText-NeuralClassifier/data_processor.py index 8cf7d8c96..51769d1f6 100644 --- a/TensorFlow/contrib/nlp/DeepText-NeuralClassifier/data_processor.py +++ b/TensorFlow/contrib/nlp/DeepText-NeuralClassifier/data_processor.py @@ -627,6 +627,7 @@ class DataProcessor(object): if mode != tf.estimator.ModeKeys.PREDICT: dataset = dataset.shuffle( buffer_size=self.config.data.shuffle_buffer) + dataset = dataset.prefetch(buffer_size=640) dataset = dataset.repeat(num_epochs) dataset = dataset.batch(batch_size, drop_remainder=True) return dataset diff --git a/TensorFlow/contrib/nlp/DeepText-NeuralClassifier/model/text_cnn.py b/TensorFlow/contrib/nlp/DeepText-NeuralClassifier/model/text_cnn.py index eb2c708b7..fcc77da60 100644 --- a/TensorFlow/contrib/nlp/DeepText-NeuralClassifier/model/text_cnn.py +++ b/TensorFlow/contrib/nlp/DeepText-NeuralClassifier/model/text_cnn.py @@ -74,9 +74,9 @@ class TextCNNEstimator(NPUEstimator): # padding="VALID", name="convolution") # 性能不好 e_shape = tf.shape(embedding) - embedding_reshape = tf.reshape(embedding, [e_shape[0],e_shape[1],e_shape[2]//8,e_shape[3]*8]) + embedding_reshape = tf.reshape(embedding, [e_shape[0],e_shape[1],e_shape[2]//25,e_shape[3]*25]) c1,w,h,c2 = filter_shape - W_reshape = tf.reshape(W, [int(c1),int(w//8), int(h*8), int(c2)]) + W_reshape = tf.reshape(W, [int(c1),int(w//25), int(h*25), int(c2)]) convolution = tf.nn.conv2d( embedding_reshape, W_reshape, strides=[1, 1, 1, 1], padding="VALID", name="convolution") -- Gitee