代码拉取完成,页面将自动刷新
同步操作将从 Ascend/ModelLink 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# coding=utf-8
# Copyright (c) 2024, HUAWEI CORPORATION. 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.
import modellink
from megatron.training import get_args
from megatron.legacy.model import GPTModel
from megatron.training.initialize import initialize_megatron
from megatron.training.arguments import core_transformer_config_from_args
from modellink.tasks.inference.text_generation.infer_base import task_factory, add_text_generate_args
def model_provider(pre_process=True, post_process=True):
"""Build the model."""
config = core_transformer_config_from_args(get_args())
init_model = GPTModel(
config,
parallel_output=False,
pre_process=pre_process,
post_process=post_process
)
return init_model
def main():
initialize_megatron(extra_args_provider=add_text_generate_args,
args_defaults={'no_load_rng': True,
'no_load_optim': True})
args = get_args()
model = GPTModel.from_pretrained(
model_provider=model_provider,
pretrained_model_name_or_path=args.load
)
system_template = ""
dialog_template = "{instruction}"
if args.inference_prompt_type == 'alpaca':
system_template = "Below is an instruction that describes a task, paired with an input that provides further " \
"context. Write a response that appropriately completes the request. " \
"Please note that you need to think through your response logically and step by step.\n\n"
dialog_template = "### Instruction:\n{instruction}\n\n### Response:"
elif args.inference_prompt_type == 'mixtral':
system_template = "<s>"
dialog_template = "[INST] {instruction} [/INST] "
task_factory(args, model, system_template=system_template, dialog_template=dialog_template)
if __name__ == "__main__":
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。