From 33bc7212afd2bbf168c6735cd66c96a6cbf69c4e Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Tue, 14 May 2024 18:15:56 +0200 Subject: [PATCH] Fixing truncation. (#1890) # What does this PR do? Fixes # (issue) ## Before submitting - [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case). - [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests), Pull Request section? - [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link to it if that's the case. - [ ] Did you make sure to update the documentation with your changes? Here are the [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation). - [ ] Did you write any new necessary tests? ## Who can review? Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR. --- router/src/validation.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/router/src/validation.rs b/router/src/validation.rs index be4bef00..f85b169c 100644 --- a/router/src/validation.rs +++ b/router/src/validation.rs @@ -119,7 +119,11 @@ impl Validation { // If we have a fast tokenizer if let Some((encoding, inputs)) = self.tokenize(inputs.clone(), truncate).await? { // Create response channel - let input_length = encoding.len(); + let input_length = if let Some(truncate) = truncate { + std::cmp::min(encoding.len(), truncate) + } else { + encoding.len() + }; // Get total tokens let max_new_tokens: u32 = if let Some(max_new_tokens) = max_new_tokens {