Downloads · 30 days
0
nakayama/lora-hh-rlhf-49k-ja-for-open-calm-7b
lora-hh-rlhf-49k-ja-for-open-calm-7b is a text generation model from nakayama. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
cyberagent/open-calm-7bに対してkunishou/ hh-rlhf-49k-jaをpeftを用いて(というよりtloen/alpaca-loraを改変して)チューニングしたものの差分です。 lora-alpacaから学習時のパラメータは特に変えていません。
Downloads · 30 days
0
Access
Public
Updated May 21, 2023
Repo size
16.8 MB
Likes
0
Public
Click a slice to open those files.
.bin16.8 MB · 100%
From the Hugging Face model README
cyberagent/open-calm-7bに対してkunishou/
hh-rlhf-49k-jaをpeftを用いて(というよりtloen/alpaca-loraを改変して)チューニングしたものの差分です。
lora-alpacaから学習時のパラメータは特に変えていません。
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
LOAD_8BIT = False
BASE_MODEL = "cyberagent/open-calm-7b"
LORA_WEIGHTS = "nakayama/lora-hh-rlhf-49k-ja-for-open-calm-7b"
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
model = AutoModelForCausalLM.from_pretrained(
BASE_MODEL,
load_in_8bit=LOAD_8BIT,
torch_dtype=torch.float16,
device_map="auto",
)
model = PeftModel.from_pretrained(
model,
LORA_WEIGHTS,
torch_dtype=torch.float16,
adapter_name=LORA_WEIGHTS
)
def generate_prompt(instruction, input=None):
if input:
return f"""以下は、タスクを説明する命令と、さらなるコンテキストを提供する入力の組み合わせです。要求を適切に満たすような応答を書きなさい。
### Instruction:
{instruction}
### Input:
{input}
### Response:"""
else:
return f"""以下は、ある作業を記述した指示です。依頼を適切に完了させる回答を書きなさい。
### Instruction:
{instruction}
### Response:"""
if not LOAD_8BIT:
model.half()
instruction="次の日本の観光地について説明してください。"
input="富士山"
prompt = generate_prompt(instruction, input)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
generation_output = model.generate(
**inputs,
do_sample=True,
temperature=0.1,
top_p=0.75,
top_k=20,
return_dict_in_generate=True,
output_scores=True,
max_new_tokens=128,
repetition_penalty=1.5,
no_repeat_ngram_size=5,
pad_token_id=tokenizer.pad_token_id,
)
s = generation_output.sequences[0]
output = tokenizer.decode(s)
print(output.split("### Response:")[1].strip())