1# 使用したプロンプトフォーマット2INSTRUCTION_KEY ="### Instruction:"3RESPONSE_KEY ="### Response:"4INTRO_BLURB ="Below is an instruction that describes a task. Write a response that appropriately completes the request."5PROMPT_FOR_GENERATION_FORMAT ="""{intro}
6{instruction_key}
7{instruction}
8{response_key}
9""".format(10 intro=INTRO_BLURB,11 instruction_key=INSTRUCTION_KEY,12 instruction="{instruction}",13 response_key=RESPONSE_KEY,14)
python
1import torch
2import transformers
3name ='Jumtra/mpt-7b-inst'4config = transformers.AutoConfig.from_pretrained(name, trust_remote_code=True)5config.attn_config['attn_impl']='torch'6config.init_device ='cuda:0'# For fast initialization directly on GPU!7model = transformers.AutoModelForCausalLM.from_pretrained(8 name,9 config=config,10 torch_dtype=torch.bfloat16,# Load model weights in bfloat1611 trust_remote_code=True12).to("cuda:0")13model.eval()1415input_text = PROMPT_FOR_GENERATION_FORMAT.format(instruction ="ニューラルネットワークとは何ですか?")1617inputs = tokenizer(input_text, return_tensors="pt").to(model.device)18input_length = inputs.input_ids.shape[1]1920# Without streaming21with torch.no_grad():22 generation_output = model.generate(23**inputs,24 max_new_tokens=2048,25 do_sample=True,26 temperature=0.01,27 top_p=0.01,28 top_k=60,29 repetition_penalty=1.1,30 return_dict_in_generate=True,31 remove_invalid_values=True,32 pad_token_id=tokenizer.pad_token_id,33 bos_token_id=tokenizer.bos_token_id,34 eos_token_id=tokenizer.eos_token_id,35)36token = generation_output.sequences[0, input_length:]37output = tokenizer.decode(token)38print(output)3940#ニューラルネットワーク(NN)は、人工知能の分野で使用される深い学習アルゴリズムの一種です。これらのアルゴリズムは、データを使って自動的に学習し、特定の目的を達成するために予測や決定を行うことができます。ニューラルネットワークは、多くの異なるアプリケーションで使用されており、自動車の運転システム、検索エンジン、画像認識などです。<|endoftext|>
引用
@online{MosaicML2023Introducing,
author = {MosaicML NLP Team},
title = {Introducing MPT-7B: A New Standard for Open-Source,
ly Usable LLMs},
year = {2023},
url = {www.mosaicml.com/blog/mpt-7b},
note = {Accessed: 2023-03-28}, % change this date
urldate = {2023-03-28} % change this date
}