-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding supervised data config (#746)
- Loading branch information
Showing
8 changed files
with
257 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
data: | ||
configs: | ||
owt: | ||
train_urls: | ||
- "gs://pubmed-mosaic/openwebtext-sharded/openwebtext_train.{1..128}-of-128.jsonl.gz" | ||
validation_urls: | ||
- "gs://pubmed-mosaic/openwebtext-sharded/openwebtext_val.{1..8}-of-8.jsonl.gz" | ||
wikitext: | ||
id: dlwh/wikitext_103_detokenized | ||
train_weights: | ||
owt: 0.6 | ||
wikitext: 0.4 | ||
tokenizer: gpt2 | ||
cache_dir: "gs://levanter-data/tokenized/data_mix" | ||
supervised_data: | ||
validation_urls: | ||
- "gs://marin-us-central2/benchmarks/mmlu/mmlu-*-dev-evaluation.jsonl.gz" | ||
cache_dir: "gs://marin-us-central2/benchmarks/tokenized-gpt2/mmlu/" | ||
model: | ||
type: gpt2 | ||
hidden_dim: 768 | ||
num_heads: 12 | ||
num_layers: 12 | ||
seq_len: 1024 | ||
gradient_checkpointing: true | ||
scale_attn_by_inverse_layer_idx: true | ||
trainer: | ||
tracker: | ||
project: "levanter" | ||
tags: [ "openwebtext+wiki", "gpt2", "itest"] | ||
|
||
mp: p=f32,c=bfloat16 | ||
model_axis_size: 1 | ||
|
||
train_batch_size: 256 | ||
num_train_steps: 20000 | ||
optimizer: | ||
learning_rate: 1E-3 | ||
weight_decay: 0.1 | ||
warmup: 0.01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Launches the "gpt_small_fast" model on a TPU node | ||
|
||
python infra/launch.py --foreground --tpu_name $(whoami)-levanter-itest-32 --zone us-central2-b --tpu_type v4-32 --preemptible -- \ | ||
python -m levanter.main.train_lm \ | ||
--config_path config/gpt2_small_fast_supervised.yaml \ | ||
--trainer.checkpointer.base_path gs://levanter-checkpoints/gpt-itest/ --trainer.checkpointer.save_interval 30m $* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import numpy as np | ||
from transformers import AutoTokenizer | ||
|
||
import haliax | ||
|
||
from levanter.data.text import _prepare_supervised_example, preprocess_supervised_example | ||
|
||
|
||
def test_supervised_eval(): | ||
examples = [ | ||
{ | ||
"input": "Find all c in Z_3 such that Z_3[x]/(x^2 + c) is a field.\nA. 0\nB. 1\nC. 2\nD. 3\nAnswer:", | ||
"output": "B", | ||
} | ||
] | ||
tokenizer = AutoTokenizer.from_pretrained("gpt2") | ||
|
||
if tokenizer.pad_token is None: | ||
tokenizer.pad_token = tokenizer.eos_token | ||
|
||
output = preprocess_supervised_example(examples, tokenizer) | ||
assert len(output["input_ids"][0]) == output["sources_len"][0] + 1 | ||
|
||
ex = { | ||
"input_ids": np.array( | ||
[ | ||
16742, | ||
477, | ||
269, | ||
287, | ||
1168, | ||
62, | ||
18, | ||
884, | ||
326, | ||
1168, | ||
62, | ||
18, | ||
58, | ||
87, | ||
60, | ||
29006, | ||
87, | ||
61, | ||
17, | ||
1343, | ||
269, | ||
8, | ||
318, | ||
257, | ||
2214, | ||
13, | ||
198, | ||
32, | ||
13, | ||
657, | ||
198, | ||
33, | ||
13, | ||
352, | ||
198, | ||
34, | ||
13, | ||
362, | ||
198, | ||
35, | ||
13, | ||
513, | ||
198, | ||
33706, | ||
25, | ||
33, | ||
], | ||
dtype=np.int32, | ||
), | ||
"sources_len": np.array(45, dtype=np.int32), | ||
} | ||
|
||
lm_ex = _prepare_supervised_example(ex, tokenizer) | ||
|
||
assert lm_ex.loss_mask["position", 44] | ||
assert haliax.sum(lm_ex.loss_mask) == 1 |