Upload train.py with huggingface_hub
Browse files
train.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# /// script
|
| 2 |
+
# dependencies = [
|
| 3 |
+
# "trl>=0.12.0",
|
| 4 |
+
# "peft>=0.13.0",
|
| 5 |
+
# "transformers>=4.45.0",
|
| 6 |
+
# "datasets>=3.0.0",
|
| 7 |
+
# "accelerate>=1.0.0",
|
| 8 |
+
# "trackio",
|
| 9 |
+
# ]
|
| 10 |
+
# ///
|
| 11 |
+
"""Lexwell SFT — Qwen2.5-3B-Instruct fine-tune on IRAC contract-review corpus.
|
| 12 |
+
|
| 13 |
+
Runs on HF Jobs. Reads 80 hand-curated SFT rows from Curious-PM/lexwell-contract-irac
|
| 14 |
+
and pushes the LoRA adapter to Curious-PM/lexwell-contract-irac-qwen2.5-3b-lora.
|
| 15 |
+
"""
|
| 16 |
+
from datasets import load_dataset
|
| 17 |
+
from peft import LoraConfig
|
| 18 |
+
from trl import SFTTrainer, SFTConfig
|
| 19 |
+
|
| 20 |
+
BASE = "Qwen/Qwen2.5-3B-Instruct"
|
| 21 |
+
DS = "Curious-PM/lexwell-contract-irac"
|
| 22 |
+
OUT = "Curious-PM/lexwell-contract-irac-qwen2.5-3b-lora"
|
| 23 |
+
|
| 24 |
+
print(f"Loading dataset {DS}...")
|
| 25 |
+
ds = load_dataset(DS, data_files="lexwell_v2.jsonl", split="train")
|
| 26 |
+
print(f"Loaded {len(ds)} rows")
|
| 27 |
+
print(f"First row keys: {list(ds[0].keys())}")
|
| 28 |
+
|
| 29 |
+
trainer = SFTTrainer(
|
| 30 |
+
model=BASE,
|
| 31 |
+
train_dataset=ds,
|
| 32 |
+
peft_config=LoraConfig(
|
| 33 |
+
r=16,
|
| 34 |
+
lora_alpha=32,
|
| 35 |
+
task_type="CAUSAL_LM",
|
| 36 |
+
target_modules=["q_proj", "k_proj", "v_proj", "o_proj"],
|
| 37 |
+
),
|
| 38 |
+
args=SFTConfig(
|
| 39 |
+
output_dir="lexwell-lora",
|
| 40 |
+
num_train_epochs=10,
|
| 41 |
+
per_device_train_batch_size=4,
|
| 42 |
+
gradient_accumulation_steps=1,
|
| 43 |
+
learning_rate=2e-4,
|
| 44 |
+
max_length=2048,
|
| 45 |
+
logging_steps=10,
|
| 46 |
+
eval_strategy="no",
|
| 47 |
+
save_strategy="no",
|
| 48 |
+
bf16=True,
|
| 49 |
+
push_to_hub=True,
|
| 50 |
+
hub_model_id=OUT,
|
| 51 |
+
hub_strategy="end",
|
| 52 |
+
report_to="trackio",
|
| 53 |
+
project="lexwell-irac",
|
| 54 |
+
run_name="qwen2.5-3b-sft-r16-e10",
|
| 55 |
+
),
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
print("Starting training...")
|
| 59 |
+
trainer.train()
|
| 60 |
+
print("Training complete. Pushing to Hub...")
|
| 61 |
+
trainer.push_to_hub()
|
| 62 |
+
print(f"\nAdapter pushed: https://huggingface.co/{OUT}")
|