Tonic commited on
Commit
07aff0d
·
1 Parent(s): 9467ea3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -1,4 +1,5 @@
1
  from transformers import AutoModelForCausalLM, AutoTokenizer
 
2
  from tokenization_yi import YiTokenizer
3
  import torch
4
  import os
@@ -6,13 +7,26 @@ import gradio as gr
6
  import sentencepiece
7
 
8
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:126'
10
 
11
  # Load the model and tokenizer using transformers
12
  model = AutoModelForCausalLM.from_pretrained("01-ai/Yi-6B-200K", device_map="auto", torch_dtype="auto", trust_remote_code=True)
13
  tokenizer = YiTokenizer(vocab_file="./tokenizer.model")
 
14
 
15
- def run(message, chat_history, max_new_tokens=4056, temperature=3.5, top_p=0.9, top_k=800):
16
  prompt = get_prompt(message, chat_history)
17
 
18
  # Encode the prompt to tensor
@@ -49,17 +63,6 @@ def get_prompt(message, chat_history):
49
  texts.append(f"{message}")
50
  return ''.join(texts)
51
 
52
- DESCRIPTION = """
53
- # 👋🏻Welcome to 🙋🏻‍♂️Tonic's🧑🏻‍🚀YI-6B-200K🚀"
54
- You can use this Space to test out the current model [01-ai/Yi-6B-200K](https://huggingface.co/01-ai/Yi-6B-200K)
55
- You can also use 🧑🏻‍🚀YI-200K🚀 by cloning this space. 🧬🔬🔍 Simply click here: <a style="display:inline-block" href="https://huggingface.co/spaces/Tonic1/YiTonic?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></h3>
56
- Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's🛠️community on 👻Discord: [Discord](https://discord.gg/nXx5wbX9) On 🤗Huggingface: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) On 🌐Github: [Polytonic](https://github.com/tonic-ai) & contribute to 🌟 [PolyGPT](https://github.com/tonic-ai/polygpt-alpha)
57
- """
58
-
59
- MAX_MAX_NEW_TOKENS = 16000
60
- DEFAULT_MAX_NEW_TOKENS = 4056
61
- MAX_INPUT_TOKEN_LENGTH = 32000
62
-
63
  def clear_and_save_textbox(message): return '', message
64
 
65
  def display_input(message, history=[]):
@@ -83,7 +86,7 @@ def generate(message, history_with_input, max_new_tokens, temperature, top_p, to
83
 
84
 
85
  def process_example(message):
86
- generator = generate(message, [], 1024, 2.5, 0.95, 900)
87
  for x in generator:
88
  pass
89
  return '', x
@@ -119,7 +122,7 @@ with gr.Blocks(theme='ParityError/Anime') as demo:
119
  with gr.Accordion(label='Advanced options', open=False):
120
  # system_prompt = gr.Textbox(label='System prompt', value=DEFAULT_SYSTEM_PROMPT, lines=5, interactive=False)
121
  max_new_tokens = gr.Slider(label='Max New Tokens', minimum=1, maximum=MAX_MAX_NEW_TOKENS, step=1, value=DEFAULT_MAX_NEW_TOKENS)
122
- temperature = gr.Slider(label='Temperature', minimum=0.1, maximum=4.0, step=0.1, value=0.1)
123
  top_p = gr.Slider(label='Top-P (nucleus sampling)', minimum=0.05, maximum=1.0, step=0.05, value=0.9)
124
  top_k = gr.Slider(label='Top-K', minimum=1, maximum=1000, step=1, value=10)
125
 
 
1
  from transformers import AutoModelForCausalLM, AutoTokenizer
2
+ from optimum.bettertransformer import BetterTransformer
3
  from tokenization_yi import YiTokenizer
4
  import torch
5
  import os
 
7
  import sentencepiece
8
 
9
 
10
+ DESCRIPTION = """
11
+ # 👋🏻Welcome to 🙋🏻‍♂️Tonic's🧑🏻‍🚀YI-6B-200K🚀"
12
+ You can use this Space to test out the current model [01-ai/Yi-6B-200K](https://huggingface.co/01-ai/Yi-6B-200K)
13
+ You can also use 🧑🏻‍🚀YI-200K🚀 by cloning this space. 🧬🔬🔍 Simply click here: <a style="display:inline-block" href="https://huggingface.co/spaces/Tonic1/YiTonic?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></h3>
14
+ Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's🛠️community on 👻Discord: [Discord](https://discord.gg/nXx5wbX9) On 🤗Huggingface: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) On 🌐Github: [Polytonic](https://github.com/tonic-ai) & contribute to 🌟 [PolyGPT](https://github.com/tonic-ai/polygpt-alpha)
15
+ """
16
+
17
+ MAX_MAX_NEW_TOKENS = 160000
18
+ DEFAULT_MAX_NEW_TOKENS = 20000
19
+ MAX_INPUT_TOKEN_LENGTH = 160000
20
+
21
+
22
  os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:126'
23
 
24
  # Load the model and tokenizer using transformers
25
  model = AutoModelForCausalLM.from_pretrained("01-ai/Yi-6B-200K", device_map="auto", torch_dtype="auto", trust_remote_code=True)
26
  tokenizer = YiTokenizer(vocab_file="./tokenizer.model")
27
+ model = BetterTransformer.transform(model)
28
 
29
+ def run(message, chat_history, max_new_tokens=20000, temperature=1.0, top_p=0.9, top_k=0.9):
30
  prompt = get_prompt(message, chat_history)
31
 
32
  # Encode the prompt to tensor
 
63
  texts.append(f"{message}")
64
  return ''.join(texts)
65
 
 
 
 
 
 
 
 
 
 
 
 
66
  def clear_and_save_textbox(message): return '', message
67
 
68
  def display_input(message, history=[]):
 
86
 
87
 
88
  def process_example(message):
89
+ generator = generate(message, [], 4056, 1.9, 0.95, 900)
90
  for x in generator:
91
  pass
92
  return '', x
 
122
  with gr.Accordion(label='Advanced options', open=False):
123
  # system_prompt = gr.Textbox(label='System prompt', value=DEFAULT_SYSTEM_PROMPT, lines=5, interactive=False)
124
  max_new_tokens = gr.Slider(label='Max New Tokens', minimum=1, maximum=MAX_MAX_NEW_TOKENS, step=1, value=DEFAULT_MAX_NEW_TOKENS)
125
+ temperature = gr.Slider(label='Temperature', minimum=0.1, maximum=2.0, step=0.1, value=0.1)
126
  top_p = gr.Slider(label='Top-P (nucleus sampling)', minimum=0.05, maximum=1.0, step=0.05, value=0.9)
127
  top_k = gr.Slider(label='Top-K', minimum=1, maximum=1000, step=1, value=10)
128