ContextReq commited on
Commit
309546c
·
verified ·
1 Parent(s): 970cc36

Delete complete.py

Browse files
Files changed (1) hide show
  1. complete.py +0 -43
complete.py DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Completion CLI: continue a prompt with a trained Notio checkpoint.
3
-
4
- Usage:
5
- src/complete.py "Once upon a time" --checkpoint out/notio.pt --n 2
6
- src/complete.py "The little cat" --temp 0.8 --top-k 40 --max-tokens 200
7
- """
8
- import argparse
9
- import sys
10
- from pathlib import Path
11
-
12
- sys.path.insert(0, str(Path(__file__).resolve().parent))
13
- import sampler
14
-
15
-
16
- def main():
17
- ap = argparse.ArgumentParser()
18
- ap.add_argument("prompt", nargs="?", default="", help="text to complete (default: story start)")
19
- ap.add_argument("--checkpoint", default="out/notio.pt")
20
- ap.add_argument("--temp", type=float, default=0.9)
21
- ap.add_argument("--top-k", type=int, default=0, help="0 = off")
22
- ap.add_argument("--max-tokens", type=int, default=256)
23
- ap.add_argument("--n", type=int, default=1, help="number of completions")
24
- ap.add_argument("--device", default=None)
25
- a = ap.parse_args()
26
-
27
- m, device, ck = sampler.load_model(a.checkpoint, a.device)
28
- print(f"checkpoint: {a.checkpoint} | step {ck['step']} | "
29
- f"train {ck.get('loss', float('nan')):.3f} | val {ck.get('val_loss', float('nan')):.3f} | {device}")
30
-
31
- prompt = a.prompt or "Once upon a time"
32
- prompt_ids = sampler.encode_prompt(prompt)
33
- block = m.cfg.layer1.block_size
34
- if len(prompt_ids) >= block:
35
- sys.exit(f"prompt too long: {len(prompt_ids)} ids, block_size {block}")
36
- print(f"prompt: {prompt!r} ({len(prompt_ids)} ids) | temp {a.temp} | top-k {a.top_k}")
37
- for i in range(a.n):
38
- ids = sampler.generate(m, device, prompt_ids, a.max_tokens, a.temp, a.top_k)
39
- print(f"\n=== completion {i} ({len(ids)} ids) ===\n{sampler.ids_to_display(ids)}")
40
-
41
-
42
- if __name__ == "__main__":
43
- main()