mssfj commited on
Commit
3f66ec1
·
verified ·
1 Parent(s): c4f7542

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +71 -1
README.md CHANGED
@@ -1,6 +1,9 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
4
  ---
5
 
6
  # Model Card for Model ID
@@ -14,6 +17,13 @@ tags: []
14
  ### Model Description
15
 
16
  <!-- Provide a longer summary of what this model is. -->
 
 
 
 
 
 
 
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
 
@@ -37,6 +47,66 @@ This is the model card of a 🤗 transformers model that has been pushed on the
37
 
38
  <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  ### Direct Use
41
 
42
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
 
1
  ---
2
  library_name: transformers
3
+ datasets:
4
+ - llm-jp/magpie-sft-v1.0
5
+ base_model:
6
+ - google/gemma-2-9b
7
  ---
8
 
9
  # Model Card for Model ID
 
17
  ### Model Description
18
 
19
  <!-- Provide a longer summary of what this model is. -->
20
+ gemma-2-9bを4bit量子化しQloraでllm-jp/magpie-sft-v0.1を用いInstruction Turnnigしたモデルです。
21
+
22
+ 以下のチャットテンプレートを定義しています。
23
+ <bos>{%- for message in messages %}
24
+ <start_of_turn>{{ message.role }}: {{ message.content }}<end_of_turn>
25
+ {%- endfor %}{% if add_generation_prompt %}
26
+ <start_of_turn>assistant: {% endif %}<eos>
27
 
28
  This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
29
 
 
47
 
48
  <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
49
 
50
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
51
+ import torch
52
+ from peft import PeftModel, PeftConfig
53
+
54
+ model_name = "mssfj/gemma-2-9b-bnb-4bit-chat-template"
55
+ lora_weight = "mssfj/gemma-2-9b-4bit-magpie"
56
+
57
+ # 量子化設定
58
+ quantization_config = BitsAndBytesConfig(
59
+ load_in_4bit=False,
60
+ bnb_4bit_compute_dtype=torch.bfloat16,
61
+ bnb_4bit_quant_type="nf4",
62
+ bnb_4bit_use_double_quant=False
63
+ )
64
+
65
+ # ベースモデルのロード
66
+ base_model = AutoModelForCausalLM.from_pretrained(
67
+ model_name,
68
+ quantization_config=quantization_config,
69
+ device_map="auto"
70
+ )
71
+
72
+ # QLoRA済みモデルの適用
73
+ model = PeftModel.from_pretrained(base_model, lora_weight)
74
+
75
+ # トークナイザのロード
76
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
77
+
78
+ input="""「図書館で本を読んだ。」という文は「どこで本を読んだ?」という疑問文に直すことができます。
79
+ このとき、「図書館」は「どこ」の疑問詞タグを持ちます。
80
+
81
+ それでは、「本」という単語はどのような疑問詞タグを持つでしょうか? 全て選んでください。対応するものがない場合は「なし」と答えてください。
82
+ """
83
+
84
+ messages = [
85
+ {"role": "system", "content": """日本で一番高い山は?
86
+ """},
87
+ {"role": "user", "content": input},
88
+ ]
89
+
90
+ # チャットテンプレートを適用
91
+ input_ids = tokenizer.apply_chat_template(
92
+ messages,
93
+ tokenize=True,
94
+ add_generation_prompt=True,
95
+ return_tensors="pt"
96
+ ).to(model.device)
97
+
98
+ outputs = model.generate(
99
+ input_ids,
100
+ max_new_tokens=256,
101
+ temperature=0.2,
102
+ do_sample=True,
103
+ eos_token_id=tokenizer.eos_token_id,
104
+ pad_token_id=tokenizer.pad_token_id,
105
+ early_stopping=True,
106
+ )
107
+
108
+ response = tokenizer.decode(outputs[0][input_ids.shape[1]:], skip_special_tokens=True)
109
+
110
  ### Direct Use
111
 
112
  <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->