jaymojnidar commited on
Commit
e4aabb2
1 Parent(s): 903e4f3

adding my data config peft

Browse files
Files changed (2) hide show
  1. model.py +17 -9
  2. requirements.txt +3 -0
model.py CHANGED
@@ -3,6 +3,7 @@ from threading import Thread
3
  from typing import Iterator
4
 
5
  import torch
 
6
  from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
7
  from huggingface_hub import login
8
 
@@ -11,6 +12,8 @@ from huggingface_hub import login
11
  #model_id = 'Trelis/Llama-2-7b-chat-hf-sharded-bf16'
12
  model_id = 'jaymojnidar/llama2-finetuned-mydata'
13
  config_model_id = 'jaymojnidar/llama2-finetuned-mydata/adapter_config.json'
 
 
14
 
15
  if torch.cuda.is_available():
16
  tok = os.environ['HF_TOKEN']
@@ -21,15 +24,20 @@ if torch.cuda.is_available():
21
  #, token="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"
22
  )
23
 
24
- config = AutoConfig.from_pretrained(config_model_id, use_auth_token=True)
25
- config.pretraining_tp = 1
26
- model = AutoModelForCausalLM.from_pretrained(
27
- model_id,
28
- config=config,
29
- torch_dtype=torch.float16,
30
- #load_in_4bit=True,
31
- device_map='auto',
32
- use_auth_token=True
 
 
 
 
 
33
  )
34
  print("Loaded the model!")
35
  else:
 
3
  from typing import Iterator
4
 
5
  import torch
6
+ from peft import PeftModel, PeftConfig
7
  from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
8
  from huggingface_hub import login
9
 
 
12
  #model_id = 'Trelis/Llama-2-7b-chat-hf-sharded-bf16'
13
  model_id = 'jaymojnidar/llama2-finetuned-mydata'
14
  config_model_id = 'jaymojnidar/llama2-finetuned-mydata/adapter_config.json'
15
+ model_type = 'PEFT'
16
+
17
 
18
  if torch.cuda.is_available():
19
  tok = os.environ['HF_TOKEN']
 
24
  #, token="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"
25
  )
26
 
27
+ if model_type == 'PEFT':
28
+ config = PeftConfig.from_pretrained("jaymojnidar/llama2-finetuned-mydata")
29
+ model = AutoModelForCausalLM.from_pretrained("Trelis/Llama-2-7b-chat-hf-sharded-bf16")
30
+ model = PeftModel.from_pretrained(model, "jaymojnidar/llama2-finetuned-mydata")
31
+ else:
32
+ config = AutoConfig.from_pretrained(model_id, use_auth_token=True)
33
+ config.pretraining_tp = 1
34
+ model = AutoModelForCausalLM.from_pretrained(
35
+ model_id,
36
+ config=config,
37
+ torch_dtype=torch.float16,
38
+ #load_in_4bit=True,
39
+ device_map='auto',
40
+ use_auth_token=True
41
  )
42
  print("Loaded the model!")
43
  else:
requirements.txt CHANGED
@@ -1,8 +1,11 @@
1
  accelerate==0.21.0
2
  bitsandbytes==0.40.2
3
  gradio==3.37.0
 
4
  protobuf==3.20.3
5
  scipy==1.11.1
6
  sentencepiece==0.1.99
 
 
7
  torch==2.0.1
8
  transformers==4.31.0
 
1
  accelerate==0.21.0
2
  bitsandbytes==0.40.2
3
  gradio==3.37.0
4
+ peft==0.5.0
5
  protobuf==3.20.3
6
  scipy==1.11.1
7
  sentencepiece==0.1.99
8
+ #--extra-index-url https://download.pytorch.org/whl/cu113
9
+ #torch
10
  torch==2.0.1
11
  transformers==4.31.0