llm-samplers
Library Listed Dormant
Token samplers for large language models
- Downloads
- 4,242
- Dependents
- 6
- Stars
- 18
- Forks
- 4
- Contributors
- 2
- Commits
- 28
- Latest release
- 0.0.7 ·
About
Token samplers for large language models, written in Rust!
Status
Extremely early in development, poorly tested. You can look at src/tests.rs for some examples of use.
Also a fairly simple example of using Mirostat with my RWKV project here: https://github.com/KerfuffleV2/smolrsrwkv/blob/60b8e8bfe64f157f1800445128af3b4adbbc64c1/smolrwkv-cli/src/main.rs#L139-L164
For notes on migrating from 0.0.6 to 0.0.7, see below.
Samplers
Using the term "sampler" here loosely, perhaps it should be renamed in the future. Right now a "sampler" could be something that manipulates the list of logits (for example, a top-k sampler might prune the list to the top K entries), it might actually pick a token or both!
- Flat bias - biases tokens by the specified amount
- Frequency / presence - Applies frequency and presence penalties
- Greedy - picks the token ID with the highest probability
- Locally typical
- Mirostat V1
- Mirostat V2
- Random distribution - picks a token ID based on weighted probabilities
- Repetition - applies a repetition penalty
- Tail free
- Temperature
- Top-K
- Top-P
- Min-P
- Top-A
Read the full README
Real descriptions may (or may not happen) eventually. For now, you can check out the llama.cpp main example README for a brief overview of some of the types of sampler: https://github.com/ggerganov/llama.cpp/blob/master/examples/main/README.md#generation-flags
Example
You probably won't usually want to use individual Samplers. The most typical
use case is going to be chaining a number of samplers together.
A simple example of constructing a [SamplerChain]:
use anyhow::Result;
use llm_samplers::prelude::*;
pub fn test_chain1() -> Result<()> {
let mut logits = Logits::try_from_iter([0.1f32, 0.2, 0.3, 0.4].into_iter())?;
// Demonstrating the different ways you can build a SamplerChain.
// These are all equivalent.
let mut sc = SamplerChain::new()
+ SampleFlatBias::new([(3, f32::NEG_INFINITY)]);
sc += SampleTemperature::new(0.8);
sc.push_sampler(SampleGreedy::new());
assert_eq!(
sc.sample_token(
// These samplers don't actually need any resources.
&mut NilSamplerResources::default(),
&mut logits)?,
Some(1)
);
// () also implements HasSamplerResources
// so you could use &mut () here.
assert_eq!(sc.sample_token(&mut (), &mut logits)?, Some(1));
Ok(())
}
The previous example is simple but not very realistic: the greedy sampler doesn't even care about temperature. Now let's look at something a bit more complicated:
use anyhow::Result;
use rand::{SeedableRng, rngs::StdRng};
use llm_samplers::prelude::*;
fn test_chain2() -> Result<()> {
let example_logits = vec![0.1f32, 0.2, 0.3, 0.4];
let mut res = SimpleSamplerResources::new(
// Optionally include an RNG resource.
Some(Box::new(StdRng::seed_from_u64(123))),
// Optionally include a last tokens resource.
Some(vec![]),
);
let mut logits = Logits::try_from_iter(example_logits.into_iter())?;
let mut logits2 = logits.clone();
let mut sc = SamplerChain::new()
// Bias logits (this example sets bias for token id 3 to -inf)
+ SampleFlatBias::new([(3, f32::NEG_INFINITY)])
// Apply a repetition penalty.
+ SampleRepetition::new(1.1, 64)
// Apply frequency and presence penalties.
+ SampleFreqPresence::new(0.05, 0.1, 64)
// Apply temperature to logits.
+ SampleTemperature::new(0.8)
// Sample a token using Mirostat1
+ SampleMirostat1::new(4, 5.0, 0.1);
// Put a value into `last_tokens`, this simulates us having already picked
// that token (3) previously.
res.with_last_tokens_mut(&mut |tokens| tokens.push(3u32))?;
assert_eq!(sc.sample_token(&mut res, &mut logits)?, Some(2));
// Now add the last selected token to the list.
res.with_last_tokens_mut(&mut |tokens| tokens.push(2u32))?;
// And pick the next one. *Important*: Note that we don't reuse `logits`.
// This is because `logits` already has all the filtering/sorting/permutation
// from the previous sample call applied to it.
assert_eq!(sc.sample_token(&mut res, &mut logits2)?, Some(1));
Ok(())
}
0.0.6 to 0.0.7 Migration
Unfortunately, this involved some breaking changes. Basically, the samplers and chains no
longer take token id and logits type variables anymore. You can have your token ids in any
color you like, as long as it's u32. Same for logits: they're always f32 now.
For example, where previously you would have done SampleRandDistrib::<u32>::new or SampleMirostat2::<u32, f32>::new,
you only need SampleRandDistrib::new, SampleMirostat2::new. Same for creating chains: SamplerChain::<u32, f32>::new will
only need SamplerChain::new.
Links
Note: Crate/docs version likely won't match this repo.
- Crate: https://crates.io/crates/llm-samplers
- Docs: https://docs.rs/llm-samplers/
Credits
Initial version closely referenced from the samplers in the llama.cpp project (although not a line-by-line port). Thanks!
Compatibility
- Runs on
- GPU support unknown
What shows it
- no dependency or feature matches a backend row
- Native code
- None found
- No native code found
- Python bindings
- No Python binding crate found
- License
- MIT
Compare with similar projects
Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
Token samplers for large language models |
4,242 downloads over 30 days | 6 | 18 | 0.0.7 | GPU support unknown | No native code found | MIT |
|
TUI for serving local LLM models. Pick a model, pick a backend, serve it. |
424 binary downloads per release | Not applicable | 417 | 0.0.7 | GPU support unknown | No native code found | MIT |
|
Middleware for serving deep learning models with batched prediction |
76 downloads over 30 days | 0 | 22 | 0.2.5 | GPU support unknown | No native code found | Apache-2.0 |
|
Inference server for LLMs, speech and embeddings: OpenAI-compatible routes with streaming, plus speech synthesis (TTS) and transcription (ASR). Serves Llama, Mistral, Qwen, Mamba2, MLA+MoE and hybrid models from SafeTensors, AWQ, GPTQ and GGUF. |
8 binary downloads per release | Not applicable | 7 | 0.7.1 | CUDA, WebGPU | Binds native code: ring (feature distributed) | Apache-2.0 |
|
oxibonsai Listed
Pure Rust 1-bit LLM inference engine for PrismML Bonsai models — umbrella crate |
1 downloads over 30 days | 0 | 137 | 0.2.3 | CUDA, Metal | No native code found | Apache-2.0 |
|
needle-rs New
600 KB WASM runtime for Cactus Compute's Needle AI tool-calling models, Needle 3, 2 and 1 from one build. Browser, Cloudflare Workers, Node.js, Python, C FFI and no_std. Token-exact with the JAX reference. No backend, no API key. |
126 downloads over 30 days | 0 | 107 | 0.3.1 | GPU support unknown | No native code found | MIT |
Why ListedNo archive, New or Featured rule places it, so it is Listed.
What it lacks for Featured
- It has 3 active dependents and 2 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days. The repository route reads 18 stars, 4 forks and 2 contributors. It needs 4,539 stars, 434 forks and 79 contributors together.
- Every version is 0.0.x.
- The project is dormant and not finished. Dormancy rule
What else the check found
- The last activity is on 9 Nov 2023, 1096 days ago. That reaches the 365 days the rules expect, so the project is dormant. Dormancy rule
Not measured: Latest release fails cargo check.
Exact rules: Listed, Featured library. The check on applied thresholds version 9.
Every rule outcome, as the check records it
expected-interval: version 0.0.7 base 450, capped at 6 releases = 300, raised to the 365-day floor: E = 365 daysdormancy: last activity 2023-11-09, 1096 days ago, E = 365: dormantfeatured: not featured: active_users 3 < 11 and new_adopters 2 < 9 and repository route stars 18 (needs 4539), forks 4 (needs 434), contributors 2 (needs 79); every version is 0.0.x; dormant and not stablelisted: listed: no archive, new or featured rule applies
Measurements and sources
Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.
Sources6 sources
- Description: the crates.io description
- crates.io database dump, fetched
- RustSec advisory database, fetched
- GitHub repository, fetched
- crates.io package, fetched
- GitHub contributors, fetched
Adoption3 active dependents, 2 new dependents in 365 days1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | 3 | crates.io database dump | Yes | |
| New dependents (365 days) | 2 | crates.io database dump | Yes | |
| Peak active dependents | 3 | crates.io database dump | Yes | |
| Active dependents as a share of the peak | 1 | crates.io database dump | Yes | |
| Binary downloads per release | Not measured | Yes |
MaintenanceLatest human commit: 3 years ago3 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2023-11-09 | GitHub repository | Yes | |
| Latest release | 2023-11-09 | crates.io database dump | Yes | |
| First release | 2023-06-22 | crates.io database dump | Yes | |
| Latest version | 0.0.7 | crates.io database dump | Yes | |
| Days the oldest outside issue waits for a reply | 0 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 0 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | true | crates.io package | Yes | |
| Published docs | true | crates.io database dump | Yes | |
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityUnpatched vulnerabilities: none
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | none | RustSec advisory database | Yes | |
| RustSec unmaintained advisory | none | RustSec advisory database | Yes | |
| Deprecation notice | none | crates.io database dump | Yes | |
| Deprecated requirement | none | crates.io database dump | Yes |
Distribution6 releases, 4,242 downloads over 30 days5 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | 6 | crates.io database dump | Yes | |
| Downloads over 30 days | 4242 | crates.io database dump | Yes | |
| Binary downloads over the last 3 releases | Not measured | Yes | ||
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | true | crates.io database dump | Yes | |
| Every version 0.0.x | true | crates.io database dump | Yes | |
| Every version yanked | false | crates.io database dump | Yes | |
| Crate deleted from crates.io | false | crates.io database dump | Yes |
Repository18 stars, 4 forks, 2 contributors, 28 commits. Stars alone never qualify a project.
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 18 | GitHub repository | Yes — one part of the repository route | |
| GitHub forks | 4 | GitHub repository | Yes — one part of the repository route | |
| Contributors with a GitHub account | 2 | GitHub contributors | Yes — one part of the repository route | |
| Commits on the default branch | 28 | GitHub repository | No | |
| Repository's main crate left out of the entry | none | crates.io database dump | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | MIT | crates.io database dump | No | |
| Runs on, from listed crates and their direct dependencies | GPU support unknown | crates.io database dump | No | |
| What shows each backend | no dependency or feature matches a backend row | crates.io database dump | No | |
| Native code, from listed crates and their dependencies | No native code found | crates.io database dump | No | |
| Python bindings, from direct dependencies of listed crates | No Python binding crate found | crates.io database dump | No | |
| Crates that depend on a listed crate directly | 6 | crates.io database dump | No |
Corrections and review history
No correction applies to this entry.
Judgments
A judgment enters only through an approved issue and a merged pull request.
No judgment applies to this entry.