Kevin Fink
commited on
Commit
·
e6614b8
1
Parent(s):
5a38614
dev
Browse files
app.py
CHANGED
@@ -20,13 +20,11 @@ def fine_tune_model(model_name, dataset_name, hub_id, api_key, num_epochs, batch
|
|
20 |
lora_dropout=0.1, # Dropout for LoRA layers
|
21 |
bias="none" # Bias handling
|
22 |
)
|
23 |
-
# Load the dataset
|
24 |
-
dataset = load_dataset(dataset_name.strip())
|
25 |
|
26 |
# Load the model and tokenizer
|
27 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name.strip(), num_labels=2)
|
28 |
model = get_peft_model(model, lora_config)
|
29 |
-
|
30 |
|
31 |
# Set training arguments
|
32 |
training_args = TrainingArguments(
|
@@ -52,6 +50,10 @@ def fine_tune_model(model_name, dataset_name, hub_id, api_key, num_epochs, batch
|
|
52 |
save_steps=40, # Save checkpoint every 500 steps
|
53 |
save_total_limit=3,
|
54 |
)
|
|
|
|
|
|
|
|
|
55 |
|
56 |
max_length = 128
|
57 |
try:
|
@@ -67,6 +69,9 @@ def fine_tune_model(model_name, dataset_name, hub_id, api_key, num_epochs, batch
|
|
67 |
#callbacks=[LoggingCallback()],
|
68 |
)
|
69 |
except:
|
|
|
|
|
|
|
70 |
# Tokenize the dataset
|
71 |
def tokenize_function(examples):
|
72 |
|
@@ -106,10 +111,7 @@ def fine_tune_model(model_name, dataset_name, hub_id, api_key, num_epochs, batch
|
|
106 |
)
|
107 |
|
108 |
|
109 |
-
|
110 |
-
if os.path.exists(training_args.output_dir) and os.listdir(training_args.output_dir):
|
111 |
-
print("Loading model from checkpoint...")
|
112 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(training_args.output_dir)
|
113 |
|
114 |
|
115 |
|
@@ -138,7 +140,7 @@ try:
|
|
138 |
gr.Textbox(label="HF hub to push to after training"),
|
139 |
gr.Textbox(label="HF API token"),
|
140 |
gr.Slider(minimum=1, maximum=10, value=3, label="Number of Epochs", step=1),
|
141 |
-
gr.Slider(minimum=1, maximum=
|
142 |
gr.Slider(minimum=1, maximum=1000, value=1, label="Learning Rate (e-5)", step=1),
|
143 |
gr.Slider(minimum=1, maximum=100, value=1, label="Gradient accumulation", step=1),
|
144 |
],
|
|
|
20 |
lora_dropout=0.1, # Dropout for LoRA layers
|
21 |
bias="none" # Bias handling
|
22 |
)
|
|
|
|
|
23 |
|
24 |
# Load the model and tokenizer
|
25 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name.strip(), num_labels=2)
|
26 |
model = get_peft_model(model, lora_config)
|
27 |
+
|
28 |
|
29 |
# Set training arguments
|
30 |
training_args = TrainingArguments(
|
|
|
50 |
save_steps=40, # Save checkpoint every 500 steps
|
51 |
save_total_limit=3,
|
52 |
)
|
53 |
+
# Check if a checkpoint exists and load it
|
54 |
+
if os.path.exists(training_args.output_dir) and os.listdir(training_args.output_dir):
|
55 |
+
print("Loading model from checkpoint...")
|
56 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(training_args.output_dir)
|
57 |
|
58 |
max_length = 128
|
59 |
try:
|
|
|
69 |
#callbacks=[LoggingCallback()],
|
70 |
)
|
71 |
except:
|
72 |
+
# Load the dataset
|
73 |
+
dataset = load_dataset(dataset_name.strip())
|
74 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
75 |
# Tokenize the dataset
|
76 |
def tokenize_function(examples):
|
77 |
|
|
|
111 |
)
|
112 |
|
113 |
|
114 |
+
|
|
|
|
|
|
|
115 |
|
116 |
|
117 |
|
|
|
140 |
gr.Textbox(label="HF hub to push to after training"),
|
141 |
gr.Textbox(label="HF API token"),
|
142 |
gr.Slider(minimum=1, maximum=10, value=3, label="Number of Epochs", step=1),
|
143 |
+
gr.Slider(minimum=1, maximum=60, value=1, label="Batch Size", step=1),
|
144 |
gr.Slider(minimum=1, maximum=1000, value=1, label="Learning Rate (e-5)", step=1),
|
145 |
gr.Slider(minimum=1, maximum=100, value=1, label="Gradient accumulation", step=1),
|
146 |
],
|