Uploaded model

  • Developed by: itirei
  • 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.

動かし方

インストール

pip install -U bitsandbytes transformers accelerate datasets peft

使用方法

from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
import torch

HF_TOKEN = "有効なHuggingFaceトークン"
from google.colab import userdata
HF_TOKEN = userdata.get('HF_API_KEY')

base_model_id = "llm-jp/llm-jp-3-13b"
adapter_id = "itirei/llm-jp-3-13b-1124"

### QLoRA設定
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16,
)

### モデルの読み込み
model = AutoModelForCausalLM.from_pretrained(
    base_model_id,
    quantization_config=bnb_config,
    device_map="auto",
    token=HF_TOKEN
)
### トークナイザーの読み込み
tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True, token=HF_TOKEN)

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

### 生成用の関数を定義
def generate_response(input):
  prompt = f"""### 指示
  {input}
  \#\#\# 回答
  """

  tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
  attention_mask = torch.ones_like(tokenized_input)

  with torch.no_grad():
      outputs = model.generate(
          tokenized_input,
          attention_mask=attention_mask,
          max_new_tokens=100,
          do_sample=False,
          repetition_penalty=1.2,
          pad_token_id=tokenizer.eos_token_id
      )[0]
  output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
  return output

### 使用例
input = "### 指示\nあなたの指示をここに入力してください\n### 回答\n"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)

with torch.no_grad():
    outputs = model.generate(**inputs, max_new_tokens=100, do_sample=False, repetition_penalty=1.2)

response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
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 third-party Inference Providers, and HF Inference API was unable to determine this model’s pipeline type.

Model tree for itirei/llm-jp-3-13b-1124

Finetuned
(1130)
this model