File size: 846 Bytes
f0b317c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
"""Step 6 verification: weights must load with strict=True and match the expected parameter count."""

import json
from pathlib import Path

from safetensors.torch import load_file

from model import GPT, GPTConfig, parameter_count

CONFIG_PATH = Path("config.json")
WEIGHTS_PATH = Path("model.safetensors")


def main() -> None:
    config_data = json.loads(
        CONFIG_PATH.read_text(
            encoding="utf-8",
        )
    )

    config = GPTConfig.from_json(config_data)

    model = GPT(config=config)

    state = load_file(
        WEIGHTS_PATH,
        device="cpu",
    )

    result = model.load_state_dict(
        state,
        strict=True,
    )

    print(result)

    parameters = parameter_count(model)

    print(f"Parameters: {parameters:,}")

    assert parameters == 4_782_336


if __name__ == "__main__":
    main()