gustavoaq IlyaGusev commited on
Commit
de2c662
0 Parent(s):

Duplicate from IlyaGusev/llama_7b_ru_turbo_alpaca_lora

Browse files

Co-authored-by: Ilya Gusev <[email protected]>

Files changed (4) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. app.py +84 -0
  4. requirements.txt +6 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Llama 7B ru_turbo_alpaca LoRA
3
+ emoji: 👁
4
+ colorFrom: indigo
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 3.23.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: IlyaGusev/llama_7b_ru_turbo_alpaca_lora
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ import torch
4
+ from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
5
+ from peft import PeftModel, PeftConfig
6
+
7
+ MODEL_NAME = "IlyaGusev/llama_7b_ru_turbo_alpaca_lora"
8
+
9
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
10
+ config = PeftConfig.from_pretrained(MODEL_NAME)
11
+ model = AutoModelForCausalLM.from_pretrained(
12
+ config.base_model_name_or_path,
13
+ load_in_8bit=True,
14
+ device_map="auto"
15
+ )
16
+ model = PeftModel.from_pretrained(model, MODEL_NAME)
17
+ model.eval()
18
+
19
+
20
+ def generate_prompt(instruction, input=None):
21
+ if input:
22
+ return f"Задание: {instruction}\nВход: {input}\nОтвет:"
23
+ return f"Задание: {instruction}\n\nОтвет:"
24
+
25
+
26
+ def evaluate(
27
+ instruction,
28
+ input=None,
29
+ temperature=1.0,
30
+ top_p=1.0,
31
+ top_k=40,
32
+ num_beams=3,
33
+ max_new_tokens=256,
34
+ **kwargs,
35
+ ):
36
+ prompt = generate_prompt(instruction, input)
37
+ inputs = tokenizer(prompt, return_tensors="pt")
38
+ input_ids = inputs["input_ids"].to(model.device)
39
+ generation_config = GenerationConfig(
40
+ temperature=temperature,
41
+ top_p=top_p,
42
+ top_k=top_k,
43
+ num_beams=num_beams,
44
+ **kwargs,
45
+ )
46
+ with torch.no_grad():
47
+ generation_output = model.generate(
48
+ input_ids=input_ids,
49
+ generation_config=generation_config,
50
+ return_dict_in_generate=True,
51
+ output_scores=True,
52
+ max_new_tokens=max_new_tokens
53
+ )
54
+ s = generation_output.sequences[0]
55
+ output = tokenizer.decode(s, skip_special_tokens=True)
56
+ return output.strip()
57
+
58
+
59
+ g = gr.Interface(
60
+ fn=evaluate,
61
+ inputs=[
62
+ gr.components.Textbox(
63
+ lines=2, label="Задание", placeholder="Почему трава зеленая?"
64
+ ),
65
+ gr.components.Textbox(lines=2, label="Вход", placeholder="Нет"),
66
+ gr.components.Slider(minimum=0, maximum=2, value=1.0, label="Temperature"),
67
+ gr.components.Slider(minimum=0, maximum=1, value=0.8, label="Top p"),
68
+ gr.components.Slider(minimum=0, maximum=100, value=40, label="Top k"),
69
+ gr.components.Slider(minimum=1, maximum=5, step=1, value=4, label="Beams"),
70
+ gr.components.Slider(
71
+ minimum=1, maximum=256, step=1, value=256, label="Max tokens"
72
+ ),
73
+ ],
74
+ outputs=[
75
+ gr.inputs.Textbox(
76
+ lines=5,
77
+ label="Output",
78
+ )
79
+ ],
80
+ title="LLaMA 7B Ru Turbo Alpaca",
81
+ description="",
82
+ )
83
+ g.queue(concurrency_count=1)
84
+ g.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ torch
2
+ sentencepiece
3
+ accelerate
4
+ bitsandbytes
5
+ git+https://github.com/huggingface/transformers.git
6
+ git+https://github.com/huggingface/peft.git