Skip to content

Add opt-in scalar calibration reuse - #21

Open
0xEljh wants to merge 1 commit into
mainfrom
t3/reuse-calibration
Open

0xEljh wants to merge 1 commit into
mainfrom
t3/reuse-calibration

Conversation

@0xEljh

@0xEljh 0xEljh commented Nov 13, 2026

Copy link
Copy Markdown

Summary

Add opt-in, JSON-compatible scalar calibration snapshots across identical model owners:

# After ordinary calibration on the original agent:
record = agent.export_calibration(key=identity)
# After releasing it and loading an identical model/tokenizer:
new_agent.import_calibration(record, key=identity)
new_agent.clear_calibration()  # before mutation; use a new identity afterward

Lazy per-agent defaults and missing-layer calibration remain unchanged. Records retain no model, tensors, KV cache, or GPU state. No filesystem service is added.

Evidence

Full external-process wall medians, three fresh counterbalanced process pairs per workload:

Model-owner sequence Useful tokens Baseline → reuse Reduction
A,A,A 96 13.275 → 10.904 s 17.86%
A,B,A,A,B,A 192 23.443 → 18.806 s 19.78%

A = pinned Qwen3-0.6B; B = pinned Qwen3-1.7B. RTX 4090, unquantized BF16, Torch 2.8.0, Transformers 4.57.1, SDPA, four threads. Each owner runs two 16-token public turns including NLL. Timings include initial calibration misses, key/profile/JSON/import/export work, model loads, first-use warmup, release, and interpreter startup/teardown. Filesystem warm; downloads, cold-disk reads, and SSH excluded. This measures startup/session throughput, not decode acceleration; no confidence interval or general guarantee.

CUDA comparisons exactly match calibration, scaled activations, first logits, token IDs, NLL, and public state across 45 controls. CPU tests cover cold hits, defaults, atomic malformed-import recovery, reset, adapter keys, tracebacks, and owner lifetime. Existing selected-model GPU tests pass; the no-BOS case skips.

Design Choices

  • The key is an operator assertion of full weights/tokenizer/adapter/execution identity. Cheap profile checks are not automatic mutation detection. Clear before mutation and use a new key.
  • Invalid imports raise ValueError and leave all norms empty. Reusable records require canonical zero-based layers; existing negative indexing remains default-only.
  • Normal exception tracebacks remain intact and can retain owners until callers release errors. Scalar records do not retain owners.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant