Downloads · 30 days
0
SODM/llm-jp-3-13b-unsloth-sft-elyza-ep2-lr2e4_lora
llm-jp-3-13b-unsloth-sft-elyza-ep2-lr2e4_lora is a machine learning model from SODM. 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. The card lists the license as cc-by-sa-4.0.
モデル名: SODM/llm-jp-3-13b-sft-basecode-ep2-lr2e4 モデルの目的: 東京大学 松尾・岩澤研究室が主催するLLM講座2024の最終課題コンペのためにベースコードを用いてSFTを施したものです。 アーキテクチャ: Transformer-based Language Model オリジナルの実装 (もしあれば): llm-jp/llm-jp-3-13b ライセンス: cc-by-sa-4.0
Downloads · 30 days
0
Access
Public
Updated Dec 19, 2024
Repo size
501 MB
Likes
0
Public
Click a slice to open those files.
.safetensors501 MB · 99%
From the Hugging Face model README
# bash
# 必要なライブラリをインストール
pip install unsloth
pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
pip install -U torch -q
pip install -U peft -q
# Python
# 必要なライブラリのインポート
import re
import json
import pprint as pp
import torch
from tqdm import tqdm
from unsloth import FastLanguageModel
from peft import PeftModel
model_id = "llm-jp/llm-jp-3-13b"
adapter_id = "SODM/llm-jp-3-13b-unsloth-sft-elyza-ep2-lr2e4_lora"
# モデルとトークナイザの読み込み
# unslothのFastLanguageModelで元のモデルをロード。
dtype = None
load_in_4bit = True
model, tokenizer = FastLanguageModel.from_pretrained(
model_name=model_id,
dtype=dtype,
load_in_4bit=load_in_4bit,
trust_remote_code=True,
)
# Hugging Face Token
HF_TOKEN = **YOUR_TOKEN**
# LoRAのアダプタを統合。
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
# 入力データの処理(評価用データがGoogleDriveのMyDrive/に保存されている場合)
datasets = []
with open("/content/drive/MyDrive/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 = ""
# 推論
FastLanguageModel.for_inference(model)
results = []
for dt in tqdm(datasets):
input = dt["input"]
prompt = f"""### 指示\n{input}\n改行せずに指示された形式で回答してください。\n### 回答\n"""
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens = 2048, 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})
# jsonlで保存
with open(f"/content/drive/output.jsonl", 'w', encoding='utf-8') as f:
for result in results:
json.dump(result, f, ensure_ascii=False)
f.write('\n')
pp.pprint(results)