Transformers
Safetensors
English
Japanese
text-generation-inference
unsloth
llama
trl
Inference Endpoints

Uploaded model

  • Developed by: rlcgn589
  • License: other
  • Finetuned from model : llm-jp/llm-jp-3-13b

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

Usage(Code for inference)

本モデルを用いてELYZA-tasks-100-TVの出力を得るためのコードです。 なお、松尾研LLM講座2024の最終コンペ課題の提出物を得ることを目的としたコードです。そのため、コンペの評価用途以外は使用禁止とします。 このコードで生成されたjsonlファイルは課題の成果として提出可能なフォーマットになっています。

環境構築

omnicampusとGoogle Colab下での環境構築方法は以下の通りです。

omnicampus

omnicampus環境下で事前にterminalで環境構築の必要があります。

# conda環境の構築
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"  

# このコマンドではいくつか質問があるので答えて下さい
bash Miniforge3-$(uname)-$(uname -m).sh  

# 以下、インストール先が/root/miniforge3であることを前提とします  
export PATH=/root/miniforge3/bin:$PATH  
conda init  

# ここで一度、terminalを立ち上げ直す必要があります。  
# 以下のリンク先に従い環境を作ります
# https://docs.unsloth.ai/get-started/installation/conda-install  
conda create --name unsloth_env python=3.10 pytorch-cuda=12.1 pytorch cudatoolkit xformers -c pytorch -c nvidia -c xformers -y  
conda activate unsloth_env  
pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"  
pip install --no-deps "trl<0.9.0" peft accelerate bitsandbytes

# jupyter notebook用のセットアップ。  
conda install -c conda-forge ipykernel -y
python -m ipykernel install --user --name=unsloth_env --display-name "Python (unsloth_env)"  

Google Colab

Google Colab環境下で推論前に環境構築の必要があります。 以下に示す推論用コードはRuntime TypeとしてPython 3、Hardware acceleratorとしてT4 GPU以上を想定しています。

!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

# ベースとなるモデルと学習したLoRAのアダプタ。
# model_idの値はomnicampusの環境におけるモデルのパスを表しており、それ以外の環境で実行する場合は変更の必要があります。
model_id = "models/models--llm-jp--llm-jp-3-13b/snapshots/cd3823f4c1fcbb0ad2e2af46036ab1b0ca13192a" # omnicampus環境の場合
model_id = "llm-jp/llm-jp-3-13b" # Google Colab環境の場合
adapter_id = "rlcgn589/llm-jp-3-13b-it-12_lora"

# Hugging Face Token を指定。
HF_TOKEN = "your Hugging Face Token" # omnicampus環境の場合

from google.colab import userdata
HF_TOKEN = userdata.get('HF_TOKEN') # Google Colab環境の場合

# unslothのFastLanguageModelで元のモデルをロード。
dtype = None # Noneにしておけば自動で設定
load_in_4bit = True # 今回は13Bモデルを扱うためTrue

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name=model_id,
    dtype=dtype,
    load_in_4bit=load_in_4bit,
    trust_remote_code=True,
)

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

# データセットの読み込み。
# omnicampusの開発環境では、左にタスクのjsonlをドラッグアンドドロップしてから実行。
# Google Colab環境下では、左のファイルアイコンをクリックしタスクのjsonlをドラッグアンドドロップしてから実行。
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 = ""

# モデルを用いてタスクの推論。

# 推論するためにモデルのモードを変更
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 = 1024, 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で保存。
jsonl_id = re.sub(".*/", "", adapter_id)
with open(f"./{jsonl_id}-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')

Datasets

Instruction tuning

本モデルは以下のデータセットでファインチューニングしました。

Language Dataset description
Japanese Aratako/Magpie-Tanuki-8B-annotated-96k MagpieとTanuki-8B-dpo-v1.0で作成されたデータにcalm3-22bでアノテーションを施した合成データを一部使用
Japanese tohoku-nlp/abc-multiple-choice オリジナルの4択の選択肢問題を一部加工(クイズと回答は変えていない)

Data Source

ファインチューニング用のデータセット作成に作成者が使用したモデルとツールを示します。データを使わせていただきありがとうございます。

Tanuki-8B-dpo-v1.0

https://huggingface.co/weblab-GENIAC/Tanuki-8B-dpo-v1.0

Magpie

@misc{xu2024magpiealignmentdatasynthesis,
      title={Magpie: Alignment Data Synthesis from Scratch by Prompting Aligned LLMs with Nothing}, 
      author={Zhangchen Xu and Fengqing Jiang and Luyao Niu and Yuntian Deng and Radha Poovendran and Yejin Choi and Bill Yuchen Lin},
      year={2024},
      eprint={2406.08464},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2406.08464}, 
}

CyberAgentLM3-22B-Chat

@misc{cyberagent-calm3-22b-chat,
      title={cyberagent/calm3-22b-chat},
      url={https://huggingface.co/cyberagent/calm3-22b-chat},
      author={Ryosuke Ishigami},
      year={2024},
}

abc-multiple-choice

https://github.com/cl-tohoku/abc-multiple-choice https://jedworkshop.github.io/JLR2024/materials/a-1.pdf

abc-multiple-choiceのライセンスに関する記載を抜粋して記します。

  • 本データセットのクイズ問題の著作権は abc/EQIDEN 実行委員会 に帰属します。
  • 本データセットは研究目的での利用許諾を得ているものです。商用目的での利用は不可とします。
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 rlcgn589/llm-jp-3-13b-it-12_lora

Finetuned
(1124)
this model

Datasets used to train rlcgn589/llm-jp-3-13b-it-12_lora