NSC64 commited on
Commit
8dc84df
·
verified ·
1 Parent(s): bbf915c

Upload samples_300m.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. samples_300m.py +40 -0
samples_300m.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Generate model-card samples from the PSSA-300M export.
2
+
3
+ Usage on the box:
4
+ cd /marimo/pssa_300m && python3 samples_300m.py artifacts/export \
5
+ artifacts/samples_300m.json
6
+ """
7
+ import json
8
+ import sys
9
+
10
+ import torch
11
+
12
+ from pssa_model import from_pretrained, generate
13
+
14
+
15
+ PROMPTS = [
16
+ ("code", "def train_step("),
17
+ ("story", "Once upon a time"),
18
+ ("web", "The history of"),
19
+ ("math", "The derivative of"),
20
+ ]
21
+
22
+
23
+ def main():
24
+ export_dir, out_path = sys.argv[1], sys.argv[2]
25
+ device = "cuda" if torch.cuda.is_available() else "cpu"
26
+ model, tok = from_pretrained(export_dir, device=device)
27
+ out = {}
28
+ for name, prompt in PROMPTS:
29
+ torch.manual_seed(1234)
30
+ text = generate(model, tok, prompt, max_new=110, temp=0.7, top_k=40,
31
+ device=device)
32
+ out[name] = text
33
+ print(f"--- {name} ---\n{text}\n", flush=True)
34
+ with open(out_path, "w") as f:
35
+ json.dump(out, f, indent=1)
36
+ print("wrote", out_path, flush=True)
37
+
38
+
39
+ if __name__ == "__main__":
40
+ main()