teapottrainer 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- teapottrainer-0.1.0/LICENSE +21 -0
- teapottrainer-0.1.0/MANIFEST.in +1 -0
- teapottrainer-0.1.0/PKG-INFO +95 -0
- teapottrainer-0.1.0/README.md +66 -0
- teapottrainer-0.1.0/pyproject.toml +51 -0
- teapottrainer-0.1.0/setup.cfg +4 -0
- teapottrainer-0.1.0/teapottrainer/__init__.py +148 -0
- teapottrainer-0.1.0/teapottrainer/config.py +54 -0
- teapottrainer-0.1.0/teapottrainer/datasets.py +734 -0
- teapottrainer-0.1.0/teapottrainer/evals.py +734 -0
- teapottrainer-0.1.0/teapottrainer/formatting.py +864 -0
- teapottrainer-0.1.0/teapottrainer/ifeval.py +284 -0
- teapottrainer-0.1.0/teapottrainer/metrics.py +550 -0
- teapottrainer-0.1.0/teapottrainer/trainer.py +1134 -0
- teapottrainer-0.1.0/teapottrainer.egg-info/PKG-INFO +95 -0
- teapottrainer-0.1.0/teapottrainer.egg-info/SOURCES.txt +17 -0
- teapottrainer-0.1.0/teapottrainer.egg-info/dependency_links.txt +1 -0
- teapottrainer-0.1.0/teapottrainer.egg-info/requires.txt +12 -0
- teapottrainer-0.1.0/teapottrainer.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zakery Clarke
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prune tests
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: teapottrainer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A modular, config-driven library for training LLMs.
|
|
5
|
+
Author-email: Zakery Clarke <zakerytclarke@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/zakerytclarke/teapot_trainer
|
|
8
|
+
Project-URL: Repository, https://github.com/zakerytclarke/teapot_trainer
|
|
9
|
+
Project-URL: Issues, https://github.com/zakerytclarke/teapot_trainer/issues
|
|
10
|
+
Keywords: llm,training,transformers,pytorch
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: torch>=2.1
|
|
18
|
+
Requires-Dist: transformers>=4.40
|
|
19
|
+
Requires-Dist: datasets>=2.14
|
|
20
|
+
Requires-Dist: pydantic>=2
|
|
21
|
+
Requires-Dist: tensorboard>=2.14
|
|
22
|
+
Requires-Dist: tqdm>=4.66
|
|
23
|
+
Requires-Dist: huggingface_hub>=0.20
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
26
|
+
Requires-Dist: build; extra == "dev"
|
|
27
|
+
Requires-Dist: twine; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# teapottrainer
|
|
31
|
+
|
|
32
|
+
`teapottrainer` is a config-driven library for pretraining and supervised fine-tuning of causal language models. You describe the model, the dataset mix, and the token budgets. `TeapotTrainer` runs pretraining, then supervised training, and can resume from the last checkpoint.
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install teapottrainer
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Train
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from teapottrainer import (
|
|
42
|
+
DatasetSpec,
|
|
43
|
+
FINEWEB_EDU,
|
|
44
|
+
GSM8K,
|
|
45
|
+
ModelConfig,
|
|
46
|
+
TeapotTrainer,
|
|
47
|
+
TrainingConfig,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
config = TrainingConfig(
|
|
51
|
+
model=ModelConfig(
|
|
52
|
+
model_type="llama",
|
|
53
|
+
hidden_size=768,
|
|
54
|
+
layers=12,
|
|
55
|
+
heads=12,
|
|
56
|
+
kv_heads=4,
|
|
57
|
+
intermediate=2048,
|
|
58
|
+
seq_len=2048,
|
|
59
|
+
),
|
|
60
|
+
pretrain_datasets=[
|
|
61
|
+
DatasetSpec(source=FINEWEB_EDU, target_tokens=1_000_000_000),
|
|
62
|
+
],
|
|
63
|
+
sft_datasets=[
|
|
64
|
+
DatasetSpec(source=GSM8K, target_tokens=4_000_000),
|
|
65
|
+
],
|
|
66
|
+
tokenizer="HuggingFaceTB/SmolLM2-135M",
|
|
67
|
+
batch_size=4,
|
|
68
|
+
grad_accum=8,
|
|
69
|
+
lr=5e-4,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
trainer = TeapotTrainer(config)
|
|
73
|
+
trainer.train(fresh=True)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`train(fresh=False)` continues from `checkpoints/resume` in the run directory: weights, optimizer, and the sample cursor. Pass `init_from` to start from an existing Hugging Face model or a local checkpoint instead of randomly initialized weights.
|
|
77
|
+
|
|
78
|
+
Set `sft_at_checkpoints=True` to fine-tune a copy of the base model at each pretrain eval and save that copy beside the base weights. Pretraining keeps going from the base model.
|
|
79
|
+
|
|
80
|
+
Runs are written under `./runs/`. Loss and task scores go to TensorBoard and to `metrics.jsonl` in the run directory.
|
|
81
|
+
|
|
82
|
+
## Datasets
|
|
83
|
+
|
|
84
|
+
Preset sources live on the package: `FINEWEB_EDU`, `DCLM_EDU`, `STACK_EDU`, `FINEMATH`, `GSM8K`, `SQUAD_V2`, `HOTPOT`, `SYNTHQA`, `TEAPOT_CHAT`, the SmolTalk subsets, and the reading, tool-calling, and instruction-following evals. A `DatasetSpec` assigns a source a token budget and a mix weight.
|
|
85
|
+
|
|
86
|
+
To add a source, build a `DatasetSourceConfig` with a `chat_template_fn` that returns a prompt and an answer. The trainer supervises the answer tokens.
|
|
87
|
+
|
|
88
|
+
## Develop
|
|
89
|
+
|
|
90
|
+
The `train.py` script in this repository is one example run. It is not part of the installed package.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install -e ".[dev]"
|
|
94
|
+
pytest
|
|
95
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# teapottrainer
|
|
2
|
+
|
|
3
|
+
`teapottrainer` is a config-driven library for pretraining and supervised fine-tuning of causal language models. You describe the model, the dataset mix, and the token budgets. `TeapotTrainer` runs pretraining, then supervised training, and can resume from the last checkpoint.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install teapottrainer
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Train
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from teapottrainer import (
|
|
13
|
+
DatasetSpec,
|
|
14
|
+
FINEWEB_EDU,
|
|
15
|
+
GSM8K,
|
|
16
|
+
ModelConfig,
|
|
17
|
+
TeapotTrainer,
|
|
18
|
+
TrainingConfig,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
config = TrainingConfig(
|
|
22
|
+
model=ModelConfig(
|
|
23
|
+
model_type="llama",
|
|
24
|
+
hidden_size=768,
|
|
25
|
+
layers=12,
|
|
26
|
+
heads=12,
|
|
27
|
+
kv_heads=4,
|
|
28
|
+
intermediate=2048,
|
|
29
|
+
seq_len=2048,
|
|
30
|
+
),
|
|
31
|
+
pretrain_datasets=[
|
|
32
|
+
DatasetSpec(source=FINEWEB_EDU, target_tokens=1_000_000_000),
|
|
33
|
+
],
|
|
34
|
+
sft_datasets=[
|
|
35
|
+
DatasetSpec(source=GSM8K, target_tokens=4_000_000),
|
|
36
|
+
],
|
|
37
|
+
tokenizer="HuggingFaceTB/SmolLM2-135M",
|
|
38
|
+
batch_size=4,
|
|
39
|
+
grad_accum=8,
|
|
40
|
+
lr=5e-4,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
trainer = TeapotTrainer(config)
|
|
44
|
+
trainer.train(fresh=True)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`train(fresh=False)` continues from `checkpoints/resume` in the run directory: weights, optimizer, and the sample cursor. Pass `init_from` to start from an existing Hugging Face model or a local checkpoint instead of randomly initialized weights.
|
|
48
|
+
|
|
49
|
+
Set `sft_at_checkpoints=True` to fine-tune a copy of the base model at each pretrain eval and save that copy beside the base weights. Pretraining keeps going from the base model.
|
|
50
|
+
|
|
51
|
+
Runs are written under `./runs/`. Loss and task scores go to TensorBoard and to `metrics.jsonl` in the run directory.
|
|
52
|
+
|
|
53
|
+
## Datasets
|
|
54
|
+
|
|
55
|
+
Preset sources live on the package: `FINEWEB_EDU`, `DCLM_EDU`, `STACK_EDU`, `FINEMATH`, `GSM8K`, `SQUAD_V2`, `HOTPOT`, `SYNTHQA`, `TEAPOT_CHAT`, the SmolTalk subsets, and the reading, tool-calling, and instruction-following evals. A `DatasetSpec` assigns a source a token budget and a mix weight.
|
|
56
|
+
|
|
57
|
+
To add a source, build a `DatasetSourceConfig` with a `chat_template_fn` that returns a prompt and an answer. The trainer supervises the answer tokens.
|
|
58
|
+
|
|
59
|
+
## Develop
|
|
60
|
+
|
|
61
|
+
The `train.py` script in this repository is one example run. It is not part of the installed package.
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install -e ".[dev]"
|
|
65
|
+
pytest
|
|
66
|
+
```
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "teapottrainer"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Zakery Clarke", email = "zakerytclarke@gmail.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "A modular, config-driven library for training LLMs."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = "MIT"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
requires-python = ">=3.10"
|
|
16
|
+
keywords = ["llm", "training", "transformers", "pytorch"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"torch>=2.1",
|
|
24
|
+
"transformers>=4.40",
|
|
25
|
+
"datasets>=2.14",
|
|
26
|
+
"pydantic>=2",
|
|
27
|
+
"tensorboard>=2.14",
|
|
28
|
+
"tqdm>=4.66",
|
|
29
|
+
"huggingface_hub>=0.20",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = ["pytest>=8", "build", "twine"]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/zakerytclarke/teapot_trainer"
|
|
37
|
+
Repository = "https://github.com/zakerytclarke/teapot_trainer"
|
|
38
|
+
Issues = "https://github.com/zakerytclarke/teapot_trainer/issues"
|
|
39
|
+
|
|
40
|
+
[tool.setuptools]
|
|
41
|
+
packages = ["teapottrainer"]
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.dynamic]
|
|
44
|
+
version = { attr = "teapottrainer.__version__" }
|
|
45
|
+
|
|
46
|
+
[tool.pytest.ini_options]
|
|
47
|
+
testpaths = ["tests"]
|
|
48
|
+
# train.py lives at the repo root and is not installed. The pytest console
|
|
49
|
+
# script does not put that directory on sys.path, so the tests that import it
|
|
50
|
+
# need it added explicitly.
|
|
51
|
+
pythonpath = ["."]
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
from .config import TrainingConfig, ModelConfig, DatasetSpec
|
|
2
|
+
from .trainer import TeapotTrainer
|
|
3
|
+
from .datasets import (
|
|
4
|
+
DatasetSourceConfig,
|
|
5
|
+
DatasetRegistry,
|
|
6
|
+
FINEWEB_EDU,
|
|
7
|
+
DCLM_EDU,
|
|
8
|
+
STACK_EDU,
|
|
9
|
+
FINEMATH,
|
|
10
|
+
INFIWEBMATH,
|
|
11
|
+
COSMOPEDIA_V2,
|
|
12
|
+
SMOLTALK,
|
|
13
|
+
SMOLTALK_MAGPIE,
|
|
14
|
+
SMOLTALK_EVERYDAY,
|
|
15
|
+
SMOLTALK_OPENHERMES,
|
|
16
|
+
SMOLTALK_CONSTRAINTS,
|
|
17
|
+
SMOLTALK_SYSTEMCHATS,
|
|
18
|
+
SMOLTALK_SUMMARIZE,
|
|
19
|
+
SMOLTALK_REWRITE,
|
|
20
|
+
SMOLTALK_APIGEN,
|
|
21
|
+
SMOLTALK_APIGEN_DECISION,
|
|
22
|
+
SMOLTALK_APIGEN_ALIASED,
|
|
23
|
+
SMOLTALK_APIGEN_MISSING,
|
|
24
|
+
SMOLTALK_APIGEN_UNRELATED,
|
|
25
|
+
SMOLTALK_METAMATH,
|
|
26
|
+
SMOLTALK_MAGPIE_TEST,
|
|
27
|
+
SMOLTALK_CONSTRAINTS_TEST,
|
|
28
|
+
SMOLTALK_APIGEN_TEST,
|
|
29
|
+
SMOLTALK_APIGEN_DECISION_TEST,
|
|
30
|
+
SMOLTALK_APIGEN_ALIASED_TEST,
|
|
31
|
+
GSM8K,
|
|
32
|
+
GSM8K_TEST,
|
|
33
|
+
WHEN2CALL,
|
|
34
|
+
WHEN2CALL_TEST,
|
|
35
|
+
WHEN2CALL_ASK,
|
|
36
|
+
WHEN2CALL_REFUSE,
|
|
37
|
+
SQUAD_V2,
|
|
38
|
+
SQUAD_V2_VAL,
|
|
39
|
+
HOTPOT,
|
|
40
|
+
HOTPOT_VAL,
|
|
41
|
+
SYNTHQA,
|
|
42
|
+
SYNTHQA_TEST,
|
|
43
|
+
SYNTHQA_ANSWERABLE,
|
|
44
|
+
SYNTHQA_UNANSWERABLE,
|
|
45
|
+
TEAPOT_CHAT,
|
|
46
|
+
SQUAD_V2_ANSWERABLE,
|
|
47
|
+
SQUAD_V2_UNANSWERABLE,
|
|
48
|
+
SQUAD_V2_CONTRASTIVE,
|
|
49
|
+
HOTPOT_CONTRASTIVE,
|
|
50
|
+
SYNTHQA_CONTRASTIVE,
|
|
51
|
+
IFEVAL,
|
|
52
|
+
MT_BENCH,
|
|
53
|
+
ALPACA_EVAL,
|
|
54
|
+
ARENA_HARD,
|
|
55
|
+
ARC_EASY,
|
|
56
|
+
ARC_EASY_VAL,
|
|
57
|
+
HELLASWAG,
|
|
58
|
+
HELLASWAG_VAL,
|
|
59
|
+
PIQA,
|
|
60
|
+
PIQA_VAL,
|
|
61
|
+
WINOGRANDE,
|
|
62
|
+
WINOGRANDE_VAL,
|
|
63
|
+
COQA,
|
|
64
|
+
COQA_VAL,
|
|
65
|
+
DROP,
|
|
66
|
+
DROP_VAL,
|
|
67
|
+
HERMES_FUNCTION_CALLING,
|
|
68
|
+
BFCL_SIMPLE,
|
|
69
|
+
BFCL_MULTIPLE,
|
|
70
|
+
BFCL_PARALLEL,
|
|
71
|
+
BFCL_IRRELEVANCE,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
__version__ = "0.1.0"
|
|
75
|
+
__all__ = [
|
|
76
|
+
"TeapotTrainer",
|
|
77
|
+
"TrainingConfig",
|
|
78
|
+
"ModelConfig",
|
|
79
|
+
"DatasetSpec",
|
|
80
|
+
"DatasetSourceConfig",
|
|
81
|
+
"DatasetRegistry",
|
|
82
|
+
"FINEWEB_EDU",
|
|
83
|
+
"DCLM_EDU",
|
|
84
|
+
"STACK_EDU",
|
|
85
|
+
"FINEMATH",
|
|
86
|
+
"INFIWEBMATH",
|
|
87
|
+
"COSMOPEDIA_V2",
|
|
88
|
+
"SMOLTALK",
|
|
89
|
+
"SMOLTALK_MAGPIE",
|
|
90
|
+
"SMOLTALK_EVERYDAY",
|
|
91
|
+
"SMOLTALK_OPENHERMES",
|
|
92
|
+
"SMOLTALK_CONSTRAINTS",
|
|
93
|
+
"SMOLTALK_SYSTEMCHATS",
|
|
94
|
+
"SMOLTALK_SUMMARIZE",
|
|
95
|
+
"SMOLTALK_REWRITE",
|
|
96
|
+
"SMOLTALK_APIGEN",
|
|
97
|
+
"SMOLTALK_APIGEN_DECISION",
|
|
98
|
+
"SMOLTALK_APIGEN_ALIASED",
|
|
99
|
+
"SMOLTALK_APIGEN_MISSING",
|
|
100
|
+
"SMOLTALK_APIGEN_UNRELATED",
|
|
101
|
+
"SMOLTALK_METAMATH",
|
|
102
|
+
"SMOLTALK_MAGPIE_TEST",
|
|
103
|
+
"SMOLTALK_CONSTRAINTS_TEST",
|
|
104
|
+
"SMOLTALK_APIGEN_TEST",
|
|
105
|
+
"SMOLTALK_APIGEN_DECISION_TEST",
|
|
106
|
+
"SMOLTALK_APIGEN_ALIASED_TEST",
|
|
107
|
+
"GSM8K",
|
|
108
|
+
"GSM8K_TEST",
|
|
109
|
+
"WHEN2CALL",
|
|
110
|
+
"WHEN2CALL_TEST",
|
|
111
|
+
"WHEN2CALL_ASK",
|
|
112
|
+
"WHEN2CALL_REFUSE",
|
|
113
|
+
"SQUAD_V2",
|
|
114
|
+
"SQUAD_V2_VAL",
|
|
115
|
+
"HOTPOT",
|
|
116
|
+
"HOTPOT_VAL",
|
|
117
|
+
"SYNTHQA",
|
|
118
|
+
"SYNTHQA_TEST",
|
|
119
|
+
"SYNTHQA_ANSWERABLE",
|
|
120
|
+
"SYNTHQA_UNANSWERABLE",
|
|
121
|
+
"TEAPOT_CHAT",
|
|
122
|
+
"SQUAD_V2_ANSWERABLE",
|
|
123
|
+
"SQUAD_V2_UNANSWERABLE",
|
|
124
|
+
"SQUAD_V2_CONTRASTIVE",
|
|
125
|
+
"HOTPOT_CONTRASTIVE",
|
|
126
|
+
"SYNTHQA_CONTRASTIVE",
|
|
127
|
+
"IFEVAL",
|
|
128
|
+
"MT_BENCH",
|
|
129
|
+
"ALPACA_EVAL",
|
|
130
|
+
"ARENA_HARD",
|
|
131
|
+
"ARC_EASY",
|
|
132
|
+
"ARC_EASY_VAL",
|
|
133
|
+
"HELLASWAG",
|
|
134
|
+
"HELLASWAG_VAL",
|
|
135
|
+
"PIQA",
|
|
136
|
+
"PIQA_VAL",
|
|
137
|
+
"WINOGRANDE",
|
|
138
|
+
"WINOGRANDE_VAL",
|
|
139
|
+
"COQA",
|
|
140
|
+
"COQA_VAL",
|
|
141
|
+
"DROP",
|
|
142
|
+
"DROP_VAL",
|
|
143
|
+
"HERMES_FUNCTION_CALLING",
|
|
144
|
+
"BFCL_SIMPLE",
|
|
145
|
+
"BFCL_MULTIPLE",
|
|
146
|
+
"BFCL_PARALLEL",
|
|
147
|
+
"BFCL_IRRELEVANCE",
|
|
148
|
+
]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field, ConfigDict
|
|
2
|
+
from typing import Optional, List, Any, Union
|
|
3
|
+
from .datasets import DatasetSourceConfig, FINEWEB_EDU
|
|
4
|
+
|
|
5
|
+
class ModelConfig(BaseModel):
|
|
6
|
+
model_type: str = "llama"
|
|
7
|
+
hidden_size: int = 768
|
|
8
|
+
layers: int = Field(12, alias="num_hidden_layers")
|
|
9
|
+
heads: int = Field(12, alias="num_attention_heads")
|
|
10
|
+
kv_heads: int = Field(4, alias="num_key_value_heads")
|
|
11
|
+
intermediate: int = Field(3072, alias="intermediate_size")
|
|
12
|
+
seq_len: int = Field(2048, alias="max_position_embeddings")
|
|
13
|
+
|
|
14
|
+
custom_config_cls: Optional[Any] = None
|
|
15
|
+
custom_model_cls: Optional[Any] = None
|
|
16
|
+
|
|
17
|
+
model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class DatasetSpec(BaseModel):
|
|
21
|
+
source: Union[DatasetSourceConfig, str] = FINEWEB_EDU
|
|
22
|
+
target_tokens: int = 1_000_000_000
|
|
23
|
+
weight: float = 1.0
|
|
24
|
+
|
|
25
|
+
model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class TrainingConfig(BaseModel):
|
|
29
|
+
model: ModelConfig = Field(default_factory=ModelConfig, alias="model_config")
|
|
30
|
+
|
|
31
|
+
pretrain_datasets: List[DatasetSpec] = Field(
|
|
32
|
+
default_factory=lambda: [DatasetSpec(source=FINEWEB_EDU, target_tokens=2_000_000_000)]
|
|
33
|
+
)
|
|
34
|
+
sft_datasets: List[DatasetSpec] = Field(default_factory=list)
|
|
35
|
+
eval_datasets: List[DatasetSpec] = Field(default_factory=list)
|
|
36
|
+
|
|
37
|
+
tokenizer: str = "Qwen/Qwen2.5-0.5B"
|
|
38
|
+
# Hugging Face id or local directory. None builds a new model from the config.
|
|
39
|
+
init_from: Optional[str] = None
|
|
40
|
+
batch_size: int = 4
|
|
41
|
+
grad_accum: int = 32
|
|
42
|
+
lr: float = 5e-4
|
|
43
|
+
weight_decay: float = 0.1
|
|
44
|
+
compile: bool = True
|
|
45
|
+
logging_dir: Optional[str] = None
|
|
46
|
+
|
|
47
|
+
eval_every_percent: float = 5.0
|
|
48
|
+
# At each pretrain eval checkpoint, train a copy on the full SFT mix and
|
|
49
|
+
# save it beside the base weights. The pretrain model keeps training.
|
|
50
|
+
sft_at_checkpoints: bool = False
|
|
51
|
+
holdout_ratio: float = 0.05
|
|
52
|
+
seed: int = 42
|
|
53
|
+
|
|
54
|
+
model_config = ConfigDict(populate_by_name=True)
|