Norod78 commited on
Commit
3a61ad1
ยท
verified ยท
1 Parent(s): 3a1f3b9

Dicta-IL's dictalm2.0-instruct

Browse files
Files changed (4) hide show
  1. README.md +11 -5
  2. app.py +148 -0
  3. requirements.txt +9 -0
  4. style.css +17 -0
README.md CHANGED
@@ -1,13 +1,19 @@
1
  ---
2
- title: Dictalm2.0 Instruct
3
- emoji: ๐Ÿ‘
4
- colorFrom: gray
5
  colorTo: gray
6
  sdk: gradio
7
- sdk_version: 4.28.3
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
1
  ---
2
+ title: Dicta-IL's dictalm2.0-instruct
3
+ emoji: ๐Ÿ•Ž
4
+ colorFrom: blue
5
  colorTo: gray
6
  sdk: gradio
7
+ sdk_version: 4.28.2
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
+ suggested_hardware: a10g-small
12
  ---
13
 
14
+ # Dicta-IL's dictalm2.0-instruct
15
+
16
+ dictalm2.0-instruct was introduced in [this Facebook post](https://www.facebook.com/groups/MDLI1/posts/2704204053076959//).
17
+
18
+ Please, check the [original model card](https://huggingface.co/dicta-il/dictalm2.0-instruct) and [their official blog post](https://dicta.org.il/dicta-lm) for more details.
19
+ You can see the other Hebrew models by Dicta-IL [here](https://huggingface.co/dicta-il)
app.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from threading import Thread
3
+ from typing import Iterator
4
+
5
+ import gradio as gr
6
+ import spaces
7
+ import torch
8
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
9
+
10
+ MAX_MAX_NEW_TOKENS = 1024
11
+ DEFAULT_MAX_NEW_TOKENS = 256
12
+ MAX_INPUT_TOKEN_LENGTH = 1024
13
+
14
+ DESCRIPTION = """\
15
+ # Dicta-IL's dictalm2.0-instruct
16
+
17
+ dictalm2.0-instruct was introduced in [this Facebook post](https://www.facebook.com/groups/MDLI1/posts/2704204053076959//).
18
+
19
+ Please, check the [original model card](https://huggingface.co/dicta-il/dictalm2.0-instruct) and [their official blog post](https://dicta.org.il/dicta-lm) for more details.
20
+ You can see the other Hebrew models by Dicta-IL [here](https://huggingface.co/dicta-il)
21
+
22
+ """
23
+
24
+ LICENSE = """
25
+ <p/>
26
+
27
+ ---
28
+ A derivative work of [mistral-7b](https://mistral.ai/news/announcing-mistral-7b/) by Mistral-AI.
29
+ The model and space are released under the Apache 2.0 license
30
+ """
31
+
32
+ if not torch.cuda.is_available():
33
+ DESCRIPTION += "\n<p>Running on CPU ๐Ÿฅถ This demo does not work on CPU.</p>"
34
+
35
+
36
+ if torch.cuda.is_available():
37
+ model_id = "dicta-il/dictalm2.0-instruct"
38
+ model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype=torch.bfloat16, low_cpu_mem_usage=True)
39
+ tokenizer_id = "dicta-il/dictalm2.0-instruct"
40
+ tokenizer = AutoTokenizer.from_pretrained(tokenizer_id)
41
+ tokenizer.use_default_system_prompt = False
42
+
43
+
44
+ @spaces.GPU
45
+ def generate(
46
+ message: str,
47
+ chat_history: list[tuple[str, str]],
48
+ max_new_tokens: int = 1024,
49
+ temperature: float = 0.6,
50
+ top_p: float = 0.9,
51
+ top_k: int = 50,
52
+ repetition_penalty: float = 1.4,
53
+ ) -> Iterator[str]:
54
+ conversation = []
55
+ for user, assistant in chat_history:
56
+ conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
57
+ conversation.append({"role": "user", "content": message})
58
+
59
+ input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt")
60
+ if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
61
+ input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
62
+ gr.Warning(f"Trimmed input from conversation as it was longer than {MAX_INPUT_TOKEN_LENGTH} tokens.")
63
+ input_ids = input_ids.to(model.device)
64
+
65
+ streamer = TextIteratorStreamer(tokenizer, timeout=10.0, skip_prompt=True, skip_special_tokens=True)
66
+ generate_kwargs = dict(
67
+ {"input_ids": input_ids},
68
+ streamer=streamer,
69
+ max_new_tokens=max_new_tokens,
70
+ do_sample=True,
71
+ top_p=top_p,
72
+ top_k=top_k,
73
+ temperature=temperature,
74
+ num_beams=1,
75
+ pad_token_id = tokenizer.eos_token_id,
76
+ repetition_penalty=repetition_penalty,
77
+ no_repeat_ngram_size=5,
78
+ early_stopping=True,
79
+ )
80
+ t = Thread(target=model.generate, kwargs=generate_kwargs)
81
+ t.start()
82
+
83
+ outputs = []
84
+ for text in streamer:
85
+ outputs.append(text)
86
+ yield "".join(outputs)
87
+
88
+
89
+ chat_interface = gr.ChatInterface(
90
+ fn=generate,
91
+ chatbot=gr.Chatbot(rtl=True, show_copy_button=True),
92
+ textbox=gr.Textbox(text_align = 'right', rtl = True),
93
+ additional_inputs=[
94
+ gr.Slider(
95
+ label="Max new tokens",
96
+ minimum=1,
97
+ maximum=MAX_MAX_NEW_TOKENS,
98
+ step=1,
99
+ value=DEFAULT_MAX_NEW_TOKENS,
100
+ ),
101
+ gr.Slider(
102
+ label="Temperature",
103
+ minimum=0.1,
104
+ maximum=4.0,
105
+ step=0.1,
106
+ value=0.3,
107
+ ),
108
+ gr.Slider(
109
+ label="Top-p (nucleus sampling)",
110
+ minimum=0.05,
111
+ maximum=1.0,
112
+ step=0.05,
113
+ value=0.3,
114
+ ),
115
+ gr.Slider(
116
+ label="Top-k",
117
+ minimum=1,
118
+ maximum=1000,
119
+ step=1,
120
+ value=30,
121
+ ),
122
+ gr.Slider(
123
+ label="Repetition penalty",
124
+ minimum=1.0,
125
+ maximum=2.0,
126
+ step=0.05,
127
+ value=1.4,
128
+ ),
129
+ ],
130
+ stop_btn=None,
131
+ examples=[
132
+ ["ืžืชื›ื•ืŸ ืœืขื•ื’ืช ืฉื•ืงื•ืœื“:"],
133
+ ["ื”ืฉืœื ืืช ื”ืกื™ืคื•ืจ ื”ืงืฆืจ ื”ื‘ื:\n ื”ืื™ืฉ ื”ืื—ืจื•ืŸ ื‘ืขื•ืœื ื™ืฉื‘ ืœื‘ื“ ื‘ื—ื“ืจื•, ื›ืฉืœืคืชืข ื ืฉืžืขื”"],
134
+ ["ืžื”ื™ ืฉืคืช ื”ืชื›ื ื•ืช ืคื™ื™ืชื•ืŸ?"],
135
+ ["ืกื›ื ื‘ืงืฆืจื” ืืช ื”ืขืœื™ืœื” ืฉืœ ืกื™ื ื“ืจืœื”"],
136
+ ["ืฉืืœื”: ืžื”ื™ ืขื™ืจ ื”ื‘ื™ืจื” ืฉืœ ืžื“ื™ื ืช ื™ืฉืจืืœ?\nืชืฉื•ื‘ื”:"],
137
+ ["ืฉืืœื”: ืื ื™ ืžืžืฉ ืขื™ื™ืฃ, ืžื” ื›ื“ืื™ ืœื™ ืœืขืฉื•ืช?\nืชืฉื•ื‘ื”:"],
138
+ ],
139
+ )
140
+
141
+ with gr.Blocks(css="style.css") as demo:
142
+ gr.Markdown(DESCRIPTION)
143
+ gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
144
+ chat_interface.render()
145
+ gr.Markdown(LICENSE)
146
+
147
+ if __name__ == "__main__":
148
+ demo.queue(max_size=20).launch()
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ accelerate==0.28.0
2
+ bitsandbytes==0.43.0
3
+ gradio==4.28.2
4
+ scipy==1.12.0
5
+ sentencepiece==0.2.0
6
+ spaces==0.26.2
7
+ torch==2.1.1
8
+ transformers==4.40.1
9
+ tokenizers==0.19.1
style.css ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ h1 {
2
+ text-align: center;
3
+ display: block;
4
+ }
5
+
6
+ #duplicate-button {
7
+ margin: auto;
8
+ color: white;
9
+ background: #1565c0;
10
+ border-radius: 100vh;
11
+ }
12
+
13
+ .contain {
14
+ max-width: 900px;
15
+ margin: auto;
16
+ padding-top: 1.5rem;
17
+ }