tanyuzhou commited on
Commit
0223f98
·
1 Parent(s): ab977cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -20
app.py CHANGED
@@ -6,25 +6,6 @@ from transformers import TextStreamer
6
 
7
  import spaces
8
 
9
- quantization_config = BitsAndBytesConfig(
10
- bnb_4bit_compute_dtype="float16",
11
- bnb_4bit_quant_storage="uint8",
12
- bnb_4bit_quant_type="nf4",
13
- bnb_4bit_use_double_quant=True,
14
- llm_int8_enable_fp32_cpu_offload=False,
15
- llm_int8_has_fp16_weight=False,
16
- llm_int8_skip_modules=None,
17
- llm_int8_threshold=6.0,
18
- load_in_4bit=True,
19
- load_in_8bit=False,
20
- quant_method="bitsandbytes"
21
- )
22
-
23
- # Load model and tokenizer
24
- model = AutoModelForCausalLM.from_pretrained("Rorical/0-roleplay", return_dict=True, trust_remote_code=True)
25
- tokenizer = AutoTokenizer.from_pretrained("Rorical/0-roleplay", trust_remote_code=True, quantization_config=quantization_config)
26
- tokenizer.chat_template = "{% for message in messages %}{{'<|im_start|>' + ((message['role'] + ':\n') if message['role'] != '' else '') + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>星野:\n' }}{% endif %}" # Be careful that this model used custom chat template.
27
-
28
  # Define the response function
29
  @spaces.GPU
30
  def respond(
@@ -35,7 +16,24 @@ def respond(
35
  temperature,
36
  top_p,
37
  ):
38
- global model, tokenizer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  # Construct the messages for the chat
41
  messages = [{"role": "", "content": system_message}]
 
6
 
7
  import spaces
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  # Define the response function
10
  @spaces.GPU
11
  def respond(
 
16
  temperature,
17
  top_p,
18
  ):
19
+ quantization_config = BitsAndBytesConfig(
20
+ bnb_4bit_compute_dtype="float16",
21
+ bnb_4bit_quant_storage="uint8",
22
+ bnb_4bit_quant_type="nf4",
23
+ bnb_4bit_use_double_quant=True,
24
+ llm_int8_enable_fp32_cpu_offload=False,
25
+ llm_int8_has_fp16_weight=False,
26
+ llm_int8_skip_modules=None,
27
+ llm_int8_threshold=6.0,
28
+ load_in_4bit=True,
29
+ load_in_8bit=False,
30
+ quant_method="bitsandbytes"
31
+ )
32
+
33
+ # Load model and tokenizer
34
+ model = AutoModelForCausalLM.from_pretrained("Rorical/0-roleplay", return_dict=True, trust_remote_code=True)
35
+ tokenizer = AutoTokenizer.from_pretrained("Rorical/0-roleplay", trust_remote_code=True, quantization_config=quantization_config)
36
+ tokenizer.chat_template = "{% for message in messages %}{{'<|im_start|>' + ((message['role'] + ':\n') if message['role'] != '' else '') + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>星野:\n' }}{% endif %}" # Be careful that this model used custom chat template.
37
 
38
  # Construct the messages for the chat
39
  messages = [{"role": "", "content": system_message}]