-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Open
Description
smol-course/units/en/unit1/3.md
Lines 474 to 537 in 5e1314b
| Ready to put theory into practice? Here's a preview of what you'll build in the exercises. You can use either Python or CLI approach: | |
| <frameworkcontent> | |
| <pythontab> | |
| ```python | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| from trl import SFTTrainer, SFTConfig | |
| from datasets import load_dataset | |
| import trackio as wandb | |
| # Initialize experiment tracking | |
| wandb.init(project="smollm3-sft", name="my-first-sft-run") | |
| # Load SmolLM3 base model | |
| model = AutoModelForCausalLM.from_pretrained("HuggingFaceTB/SmolLM3-3B-Base") | |
| tokenizer = AutoTokenizer.from_pretrained("HuggingFaceTB/SmolLM3-3B-Base") | |
| # Load SmolTalk2 dataset | |
| dataset = load_dataset("HuggingFaceTB/smoltalk2", "SFT") | |
| # Configure training with Trackio integration | |
| config = SFTConfig( | |
| output_dir="./smollm3-finetuned", | |
| per_device_train_batch_size=4, | |
| learning_rate=5e-5, | |
| max_steps=1000, | |
| report_to="trackio", # Enable Trackio logging | |
| ) | |
| # Train! | |
| trainer = SFTTrainer( | |
| model=model, | |
| tokenizer=tokenizer, | |
| train_dataset=dataset["train"], | |
| args=config, | |
| ) | |
| trainer.train() | |
| ``` | |
| </pythontab> | |
| <clitab> | |
| ```bash | |
| # Fine-tune SmolLM3 using TRL CLI with Trackio tracking | |
| trl sft \ | |
| --model_name_or_path HuggingFaceTB/SmolLM3-3B-Base \ | |
| --dataset_name HuggingFaceTB/smoltalk2 \ | |
| --dataset_config SFT \ | |
| --output_dir ./smollm3-sft-model \ | |
| --per_device_train_batch_size 4 \ | |
| --learning_rate 5e-5 \ | |
| --max_steps 1000 \ | |
| --logging_steps 50 \ | |
| --save_steps 200 \ | |
| --report_to trackio \ | |
| --push_to_hub \ | |
| --hub_model_id your-username/smollm3-custom | |
| ``` | |
| </clitab> | |
| </frameworkcontent> | |
| ## Severless Training Options |
No code is displayed when reading on my phone:
Metadata
Metadata
Assignees
Labels
No labels
