dh-mc commited on
Commit
4a18348
1 Parent(s): 3e74e95
llm_toolkit/tune_logical_reasoning.py CHANGED
@@ -6,8 +6,6 @@ from trl import SFTTrainer
6
  from transformers import TrainingArguments
7
 
8
  from dotenv import find_dotenv, load_dotenv
9
- from llm_toolkit.logical_reasoning_utils import *
10
- from llm_toolkit.llm_utils import *
11
 
12
  found_dotenv = find_dotenv(".env")
13
 
@@ -20,11 +18,14 @@ path = os.path.dirname(found_dotenv)
20
  print(f"Adding {path} to sys.path")
21
  sys.path.append(path)
22
 
 
 
 
23
  model_name = os.getenv("MODEL_NAME")
24
  token = os.getenv("HF_TOKEN") or None
25
  load_in_4bit = os.getenv("LOAD_IN_4BIT") == "true"
26
- local_model = os.getenv("LOCAL_MODEL")
27
- hub_model = os.getenv("HUB_MODEL")
28
  num_train_epochs = int(os.getenv("NUM_TRAIN_EPOCHS") or 0)
29
  data_path = os.getenv("LOGICAL_REASONING_DATA_PATH")
30
  results_path = os.getenv("LOGICAL_REASONING_RESULTS_PATH")
@@ -140,6 +141,9 @@ print(f"Peak reserved memory for training = {used_memory_for_lora} GB.")
140
  print(f"Peak reserved memory % of max memory = {used_percentage} %.")
141
  print(f"Peak reserved memory for training % of max memory = {lora_percentage} %.")
142
 
 
 
 
143
  print("Evaluating fine-tuned model: " + model_name)
144
  FastLanguageModel.for_inference(model) # Enable native 2x faster inference
145
  predictions = eval_model(model, tokenizer, datasets["test"])
@@ -160,3 +164,6 @@ save_results(
160
 
161
  metrics = calc_metrics(datasets["test"]["label"], predictions, debug=True)
162
  print(metrics)
 
 
 
 
6
  from transformers import TrainingArguments
7
 
8
  from dotenv import find_dotenv, load_dotenv
 
 
9
 
10
  found_dotenv = find_dotenv(".env")
11
 
 
18
  print(f"Adding {path} to sys.path")
19
  sys.path.append(path)
20
 
21
+ from llm_toolkit.logical_reasoning_utils import *
22
+ from llm_toolkit.llm_utils import *
23
+
24
  model_name = os.getenv("MODEL_NAME")
25
  token = os.getenv("HF_TOKEN") or None
26
  load_in_4bit = os.getenv("LOAD_IN_4BIT") == "true"
27
+ local_model = os.getenv("LOCAL_MODEL") or "gemma-2-9b-it-lora"
28
+ hub_model = os.getenv("HUB_MODEL") or "inflaton-ai/gemma-2-9b-it-lora"
29
  num_train_epochs = int(os.getenv("NUM_TRAIN_EPOCHS") or 0)
30
  data_path = os.getenv("LOGICAL_REASONING_DATA_PATH")
31
  results_path = os.getenv("LOGICAL_REASONING_RESULTS_PATH")
 
141
  print(f"Peak reserved memory % of max memory = {used_percentage} %.")
142
  print(f"Peak reserved memory for training % of max memory = {lora_percentage} %.")
143
 
144
+ model.save_pretrained(local_model) # Local saving
145
+ tokenizer.save_pretrained(local_model)
146
+
147
  print("Evaluating fine-tuned model: " + model_name)
148
  FastLanguageModel.for_inference(model) # Enable native 2x faster inference
149
  predictions = eval_model(model, tokenizer, datasets["test"])
 
164
 
165
  metrics = calc_metrics(datasets["test"]["label"], predictions, debug=True)
166
  print(metrics)
167
+
168
+ model.push_to_hub(hub_model, token=token) # Online saving
169
+ tokenizer.push_to_hub(hub_model, token=token) # Online saving