Icyud commited on
Commit
a7c8991
·
verified ·
1 Parent(s): 35969e4

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +39 -0
  2. requirement.txt +2 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from stranformer import pipeline
3
+
4
+ base_model = "minhtt/vistral-7b-chat"
5
+
6
+ bnb_config = BitsAndBytesConfig(
7
+ load_in_4bit= True,
8
+ bnb_4bit_quant_type= "nf4",
9
+ bnb_4bit_compute_dtype= torch.bfloat16,
10
+ bnb_4bit_use_double_quant= False,
11
+ )
12
+
13
+ model = AutoModelForCausalLM.from_pretrained(
14
+ base_model,
15
+ load_in_4bit=True,
16
+ quantization_config=bnb_config,
17
+ torch_dtype=torch.bfloat16,
18
+ device_map="auto",
19
+ trust_remote_code=True,
20
+ )
21
+
22
+
23
+ model.config.use_cache = False # silence the warnings. Please re-enable for inference!
24
+ model.config.pretraining_tp = 1
25
+ model.gradient_checkpointing_enable()
26
+
27
+ # Load tokenizer
28
+ tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)
29
+ tokenizer.padding_side = 'right'
30
+ tokenizer.pad_token = tokenizer.eos_token
31
+ tokenizer.add_eos_token = True
32
+ tokenizer.bos_token, tokenizer.eos_token
33
+
34
+ pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200)
35
+ text = st.text_erea()
36
+
37
+ if text:
38
+ out = pipe(text)
39
+ st.text_erea(out)
requirement.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch
2
+ transformers