Model-independent Mirostat adaptive text sampling for MoonBit
moon add xlyyyyyy112/moonbit-mirostat@0.1.2///|
import {
"xlyyyyyy112/moonbit-mirostat" @mirostat,
}///|
fn main {
let config = @mirostat.Config::new(3.0, eta=0.1).unwrap()
let sampler = @mirostat.Sampler::new(config, version=@mirostat.Version::v2())
let step = sampler.sample([4.0, 2.0, 1.0], 0.42).unwrap()
println(step.token())
}git clone https://github.com/xlyyyyyy112/moonbit-mirostat.git
cd moonbit-mirostat
moon updatemoon check --deny-warn
moon build --deny-warn
moon test --deny-warn
moon run cmd/main
moon run cmd/experiment
moon run cmd/generate
moon run cmd/batch
moon run cmd/weights
moon run cmd/process
moon run cmd/sweep
moon run cmd/jsonmoon version --all
moon check --target all --deny-warn
moon build --target all --deny-warn
moon test --target all --deny-warn
moon test --release --deny-warn
moon build --target js --release --deny-warn
node scripts/test_hf_bridge.cjs
moon fmt --check
moon info
git diff --exit-codelet config = @mirostat.Config::new(3.0, eta=0.1).unwrap()
let sampler = @mirostat.Sampler::new(config, version=@mirostat.Version::v2())
let step = sampler.sample([4.0, 2.0, 1.0], 0.42).unwrap()
println(step.token())py -3.12 -m venv --system-site-packages E:\moonbit-mirostat-venv
E:\moonbit-mirostat-venv\Scripts\python.exe -m pip install -r scripts\requirements-hf.txt
$env:HF_HOME = 'E:\moonbit-mirostat\hf-cache'
E:\moonbit-mirostat-venv\Scripts\python.exe scripts\download_hf_model.py
moon build --target js --releaseE:\moonbit-mirostat-venv\Scripts\python.exe scripts\run_hf_mirostat.py `
--prompt 'Explain why stable sorting is useful.' --version v2 `
--max-new-tokens 48 --seed 7 --report E:\moonbit-mirostat\runs\v2.jsonE:\moonbit-mirostat-venv\Scripts\python.exe scripts\run_hf_mirostat.py `
--prompt 'Explain why stable sorting is useful.' --sampler top-p `
--temperature 0.8 --top-p 0.9 --max-new-tokens 48 --seed 7 `
--report E:\moonbit-mirostat\runs\top-p.jsonfn Config::new(tau : Double, eta? : Double, initial_mu? : Double, m? : Int) -> Result[Config, SamplingError]fn Sampler::candidates(self : Sampler, logits : Array[Double]) -> Result[CandidateSet, SamplingError]fn Sampler::candidates_weights(self : Sampler, weights : Array[Double]) -> Result[CandidateSet, SamplingError]fn Sampler::observe_prepared_token(self : Sampler, row : PreparedRow, token : Int) -> Result[Step, SamplingError]fn Sampler::sample_prepared(self : Sampler, row : PreparedRow, uniform : Double) -> Result[Step, SamplingError]fn Sampler::sample_with_rng(self : Sampler, logits : Array[Double], rng : ParkMiller) -> Result[Step, SamplingError]pub struct TraceAccumulator {
target : Double
count : Int
total_surprise : Double
total_kept : Double
absolute_error : Double
final_mu : Double
} derive(Debug)fn allow_token_ids(logits : Array[Double], allowed_tokens : Array[Int]) -> Result[Array[Double], SamplingError]fn bias_logits(logits : Array[Double], biases : Array[Double]) -> Result[Array[Double], SamplingError]fn block_token_ids(logits : Array[Double], blocked : Array[Int]) -> Result[Array[Double], SamplingError]fn draw_candidates(probabilities : Array[Double], candidates : Array[Int], uniform : Double) -> Result[Int, SamplingError]fn draw_prefix(probabilities : Array[Double], order : Array[Int], keep : Int, uniform : Double) -> Result[Int, SamplingError]fn epsilon_prefix_size(probabilities : Array[Double], order : Array[Int], epsilon : Double) -> Result[Int, SamplingError]fn expected_prefix_surprise(probabilities : Array[Double], order : Array[Int], keep : Int) -> Result[Double, SamplingError]fn generate(sampler : Sampler, rng : ParkMiller, model : (Array[Int]) -> Result[Array[Double], SamplingError], limit : Int, end_token : Int?) -> Result[Generation, SamplingError]fn generate_from_prompt(sampler : Sampler, rng : ParkMiller, model : (Array[Int]) -> Result[Array[Double], SamplingError], prompt : Array[Int], limit : Int, end_token : Int?) -> Result[Generation, SamplingError]fn generate_stream(sampler : Sampler, rng : ParkMiller, model : (Array[Int]) -> Result[Array[Double], SamplingError], prompt : Array[Int], limit : Int, end_token : Int?, observer : (Step) -> Bool) -> Result[StreamGeneration, SamplingError]fn mask_logits(logits : Array[Double], allowed : Array[Bool]) -> Result[Array[Double], SamplingError]fn min_p_prefix_size(probabilities : Array[Double], order : Array[Int], min_p : Double) -> Result[Int, SamplingError]fn penalize_counts(logits : Array[Double], history : Array[Int], presence : Double, frequency : Double) -> Result[Array[Double], SamplingError]fn penalize_repetition(logits : Array[Double], history : Array[Int], penalty : Double) -> Result[Array[Double], SamplingError]fn prefix_entropy(probabilities : Array[Double], order : Array[Int], keep : Int) -> Result[Double, SamplingError]fn prefix_kl(probabilities : Array[Double], order : Array[Int], keep : Int) -> Result[Double, SamplingError]fn prefix_mass(probabilities : Array[Double], order : Array[Int], keep : Int) -> Result[Double, SamplingError]fn prefix_surprise_variance(probabilities : Array[Double], order : Array[Int], keep : Int) -> Result[Double, SamplingError]fn sample_epsilon(logits : Array[Double], epsilon : Double, uniform : Double) -> Result[Int, SamplingError]fn sample_min_p(logits : Array[Double], min_p : Double, uniform : Double) -> Result[Int, SamplingError]fn sample_shared_prepared(samplers : Array[Sampler], row : PreparedRow, uniforms : Array[Double]) -> Result[Array[Step], SamplingError]fn sample_temperature(logits : Array[Double], temperature : Double, uniform : Double) -> Result[Int, SamplingError]fn sample_top_p(logits : Array[Double], threshold : Double, uniform : Double) -> Result[Int, SamplingError]fn sample_typical(logits : Array[Double], threshold : Double, uniform : Double) -> Result[Int, SamplingError]fn top_p_prefix_size(probabilities : Array[Double], order : Array[Int], threshold : Double) -> Result[Int, SamplingError]fn typical_prefix_size(probabilities : Array[Double], order : Array[Int], threshold : Double) -> Result[Int, SamplingError]fn v2_prefix_size(probabilities : Array[Double], order : Array[Int], mu : Double) -> Result[Int, SamplingError]fn with_temperature(logits : Array[Double], temperature : Double) -> Result[Array[Double], SamplingError]fn zipf_exponent(probabilities : Array[Double], order : Array[Int], m : Int) -> Result[Double, SamplingError]Install
Download zipModel-independent Mirostat adaptive text sampling for MoonBit