Skip to content

Commit eeeb567

Browse files
authored
Merge pull request #15 from atlasia-ma/feat/wandb-tracking
Feat/wandb tracking
2 parents a1ed0f0 + c10f4e0 commit eeeb567

6 files changed

Lines changed: 18 additions & 1 deletion

File tree

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
WANDB_API_KEY=your-key-here

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ train = [
1717
"datasets>=4.3.0",
1818
"trl>=0.24.0",
1919
"unsloth>=2026.6.9",
20+
"wandb>=0.19",
21+
"python-dotenv>=1.0",
2022
]
2123

2224
[project.scripts]

src/darija_translator/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from darija_translator.evaluate import compute_translation_metrics, generate_translations
1414
from darija_translator.model import attach_lora, load_model_and_tokenizer
1515
from darija_translator.train import build_trainer, save_model
16+
from dotenv import load_dotenv
1617

1718

1819
def prepare_data(dataset_name: str, data_config: DataConfig, tokenizer):

src/darija_translator/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ class TrainConfig:
4747
group_by_length: bool = True
4848
max_seq_length: int = 2048
4949
output_dir: str = "lora_model"
50+
report_to: str = "wandb"
51+
wandb_project: str = "darija-translator"

src/darija_translator/train.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
from trl import SFTConfig, SFTTrainer
24
from unsloth.chat_templates import train_on_responses_only
35

@@ -6,6 +8,9 @@
68

79
def build_trainer(model, tokenizer, train_dataset, eval_dataset,
810
config: TrainConfig):
11+
if config.report_to == "wandb" or (isinstance(config.report_to, list) and "wandb" in config.report_to):
12+
os.environ["WANDB_PROJECT"] = config.wandb_project
13+
914
trainer = SFTTrainer(
1015
model=model,
1116
tokenizer=tokenizer,
@@ -27,7 +32,7 @@ def build_trainer(model, tokenizer, train_dataset, eval_dataset,
2732
weight_decay=config.weight_decay,
2833
lr_scheduler_type=config.lr_scheduler_type,
2934
seed=config.seed,
30-
report_to="none",
35+
report_to=config.report_to,
3136
group_by_length=config.group_by_length,
3237
),
3338
)

tests/test_config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,9 @@ def test_train_config_defaults():
5858
assert cfg.num_train_epochs == 3
5959
assert cfg.learning_rate == 2e-4
6060
assert cfg.seed == 3407
61+
62+
63+
def test_train_config_wandb_defaults():
64+
cfg = TrainConfig()
65+
assert cfg.report_to == "wandb"
66+
assert cfg.wandb_project == "darija-translator"

0 commit comments

Comments
 (0)