Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
text-generation-inference
Commits
d6d5b12e
Commit
d6d5b12e
authored
Nov 14, 2022
by
OlivierDehaene
Browse files
fix(router): Handle tokenizer errors
parent
feb7806c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
14 deletions
+22
-14
router/src/validation.rs
router/src/validation.rs
+22
-14
No files found.
router/src/validation.rs
View file @
d6d5b12e
...
...
@@ -123,20 +123,26 @@ fn validation_worker(
}
// Get the number of tokens in the input
let
inputs
=
tokenizer
.encode
(
request
.inputs
.clone
(),
false
)
.unwrap
();
let
input_length
=
inputs
.len
();
if
input_length
>
max_input_length
{
response_tx
.send
(
Err
(
ValidationError
::
InputLength
(
input_length
,
max_input_length
,
)))
.unwrap_or
(());
continue
;
}
response_tx
.send
(
Ok
((
input_length
,
request
)))
.unwrap_or
(());
match
tokenizer
.encode
(
request
.inputs
.clone
(),
false
)
{
Ok
(
inputs
)
=>
{
let
input_length
=
inputs
.len
();
if
input_length
>
max_input_length
{
response_tx
.send
(
Err
(
ValidationError
::
InputLength
(
input_length
,
max_input_length
,
)))
.unwrap_or
(());
continue
;
}
response_tx
.send
(
Ok
((
input_length
,
request
)))
.unwrap_or
(());
}
Err
(
err
)
=>
response_tx
.send
(
Err
(
ValidationError
::
Tokenizer
(
err
.to_string
())))
.unwrap_or
(()),
};
}
}
...
...
@@ -157,6 +163,8 @@ pub enum ValidationError {
MaxNewTokens
,
#[error(
"inputs must have less than {1} tokens. Given: {0}"
)]
InputLength
(
usize
,
usize
),
#[error(
"tokenizer error {0}"
)]
Tokenizer
(
String
),
}
impl
From
<
ValidationError
>
for
(
StatusCode
,
Json
<
ErrorResponse
>
)
{
...
...
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