Update README.md
Browse files
README.md
CHANGED
@@ -30,6 +30,58 @@ pip install -vvv --no-build-isolation -e .
|
|
30 |
|
31 |
### Sample code
|
32 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
```
|
35 |
|
|
|
30 |
|
31 |
### Sample code
|
32 |
```
|
33 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig
|
34 |
+
from optimum.gptq import GPTQQuantizer, load_quantized_model
|
35 |
+
import torch
|
36 |
+
model_name = "webbigdata/C3TR-Adapter_gptq"
|
37 |
+
|
38 |
+
# thanks to tk-master
|
39 |
+
# https://github.com/AutoGPTQ/AutoGPTQ/issues/406
|
40 |
+
config = AutoConfig.from_pretrained(model_name)
|
41 |
+
config.quantization_config["use_exllama"] = False
|
42 |
+
config.quantization_config["exllama_config"] = {"version":2}
|
43 |
+
|
44 |
+
max_memory={0: "12GiB", "cpu": "10GiB"}
|
45 |
+
quantized_model = AutoModelForCausalLM.from_pretrained(model_name
|
46 |
+
, torch_dtype=torch.bfloat16 # chage float16 if you use free colab or something not support bfloat16.
|
47 |
+
, device_map="auto", max_memory=max_memory
|
48 |
+
, config=config)
|
49 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
50 |
+
tokenizer.pad_token = tokenizer.unk_token
|
51 |
+
|
52 |
+
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.
|
53 |
+
|
54 |
+
### Instruction:
|
55 |
+
Translate English to Japanese.
|
56 |
+
When translating, please use the following hints:
|
57 |
+
[writing_style: web-fiction]
|
58 |
+
[Madoka: γΎγ©γ]
|
59 |
+
[Madoka_first_person_and_ending: γ γ, γγ]
|
60 |
+
[Mami: γγ]
|
61 |
+
[Mami_first_person_and_ending: η§, γγ]
|
62 |
+
[Sayaka: γγγ]
|
63 |
+
[Sayaka_first_person_and_ending: η§, γγͺ]
|
64 |
+
[Kyubey: γγ₯γ₯γΉγ]
|
65 |
+
[Kyubey_first_person_and_ending: ε, γ¦γ]
|
66 |
+
|
67 |
+
### Input:
|
68 |
+
Madoka: "Thank you all for watching! You might've seen a bit of my dark side, but... don't mind that, okay?"
|
69 |
+
Sayaka: "Well, thanks! Did my cuteness come across 100%?"
|
70 |
+
Mami: "I'm glad you watched, but it's a bit embarrassing..."
|
71 |
+
Kyubey: "Make a contract with me, and become a magical girl."
|
72 |
+
### Response:
|
73 |
+
"""
|
74 |
+
|
75 |
+
tokens = tokenizer(prompt_text, return_tensors="pt",
|
76 |
+
padding=True, max_length=1600, truncation=True).to("cuda:0").input_ids
|
77 |
+
|
78 |
+
output = quantized_model.generate(
|
79 |
+
input_ids=tokens,
|
80 |
+
max_new_tokens=800,
|
81 |
+
do_sample=True,
|
82 |
+
num_beams=3, temperature=0.5, top_p=0.3,
|
83 |
+
repetition_penalty=1.0)
|
84 |
+
print(tokenizer.decode(output[0]))
|
85 |
|
86 |
```
|
87 |
|