Crystalcareai commited on
Commit
562cf21
1 Parent(s): 2f1ae9e

Update train.py

Browse files
Files changed (1) hide show
  1. train.py +30 -28
train.py CHANGED
@@ -14,10 +14,11 @@ random.seed(random_seed)
14
 
15
  dataset = load_dataset("HuggingFaceH4/deita-10k-v0-sft", split="train_sft")
16
 
17
- n_ahead_talk_global = 4
18
  n_passes_global = 2
19
- n_ahead_global = 12
20
- full_batch_size = 8
 
21
  eval_and_logging_steps = 2
22
  save_steps = 100
23
 
@@ -43,11 +44,11 @@ def model_init(params):
43
  optimize_lm_head_only_at_start = params.get("optimize_lm_head_only_at_start", False)
44
 
45
  model_id = "Crystalcareai/Quiet-Star-Custom"
46
- tokenizer_id = "Crystalcareai/Quiet-Star-Custom"
47
  print("Loading model")
48
  model = AutoModelForCausalLM.from_pretrained(
49
  model_id,
50
- torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
51
  max_thoughts=n_ahead + n_ahead_talk + 1,
52
  merged_talk_heads=merged_talk_heads,
53
  merged_lm_and_talk_heads=False,
@@ -58,13 +59,12 @@ def model_init(params):
58
  use_complex_think_head=False,
59
  use_complex_talk_head=True,
60
  use_weighted_talk_head=True,
61
- trust_remote_code=True,
62
- load_in_4bit=True,
63
  )
64
  print("Loaded model")
65
 
66
- tokenizer = AutoTokenizer.from_pretrained(tokenizer_id)
67
- tokenizer.padding_side = "right"
68
  tokenizer.pad_token_id = tokenizer.eos_token_id
69
 
70
  special_tokens_to_add = []
@@ -103,31 +103,33 @@ training_args = TrainingArguments(
103
  output_dir="./out",
104
  num_train_epochs=3,
105
  per_device_train_batch_size=1,
106
- gradient_accumulation_steps=global_gradient_accumulation_steps,
107
- gradient_checkpointing=True,
108
- optim="adamw_bnb_8bit",
109
- logging_steps=2,
110
  save_strategy="steps",
111
  save_steps=300,
112
  bf16=True,
113
  tf32=False,
114
- learning_rate=2e-4,
115
- max_grad_norm=0.3,
116
- warmup_ratio=0.00,
117
- lr_scheduler_type="constant",
 
118
  push_to_hub=False,
119
  )
120
 
121
- peft_config = LoraConfig(
122
- lora_alpha=16,
123
- lora_dropout=0.05,
124
- r=32,
125
- bias="none",
126
- target_modules = ["q_proj", "k_proj", "v_proj", "o_proj","gate_proj", "up_proj", "down_proj",],
127
- task_type="CAUSAL_LM",
128
- use_dora=False, # Enable Dora method
129
- )
130
 
 
131
  model = model_init(None) # Initialize the model
132
  tokenizer = model.tokenizer
133
 
@@ -135,8 +137,8 @@ trainer = SFTTrainer(
135
  args=training_args,
136
  train_dataset=dataset,
137
  model=model,
138
- peft_config=peft_config,
139
  tokenizer=tokenizer,
140
  )
141
 
142
- trainer.train()
 
14
 
15
  dataset = load_dataset("HuggingFaceH4/deita-10k-v0-sft", split="train_sft")
16
 
17
+ n_ahead_talk_global = 2
18
  n_passes_global = 2
19
+ n_ahead_global = 2
20
+ n_examples = 0
21
+ full_batch_size = 2
22
  eval_and_logging_steps = 2
23
  save_steps = 100
24
 
 
44
  optimize_lm_head_only_at_start = params.get("optimize_lm_head_only_at_start", False)
45
 
46
  model_id = "Crystalcareai/Quiet-Star-Custom"
47
+ tokenizer_id = model_id
48
  print("Loading model")
49
  model = AutoModelForCausalLM.from_pretrained(
50
  model_id,
51
+ torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
52
  max_thoughts=n_ahead + n_ahead_talk + 1,
53
  merged_talk_heads=merged_talk_heads,
54
  merged_lm_and_talk_heads=False,
 
59
  use_complex_think_head=False,
60
  use_complex_talk_head=True,
61
  use_weighted_talk_head=True,
62
+ trust_remote_code=True,
63
+ device_map="auto",
64
  )
65
  print("Loaded model")
66
 
67
+ tokenizer = AutoTokenizer.from_pretrained(tokenizer_id,padding=False,truncation=True)
 
68
  tokenizer.pad_token_id = tokenizer.eos_token_id
69
 
70
  special_tokens_to_add = []
 
103
  output_dir="./out",
104
  num_train_epochs=3,
105
  per_device_train_batch_size=1,
106
+ gradient_checkpointing=False,
107
+ gradient_accumulation_steps=4,
108
+ optim="adamw_torch_fused",
109
+ logging_steps=1,
110
  save_strategy="steps",
111
  save_steps=300,
112
  bf16=True,
113
  tf32=False,
114
+ # auto_find_batch_size=True
115
+ learning_rate=2e-07,
116
+ max_grad_norm=1.0, # Gradient clipping with a maximum gradient norm of 0.3
117
+ warmup_steps=100,
118
+ lr_scheduler_type="cosine",
119
  push_to_hub=False,
120
  )
121
 
122
+ # peft_config = LoraConfig(
123
+ # r = 16, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128
124
+ # target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
125
+ # "gate_proj", "up_proj", "down_proj",],
126
+ # lora_alpha = 16,
127
+ # lora_dropout = 0, # Supports any, but = 0 is optimized
128
+ # bias = "none", # Enable Dora method
129
+ # use_dora=True,
130
+ # )
131
 
132
+ torch.autograd.set_detect_anomaly(True)
133
  model = model_init(None) # Initialize the model
134
  tokenizer = model.tokenizer
135
 
 
137
  args=training_args,
138
  train_dataset=dataset,
139
  model=model,
140
+ # peft_config=peft_config,
141
  tokenizer=tokenizer,
142
  )
143
 
144
+ trainer.train()