bisoye commited on
Commit
96ca3c6
·
verified ·
1 Parent(s): 0171302

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +27 -27
main.py CHANGED
@@ -13,43 +13,43 @@ People will talk to you about their personal life/mental health issues and you w
13
  therapist would, while being empathetic."""
14
 
15
 
16
- # def load_peft_model_and_tokenizer(peft_model, base_model):
17
 
18
- # tokenizer = AutoTokenizer.from_pretrained(peft_model)
19
 
20
 
21
- # bnb_config = BitsAndBytesConfig(
22
- # load_in_4bit=True,
23
- # bnb_4bit_use_double_quant=True,
24
- # bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16
25
- # )
26
 
27
- # # Load base model
28
- # base_model = AutoModelForCausalLM.from_pretrained(
29
- # base_model,
30
- # device_map="auto",
31
- # torch_dtype=torch.bfloat16,
32
- # quantization_config=bnb_config
33
- # )
34
 
35
 
36
- # base_model.resize_token_embeddings(len(tokenizer))
37
- # model = PeftModel.from_pretrained(model=base_model, model_id=peft_model)
38
 
39
- # return tokenizer, model
40
 
41
- def load_peft_model_and_tokenizer(peft_model):
42
- # Load the tokenizer from the specified model path or identifier
43
- tokenizer = AutoTokenizer.from_pretrained(peft_model)
44
 
45
- # Load the PEFT model for causal language modeling with specific device map and torch dtype
46
- model = AutoPeftModelForCausalLM.from_pretrained(
47
- peft_model,
48
- device_map="auto",
49
- torch_dtype=torch.float16
50
- )
51
 
52
- return tokenizer, model
53
 
54
 
55
 
 
13
  therapist would, while being empathetic."""
14
 
15
 
16
+ def load_peft_model_and_tokenizer(peft_model, base_model):
17
 
18
+ tokenizer = AutoTokenizer.from_pretrained(peft_model)
19
 
20
 
21
+ bnb_config = BitsAndBytesConfig(
22
+ load_in_4bit=True,
23
+ bnb_4bit_use_double_quant=True,
24
+ bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16
25
+ )
26
 
27
+ # Load base model
28
+ base_model = AutoModelForCausalLM.from_pretrained(
29
+ base_model,
30
+ device_map="auto",
31
+ torch_dtype=torch.bfloat16,
32
+ quantization_config=bnb_config
33
+ )
34
 
35
 
36
+ base_model.resize_token_embeddings(len(tokenizer))
37
+ model = PeftModel.from_pretrained(model=base_model, model_id=peft_model)
38
 
39
+ return tokenizer, model
40
 
41
+ # def load_peft_model_and_tokenizer(peft_model):
42
+ # # Load the tokenizer from the specified model path or identifier
43
+ # tokenizer = AutoTokenizer.from_pretrained(peft_model)
44
 
45
+ # # Load the PEFT model for causal language modeling with specific device map and torch dtype
46
+ # model = AutoPeftModelForCausalLM.from_pretrained(
47
+ # peft_model,
48
+ # device_map="auto",
49
+ # torch_dtype=torch.float16
50
+ # )
51
 
52
+ # return tokenizer, model
53
 
54
 
55