Edit model card

Model card

英日、日英翻訳用モデルC3TR-AdapterのHQQ(Half-Quadratic Quantization)4bit量子化版です。
This is the HQQ(Half-Quadratic Quantization) 4bit quantized version of the C3TR-Adapter, model for English-Japanese and Japanese-English translation.

簡単に動かす方法 (A quick way to try it)

Colab有料版(L4かA100)が必要ですが以下のColabで試す事ができます
You need a paid version of Colab (L4 or A100), but you can try it out with the following Colab
C3TR_Adapter_hqq_v2_Paid_Colab_sample

install

hqqの公式サイトをご確認下さい
Check official hqq

私はソースからhqqをインストール( pip install git+https://github.com/mobiusml/hqq.git ではなくてローカルにclone)しないと動かす事ができませんでした。
I couldn't get it to work without installing hqq from source(Not pip install git+https://github.com/mobiusml/hqq.git ).

A100や30x0シリーズのような新しいGPUが必要です。
残念ながらColabの無料版(T4)では動きません

We need Newer GPUs such as the A100 and 30x0 series. Unfortunately, this does not work with the free version of Colab(T4).

# transformers 4.41.1
pip install transformers==4.41.1

# hqq 0.1.7.post2
git clone https://github.com/mobiusml/hqq
cd hqq
pip install .

Sample code

from transformers import AutoModelForCausalLM, AutoTokenizer
from hqq.models.hf.base import AutoHQQHFModel

model_id = "webbigdata/C3TR-Adapter_hqq"
model = AutoHQQHFModel.from_quantized(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)

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.

### Instruction:
Translate Japanese to English.
When translating, please use the following hints:
[writeing_style: formal]
[岡浩: Hiroshi Oka]
[植草泰彦: Yasuhiko Uekusa]

### Input:
5月20日(現地時間同日)、エジプト・アラブ共和国の首都カイロにおいて、岡浩駐エジプト日本国特命全権大使、植草泰彦内閣府国際平和協力本部事務局参事官及びサハル・アル・ジョブリー国連パレスチナ難民救済事業機関(UNRWA)カイロ事務所長(Ms. Sahar Al Jobury, Chief, the United Nations Relief and Works Agency for Palestine Refugees in the Near East (UNRWA) Representative Office in Cairo)の列席のもと、UNRWAに対して提供する物資の供与式を実施しました。

 スリーピングマット等の支援物資は、18日(現地時間17日)、アラブ首長国連邦の備蓄倉庫からエジプトのエルアリーシュ空港に到着し、
今後、エジプト赤新月社の協力を得てガザ地区まで輸送され、パレスチナ被災民のために活用されます。

(参考)UNRWAによるパレスチナ被災民支援活動に対する物資協力
概要
 パレスチナ暫定自治区であるガザ地区において人道的な国際救援活動を行っている国際連合パレスチナ難民救済事業機関(UNRWA)に対し、国際平和協力法に基づき、先方から依頼のあった物資を提供する。
提供物資
 内閣府が人道支援のためにドバイに備蓄している以下の物資を提供。
毛布 5,000枚
給水容器 10,000個
ビニールシート 4,500枚
スリーピングマット 8,500枚

### Response:
"""

tokens = tokenizer(prompt_text, return_tensors="pt",
        padding=True, max_length=1600, truncation=True).to("cuda:0").input_ids

output = model.generate(
        input_ids=tokens,
        max_new_tokens=800,
        do_sample=True,
        num_beams=3, temperature=0.5, top_p=0.3,
        repetition_penalty=1.0)
print(tokenizer.decode(output[0]))

出力(Output)

### Response:
On May 20 (local time), H.E. Mr. Hiroshi Oka, Ambassador Extraordinary and Plenipotentiary of Japan to the Arab Republic of Egypt, Mr. Yasuhiko Uekusa, Counsellor, International Cooperation Bureau, Cabinet Office, and Ms. Sahar Al Jobury, Chief, the United Nations Relief and Works Agency for Palestine Refugees in the Near East (UNRWA) Representative Office in Cairo, attended the handover ceremony of relief supplies to be provided to UNRWA.

The relief supplies such as sleeping mats were received on May 18 (local time, May 17) at El Arish Airport in the Arab Republic of Egypt from a warehouse in the United Arab Emirates. The supplies will be transported to the Gaza Strip with the cooperation of the Egyptian Red Crescent Society and will be utilized for Palestinian refugees.

(Reference) Provision of Relief Supplies to UNRWA for Assistance to Palestinian Refugees
Overview
Based on the International Cooperation Law, Japan will provide relief supplies to the United Nations Relief and Works Agency for Palestine Refugees in the Near East (UNRWA), which is conducting humanitarian international relief activities in the Gaza Strip, Palestinian Territory.
Relief Supplies
The following relief supplies stored in Dubai for humanitarian assistance will be provided:
Blankets: 5,000 pieces
Water containers: 10,000 pieces
Plastic sheets: 4,500 pieces
Sleeping mats: 8,500 pieces<eos>

Sample code for High-speed inference (For NVIDIA Ampere or later, A100 or RTX 3090, etc.)

import torch, os
from hqq.engine.hf import AutoTokenizer
from hqq.core.quantize import *
from hqq.utils.patching import *
from hqq.models.hf.base import AutoHQQHFModel

model_id = "webbigdata/C3TR-Adapter_hqq"
os.environ["TOKENIZERS_PARALLELISM"]  = "1"
torch.backends.cuda.matmul.allow_tf32 = True
torch.backends.cudnn.allow_tf32       = True

compute_dtype = torch.bfloat16
model     = AutoHQQHFModel.from_quantized(model_id, compute_dtype=compute_dtype)
tokenizer = AutoTokenizer.from_pretrained(model_id)

patch_linearlayers(model, patch_add_quant_config,
                          BaseQuantizeConfig(nbits=4, group_size=64, quant_scale=False, quant_zero=False, axis=1))
HQQLinear.set_backend(HQQBackend.PYTORCH)

from hqq.utils.patching import prepare_for_inference
prepare_for_inference(model, backend="torchao_int4")

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.

### Instruction:
Translate Japanese to English.
When translating, please use the following hints:
[writeing_style: formal]
[米津玄師: Kenshi YONEZU]
[吉野源三郎: Genzaburo YOSHINO]

### Input:
「私自身、訳が分からない」
「おそらく、訳が分からなかったことでしょう。私自身、訳が分からないところがありました」。

 2023年2月下旬、東京都内のスタジオで上映された、「君たちはどう生きるか」の初号試写。米津玄師の歌うピアノバラードが流れ、エンド
ロールが終わった瞬間、灯りが点き、宮崎駿監督のコメントが読み上げられた。

 客席から軽い笑い声が漏れた。私もその一人だった。あまりの展開の速さと、盛り込むだけ盛り込まれた情報を消化しきれず、茫然と座り>込んでいたが、その言葉で我に返った。

 これは「宮崎アニメ」の集大成なのか、吉野源三郎の著書『君たちはどう生きるか』の再解釈なのか。とにかく、1回見ただけではとても全容を把握できなかった。

「自分のことをやるしかない」
 今回の作品は、公開前のプロモーションも、メディア関係者向けの試写も一切ないまま公開日を迎えた。異例の態勢の中、内容は無論、見たことすら口外無用のキャスト・スタッフ向け試写に、なぜ私と両親が呼ばれたのかといえば、父が『君たちはどう生きるか』の著者・吉野源三郎の長男で、私が孫にあたるからだ。

 その5年ほど前の2017年11月、父と私は東京・小金井のスタジオジブリに招かれ、宮崎監督と対面していた。さらにさかのぼること半月ほど前、とあるイベントで宮崎監督が突然、次回作のタイトルが「君たちはどう生きるか」だと明らかにし、ニュースなどで話題になっていた。親族としては寝耳に水だったのでかなり驚いたのだが、宮崎監督は「うっかり喋ってしまいました」と詫びた上で、作品について語り始めた。

### Response:
"""

tokens = tokenizer(prompt_text, return_tensors="pt",
        padding=True, max_length=1600, truncation=True).to("cuda:0").input_ids

output = model.generate(
        input_ids=tokens,
        max_new_tokens=800,
        do_sample=True,
        num_beams=3, temperature=0.5, top_p=0.3,
        repetition_penalty=1.0)
print(tokenizer.decode(output[0]))

See also

詳細はC3TR-Adapterを見てください
See also C3TR-Adapter

Downloads last month
14
Inference Examples
Inference API (serverless) does not yet support gptq models for this pipeline type.

Finetuned from

Collection including webbigdata/C3TR-Adapter_hqq