Downloads · 30 days
0
YY1128/llm-jp-3-13b-ft1
llm-jp-3-13b-ft1 is a machine learning model from YY1128. 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.
大規模言語モデル2024の最終課題向けに llm-jp/llm-jp-3-13b をファインチューニングしたモデルです。
Downloads · 30 days
0
Access
Public
Updated Dec 16, 2024
Repo size
1 GB
Likes
0
Public
Click a slice to open those files.
.safetensors1 GB · 99%
From the Hugging Face model README
大規模言語モデル2024の最終課題向けに llm-jp/llm-jp-3-13b をファインチューニングしたモデルです。
L4(24GB)を用いてクラウドGPUサービスlightning.aiで動作確認済です。
大規模言語モデル2024 講座の公式サンプルコードと記事「Lightning AI Studio + vLLMで爆速で推論する(+Omnicampus)」を参考にしました。ソースコード作者の方々に厚く御礼申し上げます。
%pip install vllm
%pip install accelerate
%pip install flash-attn
# %pip install packaging==24.1 ### packaging==24.1にしないとエラーになる!! ###
%pip install huggingface_hub
%pip install "bitsandbytes>=0.44.0"
環境変数HF_TOKENに自分のhuggingface tokenが設定されていることを前提にしています。 OSによって操作変わりますが、環境変数の設定をお願いいたします。
import json
import os
import vllm ### packaging==24.1にしないとエラーになる!! ###
from huggingface_hub import snapshot_download
from transformers import (
AutoModelForCausalLM,
AutoTokenizer,
)
from vllm.lora.request import LoRARequest
HF_TOKEN = os.getenv("HF_TOKEN")
if HF_TOKEN is None:
raise EnvironmentError("環境変数 'HF_TOKEN' が設定されていません。")
MODEL_NAME = "llm-jp/llm-jp-3-13b"
adapter_id = "YY1128/llm-jp-3-13b-ft1"
lora_path = snapshot_download(repo_id=adapter_id, use_auth_token=HF_TOKEN)
llm = vllm.LLM(
MODEL_NAME,
gpu_memory_utilization=0.95,
trust_remote_code=True,
enable_lora=True,
max_model_len=2048,
enforce_eager=True,
quantization="bitsandbytes", # 4bit量子化を有効にする
load_format="bitsandbytes", # 4bit量子化を有効にする
max_lora_rank=64
)
tokenizer = llm.get_tokenizer()
bos = tokenizer.bos_token
カレントディレクトリにelyza-tasks-100-TV_0.jsonlを配置し、読み込みます。
def read_jsonl(file_path):
"""
JSONLファイルを読み込み、辞書のリストを返す関数
Args:
file_path (str): JSONLファイルのパス
Returns:
list: 辞書のリスト
"""
data = []
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
# 各行をJSON形式でパースしてリストに追加
data.append(json.loads(line.strip()))
return data
tasks = read_jsonl("elyza-tasks-100-TV_0.jsonl")
プロンプトを作成します。
inputs = [d["input"] for d in tasks]
prompt_token_ids = [
bos + "## 指示\n" + input + "\n" + "## 回答\n"
for input in inputs
]
print(prompt_token_ids[0])
以下のような出力が得られればOKです。
<s>## 指示
野球選手が今シーズン活躍するために取り組むべき5つのことを教えてください。
## 回答
以下の設定を用いました。
sampling_params = vllm.SamplingParams(
best_of=8,
max_tokens=700,
top_p=0.9,
min_p=0.08,
seed=42,
temperature=1.0,
repetition_penalty=1.1,
) best,max_tokens=700, top_p=0.9, min_p=0.08, seed=42, temperature=1.0,repetition_penalty=1.1
)
以下のコードで推論しjsonlで保存します。 プログレスバーがバグって予測残り時間が変になりますが実際は20分もかからないで、終わります。
outputs = llm.generate(
prompts=prompt_token_ids,
sampling_params=sampling_params,
lora_request=LoRARequest("lora_1", 1, lora_path), # 第一引数は任意の文字列でよい
)
import json
data = [
{
"task_id": i,
"input": inputs[i], # あってもなくてもよい
"output": outputs[i].outputs[0].text.strip(),
}
for i in range(len(tasks))
]
file_path = "output.jsonl"
with open(file_path, "w", encoding="utf-8") as file:
for entry in data:
json.dump(entry, file, ensure_ascii=False)
file.write("\n")
これで終了です。
日本語のインストラクションチューニング用データセット DeL-TaiseiOzaki/Tengentoppa-sft-v1.0 のサブセットである YY1128/small_tengentoppa_12k でFine tuningしました。
unpreferedデータとpreferedデータがありますがpreferedデータのみを使用しました。
後で書く
後で書く
大規模言語モデル2024の最終課題リーダーボードでは2.99点でした。