Kevin Fink commited on
Commit
2a237b2
·
1 Parent(s): d1da5ff
Files changed (1) hide show
  1. app.py +2 -5
app.py CHANGED
@@ -6,7 +6,6 @@ from datasets import load_dataset, concatenate_datasets, load_from_disk
6
  import traceback
7
  from sklearn.metrics import accuracy_score
8
  import numpy as np
9
- import torch
10
 
11
  import os
12
  from huggingface_hub import login
@@ -20,14 +19,13 @@ lora_config = LoraConfig(
20
  lora_dropout=0.1, # Dropout for LoRA layers
21
  bias="none" # Bias handling
22
  )
23
- model = AutoModelForSeq2SeqLM.from_pretrained('google/t5-efficient-tiny-nh8', num_labels=2, force_download=True)
24
  model = get_peft_model(model, lora_config)
25
  model.gradient_checkpointing_enable()
26
 
27
  @spaces.GPU(duration=120)
28
  def fine_tune_model(model, dataset_name, hub_id, api_key, num_epochs, batch_size, lr, grad):
29
  try:
30
- torch.cuda.empty_cache()
31
  def compute_metrics(eval_pred):
32
  logits, labels = eval_pred
33
  predictions = np.argmax(logits, axis=1)
@@ -53,7 +51,7 @@ def fine_tune_model(model, dataset_name, hub_id, api_key, num_epochs, batch_size
53
  per_device_eval_batch_size=int(batch_size),
54
  num_train_epochs=int(num_epochs),
55
  weight_decay=0.01,
56
- gradient_accumulation_steps=int(grad),
57
  max_grad_norm = 1.0,
58
  load_best_model_at_end=True,
59
  metric_for_best_model="accuracy",
@@ -84,7 +82,6 @@ def fine_tune_model(model, dataset_name, hub_id, api_key, num_epochs, batch_size
84
  train_dataset=tokenized_train_dataset,
85
  eval_dataset=tokenized_test_dataset,
86
  compute_metrics=compute_metrics,
87
- #callbacks=[LoggingCallback()],
88
  )
89
  except:
90
  # Load the dataset
 
6
  import traceback
7
  from sklearn.metrics import accuracy_score
8
  import numpy as np
 
9
 
10
  import os
11
  from huggingface_hub import login
 
19
  lora_dropout=0.1, # Dropout for LoRA layers
20
  bias="none" # Bias handling
21
  )
22
+ model = AutoModelForSeq2SeqLM.from_pretrained('google/t5-efficient-tiny', num_labels=2, force_download=True)
23
  model = get_peft_model(model, lora_config)
24
  model.gradient_checkpointing_enable()
25
 
26
  @spaces.GPU(duration=120)
27
  def fine_tune_model(model, dataset_name, hub_id, api_key, num_epochs, batch_size, lr, grad):
28
  try:
 
29
  def compute_metrics(eval_pred):
30
  logits, labels = eval_pred
31
  predictions = np.argmax(logits, axis=1)
 
51
  per_device_eval_batch_size=int(batch_size),
52
  num_train_epochs=int(num_epochs),
53
  weight_decay=0.01,
54
+ #gradient_accumulation_steps=int(grad),
55
  max_grad_norm = 1.0,
56
  load_best_model_at_end=True,
57
  metric_for_best_model="accuracy",
 
82
  train_dataset=tokenized_train_dataset,
83
  eval_dataset=tokenized_test_dataset,
84
  compute_metrics=compute_metrics,
 
85
  )
86
  except:
87
  # Load the dataset