Downloads · 30 days
48
44% of all-time downloads
kazuHF/llm-jp-3-13b-it2_lora
llm-jp-3-13b-it2_lora is a text generation model from kazuHF. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
- Developed by: kazuHF - License: apache-2.0 - Finetuned from model : llm-jp/llm-jp-3-13b
Downloads · 30 days
48
44% of all-time downloads
All-time downloads
108
Public
Parameters
14.1B
9.6 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors9.1 GB · 100%
How the weights are stored.
U813.1B · 93%
From the Hugging Face model README
This llama model was trained 2x faster with Unsloth and Huggingface's TRL library.
# Googleドライブに接続
from google.colab import drive
drive.mount('/content/drive')
# 接続しているGPUの種類の表示
!nvidia-smi
# 必要なライブラリのインストール
!pip uninstall unsloth -y
!pip install xformers -q
!pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git" -q
!pip install -U torch -q
!pip install -U peft -q
# 必要なライブラリの読み込み
from unsloth import FastLanguageModel
from peft import PeftModel
import torch
import json
from tqdm import tqdm
import re
# ベースとなるモデルと学習したLoRAのアダプタ(本モデル)のIDやHugging face tokenを指定。
model_id = "llm-jp/llm-jp-3-13b"
adapter_id = "kazuHF/llm-jp-3-13b-it2_lora"
HF_TOKEN = "huggingface_token"
# unslothのFastLanguageModelで元のモデルとトークナイザーをロード。
model, tokenizer = FastLanguageModel.from_pretrained(
model_name=model_id,
dtype=None,
load_in_4bit=True,
trust_remote_code=True,
)
# 元のモデルにLoRAのアダプタを統合。
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
# 単一の入力文に基づいて推論する関数の定義。
def Decoder(input):
# 推論するためにモデルのモードを変更
FastLanguageModel.for_inference(model)
# 入力文による推論
prompt = f"""### 指示\n\n{str(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]
print(prompt)
print(prediction)
◇ 使用例
Decoder('犬と猫の見分け方は何か。')
# jsonlで作製されたタスクを一括処理する場合。
datasets = []
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
for line in f:
if line.strip():
datasets.append(json.loads(line))
# モデルで入力を一括処理。
results = []
for dt in tqdm(datasets):
# 推論するためにモデルのモードを変更
FastLanguageModel.for_inference(model)
# 入力文による推論
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})
# 結果をjsonlで保存。
json_file_id = re.sub(".*/", "", adapter_id)
with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
for result in results:
json.dump(result, f, ensure_ascii=False)
f.write('\n')
◆ Google Colaboratory上のGPUで推論する場合
◇ 環境設定
◇ 推論