Initial commit: Future-Entropy Sampler prototype

llama.cpp-based implementation of the countbayesie Future-Entropy Sampler,
built via a direct ctypes binding to libllama.so. Includes a one-shot CLI
(entropy_cli.py), an OpenAI-compatible server (entropy_server.py), and the
tuning/benchmark scripts used to derive the alpha/confidence-threshold
defaults documented in the README.

Model path and llama.cpp library path are now read from environment
variables (ENTROPY_SAMPLER_MODEL, LLAMA_CPP_LIB) instead of being hardcoded,
and gguf-py is pulled from PyPI instead of a local llama.cpp checkout, so
this runs on any machine with a compatible llama.cpp build and model.
This commit is contained in:
2026-07-11 19:28:38 -05:00
commit e25ee046a3
18 changed files with 2012 additions and 0 deletions

27
tune_offset_sine.py Normal file
View File

@@ -0,0 +1,27 @@
"""Offset-sine sweep: dip the wave deeper into safe/coherent territory than
it peaks into entropy-chasing territory, to see if it keeps the occasional
surprise from tune_alpha.py's best run (period=16 amp=0.6) without ever
grazing the +0.3-and-above coherence cliff found there.
"""
from entropy_sampler import EntropySampler, sine_alpha_schedule
from tune_alpha import PROMPT, MAX_NEW_TOKENS, run_labeled
CONFIGS = [
{"period_tokens": 16, "amplitude": 0.6, "offset": -0.2}, # peak +0.4 / trough -0.8
{"period_tokens": 16, "amplitude": 0.7, "offset": -0.3}, # peak +0.4 / trough -1.0
{"period_tokens": 12, "amplitude": 0.8, "offset": -0.2}, # shorter period, same bias
{"period_tokens": 16, "amplitude": 0.6, "offset": 0.0}, # unbiased baseline for comparison
]
if __name__ == "__main__":
sampler = EntropySampler(top_k=12, top_n_future=20, n_ctx=4096)
try:
for cfg in CONFIGS:
schedule = sine_alpha_schedule(**cfg)
label = (
f"sine period={cfg['period_tokens']} amp={cfg['amplitude']} "
f"offset={cfg['offset']}"
)
run_labeled(sampler, label, schedule)
finally:
sampler.close()