-
Notifications
You must be signed in to change notification settings - Fork 818
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perf improvement 16% by removing offsets. (#1587)
* [Breaking Change] Perf improvement 16% by removing offsets. Offsets calculation are always calculated in Python land. By changing it to not being calculated, we win 16% of the runtime. This is not the total extent of it because offsets are still calculated in bytes. * Required features. * Remove clippy error. * Make it non breaking and still show perf improvement. * Even faster without offsets. * Update doc. * Fmt. * Apply suggestions from code review Co-authored-by: Arthur <[email protected]> * fmt. --------- Co-authored-by: Arthur <[email protected]>
- Loading branch information
1 parent
bd27fa5
commit bfd9cde
Showing
8 changed files
with
247 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#[macro_use] | ||
extern crate criterion; | ||
|
||
use criterion::{Criterion, Throughput}; | ||
use tokenizers::Tokenizer; | ||
|
||
pub fn llama3(c: &mut Criterion) { | ||
let data = std::fs::read_to_string("data/big.txt").unwrap(); | ||
let mut group = c.benchmark_group("llama3-encode"); | ||
group.throughput(Throughput::Bytes(data.bytes().len() as u64)); | ||
group.bench_function("llama3-offsets", |b| { | ||
let tokenizer = | ||
Tokenizer::from_pretrained("meta-llama/Meta-Llama-3.1-8B-Instruct", None).unwrap(); | ||
let data: Vec<_> = data.lines().collect(); | ||
let add_special_tokens = false; | ||
b.iter(|| { | ||
tokenizer | ||
.encode_batch_char_offsets(criterion::black_box(data.clone()), add_special_tokens) | ||
.unwrap() | ||
}) | ||
}); | ||
group.bench_function("llama3-nooffsets", |b| { | ||
let tokenizer = | ||
Tokenizer::from_pretrained("meta-llama/Meta-Llama-3.1-8B-Instruct", None).unwrap(); | ||
let data: Vec<_> = data.lines().collect(); | ||
let add_special_tokens = false; | ||
b.iter(|| { | ||
tokenizer | ||
.encode_batch(criterion::black_box(data.clone()), add_special_tokens) | ||
.unwrap() | ||
}) | ||
}); | ||
group.finish(); | ||
} | ||
|
||
criterion_group! { | ||
name = bert_benches; | ||
config = Criterion::default().sample_size(10); | ||
targets = llama3 | ||
} | ||
|
||
criterion_main!(bert_benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use tokenizers::Tokenizer; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | ||
let tokenizer = Tokenizer::from_pretrained("meta-llama/Meta-Llama-3.1-8B-Instruct", None)?; | ||
|
||
let data = std::fs::read_to_string("data/big.txt")?; | ||
let data: Vec<_> = data.lines().collect(); | ||
let add_special_tokens = false; | ||
tokenizer.encode_batch_char_offsets(data, add_special_tokens)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters