dahara1 commited on
Commit
3f4726a
·
verified ·
1 Parent(s): 9838985

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +68 -0
README.md CHANGED
@@ -98,6 +98,74 @@ Plastic sheets: 4,500 pieces
98
  Sleeping mats: 8,500 pieces<eos>
99
  ```
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  ### See also
102
 
103
  詳細は[C3TR-Adapter](https://huggingface.co/webbigdata/C3TR-Adapter)を見てください
 
98
  Sleeping mats: 8,500 pieces<eos>
99
  ```
100
 
101
+ ### Sample code for High-speed inference (For NVIDIA Ampere or later, A100 or RTX 3090, etc.)
102
+ ```
103
+ import torch, os
104
+ from hqq.engine.hf import AutoTokenizer
105
+ from hqq.core.quantize import *
106
+ from hqq.utils.patching import *
107
+ from hqq.models.hf.base import AutoHQQHFModel
108
+
109
+ model_id = "webbigdata/C3TR-Adapter_hqq"
110
+ os.environ["TOKENIZERS_PARALLELISM"] = "1"
111
+ torch.backends.cuda.matmul.allow_tf32 = True
112
+ torch.backends.cudnn.allow_tf32 = True
113
+
114
+ compute_dtype = torch.bfloat16
115
+ model = AutoHQQHFModel.from_quantized(model_id, compute_dtype=compute_dtype)
116
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
117
+
118
+ patch_linearlayers(model, patch_add_quant_config,
119
+ BaseQuantizeConfig(nbits=4, group_size=64, quant_scale=False, quant_zero=False, axis=1))
120
+ HQQLinear.set_backend(HQQBackend.PYTORCH)
121
+ model.eval();
122
+
123
+ from hqq.utils.patching import prepare_for_inference
124
+ prepare_for_inference(model, backend="torchao_int4")
125
+
126
+ prompt_text = """You are a highly skilled professional Japanese-English and English-Japanese translator. Translate the given text accurately, taking into account the context and specific instructions provided. Steps may include hints enclosed in square brackets [] with the key and value separated by a colon:. Only when the subject is specified in the Japanese sentence, the subject will be added when translating into English. If no additional instructions or context are provided, use your expertise to consider what the most appropriate context is and provide a natural translation that aligns with that context. When translating, strive to faithfully reflect the meaning and tone of the original text, pay attention to cultural nuances and differences in language usage, and ensure that the translation is grammatically correct and easy to read. After completing the translation, review it once more to check for errors or unnatural expressions. For technical terms and proper nouns, either leave them in the original language or use appropriate translations as necessary. Take a deep breath, calm down, and start translating.
127
+
128
+ ### Instruction:
129
+ Translate Japanese to English.
130
+ When translating, please use the following hints:
131
+ [writeing_style: formal]
132
+ [米津玄師: Kenshi YONEZU]
133
+ [吉野源三郎: Genzaburo YOSHINO]
134
+
135
+ ### Input:
136
+ 「私自身、訳が分からない」
137
+ 「おそらく、訳が分からなかったことでしょう。私自身、訳が分からないところがありました」。
138
+
139
+  2023年2月下旬、東京都内のスタジオで上映された、「君たちはどう生きるか」の初号試写。米津玄師の歌うピアノバラードが流れ、エンド
140
+ ロールが終わった瞬間、灯りが点き、宮崎駿監督のコメントが読み上げられた。
141
+
142
+  客席から軽い笑い声が漏れた。私もその一人だった。あまりの展開の速さと、盛り込むだけ盛り込まれた情報を消化しきれず、茫然と座り>込んでいたが、その言葉で我に返った。
143
+
144
+  これは「宮崎アニメ」の集大成なのか、吉野源三郎の著書『君たちはどう生きるか』の再解釈なのか。とにかく、1回見ただけではとても全
145
+ 容を把握できなかった。
146
+
147
+ 「自分のことをやるしかない」
148
+  今回の作品は、公開前のプロモーションも、メディア関係者向けの試写も一切ないまま公開日を迎えた。異例の態勢の中、内容は無論、見>たことすら口外無用のキャスト・スタッフ向け試写に、なぜ私と両親が呼ばれたのかといえば、父が『君たちはどう生きるか』の著者・吉野>源三郎の長男で、私が孫にあたるからだ。
149
+
150
+  その5年ほど前の2017年11月、父と私は東京・小金井のスタジオジブリに招かれ、宮崎監督と対面していた。さらにさかのぼること半月ほど
151
+ 前、とあるイベントで宮崎監督が突然、次回作のタイトルが「君たちはどう生きるか」だと明らかにし、ニュースなどで話題になっていた。親族としては寝耳に水だったのでかなり驚いたのだが、宮崎監督は「うっかり喋ってしまいました」と詫びた上で、作品について語り始めた>。
152
+
153
+ ### Response:
154
+ """
155
+
156
+ tokens = tokenizer(prompt_text, return_tensors="pt",
157
+ padding=True, max_length=1600, truncation=True).to("cuda:0").input_ids
158
+
159
+ output = model.generate(
160
+ input_ids=tokens,
161
+ max_new_tokens=800,
162
+ do_sample=True,
163
+ num_beams=3, temperature=0.5, top_p=0.3,
164
+ repetition_penalty=1.0)
165
+ print(tokenizer.decode(output[0]))
166
+
167
+ ```
168
+
169
  ### See also
170
 
171
  詳細は[C3TR-Adapter](https://huggingface.co/webbigdata/C3TR-Adapter)を見てください