asusevski commited on
Commit
d201139
·
1 Parent(s): d98c789

app.py peftmodel update

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForCausalLM
3
  import torch
 
4
 
5
 
6
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
@@ -12,10 +13,27 @@ ft_model_id = "asusevski/mistraloo-sft"
12
 
13
  tokenizer = AutoTokenizer.from_pretrained(
14
  base_model_id,
15
- add_bos_token=True,
16
  )
17
 
18
- model = AutoModelForCausalLM.from_pretrained(ft_model_id).to(device)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  model.eval()
20
 
21
 
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3
  import torch
4
+ from peft import PeftModel
5
 
6
 
7
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
13
 
14
  tokenizer = AutoTokenizer.from_pretrained(
15
  base_model_id,
16
+ add_bos_token=True
17
  )
18
 
19
+
20
+ base_model_id = "mistralai/Mistral-7B-v0.1"
21
+ bnb_config = BitsAndBytesConfig(
22
+ load_in_4bit=True,
23
+ bnb_4bit_use_double_quant=True,
24
+ bnb_4bit_quant_type="nf4",
25
+ bnb_4bit_compute_dtype=torch.bfloat16
26
+ )
27
+
28
+ base_model = AutoModelForCausalLM.from_pretrained(
29
+ base_model_id,
30
+ quantization_config=bnb_config,
31
+ device_map="auto",
32
+ trust_remote_code=True,
33
+ token=True
34
+ )
35
+
36
+ model = PeftModel.from_pretrained(base_model, ft_model_id).to(device)
37
  model.eval()
38
 
39