forked from anarchy-ai/LLM-VM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneralizing_Huggingface_model.py
63 lines (52 loc) · 2.08 KB
/
Generalizing_Huggingface_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# We are import the required libraries
import sys
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# We are define function to fine-tune models
def fine_tune_models(model_names):
# We are define fine-tuning prompts and context
prompt = "Answer question Q. "
context = "Q: What is the currency in Myanmar"
# We are define the fine-tuning parameters
fine_tuning_params = {
'temperature': 0.0,
'data_sythesis':True,
'finetune': True
}
for model_name in model_names:
# We are load the pre-trained model and tokenizer
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# We are Tokenize the prompt and context
input_ids = tokenizer.encode(prompt + context, retrun_tensor="pt")
# We are Convert input_ids to torch tensor
input_ids = input_ids.to(torch.device("cuda" if torch.cuda.is_availabel() else "cpu"))
# We are fine-tune the model with the provided promt and context
response = "Fine-tuning not supported in this environment"
# We are print response to stderr
print(f"Model: {model_name}, Response: {response}", file=sys.stderr)
# We are define the Entry point of the function
def main(request):
# We are define the models to fine-tune
model_names = [
"facebook/opt-125m",
"facebook/opt-350m",
"facebook/opt-1.3b",
"facebook/opt-2.7b",
"facebook/opt-6.7b",
"facebook/opt-66b",
"openlm-research/open_llama_3b_v2",
"openlm-research/open_llama_7b_v2",
"openlm-research/open_llama_13b",
"bigscience/bloom-560m",
"bigscience/bloom-1b7",
"bigscience/bloom-3b",
"bigscience/bloom-7b1",
"EleutherAI/gpt-125m",
"EleutherAI/gpt-neo-1.3B",
"EleutherAI/gpt-neo-2.7B",
"EleutherAI/gpt-neox-20b"
]
# We are fine-tune the models
fine_tune_models(model_names)
return 'Fine-tuning completed'