Make BF16 the canonical GPU weight format
Browse files- README.md +5 -1
- config.json +2 -2
- model.bf16.safetensors +0 -3
- model.safetensors +2 -2
- tiny_english/generate.py +9 -5
- training_summary.json +1 -1
README.md
CHANGED
|
@@ -71,9 +71,13 @@ These scores show clear progress over the project’s earlier checkpoints, but t
|
|
| 71 |
|
| 72 |
This repository is a native safetensors export rather than a Transformers `AutoModel` package. It includes the minimal `tiny_english` inference module.
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
```bash
|
| 75 |
pip install -r requirements.txt
|
| 76 |
-
python -m tiny_english.generate --model-dir . --prompt "The invention of the printing press changed" --max-new-tokens 128 --temperature 0.7 --top-k 40 --seed 42
|
| 77 |
```
|
| 78 |
|
| 79 |
Generation can repeat phrases, make factual errors, or produce incoherent continuations. Do not use it for high-stakes decisions or as an assistant without additional evaluation and alignment work.
|
|
|
|
| 71 |
|
| 72 |
This repository is a native safetensors export rather than a Transformers `AutoModel` package. It includes the minimal `tiny_english` inference module.
|
| 73 |
|
| 74 |
+
## Weights
|
| 75 |
+
|
| 76 |
+
`model.safetensors` contains the single BF16 release (624 MB; SHA-256 `fce44c1f7fc64a51a775d8802cfa75277dc68a34ef5d2908f541caa21fad66c2`). It requires a BF16-capable CUDA GPU, such as the RTX 3060 Ti used for training. The bundled inference command defaults to CUDA.
|
| 77 |
+
|
| 78 |
```bash
|
| 79 |
pip install -r requirements.txt
|
| 80 |
+
python -m tiny_english.generate --model-dir . --device cuda --prompt "The invention of the printing press changed" --max-new-tokens 128 --temperature 0.7 --top-k 40 --seed 42
|
| 81 |
```
|
| 82 |
|
| 83 |
Generation can repeat phrases, make factual errors, or produce incoherent continuations. Do not use it for high-stakes decisions or as an assistant without additional evaluation and alignment work.
|
config.json
CHANGED
|
@@ -11,14 +11,14 @@
|
|
| 11 |
"heads": 16,
|
| 12 |
"intermediate_size": 2752
|
| 13 |
},
|
| 14 |
-
"dtype": "
|
| 15 |
"parameter_count": 311866368,
|
| 16 |
"checkpoint_step": 15259,
|
| 17 |
"stage_tokens": 2000027648,
|
| 18 |
"previous_tokens": 3000238080,
|
| 19 |
"training_tokens": 5000265728,
|
| 20 |
"tokenizer_sha256": "40d36acc35e5364d90fdcdae773143b7571b5ec3b7ace2030d12d4bd5a3a1025",
|
| 21 |
-
"weights_sha256": "
|
| 22 |
"data_manifest_sha256": "cf6ca78377e03aef753b073d25f710d665de31f0a91d285032955feecc565934",
|
| 23 |
"eos_token_id": 1,
|
| 24 |
"unk_token_id": 0
|
|
|
|
| 11 |
"heads": 16,
|
| 12 |
"intermediate_size": 2752
|
| 13 |
},
|
| 14 |
+
"dtype": "bfloat16",
|
| 15 |
"parameter_count": 311866368,
|
| 16 |
"checkpoint_step": 15259,
|
| 17 |
"stage_tokens": 2000027648,
|
| 18 |
"previous_tokens": 3000238080,
|
| 19 |
"training_tokens": 5000265728,
|
| 20 |
"tokenizer_sha256": "40d36acc35e5364d90fdcdae773143b7571b5ec3b7ace2030d12d4bd5a3a1025",
|
| 21 |
+
"weights_sha256": "fce44c1f7fc64a51a775d8802cfa75277dc68a34ef5d2908f541caa21fad66c2",
|
| 22 |
"data_manifest_sha256": "cf6ca78377e03aef753b073d25f710d665de31f0a91d285032955feecc565934",
|
| 23 |
"eos_token_id": 1,
|
| 24 |
"unk_token_id": 0
|
model.bf16.safetensors
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:fce44c1f7fc64a51a775d8802cfa75277dc68a34ef5d2908f541caa21fad66c2
|
| 3 |
-
size 623748472
|
|
|
|
|
|
|
|
|
|
|
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fce44c1f7fc64a51a775d8802cfa75277dc68a34ef5d2908f541caa21fad66c2
|
| 3 |
+
size 623748472
|
tiny_english/generate.py
CHANGED
|
@@ -25,12 +25,16 @@ def load_model(checkpoint_path, tokenizer_path, device="cpu"):
|
|
| 25 |
return model.to(device).eval(), tokenizer, step
|
| 26 |
|
| 27 |
|
| 28 |
-
def load_export(directory, device="cpu"):
|
| 29 |
from safetensors.torch import load_file
|
| 30 |
directory = Path(directory)
|
| 31 |
metadata = json.loads((directory / "config.json").read_text(encoding="utf-8"))
|
| 32 |
-
if metadata.get("format") != "tiny-english-safetensors-v1":
|
| 33 |
-
raise ValueError("Unsupported exported model format")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
tokenizer_path = directory / "tokenizer.json"
|
| 35 |
weights_path = directory / "model.safetensors"
|
| 36 |
if digest_file(tokenizer_path) != metadata["tokenizer_sha256"]:
|
|
@@ -42,7 +46,7 @@ def load_export(directory, device="cpu"):
|
|
| 42 |
if tokenizer.get_vocab_size() != model.config.vocab_size:
|
| 43 |
raise ValueError("Export tokenizer vocabulary does not match model")
|
| 44 |
model.load_state_dict(load_file(str(weights_path), device="cpu"), strict=True)
|
| 45 |
-
return model.to(device).eval(), tokenizer, metadata["checkpoint_step"]
|
| 46 |
|
| 47 |
|
| 48 |
def complete(model, tokenizer, prompt, max_new_tokens=150, temperature=0.8, top_k=40, seed=42, deadline=None, strict_context=False):
|
|
@@ -90,7 +94,7 @@ def main():
|
|
| 90 |
parser.add_argument("--max-new-tokens", type=int, default=150)
|
| 91 |
parser.add_argument("--temperature", type=float, default=0.8)
|
| 92 |
parser.add_argument("--top-k", type=int, default=40)
|
| 93 |
-
parser.add_argument("--device", choices=["cpu", "cuda"], default="
|
| 94 |
parser.add_argument("--threads", type=int, default=8)
|
| 95 |
parser.add_argument("--seed", type=int, default=42)
|
| 96 |
args = parser.parse_args()
|
|
|
|
| 25 |
return model.to(device).eval(), tokenizer, step
|
| 26 |
|
| 27 |
|
| 28 |
+
def load_export(directory, device="cpu"):
|
| 29 |
from safetensors.torch import load_file
|
| 30 |
directory = Path(directory)
|
| 31 |
metadata = json.loads((directory / "config.json").read_text(encoding="utf-8"))
|
| 32 |
+
if metadata.get("format") != "tiny-english-safetensors-v1":
|
| 33 |
+
raise ValueError("Unsupported exported model format")
|
| 34 |
+
if metadata.get("dtype") != "bfloat16":
|
| 35 |
+
raise ValueError("This export requires BF16 weights")
|
| 36 |
+
if device != "cuda":
|
| 37 |
+
raise ValueError("This BF16 export requires a CUDA GPU; use --device cuda")
|
| 38 |
tokenizer_path = directory / "tokenizer.json"
|
| 39 |
weights_path = directory / "model.safetensors"
|
| 40 |
if digest_file(tokenizer_path) != metadata["tokenizer_sha256"]:
|
|
|
|
| 46 |
if tokenizer.get_vocab_size() != model.config.vocab_size:
|
| 47 |
raise ValueError("Export tokenizer vocabulary does not match model")
|
| 48 |
model.load_state_dict(load_file(str(weights_path), device="cpu"), strict=True)
|
| 49 |
+
return model.to(device=device, dtype=torch.bfloat16).eval(), tokenizer, metadata["checkpoint_step"]
|
| 50 |
|
| 51 |
|
| 52 |
def complete(model, tokenizer, prompt, max_new_tokens=150, temperature=0.8, top_k=40, seed=42, deadline=None, strict_context=False):
|
|
|
|
| 94 |
parser.add_argument("--max-new-tokens", type=int, default=150)
|
| 95 |
parser.add_argument("--temperature", type=float, default=0.8)
|
| 96 |
parser.add_argument("--top-k", type=int, default=40)
|
| 97 |
+
parser.add_argument("--device", choices=["cpu", "cuda"], default="cuda")
|
| 98 |
parser.add_argument("--threads", type=int, default=8)
|
| 99 |
parser.add_argument("--seed", type=int, default=42)
|
| 100 |
args = parser.parse_args()
|
training_summary.json
CHANGED
|
@@ -30,6 +30,6 @@
|
|
| 30 |
"previous_tokens": 3000238080,
|
| 31 |
"training_tokens": 5000265728,
|
| 32 |
"sampled_validation_loss": 2.609314309898764,
|
| 33 |
-
"export_dtype": "
|
| 34 |
"optimizer_state_included": false
|
| 35 |
}
|
|
|
|
| 30 |
"previous_tokens": 3000238080,
|
| 31 |
"training_tokens": 5000265728,
|
| 32 |
"sampled_validation_loss": 2.609314309898764,
|
| 33 |
+
"export_dtype": "bfloat16",
|
| 34 |
"optimizer_state_included": false
|
| 35 |
}
|