Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,29 +45,33 @@ else:
|
|
| 45 |
)
|
| 46 |
model = get_peft_model(model, lora_config)
|
| 47 |
|
| 48 |
-
# Load dataset
|
| 49 |
dataset = load_dataset("mbpp", split="train")
|
| 50 |
|
|
|
|
| 51 |
def tokenize_function(examples):
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
|
| 54 |
tokenized_dataset = dataset.map(tokenize_function, batched=True)
|
| 55 |
|
| 56 |
# Data collator
|
| 57 |
data_collator = DataCollatorForSeq2Seq(tokenizer, return_tensors="pt")
|
| 58 |
|
|
|
|
| 59 |
training_args = TrainingArguments(
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
)
|
| 71 |
|
| 72 |
# Trainer
|
| 73 |
trainer = Trainer(
|
|
|
|
| 45 |
)
|
| 46 |
model = get_peft_model(model, lora_config)
|
| 47 |
|
| 48 |
+
# Load dataset
|
| 49 |
dataset = load_dataset("mbpp", split="train")
|
| 50 |
|
| 51 |
+
# 🔥 Fix: Set `labels` properly
|
| 52 |
def tokenize_function(examples):
|
| 53 |
+
inputs = tokenizer(examples["text"], padding="max_length", truncation=True, max_length=512)
|
| 54 |
+
inputs["labels"] = inputs["input_ids"].copy() # ✅ Fix: Ensure labels exist
|
| 55 |
+
return inputs
|
| 56 |
|
| 57 |
tokenized_dataset = dataset.map(tokenize_function, batched=True)
|
| 58 |
|
| 59 |
# Data collator
|
| 60 |
data_collator = DataCollatorForSeq2Seq(tokenizer, return_tensors="pt")
|
| 61 |
|
| 62 |
+
# Training arguments
|
| 63 |
training_args = TrainingArguments(
|
| 64 |
+
per_device_train_batch_size=1,
|
| 65 |
+
num_train_epochs=1, # Reduce epochs for quick training
|
| 66 |
+
learning_rate=3e-4,
|
| 67 |
+
output_dir=model_path,
|
| 68 |
+
save_strategy="epoch",
|
| 69 |
+
logging_dir="./logs",
|
| 70 |
+
logging_steps=10,
|
| 71 |
+
save_total_limit=2,
|
| 72 |
+
evaluation_strategy="no", # ✅ Fix: No evaluation dataset needed
|
| 73 |
+
load_best_model_at_end=False # ✅ Fix: Prevents conflict with no eval dataset
|
| 74 |
+
)
|
| 75 |
|
| 76 |
# Trainer
|
| 77 |
trainer = Trainer(
|