Downloads · 30 days
0
myamafuj/gemma-2-27b-it
gemma-2-27b-it is a machine learning model from myamafuj. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
※Omnicampusの環境では依存環境が壊れてunslothが使えなかったのでColab L4での再現方法
Downloads · 30 days
0
Access
Public
Updated Dec 17, 2024
Repo size
495 MB
Likes
0
Public
Click a slice to open those files.
.safetensors457 MB · 92%
From the Hugging Face model README
※Omnicampusの環境では依存環境が壊れてunslothが使えなかったのでColab L4での再現方法
!pip install --no-cache-dir unsloth==2024.12.4 ipywidgets flash-attn==2.7.0.post2
import json
from tqdm import tqdm
from unsloth import FastLanguageModel
model_name = 'myamafuj/gemma-2-27b-it'
max_seq_length = 2048
dtype = None
load_in_4bit = True
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = model_name,
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
trust_remote_code=True,
)
FastLanguageModel.for_inference(model)
datasets = []
with open("/content/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 = ""
prompt_template = \
"""###以下は、タスクを説明する指示です。要求を適切に満たす応答を書きなさい。
### 指示:
{}
### 応答:
"""
results = []
for dt in tqdm(datasets):
input = dt["input"]
prompt = prompt_template.format(input)
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})
with open(f"{model_name}_output.jsonl".split('/')[-1], 'w', encoding='utf-8') as f:
for result in results:
json.dump(result, f, ensure_ascii=False)
f.write('\n')
base_model: unsloth/gemma-2-27b-bnb-4bit tags:
This gemma2 model was trained 2x faster with Unsloth and Huggingface's TRL library.