Downloads · 30 days
0
Atsu-Taiyo/llm-jp-3-13b-finetune
llm-jp-3-13b-finetune is a machine learning model from Atsu-Taiyo. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers.
Downloads · 30 days
0
Access
Public
Updated Dec 15, 2024
Repo size
501 MB
Likes
0
Public
Click a slice to open those files.
.safetensors250 MB · 98%
From the Hugging Face model README
概要
LLM松尾研究室の最終課題で作成したモデル
BaseModelには,
https://huggingface.co/collections/llm-jp/llm-jp-3-pre-trained-models-672c6096472b65839d76a1fa
を用いてFineTuningを行った.
以下のデータをFineTuningに利用した
https://liat-aip.sakura.ne.jp/wp/llmのための日本語インストラクションデータ作成/llmのための日本語インストラクションデータ-公開/
関根聡, 安藤まや, 後藤美知子, 鈴木久美, 河原大輔, 井之上直也, 乾健太郎. ichikara-instruction: LLMのための日本語インストラクションデータの構築. 言語処理学会第30回年次大会(2024)
以下のコードを使用して、データセットに基づく推論を実行できる
from transformers import (
AutoModelForCausalLM,
AutoTokenizer,
BitsAndBytesConfig,
)
from peft import PeftModel
import torch
from tqdm import tqdm
import json
# モデルとトークナイザーをロード
model_id = "model_id" # 使用するモデルIDを指定
HF_TOKEN = "huggingface_token" # Hugging Faceの認証トークン
adapter_id = "adapter_id" # アップロードしたHugging FaceのID
# QLoRA config
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
)
model = AutoModelForCausalLM.from_pretrained(
model_id,
quantization_config=bnb_config,
device_map="auto", # モデルをGPU/CPUに自動配置
token=HF_TOKEN
)
# 元のモデルにLoRAのアダプタを統合。
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)\
tokenizer = AutoTokenizer.from_pretrained(model_id, token=HF_TOKEN)
# 推論データ
datasets = [
{"task_id": 1, "input": "こんにちは、今日の天気を教えてください。"},
{"task_id": 2, "input": "自己紹介をしてください。"}
]
# 推論を実行
results = []
for data in tqdm(datasets):
input = data["input"]
# プロンプトを作成
prompt = f"""### 指示
{input}
### 回答
"""
# 入力をトークン化
input_ids = tokenizer(prompt, return_tensors="pt").to(model.device)
# 推論実行
outputs = model.generate(
**input_ids,
max_new_tokens=100,
do_sample=False,
repetition_penalty=1.2
)
# 出力をデコード
output = tokenizer.decode(outputs[0][input_ids.input_ids.size(1):], skip_special_tokens=True)
# 結果を保存
results.append({"task_id": data["task_id"], "output": output})