From faca40da322d539030addb356169f7a59037e25e Mon Sep 17 00:00:00 2001 From: xuyongfei Date: Mon, 5 Jul 2021 11:23:20 +0800 Subject: [PATCH] Serving, pangu alpha flask client bugfix --- .../pangu_alpha/scripts/run_distribute_export.sh | 15 +++++++++++++++ .../pangu_alpha/scripts/run_distribute_predict.sh | 15 +++++++++++++++ .../pangu_alpha/serving_increment/flask/client.py | 4 ++-- .../pangu_alpha/serving_increment/start_pangu.sh | 14 ++++++++++++++ .../pangu_alpha/serving_increment/stop_pangu.sh | 14 ++++++++++++++ .../official/nlp/pangu_alpha/src/generate.py | 1 - 6 files changed, 60 insertions(+), 3 deletions(-) diff --git a/model_zoo/official/nlp/pangu_alpha/scripts/run_distribute_export.sh b/model_zoo/official/nlp/pangu_alpha/scripts/run_distribute_export.sh index 3deaf7f6390..2fd73300c7b 100644 --- a/model_zoo/official/nlp/pangu_alpha/scripts/run_distribute_export.sh +++ b/model_zoo/official/nlp/pangu_alpha/scripts/run_distribute_export.sh @@ -1,4 +1,19 @@ #!/bin/bash +# 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. +# ============================================================================ + execute_path=$(pwd) script_self=$(readlink -f "$0") self_path=$(dirname "${script_self}") diff --git a/model_zoo/official/nlp/pangu_alpha/scripts/run_distribute_predict.sh b/model_zoo/official/nlp/pangu_alpha/scripts/run_distribute_predict.sh index 0afd0559f71..be23cf48a4f 100644 --- a/model_zoo/official/nlp/pangu_alpha/scripts/run_distribute_predict.sh +++ b/model_zoo/official/nlp/pangu_alpha/scripts/run_distribute_predict.sh @@ -1,4 +1,19 @@ #!/bin/bash +# 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. +# ============================================================================ + execute_path=$(pwd) script_self=$(readlink -f "$0") self_path=$(dirname "${script_self}") diff --git a/model_zoo/official/nlp/pangu_alpha/serving_increment/flask/client.py b/model_zoo/official/nlp/pangu_alpha/serving_increment/flask/client.py index 89ada8a857c..b313c1b0c85 100644 --- a/model_zoo/official/nlp/pangu_alpha/serving_increment/flask/client.py +++ b/model_zoo/official/nlp/pangu_alpha/serving_increment/flask/client.py @@ -41,8 +41,8 @@ def generate(input_sentence): @app.route('/query') def do_query(): s = request.args.get('u') - output_sentence, end_flag = generate(s) - return jsonify(ok=True, rsvp=output_sentence, end_flag=end_flag) + output_sentence = generate(s) + return jsonify(ok=True, rsvp=output_sentence) @app.route('/') diff --git a/model_zoo/official/nlp/pangu_alpha/serving_increment/start_pangu.sh b/model_zoo/official/nlp/pangu_alpha/serving_increment/start_pangu.sh index a00d3f514a4..394a6da72d9 100644 --- a/model_zoo/official/nlp/pangu_alpha/serving_increment/start_pangu.sh +++ b/model_zoo/official/nlp/pangu_alpha/serving_increment/start_pangu.sh @@ -1,4 +1,18 @@ #!/bin/bash +# 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. +# ============================================================================ unset http_proxy unset https_proxy diff --git a/model_zoo/official/nlp/pangu_alpha/serving_increment/stop_pangu.sh b/model_zoo/official/nlp/pangu_alpha/serving_increment/stop_pangu.sh index 194dc83a0d9..006b7c38fee 100644 --- a/model_zoo/official/nlp/pangu_alpha/serving_increment/stop_pangu.sh +++ b/model_zoo/official/nlp/pangu_alpha/serving_increment/stop_pangu.sh @@ -1,4 +1,18 @@ #!/bin/bash +# 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. +# ============================================================================ CURRUSER=$(whoami) diff --git a/model_zoo/official/nlp/pangu_alpha/src/generate.py b/model_zoo/official/nlp/pangu_alpha/src/generate.py index a4396914f5c..dbdb1bd55dd 100644 --- a/model_zoo/official/nlp/pangu_alpha/src/generate.py +++ b/model_zoo/official/nlp/pangu_alpha/src/generate.py @@ -205,7 +205,6 @@ def generate_increment(model, origin_inputs, config): log_probs = logits.reshape(1, config.vocab_size) # Get the revised log_probs considering frequency and presence penalty to eliminate duplicate in generated results - log_probs = log_probs.asnumpy().reshape(1, config.vocab_size) log_probs_revised = log_probs - frequency_list * frequency_penalty - (frequency_list > 0) * presence_penalty p, p_args = sampler(log_probs_revised, top_p, top_k_num, use_pynative)