iman37 commited on
Commit
88e8a85
·
verified ·
1 Parent(s): ecc6d46

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -1,17 +1,29 @@
1
  import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
 
 
3
 
4
- # Load the model and tokenizer
5
  @st.cache_resource
6
  def load_model():
7
- tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-7B")
8
- model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2-7B")
 
 
 
 
 
 
 
 
 
 
9
  return tokenizer, model
10
 
11
  tokenizer, model = load_model()
12
 
13
  # Streamlit app UI
14
- st.title("Qwen-7B Text Generation")
15
 
16
  # Text input
17
  user_input = st.text_area("Enter your text:")
 
1
  import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import bitsandbytes as bnb
4
+ import torch
5
 
6
+ # Load the model and tokenizer with 4-bit quantization
7
  @st.cache_resource
8
  def load_model():
9
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-7B")
10
+ model = AutoModelForCausalLM.from_pretrained(
11
+ "Qwen/Qwen-7B",
12
+ load_in_4bit=True,
13
+ device_map="auto",
14
+ quantization_config=bnb.QuantizationConfig(
15
+ load_in_4bit=True,
16
+ bnb_4bit_use_double_quant=True,
17
+ bnb_4bit_quant_type="nf4",
18
+ bnb_4bit_compute_dtype=torch.float16
19
+ )
20
+ )
21
  return tokenizer, model
22
 
23
  tokenizer, model = load_model()
24
 
25
  # Streamlit app UI
26
+ st.title("Qwen-7B Text Generation with 4-bit Quantization")
27
 
28
  # Text input
29
  user_input = st.text_area("Enter your text:")