SixpertAI commited on
Commit
0dc9af3
·
verified ·
1 Parent(s): 5d7d4e2

Upload examples/benchmark.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. examples/benchmark.py +109 -0
examples/benchmark.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Sixpert K1 - Quick Benchmark Script
4
+ ====================================
5
+ Runs basic performance benchmarks for Sixpert K1 including:
6
+ - Token generation speed (tokens/second)
7
+ - Context processing speed
8
+ - Memory usage estimation
9
+
10
+ Usage:
11
+ python benchmark.py --model SixpertK1.gguf
12
+ """
13
+
14
+ import argparse
15
+ import time
16
+ import sys
17
+
18
+ try:
19
+ from llama_cpp import Llama
20
+ except ImportError:
21
+ print("Installing llama-cpp-python...")
22
+ import subprocess
23
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "llama-cpp-python"])
24
+ from llama_cpp import Llama
25
+
26
+
27
+ def benchmark_generation(model_path: str, tokens: int = 512):
28
+ """Benchmark token generation speed."""
29
+ print("\n=== Generation Benchmark ===")
30
+ print(f"Generating {tokens} tokens...\n")
31
+
32
+ llm = Llama(
33
+ model_path=model_path,
34
+ n_ctx=4096,
35
+ n_gpu_layers=-1,
36
+ verbose=False,
37
+ )
38
+
39
+ start = time.time()
40
+ output = llm(
41
+ "<|im_start|>user\nWrite a detailed essay about artificial intelligence.<|im_end|>\n<|im_start|>assistant\n",
42
+ max_tokens=tokens,
43
+ temperature=0.7,
44
+ stream=False,
45
+ )
46
+ elapsed = time.time() - start
47
+
48
+ gen_tokens = len(output["choices"][0]["text"].split())
49
+ tokens_per_sec = tokens / elapsed
50
+
51
+ print(f"Generated: {tokens} tokens")
52
+ print(f"Time: {elapsed:.2f}s")
53
+ print(f"Speed: {tokens_per_sec:.1f} tokens/sec")
54
+ print(f"Est. words: ~{gen_tokens}")
55
+
56
+
57
+ def benchmark_context(model_path: str, context_length: int = 8192):
58
+ """Benchmark context processing speed."""
59
+ print(f"\n=== Context Processing Benchmark ===")
60
+ print(f"Processing {context_length} token context...\n")
61
+
62
+ llm = Llama(
63
+ model_path=model_path,
64
+ n_ctx=context_length + 512,
65
+ n_gpu_layers=-1,
66
+ verbose=False,
67
+ )
68
+
69
+ # Create a long context prompt
70
+ filler = "The quick brown fox jumps over the lazy dog. " * (context_length // 10)
71
+ prompt = f"<|im_start|>user\n{filler}\nSummarize the above text in one sentence.<|im_end|>\n<|im_start|>assistant\n"
72
+
73
+ start = time.time()
74
+ output = llm(prompt, max_tokens=100, stream=False)
75
+ elapsed = time.time() - start
76
+
77
+ prompt_tokens = output["usage"]["prompt_eval_count"]
78
+ eval_time = output["usage"].get("prompt_eval_time", 1000) / 1000
79
+
80
+ print(f"Context tokens: {prompt_tokens}")
81
+ print(f"Processing time: {eval_time:.2f}s")
82
+ print(f"Speed: {prompt_tokens / eval_time:.1f} tokens/sec")
83
+
84
+
85
+ def main():
86
+ parser = argparse.ArgumentParser(description="Sixpert K1 Benchmark")
87
+ parser.add_argument("--model", type=str, default="SixpertK1.gguf", help="Path to GGUF model")
88
+ parser.add_argument("--gen-tokens", type=int, default=512, help="Generation benchmark tokens")
89
+ parser.add_argument("--ctx-length", type=int, default=8192, help="Context benchmark length")
90
+ parser.add_argument("--all", action="store_true", help="Run all benchmarks")
91
+
92
+ args = parser.parse_args()
93
+
94
+ print("=" * 60)
95
+ print(" Sixpert K1 Benchmark Suite")
96
+ print(" Precision Logic Engine")
97
+ print("=" * 60)
98
+
99
+ if args.all or True:
100
+ benchmark_generation(args.model, args.gen_tokens)
101
+ benchmark_context(args.model, args.ctx_length)
102
+
103
+ print("\n" + "=" * 60)
104
+ print(" Benchmark complete!")
105
+ print("=" * 60)
106
+
107
+
108
+ if __name__ == "__main__":
109
+ main()