Update README.md (Fix)
#1
by
qpqpqpqpqpqp
- opened
README.md
CHANGED
|
@@ -15,7 +15,7 @@ base_model: HuggingFaceTB/SmolLM3-3B-Base
|
|
| 15 |
# Model Card for SmolLM3-3B-Instruct-Anime
|
| 16 |
|
| 17 |
This model is a fine-tuned version of [HuggingFaceTB/SmolLM3-3B-Base](https://huggingface.co/HuggingFaceTB/SmolLM3-3B-Base).
|
| 18 |
-
It
|
| 19 |
|
| 20 |
## Quick start
|
| 21 |
|
|
@@ -24,11 +24,11 @@ import torch
|
|
| 24 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 25 |
from peft import PeftModel
|
| 26 |
|
| 27 |
-
# Define paths
|
| 28 |
base_model_path = "./SmolLM3-3B-Base/"
|
| 29 |
adapter_path = "./SmolLM3-3B-Instruct-Anime/"
|
| 30 |
|
| 31 |
-
# Load the base model and tokenizer in bf16
|
| 32 |
print("Loading base model and tokenizer...")
|
| 33 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 34 |
base_model_path,
|
|
@@ -82,11 +82,11 @@ dataset_path = "./Instruct-Anime/instruct_dataset.jsonl"
|
|
| 82 |
output_dir = "./SmolLM3-3B-Instruct-Anime"
|
| 83 |
project_name = "smollm3-sft-anime"
|
| 84 |
|
| 85 |
-
# --- 1. Initialize
|
| 86 |
trackio.init(project=project_name)
|
| 87 |
|
| 88 |
-
# --- 2. Load
|
| 89 |
-
print("Loading model and tokenizer...")
|
| 90 |
model = AutoModelForCausalLM.from_pretrained(
|
| 91 |
model_name,
|
| 92 |
device_map="auto",
|
|
@@ -101,20 +101,20 @@ if tokenizer.pad_token is None:
|
|
| 101 |
tokenizer.pad_token = tokenizer.eos_token
|
| 102 |
model.config.pad_token_id = model.config.eos_token_id
|
| 103 |
|
| 104 |
-
# Load and set chat template from the jinja file
|
| 105 |
with open("chat_template.jinja", "r") as f:
|
| 106 |
chat_template = f.read()
|
| 107 |
tokenizer.chat_template = chat_template
|
| 108 |
-
print("
|
| 109 |
|
| 110 |
|
| 111 |
-
# --- Enable
|
| 112 |
print("Enabling Gradient Checkpointing...")
|
| 113 |
model.gradient_checkpointing_enable()
|
| 114 |
|
| 115 |
|
| 116 |
-
# --- 3. Load and
|
| 117 |
-
print("Loading and processing dataset...")
|
| 118 |
dataset = load_dataset("json", data_files=dataset_path, split="train")
|
| 119 |
|
| 120 |
def formatting_prompts_func(example):
|
|
@@ -128,8 +128,8 @@ dataset = dataset.map(formatting_prompts_func, remove_columns=["messages", "sour
|
|
| 128 |
print(f"Dataset loaded and formatted with {len(dataset)} examples.")
|
| 129 |
|
| 130 |
|
| 131 |
-
# --- 4. Configure LoRA ---
|
| 132 |
-
print("Configuring LoRA...")
|
| 133 |
peft_config = LoraConfig(
|
| 134 |
r=8,
|
| 135 |
lora_alpha=16,
|
|
@@ -139,7 +139,7 @@ peft_config = LoraConfig(
|
|
| 139 |
task_type="CAUSAL_LM",
|
| 140 |
)
|
| 141 |
|
| 142 |
-
# --- 5. Configure
|
| 143 |
# Balanced learning rate and batch size for a GPU with ~24GB VRAM
|
| 144 |
print("Configuring training arguments...")
|
| 145 |
training_args = SFTConfig(
|
|
@@ -162,7 +162,7 @@ training_args = SFTConfig(
|
|
| 162 |
greater_is_better=false
|
| 163 |
)
|
| 164 |
|
| 165 |
-
# --- 6. Create and
|
| 166 |
print("Creating SFTTrainer...")
|
| 167 |
trainer = SFTTrainer(
|
| 168 |
model=model,
|
|
@@ -176,10 +176,10 @@ print("Starting training...")
|
|
| 176 |
trainer.train() #resume_from_checkpoint=True
|
| 177 |
|
| 178 |
# --- 7. Save the final adapter ---
|
| 179 |
-
print("Training finished. Saving adapter.")
|
| 180 |
trainer.save_model(output_dir)
|
| 181 |
|
| 182 |
-
print(f"LoRA adapter saved to {output_dir}")
|
| 183 |
trackio.finish()
|
| 184 |
```
|
| 185 |
|
|
|
|
| 15 |
# Model Card for SmolLM3-3B-Instruct-Anime
|
| 16 |
|
| 17 |
This model is a fine-tuned version of [HuggingFaceTB/SmolLM3-3B-Base](https://huggingface.co/HuggingFaceTB/SmolLM3-3B-Base).
|
| 18 |
+
It was trained using [zerofata/Instruct-Anime](https://huggingface.co/datasets/zerofata/Instruct-Anime).
|
| 19 |
|
| 20 |
## Quick start
|
| 21 |
|
|
|
|
| 24 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 25 |
from peft import PeftModel
|
| 26 |
|
| 27 |
+
# Define the paths
|
| 28 |
base_model_path = "./SmolLM3-3B-Base/"
|
| 29 |
adapter_path = "./SmolLM3-3B-Instruct-Anime/"
|
| 30 |
|
| 31 |
+
# Load the base model and the tokenizer in bf16
|
| 32 |
print("Loading base model and tokenizer...")
|
| 33 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 34 |
base_model_path,
|
|
|
|
| 82 |
output_dir = "./SmolLM3-3B-Instruct-Anime"
|
| 83 |
project_name = "smollm3-sft-anime"
|
| 84 |
|
| 85 |
+
# --- 1. Initialize Trackio ---
|
| 86 |
trackio.init(project=project_name)
|
| 87 |
|
| 88 |
+
# --- 2. Load the model and the tokenizer ---
|
| 89 |
+
print("Loading the model and the tokenizer...")
|
| 90 |
model = AutoModelForCausalLM.from_pretrained(
|
| 91 |
model_name,
|
| 92 |
device_map="auto",
|
|
|
|
| 101 |
tokenizer.pad_token = tokenizer.eos_token
|
| 102 |
model.config.pad_token_id = model.config.eos_token_id
|
| 103 |
|
| 104 |
+
# Load and set the chat template from the jinja file
|
| 105 |
with open("chat_template.jinja", "r") as f:
|
| 106 |
chat_template = f.read()
|
| 107 |
tokenizer.chat_template = chat_template
|
| 108 |
+
print("The chat template has been loaded from chat_template.jinja and set on the tokenizer.")
|
| 109 |
|
| 110 |
|
| 111 |
+
# --- Enable gradient checkpointing ---
|
| 112 |
print("Enabling Gradient Checkpointing...")
|
| 113 |
model.gradient_checkpointing_enable()
|
| 114 |
|
| 115 |
|
| 116 |
+
# --- 3. Load and process the dataset ---
|
| 117 |
+
print("Loading and processing the dataset...")
|
| 118 |
dataset = load_dataset("json", data_files=dataset_path, split="train")
|
| 119 |
|
| 120 |
def formatting_prompts_func(example):
|
|
|
|
| 128 |
print(f"Dataset loaded and formatted with {len(dataset)} examples.")
|
| 129 |
|
| 130 |
|
| 131 |
+
# --- 4. Configure the LoRA ---
|
| 132 |
+
print("Configuring the LoRA...")
|
| 133 |
peft_config = LoraConfig(
|
| 134 |
r=8,
|
| 135 |
lora_alpha=16,
|
|
|
|
| 139 |
task_type="CAUSAL_LM",
|
| 140 |
)
|
| 141 |
|
| 142 |
+
# --- 5. Configure training ---
|
| 143 |
# Balanced learning rate and batch size for a GPU with ~24GB VRAM
|
| 144 |
print("Configuring training arguments...")
|
| 145 |
training_args = SFTConfig(
|
|
|
|
| 162 |
greater_is_better=false
|
| 163 |
)
|
| 164 |
|
| 165 |
+
# --- 6. Create and run the trainer ---
|
| 166 |
print("Creating SFTTrainer...")
|
| 167 |
trainer = SFTTrainer(
|
| 168 |
model=model,
|
|
|
|
| 176 |
trainer.train() #resume_from_checkpoint=True
|
| 177 |
|
| 178 |
# --- 7. Save the final adapter ---
|
| 179 |
+
print("Training has finished. Saving the adapter.")
|
| 180 |
trainer.save_model(output_dir)
|
| 181 |
|
| 182 |
+
print(f"The LoRA adapter saved to {output_dir}")
|
| 183 |
trackio.finish()
|
| 184 |
```
|
| 185 |
|