YAML Metadata
Warning:
empty or missing yaml metadata in repo card
(https://huggingface.co/docs/hub/model-cards#model-card-metadata)
base_model: llm-jp/llm-jp-3-13b
セットアップ
!pip uninstall torch torchvision torchaudio unsloth -y
!pip cache purge
!pip install --upgrade --force-reinstall --no-cache-dir torch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 triton pillow==10.2.0 --index-url https://download.pytorch.org/whl/cu121 --default-timeout=1000
## unsloth
!pip install "unsloth[cu121-torch211] @ git+https://github.com/unslothai/unsloth.git"
!pip install "unsloth[cu121-ampere-torch211] @ git+https://github.com/unslothai/unsloth.git"
!pip install -U bitsandbytes
!pip install -U transformers
!pip install -U accelerate
!pip install -U datasets
!pip install -U pef
ランタイム(セッション)の再起動
※上記インストール後、ライブラリの整合性を保証するため、ランタイム(セッション)の再起動をお願いします。
モデル・トークナイザの読み込み
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from unsloth import FastLanguageModel
import torch
# param
new_model_id = "3-13b-r16-alpha24-epo3-ichi-ely-oz_241130"
HF_TOKEN = "YOUR-HF-TOKEN"
model_id = "llm-jp/llm-jp-3-13b"
adapter_id = f'monamonamona/{new_model_id}_lora'
max_seq_length = 512
dtype = None
load_in_4bit = True
# Base model
model, tokenizer = FastLanguageModel.from_pretrained(
model_name=model_id,
dtype=dtype,
load_in_4bit=load_in_4bit,
trust_remote_code=True,
)
# LoRA join
from peft import PeftModel
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
入力データの準備
./elyza-tasks-100-TV_0.jsonlというファイルからデータセットをロードします。
import json
datasets = []
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
item = ""
for line in f:
line = line.strip()
item += line
if item.endswith("}"):
datasets.append(json.loads(item))
item = ""
推論
from tqdm import tqdm
FastLanguageModel.for_inference(model)
results = []
for dt in tqdm(datasets):
input = dt["input"]
prompt = f"""### 指示\n{input}\n### 回答\n"""
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
出力の保存
import re
import json
file_name = f"{new_model_id}-outputs.jsonl"
# ファイルにデータを書き込む
with open(file_name, 'w', encoding='utf-8') as f:
for result in results:
json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
f.write('\n')
Inference Providers
NEW
This model is not currently available via any of the supported Inference Providers.
The model cannot be deployed to the HF Inference API:
The model has no library tag.