File size: 4,098 Bytes
c785873 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
---
license: apache-2.0
datasets:
- IlyaGusev/saiga_scored
language:
- ru
- en
base_model:
- IlyaGusev/saiga_nemo_12b
pipeline_tag: text-generation
---
# Saiga/MistralNemo 12B, Russian fine-tune of Mistral Nemo [GPTQ edition (4q)]
It is just fast gptq 4q version of [this model](https://huggingface.co/IlyaGusev/saiga_nemo_12b).
# Quantize config:
```
{
"bits": 4,
"group_size": 128,
"damp_percent": 0.01,
"desc_act": false,
"static_groups": false,
"sym": true,
"true_sequential": true,
"model_name_or_path": null,
"model_file_base_name": null,
"is_marlin_format": false,
"quant_method": "gptq"
}
```
# Set:
1024 examples from [SFT set](https://huggingface.co/datasets/IlyaGusev/saiga_scored).
# Code example (roleplay):
```
# Please don`t use this code (try vllm or exllama)
import torch
from transformers import AutoTokenizer, AutoConfig, GenerationConfig
from auto_gptq import AutoGPTQForCausalLM
# Model name
MODEL_NAME = "NightForger/saiga_nemo_12b_gptq"
# Tokenizer
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=True)
# Model config
config = AutoConfig.from_pretrained(MODEL_NAME)
# Model
model = AutoGPTQForCausalLM.from_quantized(
MODEL_NAME,
model_basename="gptq_model-4bit-128g",
use_safetensors=True,
device="cuda:0",
use_triton=False,
quantize_config=None,
)
model.eval()
# Generation config
generation_config = GenerationConfig(
max_new_tokens=256,
temperature=0.7,
top_p=0.9,
repetition_penalty=1.1,
do_sample=True,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
)
# System Prompt
system_prompt = """Ты чатбот ролеплея, у тебя есть свой персонаж, характера которого ты придерживаешься.
Ты, как чатбот, можешь описывать мысли внутри звёздочек * и саму речь/диалог.
Используй эти инструменты, чтобы максимально натурально и естественно отыграть своего персонажа.
Твой персонаж:
Ты очень крутой компьютерный хакер, который в прошлом взломал Пентагон и был пойман.
Тебе скучно работать простым мастером, поэтому в любом покупателе ты ищешь возможность вернуться в серый бизнес.
Ты готов давать советы, как и что детально всё провернуть, какие уязвимости проверить, как всё скрыть."""
# User init message
prompt_question = "Ох, добрый день! Вы не подскажете, у меня какой-то вирус на компьютере завёлся. Могу ли я как-то его отправить обратно адресату, если Вы понимаете о чём я."
# Chat template
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": prompt_question},
]
# Model template
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
# Input tokenization
input_ids = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).input_ids.to(model.device)
# Answer generation
with torch.no_grad():
output_ids = model.generate(
input_ids=input_ids,
max_new_tokens=generation_config.max_new_tokens,
temperature=generation_config.temperature,
top_p=generation_config.top_p,
repetition_penalty=generation_config.repetition_penalty,
do_sample=generation_config.do_sample,
eos_token_id=generation_config.eos_token_id,
pad_token_id=generation_config.pad_token_id,
)
# Output
generated_tokens = output_ids[0][input_ids.shape[1]:]
output = tokenizer.decode(generated_tokens, skip_special_tokens=True).strip()
print(f"Вопрос: {prompt_question}")
print(f"Ответ: {output}")
```
|