Skip to content

feat: truncation (no stride/windowing) - #2366

Open
SBrandeis wants to merge 10 commits into
feat/train_encode_splitfrom
feat/truncation
Open

SBrandeis wants to merge 10 commits into
feat/train_encode_splitfrom
feat/truncation

Conversation

@SBrandeis

@SBrandeis SBrandeis commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Implement truncation in the PipelineTokenizer.encode() path
stride != 0 (ie windowing) is not supported yet

@SBrandeis
SBrandeis requested a review from ArthurZucker August 26, 2026 16:27
@SBrandeis SBrandeis changed the title implement basic truncation wip: truncation Aug 26, 2026
@SBrandeis SBrandeis changed the title wip: truncation feat: truncation (no stride/windowing) Aug 28, 2026

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty!

Comment on lines +1211 to +1215
#[test]
fn truncation_makes_room_for_the_specials_the_template_adds() {
let pipeline = pipeline_with(
bert_post_processor(),
truncation(5, TruncationStrategy::LongestFirst),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same to move out imo!

pub fn slices(&self) -> &[Slice] {
&self.slices
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep nicely moved!

Comment on lines +83 to +87
// XXX: maybe we should error out when instantiating the PipelineTokenizer to avoid this
warn!(
"Truncation max_length is too short to include the tokens: `max_length` is {}, the post-processor adds {num_added_special_tokens} special tokens. Returning an empty sequence",
truncation.max_length
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we can break in v1, I'd say let's make it make sense?

Comment on lines +12 to +16
// A `stride` asks for what the released crate returns as `overflowing` encodings: windows of
// `max_length` tokens that consecutive windows share `stride` of. The pipeline keeps the first
// window and drops the rest, so the value is read and carried rather than refused. 395 of the
// 5,053 popular Hub configs surveyed carry one, all question-answering fine-tunes, and
// transformers rebuilds truncation from the per-call `stride` anyway, so the file's value never

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to update

Base automatically changed from feat/truncation-padding to feat/train_encode_split September 2, 2026 11:13
@SBrandeis
SBrandeis changed the base branch from feat/train_encode_split to feat/rework-python-bindings September 10, 2026 09:16
@SBrandeis
SBrandeis force-pushed the feat/truncation branch 3 times, most recently from 14700c0 to f3d8d5f Compare September 15, 2026 13:14
Base automatically changed from feat/rework-python-bindings to feat/train_encode_split September 15, 2026 15:24
@SBrandeis
SBrandeis marked this pull request as ready for review September 15, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants