|
--- |
|
base_model: |
|
- Google/gemma-2-27b |
|
- Hibiki252/gemma-2-27b-4bit |
|
tags: |
|
- text-generation-inference |
|
- transformers |
|
- unsloth |
|
- gemma2 |
|
- trl |
|
license: apache-2.0 |
|
language: |
|
- en |
|
--- |
|
|
|
# Uploaded model |
|
|
|
- **Developed by:** Hibiki252 |
|
- **License:** apache-2.0 |
|
- **Finetuned from model :** Hibiki252/gemma-2-27b-4bit |
|
|
|
This model is SFTed using data from DeL-TaiseiOzaki/Tengentoppa-sft-v1.0 against Hibiki252/gemma-2-27b-4bit, which is a model stored in google/gemma-2-27b with 4bit settings. |
|
This gemma2 model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library. |
|
|
|
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth) |
|
|
|
### Training Data and License |
|
|
|
This model is fine-tuned using the dataset [DeL-TaiseiOzaki/Tengentoppa-sft-v1.0](https://huggingface.co/datasets/DeL-TaiseiOzaki/Tengentoppa-sft-v1.0) under the [CC BY 4.0 License](https://creativecommons.org/licenses/by/4.0/). |
|
The dataset was compiled from the following publicly available datasets: |
|
・Hachi-Alpaca_newans (GENIAC-Team-Ozaki/Hachi-Alpaca_newans) |
|
・Chatbot Arena Japanese Dataset for Karakuri LM 8x7B Chat v0.1 AWQ (GENIAC-Team-Ozaki/chatbot-arena-ja-karakuri-lm-8x7b-chat-v0.1-awq) |
|
・WikiHow NFQA Japanese Cleaned Dataset (GENIAC-Team-Ozaki/WikiHowNFQA-ja_cleaned) |
|
・Evolutionary Alpaca Generation 3 500 Cleaned Dataset (GENIAC-Team-Ozaki/Evol-Alpaca-gen3-500_cleaned) |
|
・Open Assistant 33k Japanese Reformatted Dataset (GENIAC-Team-Ozaki/oasst2-33k-ja_reformatted) |
|
・SFT Dataset For Self-Taught Evaluators Iteration 1 (Aratako/SFT-Dataset-For-Self-Taught-Evaluators-iter1) |
|
・Japanese Debate Argument Instruction Dataset (GENIAC-Team-Ozaki/debate_argument_instruction_dataset_ja) |
|
・Japanese Helpful-Harmless RLHF 49k Dataset (fujiki/japanese_hh-rlhf-49k) |
|
・Japanese Government FAQs 22k Dataset (GENIAC-Team-Ozaki/JaGovFaqs-22k) |
|
・Evolutionary Helpful-Harmless RLHF Generation 3 1k Cleaned Dataset (GENIAC-Team-Ozaki/Evol-hh-rlhf-gen3-1k_cleaned) |
|
・Magpie Qwen 2.5 32B Reasoning 100k Dataset (DeL-TaiseiOzaki/magpie-qwen2.5-32b-reasoning-100k) |
|
・Japanese Reasoning Finetuning Dataset (DeL-TaiseiOzaki/reasoning-finetuning-ja) |
|
・Magpie LLM Japanese 3.13B 20k Dataset (DeL-TaiseiOzaki/magpie-llm-jp-3-13b-20k) |
|
・Magpie SFT Version 1.0 Dataset (llm-jp/magpie-sft-v1.0) |
|
・Aya Japanese Nemotron DPO Masked Dataset (weblab-GENIAC/aya-ja-nemotron-dpo-masked) |
|
・Open Platypus Japanese Masked Dataset (weblab-GENIAC/Open-Platypus-Japanese-masked) |
|
・Synthesis sft data by mixtral-8×22B (hatakeyama-llm-team/AutoGeneratedJapaneseQA-CC) |
|
|
|
### Interfere Guide |
|
To perform inference, execute the following code. |
|
```python |
|
# 必要なライブラリを読み込み |
|
from unsloth import FastLanguageModel |
|
from peft import PeftModel |
|
import torch |
|
import json |
|
from tqdm import tqdm |
|
import re |
|
|
|
# ベースとなるモデルと学習したLoRAのアダプタ(Hugging FaceのIDを指定)。 |
|
model_id = "Hibiki252/gemma-2-27b-4bit" |
|
adapter_id = "Hibiki252/gemma-2-27b-ten-adapter" |
|
|
|
# Hugging Face Token を指定。 |
|
HF_TOKEN = <your token> |
|
|
|
# unslothのFastLanguageModelで元のモデルをロード。 |
|
dtype = None # 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, |
|
) |
|
|
|
# 元のモデルにLoRAのアダプタを統合。 |
|
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 = "" |
|
|
|
# プロンプト |
|
base_prompt = ( |
|
"""あなたは世界最高峰のAIアシスタントです。以下のルールと指示に従って、入力されたタスクに対して具体的かつ正確な回答をしてください。 |
|
【ルール】 |
|
- タスクの意図を十分に理解して回答してください。 |
|
- 質問と直接関係ない情報は書かないでください。 |
|
- 特別な指定がない限り、プログラミングコードは出力しないでください。 |
|
- 回答は特別な指示がない限り日本語で答えてください。 |
|
- 必要に応じて根拠や理由を説明してください。 |
|
以下がタスクです。""" |
|
|
|
# モデルを用いてタスクの推論。 |
|
|
|
# 推論するためにモデルのモードを変更 |
|
FastLanguageModel.for_inference(model) |
|
|
|
results = [] |
|
for dt in tqdm(datasets): |
|
input = dt["input"] |
|
|
|
prompt = f"""{base_prompt}\n### 指示\n{input}\n### 回答\n""" |
|
|
|
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device) |
|
|
|
outputs = model.generate(**inputs, max_new_tokens = 4048, 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("gemma27b_ten", 'w', encoding='utf-8') as f: |
|
for result in results: |
|
json.dump(result, f, ensure_ascii=False) |
|
f.write('\n') |