Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
7b076cfb
Unverified
Commit
7b076cfb
authored
Jun 27, 2025
by
Muthuraj Ramalingakumar
Committed by
GitHub
Jun 27, 2025
Browse files
feat: Parallelize tokenization during batch completion (#1657)
parent
9d7624f1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
lib/llm/src/preprocessor.rs
lib/llm/src/preprocessor.rs
+10
-7
No files found.
lib/llm/src/preprocessor.rs
View file @
7b076cfb
...
...
@@ -29,6 +29,7 @@ pub mod tools;
use
anyhow
::
Result
;
use
futures
::
stream
::{
self
,
StreamExt
};
use
prompt
::
OAIPromptFormatter
;
use
rayon
::
iter
::{
IntoParallelRefIterator
,
ParallelIterator
};
use
std
::{
collections
::
HashMap
,
sync
::
Arc
};
use
tracing
;
...
...
@@ -220,13 +221,15 @@ impl OpenAIPreprocessor {
builder
.token_ids
(
encoding
.token_ids
);
}
TextInput
::
Batch
(
texts
)
=>
{
let
mut
token_batches
=
Vec
::
new
();
// TODO: room for optimization here
for
text
in
texts
{
let
encoding
=
tokio
::
task
::
block_in_place
(||
self
.tokenizer
.encode
(
&
text
))
?
;
token_batches
.push
(
encoding
.token_ids
);
}
let
token_batches
:
Result
<
Vec
<
Vec
<
u32
>>
,
_
>
=
texts
.par_iter
()
.map
(|
text
|
{
tokio
::
task
::
block_in_place
(||
self
.tokenizer
.encode
(
text
))
.map
(|
encoding
|
encoding
.token_ids
)
})
.collect
();
let
token_batches
=
token_batches
?
;
builder
.batch_token_ids
(
Some
(
token_batches
));
builder
.token_ids
(
vec!
[]);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment