LeroyDyer commited on
Commit
f429ed8
·
verified ·
1 Parent(s): 42fcfa0

Delete LOAD_THIS_MODEL.py

Browse files
Files changed (1) hide show
  1. LOAD_THIS_MODEL.py +0 -126
LOAD_THIS_MODEL.py DELETED
@@ -1,126 +0,0 @@
1
- from transformers import AutoTokenizer, AutoModelForCausalLM, TextGenerationPipeline, AutoConfig, BitsAndBytesConfig
2
-
3
-
4
-
5
-
6
- import torch
7
- n_ahead_talk_global = 4
8
- n_passes_global = 2
9
- n_ahead_global = 8
10
- n_examples = 0
11
-
12
- def model_init(params):
13
- original = False
14
- if params is None:
15
- params = {}
16
- else:
17
- params = params.params
18
- # save params to file
19
- n_ahead = params.get("n_ahead", n_ahead_global if not original else 1)
20
- n_ahead_talk = params.get("n_ahead_talk", n_ahead_talk_global if not original else 1)
21
- n_passes = params.get("n_passes", n_passes_global if not original else 1)
22
- gumbel_temperature = params.get("gumbel_temperature", 1)
23
- use_start_thought_token = params.get("use_start_thought_token", True)
24
- use_end_thought_token = params.get("use_end_thought_token", True)
25
- include_policy_loss = params.get("include_policy_loss", True)
26
- gumbel_detach = params.get("gumbel_detach", True)
27
- merged_talk_heads = params.get("merged_talk_heads", True)
28
- residual_think_head = params.get("residual_think_head", False)
29
- optimize_lm_head_only_at_start = params.get("optimize_lm_head_only_at_start", False)
30
-
31
- model_id = "LeroyDyer/_Spydaz_Web_AI_V2_Aligned"
32
- tokenizer_id = model_id
33
- print("Loading model")
34
-
35
- model = AutoModelForCausalLM.from_pretrained(
36
- model_id,
37
- torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
38
- max_thoughts=n_ahead + n_ahead_talk + 1,
39
- merged_talk_heads=merged_talk_heads,
40
- merged_lm_and_talk_heads=False,
41
- merged_lm_and_think_heads=True,
42
- use_concat_talk_head=True,
43
- use_shallow_think=True,
44
- use_shallow_talk=False,
45
- use_complex_think_head=False,
46
- use_complex_talk_head=True,
47
- use_weighted_talk_head=True,
48
- trust_remote_code=True,
49
- device_map="auto",
50
- )
51
- print("Loaded model")
52
-
53
- tokenizer = AutoTokenizer.from_pretrained(tokenizer_id, truncation=True, padding_side="right")
54
- tokenizer.pad_token_id = tokenizer.eos_token_id
55
-
56
- special_tokens_to_add = []
57
- if model.use_start_thought_token:
58
- special_tokens_to_add.append("<|startthought|>")
59
- if model.use_end_thought_token:
60
- special_tokens_to_add.append("<|endthought|>")
61
- if special_tokens_to_add:
62
- tokenizer.add_special_tokens({"additional_special_tokens": special_tokens_to_add})
63
- model.resize_token_embeddings(len(tokenizer))
64
- model.tokenizer = tokenizer
65
- for name, module in model.named_modules():
66
- if "embed" in name:
67
- print(module, flush=True)
68
-
69
- model.gumbel_detach = gumbel_detach
70
- model.include_policy_loss = include_policy_loss
71
- model.use_end_thought_token = use_end_thought_token
72
- model.use_start_thought_token = use_start_thought_token
73
- model.n_ahead = n_ahead
74
- model.n_ahead_talk = n_ahead_talk
75
- model.n_passes = n_passes
76
- model.residual_think_head = residual_think_head
77
- model.optimize_lm_head_only_at_start = optimize_lm_head_only_at_start
78
- model.gumbel_temperature = gumbel_temperature
79
- model.original_mode = original
80
- model.config_params = params
81
- model.run_start = int(time.time())
82
- model.train()
83
- return model,tokenizer
84
-
85
- model,tokenizer = model_init(None)
86
- tokenizer.save_pretrained("IModel")
87
- model.save_pretrained("IModel")
88
-
89
-
90
-
91
-
92
-
93
- from datasets import load_dataset
94
-
95
- ### DATA SET FOR TRAINING
96
-
97
-
98
- alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
99
-
100
- ### Instruction:
101
- {}
102
-
103
- ### Input:
104
- {}
105
-
106
- ### Response:
107
- {}"""
108
-
109
-
110
- EOS_TOKEN = tokenizer.eos_token # Must add EOS_TOKEN
111
- def formatting_prompts_func(examples):
112
- instructions = examples["instruction"]
113
- inputs = examples["input"]
114
- outputs = examples["output"]
115
- texts = []
116
- for instruction, input, output in zip(instructions, inputs, outputs):
117
- # Must add EOS_TOKEN, otherwise your generation will go on forever!
118
- text = alpaca_prompt.format(instruction, input, output) + EOS_TOKEN
119
- texts.append(text)
120
- return { "text" : texts, }
121
- pass
122
-
123
- from datasets import load_dataset
124
- dataset = load_dataset("gate369/Alpaca-Star", split = "train[:2000]")
125
- dataset = dataset.shuffle(seed=3704)
126
- dataset = dataset.map(formatting_prompts_func, batched = True,)