forked from rasbt/LLMs-from-scratch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
40 lines (31 loc) · 1.23 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Copyright (c) Sebastian Raschka under Apache License 2.0 (see LICENSE.txt).
# Source for "Build a Large Language Model From Scratch"
# - https://www.manning.com/books/build-a-large-language-model-from-scratch
# Code: https://github.com/rasbt/LLMs-from-scratch
# File for internal use (unit tests)
import pytest
from train import main
@pytest.fixture
def gpt_config():
return {
"vocab_size": 50257,
"ctx_len": 12, # small for testing efficiency
"emb_dim": 32, # small for testing efficiency
"n_heads": 4, # small for testing efficiency
"n_layers": 2, # small for testing efficiency
"drop_rate": 0.1,
"qkv_bias": False
}
@pytest.fixture
def other_hparams():
return {
"learning_rate": 5e-4,
"num_epochs": 1, # small for testing efficiency
"batch_size": 2,
"weight_decay": 0.1
}
def test_main(gpt_config, other_hparams):
train_losses, val_losses, tokens_seen, model = main(gpt_config, other_hparams)
assert len(train_losses) == 39, "Unexpected number of training losses"
assert len(val_losses) == 39, "Unexpected number of validation losses"
assert len(tokens_seen) == 39, "Unexpected number of tokens seen"