Text Generation
Transformers
PyTorch
Japanese
open-llama
Inference Endpoints
tahomatx commited on
Commit
f6cc9cf
1 Parent(s): 13f2a3e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +50 -14
README.md CHANGED
@@ -26,21 +26,56 @@ Wikipediaのデータが中心なので、回答はWikipediaっぽい感じに
26
  V1に比べると、モノや場所などの概念を持っているようないないような。
27
  データセットはV1と同じですが、学習ステップ数が76,000と延長。
28
 
 
 
29
 
30
- サンプルコード。モデルのロードは少し時間が掛かりますが、Inferenceは結構速いです。
31
- GenerationConfigが必須。モデルが小さいので、beam searchや repeat関係は結構重要。
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  ```python
35
- from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
36
  import torch
37
- import time
38
  import random
39
  import numpy as np
 
 
40
 
41
  #
42
  # Fix seed
43
  #
 
44
  seed = 42
45
 
46
  random.seed(seed)
@@ -55,14 +90,11 @@ torch.use_deterministic_algorithms = True
55
  torch.set_default_dtype(torch.bfloat16)
56
 
57
 
58
-
59
- model_id = "aerner/lm-v1"
60
-
61
 
62
  text = """### Instruction:
63
  東京駅について説明してください。
64
 
65
-
66
  ### Context:
67
 
68
 
@@ -71,21 +103,25 @@ text = """### Instruction:
71
  """
72
 
73
  with torch.no_grad():
74
- tokenizer = AutoTokenizer.from_pretrained(model_id)
75
- tokenized_input = tokenizer(text, return_tensors="pt").to('cuda')
76
-
77
  model = AutoModelForCausalLM.from_pretrained(
78
- model_id, device_map="auto", torch_dtype=torch.bfloat16)
 
 
 
 
79
 
80
  generation_config = GenerationConfig(
81
  max_new_tokens=256,
82
  min_new_tokens=1,
83
  early_stopping=True,
84
- do_sample=True,
85
 
 
86
  num_beams=8,
 
87
  temperature=1.0,
88
  top_p=0.6,
 
89
  penalty_alpha=0.4,
90
  no_repeat_ngram_size=4,
91
  repetition_penalty=1.4,
@@ -96,13 +132,13 @@ with torch.no_grad():
96
 
97
  start = time.time()
98
 
 
99
  generation_output = model.generate(
100
  input_ids=tokenized_input['input_ids'],
101
  generation_config=generation_config,
102
  return_dict_in_generate=True,
103
  output_scores=True,
104
  )
105
-
106
  for s in generation_output.sequences:
107
  output = tokenizer.decode(s)
108
  print(output)
 
26
  V1に比べると、モノや場所などの概念を持っているようないないような。
27
  データセットはV1と同じですが、学習ステップ数が76,000と延長。
28
 
29
+ 学習記録はこちら
30
+ https://wandb.ai/tahomatx/huggingface/runs/xyy19rbx
31
 
 
 
32
 
33
+ Instruction-Answer例
34
+ ※ モデルは、Instructionの後に、Answerを追記します。入力は、Instruction部分までを入力します。
35
+
36
+ ```
37
+ ### Instruction:
38
+ 東京駅について説明してください。
39
+
40
+ ### Context:
41
+
42
+
43
+
44
+ ### Answer:
45
+ 東急東横線・神楽坂駅から徒歩約10分のところに位置している。改札口は1ヶ所のみで、乗車券は駅前ロータリーに設置されており、自動券売機等の設備はない。出入口は1番から4番までの合計6ヵ所あり、それぞれのホームには駐輪場が設けられている(2019年3月現在)。 ⁇ 無人駅である。 ⁇ 簡易委託駅であったが、2018年3月31日をもって廃止され、有人駅時代の駅舎は取り壊されてしまった。
46
+ JR東日本ステーションサービスによる業務
47
+ ```
48
+
49
+ ```
50
+ ### Instruction:
51
+ ドラえもんについて説明してください。
52
+
53
+
54
+ ### Context:
55
+
56
+
57
+
58
+ ### Answer:
59
+ 2007年10月1日から2008年3月31日まで放送された約5分の短編ドラマ。主演は声優の山口智充、脚本・演出は鈴木亜美子。原作とは異なるストーリーが展開されており、登場人物の設定もそれに合わせて変更され ている。
60
+ ```
61
+
62
+
63
+
64
+
65
+ サンプルコードです。
66
 
67
  ```python
68
+ from transformers import OpenLlamaForCausalLM, LlamaTokenizer, GenerationConfig, TextStreamer, AutoModelForCausalLM
69
  import torch
 
70
  import random
71
  import numpy as np
72
+ import time
73
+
74
 
75
  #
76
  # Fix seed
77
  #
78
+
79
  seed = 42
80
 
81
  random.seed(seed)
 
90
  torch.set_default_dtype(torch.bfloat16)
91
 
92
 
93
+ model_id = "aerner/lm-v2"
 
 
94
 
95
  text = """### Instruction:
96
  東京駅について説明してください。
97
 
 
98
  ### Context:
99
 
100
 
 
103
  """
104
 
105
  with torch.no_grad():
106
+ tokenizer = LlamaTokenizer.from_pretrained(model_id)
 
 
107
  model = AutoModelForCausalLM.from_pretrained(
108
+ model_id,
109
+ device_map="auto",
110
+ torch_dtype=torch.bfloat16,
111
+ # load_in_8bit=True,
112
+ )
113
 
114
  generation_config = GenerationConfig(
115
  max_new_tokens=256,
116
  min_new_tokens=1,
117
  early_stopping=True,
 
118
 
119
+ do_sample=True,
120
  num_beams=8,
121
+
122
  temperature=1.0,
123
  top_p=0.6,
124
+
125
  penalty_alpha=0.4,
126
  no_repeat_ngram_size=4,
127
  repetition_penalty=1.4,
 
132
 
133
  start = time.time()
134
 
135
+ tokenized_input = tokenizer(text, return_tensors="pt").to('cuda')
136
  generation_output = model.generate(
137
  input_ids=tokenized_input['input_ids'],
138
  generation_config=generation_config,
139
  return_dict_in_generate=True,
140
  output_scores=True,
141
  )
 
142
  for s in generation_output.sequences:
143
  output = tokenizer.decode(s)
144
  print(output)