FoolDev Claude Fable 5 commited on
Commit
e2e20a9
·
1 Parent(s): d511b99

fix(check_bridge_sync): cast params by value shape, not a key whitelist

Browse files

parse_modelfile only numerically cast a hardcoded whitelist of param
keys; any other numeric param (min_p, presence_penalty, mirostat, …)
stayed a Python str while the bridge `params` JSON parsed it as a
number. The dict comparison then reads e.g. '0.05' (str) != 0.05
(float) and reports a false "params drift" even when the two files
agree. It doesn't fire today (all five live params are whitelisted),
but it's a latent trap the moment a non-whitelisted numeric param is
added in sync.

Cast every non-stop value with int() then float() (mirroring
json.loads); non-numeric values (e.g. q8_0) fall back to str. This also
fixes the old branch mis-leaving exponent forms like 1e-5 as strings.
Verified: real check still exits 0, and a synced min_p no longer drifts.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Files changed (1) hide show
  1. scripts/check_bridge_sync.py +8 -4
scripts/check_bridge_sync.py CHANGED
@@ -64,11 +64,15 @@ def parse_modelfile(text: str) -> tuple[str, str, dict[str, object]]:
64
  if key == "stop":
65
  stops.append(value) # type: ignore[arg-type]
66
  continue
67
- # Cast known numeric params.
68
- if key in {"temperature", "top_p", "top_k", "repeat_penalty",
69
- "num_ctx", "num_predict", "num_gpu", "num_batch", "seed"}:
 
 
 
 
70
  try:
71
- value = float(value) if "." in str(value) else int(value) # type: ignore[arg-type]
72
  except (TypeError, ValueError):
73
  pass
74
  params[key] = value
 
64
  if key == "stop":
65
  stops.append(value) # type: ignore[arg-type]
66
  continue
67
+ # Cast anything numeric so it compares equal to the JSON-parsed
68
+ # bridge value (int() then float() mirrors json.loads). A key
69
+ # whitelist would leave any new numeric param a str and trip a
70
+ # false "params drift" against its JSON number.
71
+ try:
72
+ value = int(value) # type: ignore[arg-type]
73
+ except (TypeError, ValueError):
74
  try:
75
+ value = float(value) # type: ignore[arg-type]
76
  except (TypeError, ValueError):
77
  pass
78
  params[key] = value