Wiself commited on
Commit
285bb31
·
1 Parent(s): 271bd15

benchmarking: refresh run logs and shim

Browse files
Files changed (1) hide show
  1. benchmarking/shim.py +17 -4
benchmarking/shim.py CHANGED
@@ -12,13 +12,14 @@ reverse-proxies everything else untouched:
12
  content[{token, logprob, top_logprobs}]; harness expects legacy
13
  {token_logprobs[], top_logprobs[]}. Translated field-for-field.
14
  - /v1/chat/completions: system messages are folded into the following user
15
- turn (Gemma supports only user/model roles; same info, valid roles).
16
  - Sidecar: every completions request + raw response (incl. reasoning_content)
17
  is appended to thinking-log.jsonl for later inspection. Scoring untouched.
18
 
19
  Usage: python3 shim.py [upstream] [port]
20
  """
21
  import json
 
22
  import sys
23
  import time
24
  import urllib.request
@@ -26,7 +27,7 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
26
 
27
  UPSTREAM = sys.argv[1] if len(sys.argv) > 1 else "http://host.docker.internal:8080"
28
  PORT = int(sys.argv[2]) if len(sys.argv) > 2 else 8081
29
- THINK_LOG = "benchmarking/thinking-log.jsonl"
30
 
31
 
32
  def _up(method, path, body=None):
@@ -75,6 +76,18 @@ def _info():
75
  "chat_template": tmpl}
76
 
77
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  def _fix_logprobs(raw):
79
  try:
80
  obj = json.loads(raw)
@@ -110,7 +123,7 @@ def _fold_system(body):
110
 
111
 
112
  INFO = _info()
113
-
114
 
115
  class H(BaseHTTPRequestHandler):
116
  protocol_version = "HTTP/1.1"
@@ -153,7 +166,7 @@ class H(BaseHTTPRequestHandler):
153
  {"tokens": body.get("tokens", [])})
154
  text = json.loads(raw).get("content", "")
155
  return self._send(code, {"prompt": text})
156
- if self.path == "/v1/chat/completions":
157
  body = _fold_system(body)
158
  try:
159
  code, raw = _up("POST", self.path, body)
 
12
  content[{token, logprob, top_logprobs}]; harness expects legacy
13
  {token_logprobs[], top_logprobs[]}. Translated field-for-field.
14
  - /v1/chat/completions: system messages are folded into the following user
15
+ turn, but only for families without a system role (Gemma). See families.py.
16
  - Sidecar: every completions request + raw response (incl. reasoning_content)
17
  is appended to thinking-log.jsonl for later inspection. Scoring untouched.
18
 
19
  Usage: python3 shim.py [upstream] [port]
20
  """
21
  import json
22
+ import os
23
  import sys
24
  import time
25
  import urllib.request
 
27
 
28
  UPSTREAM = sys.argv[1] if len(sys.argv) > 1 else "http://host.docker.internal:8080"
29
  PORT = int(sys.argv[2]) if len(sys.argv) > 2 else 8081
30
+ THINK_LOG = os.path.join(os.path.dirname(os.path.abspath(__file__)), "thinking-log.jsonl")
31
 
32
 
33
  def _up(method, path, body=None):
 
76
  "chat_template": tmpl}
77
 
78
 
79
+ def _family():
80
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
81
+ import families
82
+ try:
83
+ _, raw = _up("GET", "/props")
84
+ tmpl = json.loads(raw).get("chat_template", "")
85
+ except Exception:
86
+ tmpl = ""
87
+ name = families.detect(tmpl, sys.argv[3] if len(sys.argv) > 3 else "")
88
+ sys.stderr.write(f"shim: family={name}\n")
89
+ return families.profile(name)
90
+
91
  def _fix_logprobs(raw):
92
  try:
93
  obj = json.loads(raw)
 
123
 
124
 
125
  INFO = _info()
126
+ FAMILY = _family()
127
 
128
  class H(BaseHTTPRequestHandler):
129
  protocol_version = "HTTP/1.1"
 
166
  {"tokens": body.get("tokens", [])})
167
  text = json.loads(raw).get("content", "")
168
  return self._send(code, {"prompt": text})
169
+ if self.path == "/v1/chat/completions" and FAMILY["fold_system"]:
170
  body = _fold_system(body)
171
  try:
172
  code, raw = _up("POST", self.path, body)