Uploaded model

  • Developed by: ryusuke009
  • License: apache-2.0
  • Finetuned from model : llm-jp/llm-jp-3-13b

This llama model was trained 2x faster with Unsloth and Huggingface's TRL library.

実行方法

  • このコードはGoogleColabを使い、ELYZA-tasks-100-TVの出力を得るためのものです。
  • 推論用のファイル(json)を準備し、"推論用のJSONLファイルをアップロードしてください..."が表示されたら実行してください。

# 必要なライブラリをインストール
!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
!pip install -U peft

# 必要なライブラリを読み込み
from unsloth import FastLanguageModel
from peft import PeftModel
import torch
import json
from tqdm import tqdm
import re
from google.colab import files  # ファイルアップロード/ダウンロード用
from transformers import BitsAndBytesConfig

# ベースとなるモデルと学習したLoRAのアダプタ
model_id = "llm-jp/llm-jp-3-13b"
adapter_id = "ryusuke009/llm-jp-3-13b-finetune-2"

# 4bit量子化の設定
quantization_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_compute_dtype=torch.float16,
    bnb_4bit_use_double_quant=True,
    bnb_4bit_quant_type="nf4",
    llm_int8_enable_fp32_cpu_offload=True
)

# unslothのFastLanguageModelで元のモデルをロード
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name=model_id,
    quantization_config=quantization_config,
    trust_remote_code=True,
)

# 元のモデルにLoRAのアダプタを統合
model = PeftModel.from_pretrained(model, adapter_id)

# タスクとなるデータの読み込み(ファイルアップロード方式)
print("推論用のJSONLファイルをアップロードしてください...")
uploaded = files.upload()

# アップロードされたファイルを処理
datasets = []
filename = list(uploaded.keys())[0]
with open(filename, "r") as f:
    item = ""
    for line in f:
        line = line.strip()
        item += line
        if item.endswith("}"):
            datasets.append(json.loads(item))
            item = ""

print(f"データセットの読み込み完了: {len(datasets)}件のデータを処理します")

# 推論するためにモデルのモードを変更
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]
    prediction = re.sub(r"[*#]", "", prediction)
    
    results.append({"task_id": dt["task_id"], "input": input, "output": prediction})

# 結果をjsonlで保存とダウンロード
output_filename = "model_predictions_output.jsonl"
with open(output_filename, 'w', encoding='utf-8') as f:
    for result in results:
        json.dump(result, f, ensure_ascii=False)
        f.write('\n')

# 結果ファイルをダウンロード
files.download(output_filename)
print("処理が完了しました。結果ファイルがダウンロードされます。")
Downloads last month

-

Downloads are not tracked for this model. How to track
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 pipeline_tag.

Model tree for ryusuke009/llm-jp-3-13b-finetune-2

Finetuned
(1119)
this model