Downloads · 30 days
0
ryomac/llm-jp-3-13b-ry-ft1
llm-jp-3-13b-ry-ft1 is a machine learning model from ryomac. 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 llama3.1.
- Developed by: ryomac - Finetuned from model : llm-jp/llm-jp-3-13b
Downloads · 30 days
0
Access
Public
Updated Dec 26, 2024
Repo size
250 MB
Likes
0
Public
Click a slice to open those files.
.safetensors250 MB · 98%
From the Hugging Face model README
以下は、elyza-tasks-100-TV_0.jsonlの回答のための推論用のコードです。
!pip install -U pip==24.3.1
!pip install -U transformers==4.46.3
!pip install -U bitsandbytes==0.45.0
!pip install -U accelerate==1.2.1
!pip install -U datasets==3.2.0
!pip install -U peft==0.14.0
!pip install -U trl==0.12.2
from transformers import (
AutoModelForCausalLM,
AutoTokenizer,
BitsAndBytesConfig,
TrainingArguments,
logging,
)
from peft import (
LoraConfig,
PeftModel,
get_peft_model,
)
import os, torch, gc, re
from datasets import load_dataset
import bitsandbytes as bnb
from trl import SFTTrainer
# 各自HugginFaceのトークンを取得してください
HF_TOKEN = "your-token"
model_id = "llm-jp/llm-jp-3-13b"
adapter_id = "ryomac/llm-jp-3-13b-ry-ft1"
# QLoRA用の設定
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",
token=HF_TOKEN
)
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True, token=HF_TOKEN)
# Peftモデルを適用
model = PeftModel.from_pretrained(model, adapter_id, token=HF_TOKEN)
# データセットの読み込み。
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 = ""
results = []
for data in tqdm(datasets):
input = data["input"]
prompt = f"""### 指示
{input}
### 回答:
"""
tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
tokenized_input,
max_new_tokens=300,
do_sample=False,
repetition_penalty=1.2
)[0]
output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
results.append({"task_id": data["task_id"], "input": input, "output": output})
model_name = re.sub(".*/", "", model_name)
with open(f"./{model_name}-my-original-outputs.jsonl", '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')