Phanh2532 commited on
Commit
bfd9221
·
verified ·
1 Parent(s): 3ffbd1b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +95 -3
README.md CHANGED
@@ -1,5 +1,97 @@
1
  ---
2
- license: other
3
- license_name: gama-platform
4
- license_link: LICENSE
 
 
 
 
5
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ library_name: transformers
3
+ base_model: mistralai/Mistral-7B-v0.1
4
+ language:
5
+ - en
6
+ pipeline_tag: text-generation
7
+ tags:
8
+ - code
9
  ---
10
+
11
+ # Model Card for Model ID
12
+
13
+ <!-- Provide a quick summary of what the model is/does. -->
14
+
15
+ > This finetuned model is already merged with Mistral7B (Base model)
16
+ > There will be 2 options running this model for inference
17
+ > - _Option 1:_ Load base model and use **Peft library** to load parameters of finetuned model on base model
18
+ > - _Option 2:_ Load finetuned model straight from this huggingface hub
19
+
20
+ ## Approach 1
21
+ ### Run Inference on Google Colab
22
+ 1. First run this code to load the base model which is Mistral-7B-v0.1
23
+ ```py
24
+ import torch
25
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
26
+
27
+ base_model_id = "mistralai/Mistral-7B-v0.1"
28
+ bnb_config = BitsAndBytesConfig(
29
+ load_in_4bit=True,
30
+ bnb_4bit_use_double_quant=True,
31
+ bnb_4bit_quant_type="nf4",
32
+ bnb_4bit_compute_dtype=torch.bfloat16
33
+ )
34
+
35
+ base_model = AutoModelForCausalLM.from_pretrained(
36
+ base_model_id, # Mistral, same as before
37
+ quantization_config=bnb_config, # Same quantization config as before
38
+ device_map="auto",
39
+ trust_remote_code=True,
40
+ use_auth_token=True
41
+ )
42
+
43
+ eval_tokenizer = AutoTokenizer.from_pretrained(base_model_id, add_bos_token=True, trust_remote_code=True)
44
+
45
+ ```
46
+ 2. After that, we would use Peft library to merge the new parameters that we already finetuned with GAML with this code
47
+ ```py
48
+ from peft import PeftModel
49
+ import torch
50
+ # ft_model = PeftModel.from_pretrained(base_model, "mistral-gama-finetune_allblocks_newdata/checkpoint-45")
51
+ ft_model = PeftModel.from_pretrained(base_model, "Phanh2532/GAML-151-500")
52
+ #ft_model3 = PeftModel.from_pretrained(base_model, "mistral-allbloclks//checkpoint-250")
53
+ #ft_model.save_pretrained('/content/mistral-allblocksft/')
54
+ eval_prompt = "Create a GAML code snippet inspired by water pollution in real life"
55
+ model_input = eval_tokenizer(eval_prompt, return_tensors="pt").to("cuda")
56
+ ft_model.eval()
57
+ with torch.no_grad():
58
+ print(eval_tokenizer.decode(ft_model.generate(**model_input, max_new_tokens=2000, repetition_penalty=1.15)[0], skip_special_tokens=True))
59
+ print('----------------------------------------------------------------------')
60
+ #print(eval_tokenizer.decode(ft_model2.generate(**model_input, max_new_tokens=2000, repetition_penalty=1.15)[0], skip_special_tokens=True))
61
+ ```
62
+
63
+ ## Approach 2
64
+ Run this code snippet
65
+ ```py
66
+ import torch
67
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
68
+
69
+ # Load Mistral 7B model and tokenizer
70
+ model_id = "Phanh2532/GAML-151-500"
71
+ bnb_config = BitsAndBytesConfig(
72
+ load_in_4bit=True,
73
+ bnb_4bit_use_double_quant=True,
74
+ bnb_4bit_quant_type="nf4",
75
+ bnb_4bit_compute_dtype=torch.bfloat16
76
+ )
77
+
78
+ model = AutoModelForCausalLM.from_pretrained(
79
+ model_id,
80
+ quantization_config=bnb_config,
81
+ device_map="auto",
82
+ trust_remote_code=True,
83
+ use_auth_token=True
84
+ )
85
+
86
+ # Load the tokenizer
87
+ tokenizer = AutoTokenizer.from_pretrained(model_id, add_bos_token=True, trust_remote_code=True)
88
+ with torch.no_grad():
89
+ print(tokenizer.decode(model.generate(**model_input, max_new_tokens=2000, repetition_penalty=1.15)[0], skip_special_tokens=True))
90
+ print('----------------------------------------------------------------------')
91
+ # print(eval_tokenizer.decode(ft_model2.generate(**model_input, max_new_tokens=2000, repetition_penalty=1.15)[0], skip_special_tokens=True))
92
+ ```
93
+
94
+
95
+ ### Framework versions
96
+
97
+ - PEFT 0.7.2.dev0