Update README.md
Browse files
README.md
CHANGED
@@ -1,8 +1,113 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# Model Card for Model ID
|
7 |
|
8 |
<!-- Provide a quick summary of what the model is/does. -->
|
@@ -17,12 +122,12 @@ tags: []
|
|
17 |
|
18 |
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
19 |
|
20 |
-
- **Developed by:** [
|
21 |
- **Funded by [optional]:** [More Information Needed]
|
22 |
- **Shared by [optional]:** [More Information Needed]
|
23 |
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [
|
25 |
-
- **License:** [
|
26 |
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
|
28 |
### Model Sources [optional]
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
+
license: cc-by-2.0
|
4 |
+
datasets:
|
5 |
+
- llm-jp/databricks-dolly-15k-ja
|
6 |
+
- kinokokoro/ichikara-instruction-003
|
7 |
+
language:
|
8 |
+
- ja
|
9 |
+
base_model:
|
10 |
+
- llm-jp/llm-jp-3-13b-instruct
|
11 |
---
|
12 |
|
13 |
+
# sample use
|
14 |
+
"""
|
15 |
+
!pip install -U bitsandbytes
|
16 |
+
!pip install -U transformers
|
17 |
+
!pip install -U accelerate
|
18 |
+
!pip install -U datasets
|
19 |
+
!pip install -U peft
|
20 |
+
|
21 |
+
#### notebookでインタラクティブな表示を可能とする(ただし、うまく動かない場合あり)
|
22 |
+
!pip install ipywidgets --upgrade
|
23 |
+
|
24 |
+
from transformers import (
|
25 |
+
AutoModelForCausalLM,
|
26 |
+
AutoTokenizer,
|
27 |
+
BitsAndBytesConfig,
|
28 |
+
)
|
29 |
+
from peft import PeftModel
|
30 |
+
import torch
|
31 |
+
from tqdm import tqdm
|
32 |
+
import json
|
33 |
+
|
34 |
+
#### Hugging Faceで取得したTokenをこちらに貼る。
|
35 |
+
HF_TOKEN = "Your Hugging Face Token"
|
36 |
+
|
37 |
+
#### ベースとなるモデルと学習したLoRAのアダプタ。
|
38 |
+
# model_idの値はomnicampusの環境におけるモデルのパスを表しており、それ以外の環境で実行する場合は変更の必要があります。
|
39 |
+
model_id = "models/models--llm-jp--llm-jp-3-13b/snapshots/cd3823f4c1fcbb0ad2e2af46036ab1b0ca13192a"
|
40 |
+
|
41 |
+
adapter_id = "https://huggingface.co/karsh-uk/llm-jp-3-13b-finetune05" # こちらにアップロードしたHugging FaceのIDを指定してください。
|
42 |
+
|
43 |
+
#### QLoRA config
|
44 |
+
bnb_config = BitsAndBytesConfig(
|
45 |
+
load_in_4bit=True,
|
46 |
+
bnb_4bit_quant_type="nf4",
|
47 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
48 |
+
)
|
49 |
+
|
50 |
+
#### Load model
|
51 |
+
model = AutoModelForCausalLM.from_pretrained(
|
52 |
+
model_id,
|
53 |
+
quantization_config=bnb_config,
|
54 |
+
device_map="auto",
|
55 |
+
token = HF_TOKEN
|
56 |
+
)
|
57 |
+
|
58 |
+
#### Load tokenizer
|
59 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True, token = HF_TOKEN)
|
60 |
+
|
61 |
+
#### 元のモデルにLoRAのアダプタを統合。
|
62 |
+
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
|
63 |
+
|
64 |
+
#### データセットの読み込み。
|
65 |
+
datasets = []
|
66 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
67 |
+
item = ""
|
68 |
+
for line in f:
|
69 |
+
line = line.strip()
|
70 |
+
item += line
|
71 |
+
if item.endswith("}"):
|
72 |
+
datasets.append(json.loads(item))
|
73 |
+
item = ""
|
74 |
+
|
75 |
+
#### llmjp
|
76 |
+
results = []
|
77 |
+
for data in tqdm(datasets):
|
78 |
+
|
79 |
+
input = data["input"]
|
80 |
+
|
81 |
+
prompt = f"""### 指示
|
82 |
+
{input}
|
83 |
+
### 回答
|
84 |
+
"""
|
85 |
+
|
86 |
+
tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
|
87 |
+
attention_mask = torch.ones_like(tokenized_input)
|
88 |
+
with torch.no_grad():
|
89 |
+
outputs = model.generate(
|
90 |
+
tokenized_input,
|
91 |
+
attention_mask=attention_mask,
|
92 |
+
max_new_tokens=100,
|
93 |
+
do_sample=False,
|
94 |
+
repetition_penalty=1.2,
|
95 |
+
pad_token_id=tokenizer.eos_token_id
|
96 |
+
)[0]
|
97 |
+
output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
|
98 |
+
|
99 |
+
results.append({"task_id": data["task_id"], "input": input, "output": output})
|
100 |
+
|
101 |
+
import re
|
102 |
+
jsonl_id = re.sub(".*/", "", adapter_id)
|
103 |
+
with open(f"./{jsonl_id}-outputs05.jsonl", 'w', encoding='utf-8') as f:
|
104 |
+
for result in results:
|
105 |
+
json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
|
106 |
+
f.write('\n')
|
107 |
+
|
108 |
+
"""
|
109 |
+
|
110 |
+
|
111 |
# Model Card for Model ID
|
112 |
|
113 |
<!-- Provide a quick summary of what the model is/does. -->
|
|
|
122 |
|
123 |
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
124 |
|
125 |
+
- **Developed by:** [Y.Takahashi]
|
126 |
- **Funded by [optional]:** [More Information Needed]
|
127 |
- **Shared by [optional]:** [More Information Needed]
|
128 |
- **Model type:** [More Information Needed]
|
129 |
+
- **Language(s) (NLP):** [Japanese]
|
130 |
+
- **License:** [Creative Commons Attribution Share Alike 3.0]
|
131 |
- **Finetuned from model [optional]:** [More Information Needed]
|
132 |
|
133 |
### Model Sources [optional]
|