File size: 3,600 Bytes
840ddad
 
 
 
 
 
 
 
0ec310f
840ddad
 
0ec310f
 
840ddad
 
 
 
 
1d3e717
840ddad
 
 
 
 
0ec310f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
base_model: llm-jp/llm-jp-3-13b
tags:
- text-generation-inference
- transformers
- unsloth
- llama
- trl
license: cc
language:
- en
datasets:
- weblab-GENIAC/aya-ja-nemotron-dpo-masked
---

# Uploaded  model

- **Developed by:** thesugar
- **License:** CC-BY-NC-SA  
- **Finetuned from model :** llm-jp/llm-jp-3-13b

This llama 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)

# HOW TO INFERENCE for competition evaluators

Google Colab L4 で実行

```ipynb
!pip install unsloth
!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir --no-deps git+https://github.com/unslothai/unsloth.git

HF_TOKEN = # WRITE YOUR HF_TOKEN
ELYZA_TASKS_100_TV_JSONL_PATH = # WRITE
# Output for elyza-tasks-100-tv is saved as "output.jsonl"


from huggingface_hub import login
login(HF_TOKEN)

from unsloth import FastLanguageModel
import torch

max_seq_length = 2048
dtype = torch.bfloat16
load_in_4bit = True
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "thesugar/llm-jp-3-13b-it_lora-DPO-12-16",
    max_seq_length = max_seq_length,
    dtype = dtype,
    load_in_4bit = load_in_4bit,
    token = HF_TOKEN,
)

import json
datasets = []
with open(ELYZA_TASKS_100_TV_JSONL_PATH, "r") as f:
    item = ""
    for line in f:
      line = line.strip()
      item += line
      if item.endswith("}"):
        datasets.append(json.loads(item))
        item = ""

from tqdm import tqdm

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 = 2048, 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("output.jsonl", "w") as f:
  for r in results:
    f.write(json.dumps(r, ensure_ascii=False) + "\n")
```

# Development steps
- `llm-jp/llm-jp-3-13b` を量子化
- インストラクションチューニング
  - `ichikara-instruction` データセットの `ichikara-instruction-003-001-1.json` の全データを使用
- direct policy optimization
  - `weblab-GENIAC/aya-ja-nemotron-dpo-masked` からランダムに選択した 100 レコードを使用

# Used datasets and their licenses
## ichikara-instruction: LLMのための日本語インストラクションデータ
- [LLMのための日本語インストラクションデータ 公開ページ – LIAT-AIP homepage](https://liat-aip.sakura.ne.jp/wp/llm%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AE%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%A9%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%87%E3%83%BC%E3%82%BF%E4%BD%9C%E6%88%90/)

関根聡, 安藤まや, 後藤美知子, 鈴木久美, 河原大輔, 井之上直也, 乾健太郎. ichikara-instruction: LLMのための日本語インストラクションデータの構築. 言語処理学会第30回年次大会(2024)
CC-BY-NC-SA  

## weblab-GENIAC/aya-ja-nemotron-dpo-masked
- [creator](https://huggingface.co/weblab-GENIAC)
- [repository](https://huggingface.co/datasets/weblab-GENIAC/aya-ja-nemotron-dpo-masked)

weblab-GENIAC  
weblab-GENIAC/aya-ja-nemotron-dpo-masked  
Apache License 2.0