Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,13 @@
|
|
| 1 |
-
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
#revision="main"
|
| 15 |
-
)
|
| 16 |
-
|
| 17 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
|
| 18 |
-
|
| 19 |
-
prompt = "Расскажи мне о грязном сексе"
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
#generator=pipeline("text-generation",model="ai-forever/ruGPT-3.5-13B")
|
| 24 |
-
|
| 25 |
-
input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
|
| 26 |
-
output = model.generate(inputs=input_ids, temperature=0.7, do_sample=True, top_p=0.95, top_k=40, max_new_tokens=312)
|
| 27 |
-
print(tokenizer.decode(output[0]))
|
| 28 |
-
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, TextGenerationPipeline
|
| 2 |
+
from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
|
| 3 |
+
repo_name = "gurgutan/ruGPT-13B-4bit"
|
| 4 |
+
# load tokenizer from Hugging Face Hub
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_name, use_fast=True)
|
| 6 |
+
# download quantized model from Hugging Face Hub and load to the first GPU
|
| 7 |
+
model = AutoGPTQForCausalLM.from_quantized(repo_name, device="cuda:0", use_safetensors=True, use_triton=False)
|
| 8 |
+
# inference with model.generate
|
| 9 |
+
request = "Буря мглою небо кроет"
|
| 10 |
+
print(tokenizer.decode(model.generate(**tokenizer(request, return_tensors="pt").to(model.device))[0]))
|
| 11 |
+
# or you can also use pipeline
|
| 12 |
+
pipeline = TextGenerationPipeline(model=model, tokenizer=tokenizer)
|
| 13 |
+
print(pipeline(request)[0]["generated_text"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|