Skip to content

Commit

Permalink
Fix bnf.
Browse files Browse the repository at this point in the history
  • Loading branch information
cryscan committed Jun 14, 2024
1 parent 370092a commit 2b1150c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/ai00-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bytemuck = "1"
cbor4ii = { version = "0.3.2", features = ["serde1"] }
fastrand = "2"
half = "2.4"
kbnf = "0.1.2"
kbnf = "0.1.3"
qp-trie = "0.8"
rustc-hash = "1.1.0"
uuid = { version = "1.8.0", features = ["serde", "v4"] }
Expand Down
3 changes: 3 additions & 0 deletions crates/ai00-core/src/sampler/bnf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ impl BnfSampler {
.token_index_to_bytes()
.iter()
.enumerate()
.filter(|(_, v)| !v.is_empty())
.map(|(k, v)| (k as u32, Token(v.clone().into_boxed_slice())))
.collect();
let strings = tokenizer
.token_index_to_bytes()
.iter()
.enumerate()
.filter(|(_, v)| !v.is_empty())
.map(|(k, v)| (k as u32, String::from_utf8_lossy(v).to_string()))
.collect();
let vocab = Vocabulary::new(tokens, strings)?;
Expand All @@ -31,6 +33,7 @@ impl BnfSampler {

impl Transformer for BnfSampler {
fn transform(&self, output: &mut [f32]) {
let output = &mut output[..self.0.vocab().vocab_size()];
self.0.mask_logits(output).expect("bnf transform error")
}

Expand Down

0 comments on commit 2b1150c

Please sign in to comment.