Upload minimal_test.py with huggingface_hub
Browse files- minimal_test.py +38 -0
minimal_test.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# /// script
|
| 2 |
+
# dependencies = ["trl", "peft", "transformers", "datasets", "accelerate", "torch"]
|
| 3 |
+
# ///
|
| 4 |
+
|
| 5 |
+
print("Starting...")
|
| 6 |
+
|
| 7 |
+
from datasets import load_dataset
|
| 8 |
+
from peft import LoraConfig
|
| 9 |
+
from trl import SFTTrainer, SFTConfig
|
| 10 |
+
|
| 11 |
+
print("Loading dataset...")
|
| 12 |
+
ds = load_dataset("trl-lib/Capybara", split="train[:100]")
|
| 13 |
+
print(f"Loaded {len(ds)} examples")
|
| 14 |
+
|
| 15 |
+
config = SFTConfig(
|
| 16 |
+
output_dir="test-output",
|
| 17 |
+
num_train_epochs=1,
|
| 18 |
+
per_device_train_batch_size=1,
|
| 19 |
+
logging_steps=5,
|
| 20 |
+
report_to="none",
|
| 21 |
+
push_to_hub=True,
|
| 22 |
+
hub_model_id="luiscosio/qwen25-minimal-test",
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
peft_config = LoraConfig(r=8, lora_alpha=16, task_type="CAUSAL_LM", target_modules=["q_proj", "v_proj"])
|
| 26 |
+
|
| 27 |
+
print("Creating trainer...")
|
| 28 |
+
trainer = SFTTrainer(
|
| 29 |
+
model="Qwen/Qwen2.5-0.5B",
|
| 30 |
+
train_dataset=ds,
|
| 31 |
+
args=config,
|
| 32 |
+
peft_config=peft_config,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
print("Training...")
|
| 36 |
+
trainer.train()
|
| 37 |
+
trainer.push_to_hub()
|
| 38 |
+
print("Done!")
|