From 9ad7d967a373d14015f05d41662c8508feb5fef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91cyc=E5=AE=87?= <1251519599@qq.com> Date: Mon, 12 Dec 2022 10:35:22 +0000 Subject: [PATCH 01/11] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20TextToTextTransferTr?= =?UTF-8?q?ansformer=5FID4150=5Ffor=5FTensorFlow2.X?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/.keep diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/.keep b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From 7f6d87fb03678082a4871c382319f89173966352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91cyc=E5=AE=87?= <1251519599@qq.com> Date: Mon, 12 Dec 2022 10:36:25 +0000 Subject: [PATCH 02/11] =?UTF-8?q?=E9=A6=96=E6=AC=A1=E6=8F=90=E4=BA=A4TextT?= =?UTF-8?q?oTextTransferTransformer=5FID4150=5Ffor=5FTensorFlow2.X?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A8=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 黑cyc宇 <1251519599@qq.com> --- .../main.py | 91 +++++++++++++++++++ .../questions.txt | 4 + .../readme.txt | 81 +++++++++++++++++ .../readme_en.txt | 0 .../requirements.txt | 3 + 5 files changed, 179 insertions(+) create mode 100644 TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py create mode 100644 TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/questions.txt create mode 100644 TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.txt create mode 100644 TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme_en.txt create mode 100644 TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/requirements.txt diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py new file mode 100644 index 000000000..84f9b776b --- /dev/null +++ b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py @@ -0,0 +1,91 @@ +#!/usr/bin/python3 +# -*- encoding: utf-8 -*- +""" +@File : main.py +@Time : 2022/12/12/14:45 +@Author : 曹禹臣 +@Software : Pycharm +@Description: +""" +import argparse +import os +from collections import OrderedDict + +import tensorflow as tf +import tensorflow.compat.v1 as tf1 +import tensorflow_text + +# 在使用t5时需要使用 tensorflow_text 注册一些算子,不导入该萨嘎无法有问题 +# 在推理代码中,虽并未明文使用,但是不加这一句会因为代码格式化因模块未使用成果被优化掉,故加上这一句更好 +_ = tensorflow_text + + +def get_config(): + import npu_device + from npu_device.compat.v1.npu_init import RewriterConfig + npu_device.compat.enable_v1() + config = tf1.ConfigProto() + custom_op = config.graph_options.rewrite_options.custom_optimizers.add() + custom_op.name = 'NpuOptimizer' + config.graph_options.rewrite_options.remapping = RewriterConfig.OFF # 必须显式关闭 + config.graph_options.rewrite_options.memory_optimization = RewriterConfig.OFF # 必须显式关闭 + return config + + +class T5: + def __init__(self, pb_file, config): + graph = tf.Graph() + with graph.as_default(): + with tf.io.gfile.GFile(pb_file, 'rb') as f: + graph_def = tf1.GraphDef() + graph_def.ParseFromString(f.read()) + tf.import_graph_def(graph_def, name="") + self.graph = graph + self.config = config + + def predict(self, questions): + results = OrderedDict() + with tf1.Session(graph=self.graph, config=self.config) as sess: + out_nodes = ['strided_slice_1:0', 'strided_slice_2:0'] + input_node = self.graph.get_tensor_by_name('inputs:0') + for question in questions: + feed_dict = {input_node: [question]} + results[question] = sess.run(out_nodes, feed_dict=feed_dict) + return results + + def answer(self, questions): + return OrderedDict([(k, v[1][0].decode('utf8')) for k, v in self.predict(questions).items()]) + + +def parse_args(): + parser = argparse.ArgumentParser(description='t5 runner') + parser.add_argument('-m', '--model', '--model-path', dest='model_path', type=str, default='model/t5.pb', + help='model路径') + parser.add_argument('-f', '--file', dest='question_file', type=str, default='', + help='问题所在文本文件,以\\n分隔,如果此参数有值,则优先使用此参数') + parser.add_argument(nargs='*', dest='questions', default=list(), help='问题列表') + args = parser.parse_args() + return args + + +def main(): + args = parse_args() + + if os.path.exists(args.question_file): + with open(args.question_file, encoding='utf8') as f: + questions = [question for question in f.read().split('\n') if question] + else: + questions = args.questions + + assert questions, '请提供问题' + + t5 = T5(args.model_path, config=get_config()) + result_dict = t5.answer(questions) + print('-' * 50) + for question, answer in result_dict.items(): + print(f"{question}:\n {answer}") + print('=' * 50) + + +if __name__ == '__main__': + main() diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/questions.txt b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/questions.txt new file mode 100644 index 000000000..7677936e0 --- /dev/null +++ b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/questions.txt @@ -0,0 +1,4 @@ +nq question: where is google's headquarters +nq question: what is the most populous country in the world +nq question: name a member of the beatles +nq question: how many teeth do humans have \ No newline at end of file diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.txt b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.txt new file mode 100644 index 000000000..e33379f2b --- /dev/null +++ b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.txt @@ -0,0 +1,81 @@ +中文|[英文](readme_en.md) + +# TextToTextTransferTransformer Tensorflow 2.x 在线推理 +> 此链接提供 TextToTextTransferTransformer TensorFlow 2.x pb模型在NPU上在线推理的脚本和方法 + +# 注意 +> 此案例仅为您学习Ascend软件栈提供学习参考,不用于商业目的。 + +在开始之前,请注意以下适配条件。如果不匹配,可能导致运行失败 + +|依赖|要求| +|---|---| +|CANN 版本|>=6.0.0| +|芯片平台|Ascend310/Ascend310P3| +|第三主依赖|请参考 requirements.txt| + +## 1. 拷贝代码 + +```shell +git clone https://gitee.com/ascend/ModelZoo-TensorFlow.git +cd ModelZoo-TensorFlow/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X +``` + +## 2. 下载pb模型 +1. [下载pb模型](https://ascend-repo-modelzoo.obs.cn-east-2.myhuaweicloud.com/model/2022-12-12_tf/t5_tf2_online_inference/t5.pb) +2. 将pb模型放置在任意位置,建议路径为 ./model/t5.pb +3. 目录结构如下 +``` +TextToTextTransferTransformer_ID4150_for_TensorFlow2.x +|---model +|---|---t5.pb +|---main.py +|---questions.txt +|---readme.md +|---readme_en.md +|---requirements.txt +``` + +## 3. 在线推理 + +> 请准备好输入数据,即文本问题,可以是txt文件,也可以是字符串,以下两种方法皆可 + +```python3.7 +python3 main.py -f questions.txt +python3 main.py 'question1' 'question2' +``` + +## 性能结果 +本结果是通过运行上边适配的推理脚本获得的。 + +1. gpu 结果 +|设备|结果| +|---|---| +|nq question: where is google's headquarters|in Columbus, Ohio| +|nq question: what is the most populous country in the world|China| +|nq question: name a member of the beatles|Harrison| +|nq question: how many teeth do humans have|20 primary| + +1. npu 结果 +|设备|结果| +|---|---| +|nq question: where is google's headquarters|in Columbus, Ohio| +|nq question: what is the most populous country in the world|China| +|nq question: name a member of the beatles|Harrison| +|nq question: how many teeth do humans have|20 primary| + + +## 参考 +[谷歌t5网络 github地址](https://github.com/google-research/text-to-text-transfer-transformer) +兄弟, 我这边需要把网络用例上线, 可以先让我使用一会嘛 +兄弟, 我这边需要把网络用例上线, 可以先让我使用一会嘛 +兄弟, 我这边需要把网络用例上线, 可以先让我使用一会嘛 +兄弟, 我这边需要把网络用例上线, 可以先让我使用一会嘛 +兄弟, 我这边需要把网络用例上线, 可以先让我使用一会嘛 +我是 cwx1066669 曹禹臣 +我是 cwx1066669 曹禹臣 +我是 cwx1066669 曹禹臣 +我是 cwx1066669 曹禹臣 +我是 cwx1066669 曹禹臣 +我是 cwx1066669 曹禹臣 +我是 cwx1066669 曹禹臣 diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme_en.txt b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme_en.txt new file mode 100644 index 000000000..e69de29bb diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/requirements.txt b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/requirements.txt new file mode 100644 index 000000000..81743e7f5 --- /dev/null +++ b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/requirements.txt @@ -0,0 +1,3 @@ +tensorflow>=2.6.0 +tensorflow-text==tensorflow>=2.6.0 +npu-device CANN平台提供 \ No newline at end of file -- Gitee From c6b15bb35bcd926a1b5cd3507025f4cde8e6027d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91cyc=E5=AE=87?= <1251519599@qq.com> Date: Mon, 12 Dec 2022 10:36:37 +0000 Subject: [PATCH 03/11] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/model/.keep diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/model/.keep b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/model/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From 7d406dea4c5b95736b4bee984b4ef8fed84493c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91cyc=E5=AE=87?= <1251519599@qq.com> Date: Mon, 12 Dec 2022 10:41:31 +0000 Subject: [PATCH 04/11] update TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.txt. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 黑cyc宇 <1251519599@qq.com> --- .../readme.txt | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.txt b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.txt index e33379f2b..268889843 100644 --- a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.txt +++ b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.txt @@ -67,15 +67,4 @@ python3 main.py 'question1' 'question2' ## 参考 [谷歌t5网络 github地址](https://github.com/google-research/text-to-text-transfer-transformer) -兄弟, 我这边需要把网络用例上线, 可以先让我使用一会嘛 -兄弟, 我这边需要把网络用例上线, 可以先让我使用一会嘛 -兄弟, 我这边需要把网络用例上线, 可以先让我使用一会嘛 -兄弟, 我这边需要把网络用例上线, 可以先让我使用一会嘛 -兄弟, 我这边需要把网络用例上线, 可以先让我使用一会嘛 -我是 cwx1066669 曹禹臣 -我是 cwx1066669 曹禹臣 -我是 cwx1066669 曹禹臣 -我是 cwx1066669 曹禹臣 -我是 cwx1066669 曹禹臣 -我是 cwx1066669 曹禹臣 -我是 cwx1066669 曹禹臣 + -- Gitee From 71742f09c363420473b5acbefc1090d6fb8081a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91cyc=E5=AE=87?= <1251519599@qq.com> Date: Mon, 12 Dec 2022 10:46:06 +0000 Subject: [PATCH 05/11] update TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 黑cyc宇 <1251519599@qq.com> --- .../main.py | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py index 84f9b776b..72f64a9b9 100644 --- a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py +++ b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py @@ -1,12 +1,37 @@ #!/usr/bin/python3 -# -*- encoding: utf-8 -*- -""" -@File : main.py -@Time : 2022/12/12/14:45 -@Author : 曹禹臣 -@Software : Pycharm -@Description: -""" +# -*- coding: utf-8 -*- +# +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# @Time : 2020/10/20 11:03 下午 +# @File : main.py +# @Software: PyCharm import argparse import os from collections import OrderedDict -- Gitee From c9dccff3c3bd7005d47327f88ae9f3ff98e0c944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91cyc=E5=AE=87?= <1251519599@qq.com> Date: Mon, 12 Dec 2022 10:58:32 +0000 Subject: [PATCH 06/11] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=20TensorFlow2?= =?UTF-8?q?/built-in/nlp/TextToTextTransferTransformer=5FID4150=5Ffor=5FTe?= =?UTF-8?q?nsorFlow2.X/readme.txt=20=E4=B8=BA=20TensorFlow2/built-in/nlp/T?= =?UTF-8?q?extToTextTransferTransformer=5FID4150=5Ffor=5FTensorFlow2.X/rea?= =?UTF-8?q?dme.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{readme.txt => readme.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/{readme.txt => readme.md} (100%) diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.txt b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md similarity index 100% rename from TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.txt rename to TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md -- Gitee From b304e3a9fc203bcc53d6aada07c8cae48db01618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91cyc=E5=AE=87?= <1251519599@qq.com> Date: Mon, 12 Dec 2022 10:58:46 +0000 Subject: [PATCH 07/11] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=20TensorFlow2?= =?UTF-8?q?/built-in/nlp/TextToTextTransferTransformer=5FID4150=5Ffor=5FTe?= =?UTF-8?q?nsorFlow2.X/readme=5Fen.txt=20=E4=B8=BA=20TensorFlow2/built-in/?= =?UTF-8?q?nlp/TextToTextTransferTransformer=5FID4150=5Ffor=5FTensorFlow2.?= =?UTF-8?q?X/readme=5Fen.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{readme_en.txt => readme_en.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/{readme_en.txt => readme_en.md} (100%) diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme_en.txt b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme_en.md similarity index 100% rename from TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme_en.txt rename to TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme_en.md -- Gitee From c1cbad9ccb961b110c20df811a871ba9b696d4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91cyc=E5=AE=87?= <1251519599@qq.com> Date: Mon, 12 Dec 2022 10:59:54 +0000 Subject: [PATCH 08/11] update TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 黑cyc宇 <1251519599@qq.com> --- .../readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md index 268889843..c71bbb364 100644 --- a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md +++ b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md @@ -49,6 +49,7 @@ python3 main.py 'question1' 'question2' 本结果是通过运行上边适配的推理脚本获得的。 1. gpu 结果 + |设备|结果| |---|---| |nq question: where is google's headquarters|in Columbus, Ohio| @@ -57,6 +58,7 @@ python3 main.py 'question1' 'question2' |nq question: how many teeth do humans have|20 primary| 1. npu 结果 + |设备|结果| |---|---| |nq question: where is google's headquarters|in Columbus, Ohio| -- Gitee From b42540c87037ebf932e6873a8c4d1c98ba286c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91cyc=E5=AE=87?= <1251519599@qq.com> Date: Mon, 12 Dec 2022 11:02:00 +0000 Subject: [PATCH 09/11] update TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 黑cyc宇 <1251519599@qq.com> --- .../readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md index c71bbb364..3da5083d0 100644 --- a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md +++ b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md @@ -50,7 +50,7 @@ python3 main.py 'question1' 'question2' 1. gpu 结果 -|设备|结果| +|问题|结果| |---|---| |nq question: where is google's headquarters|in Columbus, Ohio| |nq question: what is the most populous country in the world|China| @@ -59,7 +59,7 @@ python3 main.py 'question1' 'question2' 1. npu 结果 -|设备|结果| +|问题|结果| |---|---| |nq question: where is google's headquarters|in Columbus, Ohio| |nq question: what is the most populous country in the world|China| -- Gitee From dd11cec16bb52e0b9a0a9fb23c15fca0d43e74f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91cyc=E5=AE=87?= <1251519599@qq.com> Date: Mon, 12 Dec 2022 11:02:37 +0000 Subject: [PATCH 10/11] update TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 黑cyc宇 <1251519599@qq.com> --- .../readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md index 3da5083d0..8f735baaa 100644 --- a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md +++ b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/readme.md @@ -14,6 +14,8 @@ |芯片平台|Ascend310/Ascend310P3| |第三主依赖|请参考 requirements.txt| +# 使用步骤 + ## 1. 拷贝代码 ```shell -- Gitee From 650c16faf6fb0b682606d03f094804f70f13c6e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91cyc=E5=AE=87?= <1251519599@qq.com> Date: Mon, 12 Dec 2022 11:17:07 +0000 Subject: [PATCH 11/11] update TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 黑cyc宇 <1251519599@qq.com> --- .../main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py index 72f64a9b9..cc49fdea5 100644 --- a/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py +++ b/TensorFlow2/built-in/nlp/TextToTextTransferTransformer_ID4150_for_TensorFlow2.X/main.py @@ -38,10 +38,11 @@ from collections import OrderedDict import tensorflow as tf import tensorflow.compat.v1 as tf1 + +# 在使用t5时需要使用 tensorflow_text 注册一些算子,不导入该模块会有问题 import tensorflow_text -# 在使用t5时需要使用 tensorflow_text 注册一些算子,不导入该萨嘎无法有问题 -# 在推理代码中,虽并未明文使用,但是不加这一句会因为代码格式化因模块未使用成果被优化掉,故加上这一句更好 +# 在推理代码中,虽并未明文使用,但是不加这一句会在代码格式化时因模块未使用而被优化掉,故加上这一句更好 _ = tensorflow_text @@ -64,7 +65,7 @@ class T5: with tf.io.gfile.GFile(pb_file, 'rb') as f: graph_def = tf1.GraphDef() graph_def.ParseFromString(f.read()) - tf.import_graph_def(graph_def, name="") + tf.import_graph_def(graph_def, name='') self.graph = graph self.config = config -- Gitee