Upload 9 files
Browse files- config.json +33 -0
- generation_config.json +6 -0
- merges.txt +0 -0
- model.safetensors +3 -0
- special_tokens_map.json +30 -0
- tokenizer.json +0 -0
- tokenizer_config.json +20 -0
- use.py +96 -0
- vocab.json +0 -0
config.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "VDrontV1",
|
| 3 |
+
"activation_function": "gelu_new",
|
| 4 |
+
"architectures": [
|
| 5 |
+
"GPT2LMHeadModel"
|
| 6 |
+
],
|
| 7 |
+
"attn_pdrop": 0.1,
|
| 8 |
+
"bos_token_id": 50256,
|
| 9 |
+
"embd_pdrop": 0.1,
|
| 10 |
+
"eos_token_id": 50256,
|
| 11 |
+
"initializer_range": 0.02,
|
| 12 |
+
"layer_norm_epsilon": 1e-05,
|
| 13 |
+
"model_type": "gpt2",
|
| 14 |
+
"n_ctx": 512,
|
| 15 |
+
"n_embd": 768,
|
| 16 |
+
"n_head": 12,
|
| 17 |
+
"n_inner": null,
|
| 18 |
+
"n_layer": 9,
|
| 19 |
+
"n_positions": 512,
|
| 20 |
+
"reorder_and_upcast_attn": false,
|
| 21 |
+
"resid_pdrop": 0.1,
|
| 22 |
+
"scale_attn_by_inverse_layer_idx": false,
|
| 23 |
+
"scale_attn_weights": true,
|
| 24 |
+
"summary_activation": null,
|
| 25 |
+
"summary_first_dropout": 0.1,
|
| 26 |
+
"summary_proj_to_labels": true,
|
| 27 |
+
"summary_type": "cls_index",
|
| 28 |
+
"summary_use_proj": true,
|
| 29 |
+
"torch_dtype": "float32",
|
| 30 |
+
"transformers_version": "4.46.3",
|
| 31 |
+
"use_cache": false,
|
| 32 |
+
"vocab_size": 50257
|
| 33 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 50256,
|
| 4 |
+
"eos_token_id": 50256,
|
| 5 |
+
"transformers_version": "4.46.3"
|
| 6 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:af87afca5fd46394db9246cfef3ab4d0d88120a58b65ac2c1dd1af1413ea6580
|
| 3 |
+
size 411143192
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<|endoftext|>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": true,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"eos_token": {
|
| 10 |
+
"content": "<|endoftext|>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": true,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": {
|
| 17 |
+
"content": "<|endoftext|>",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": true,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"unk_token": {
|
| 24 |
+
"content": "<|endoftext|>",
|
| 25 |
+
"lstrip": false,
|
| 26 |
+
"normalized": true,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
}
|
| 30 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"added_tokens_decoder": {
|
| 4 |
+
"50256": {
|
| 5 |
+
"content": "<|endoftext|>",
|
| 6 |
+
"lstrip": false,
|
| 7 |
+
"normalized": true,
|
| 8 |
+
"rstrip": false,
|
| 9 |
+
"single_word": false,
|
| 10 |
+
"special": true
|
| 11 |
+
}
|
| 12 |
+
},
|
| 13 |
+
"bos_token": "<|endoftext|>",
|
| 14 |
+
"clean_up_tokenization_spaces": false,
|
| 15 |
+
"eos_token": "<|endoftext|>",
|
| 16 |
+
"model_max_length": 1024,
|
| 17 |
+
"pad_token": "<|endoftext|>",
|
| 18 |
+
"tokenizer_class": "GPT2Tokenizer",
|
| 19 |
+
"unk_token": "<|endoftext|>"
|
| 20 |
+
}
|
use.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 3 |
+
from threading import Thread
|
| 4 |
+
|
| 5 |
+
MODEL_PATH = "VDrontV1"
|
| 6 |
+
TEMPERATURE = 0.40
|
| 7 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def load_model_and_tokenizer(model_path):
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=False)
|
| 12 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 13 |
+
model_path,
|
| 14 |
+
torch_dtype=torch.float16 if DEVICE == "cuda" else torch.float32,
|
| 15 |
+
device_map="auto",
|
| 16 |
+
trust_remote_code=False
|
| 17 |
+
)
|
| 18 |
+
if tokenizer.pad_token is None:
|
| 19 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 20 |
+
|
| 21 |
+
# Получаем ID токена <|endoftext|> если он есть в словаре
|
| 22 |
+
endoftext_id = tokenizer.convert_tokens_to_ids("<|endoftext|>")
|
| 23 |
+
if endoftext_id != tokenizer.unk_token_id: # если токен существует
|
| 24 |
+
model.config.eos_token_id = endoftext_id
|
| 25 |
+
tokenizer.eos_token = "<|endoftext|>"
|
| 26 |
+
tokenizer.eos_token_id = endoftext_id
|
| 27 |
+
|
| 28 |
+
return model, tokenizer
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def generate_stream(model, tokenizer, prompt, temperature=0.4, max_new_tokens=128):
|
| 32 |
+
# Text continuation generator without chat history
|
| 33 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=2048)
|
| 34 |
+
inputs = {k: v.to(model.device) for k, v in inputs.items()}
|
| 35 |
+
|
| 36 |
+
streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
|
| 37 |
+
|
| 38 |
+
# Получаем eos_token_id для генерации
|
| 39 |
+
eos_token_id = tokenizer.eos_token_id
|
| 40 |
+
|
| 41 |
+
generation_kwargs = dict(
|
| 42 |
+
**inputs,
|
| 43 |
+
max_new_tokens=max_new_tokens,
|
| 44 |
+
temperature=temperature,
|
| 45 |
+
do_sample=True,
|
| 46 |
+
top_p=0.95,
|
| 47 |
+
repetition_penalty=1.1,
|
| 48 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 49 |
+
eos_token_id=eos_token_id,
|
| 50 |
+
streamer=streamer,
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
| 54 |
+
thread.start()
|
| 55 |
+
|
| 56 |
+
for new_text in streamer:
|
| 57 |
+
# Проверяем, не содержит ли текст <|endoftext|>
|
| 58 |
+
if "<|endoftext|>" in new_text:
|
| 59 |
+
# Обрезаем до маркера
|
| 60 |
+
new_text = new_text.split("<|endoftext|>")[0]
|
| 61 |
+
yield new_text
|
| 62 |
+
break
|
| 63 |
+
yield new_text
|
| 64 |
+
|
| 65 |
+
thread.join()
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def interactive_chat(model, tokenizer, temperature):
|
| 69 |
+
print(f"Simple text continuation (temp={temperature})")
|
| 70 |
+
print("Enter the beginning of the text, and the model will continue it.")
|
| 71 |
+
print("Commands: 'exit' or 'quit' — exit.")
|
| 72 |
+
|
| 73 |
+
while True:
|
| 74 |
+
try:
|
| 75 |
+
user_input = input("\nYou: ").strip()
|
| 76 |
+
except (KeyboardInterrupt, EOFError):
|
| 77 |
+
print("\nGoodbye!")
|
| 78 |
+
break
|
| 79 |
+
|
| 80 |
+
if user_input.lower() in ["exit", "quit"]:
|
| 81 |
+
print("Goodbye!")
|
| 82 |
+
break
|
| 83 |
+
|
| 84 |
+
if not user_input:
|
| 85 |
+
continue
|
| 86 |
+
|
| 87 |
+
print() # empty line before continuation
|
| 88 |
+
for token in generate_stream(model, tokenizer, "<|user|> " + user_input + " <|assistant|>",
|
| 89 |
+
temperature=temperature):
|
| 90 |
+
print(token, end="", flush=True)
|
| 91 |
+
print() # finish the line
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
if __name__ == "__main__":
|
| 95 |
+
model, tokenizer = load_model_and_tokenizer(MODEL_PATH)
|
| 96 |
+
interactive_chat(model, tokenizer, temperature=TEMPERATURE)
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|