Kevin Fink commited on
Commit
b994095
·
1 Parent(s): 069bfa6
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -12,10 +12,20 @@ import os
12
  from huggingface_hub import login
13
  from peft import get_peft_model, LoraConfig
14
 
15
- #os.environ['HF_HOME'] = '/data/.huggingface'
 
 
 
 
 
 
 
 
 
 
16
 
17
  @spaces.GPU(duration=120)
18
- def fine_tune_model(model_name, dataset_name, hub_id, api_key, num_epochs, batch_size, lr, grad):
19
  try:
20
  torch.cuda.empty_cache()
21
  def compute_metrics(eval_pred):
@@ -27,17 +37,10 @@ def fine_tune_model(model_name, dataset_name, hub_id, api_key, num_epochs, batch
27
  'eval_loss': eval_pred.loss, # If you want to include loss as well
28
  }
29
  login(api_key.strip())
30
- lora_config = LoraConfig(
31
- r=16, # Rank of the low-rank adaptation
32
- lora_alpha=32, # Scaling factor
33
- lora_dropout=0.1, # Dropout for LoRA layers
34
- bias="none" # Bias handling
35
- )
36
 
37
  # Load the model and tokenizer
38
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name.strip(), num_labels=2, force_download=True)
39
- model.gradient_checkpointing_enable()
40
- #model = get_peft_model(model, lora_config)
41
 
42
 
43
  # Set training arguments
@@ -86,7 +89,7 @@ def fine_tune_model(model_name, dataset_name, hub_id, api_key, num_epochs, batch
86
  except:
87
  # Load the dataset
88
  dataset = load_dataset(dataset_name.strip())
89
- tokenizer = AutoTokenizer.from_pretrained(model_name)
90
  # Tokenize the dataset
91
  def tokenize_function(examples):
92
 
@@ -148,7 +151,6 @@ try:
148
  iface = gr.Interface(
149
  fn=fine_tune_model,
150
  inputs=[
151
- gr.Textbox(label="Model Name (e.g., 'google/t5-efficient-tiny-nh8')"),
152
  gr.Textbox(label="Dataset Name (e.g., 'imdb')"),
153
  gr.Textbox(label="HF hub to push to after training"),
154
  gr.Textbox(label="HF API token"),
 
12
  from huggingface_hub import login
13
  from peft import get_peft_model, LoraConfig
14
 
15
+ os.environ['HF_HOME'] = '/data/.huggingface'
16
+
17
+ lora_config = LoraConfig(
18
+ r=16, # Rank of the low-rank adaptation
19
+ lora_alpha=32, # Scaling factor
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(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):
 
37
  'eval_loss': eval_pred.loss, # If you want to include loss as well
38
  }
39
  login(api_key.strip())
40
+
 
 
 
 
 
41
 
42
  # Load the model and tokenizer
43
+
 
 
44
 
45
 
46
  # Set training arguments
 
89
  except:
90
  # Load the dataset
91
  dataset = load_dataset(dataset_name.strip())
92
+ tokenizer = AutoTokenizer.from_pretrained('google/t5-efficient-tiny-nh8')
93
  # Tokenize the dataset
94
  def tokenize_function(examples):
95
 
 
151
  iface = gr.Interface(
152
  fn=fine_tune_model,
153
  inputs=[
 
154
  gr.Textbox(label="Dataset Name (e.g., 'imdb')"),
155
  gr.Textbox(label="HF hub to push to after training"),
156
  gr.Textbox(label="HF API token"),