ChatTokenizer

Struct ChatTokenizer 

Source
pub struct ChatTokenizer { /* private fields */ }

Implementations§

Source§

impl ChatTokenizer

Source

pub fn image_pad_token_id(&self, declared: u32) -> Option<u32>

2026-09-26: The image placeholder token id.

declared is the image_token_id from the checkpoint’s config (top level or under vision_config) and wins when non-zero. Otherwise the id is that of <|image_pad|> when the string encodes to exactly one token, else None. With None, expand_vision_pads leaves image placeholders unexpanded and reports nothing.

Source

pub fn video_pad_token_id(&self, declared: u32) -> Option<u32>

2026-09-26: The video placeholder token id, with the same rule as image_pad_token_id: declared when non-zero, else <|video_pad|> when it encodes to one token, else None.

Source

pub fn expand_vision_pads( &self, tokens: Vec<u32>, pad_counts: &[usize], declared: (u32, u32), ) -> Vec<u32>

2026-09-26: Expand the image and video placeholders of a rendered token sequence, the i-th placeholder to pad_counts[i] copies (at least one), so the prompt holds one placeholder per vision-encoder output row. The Qwen3.6 templates in test_data/chat_templates write one placeholder per image or video. Returns tokens unchanged when every count is at most 1; see fan_out_pads for mismatched counts.

Source§

impl ChatTokenizer

Source

pub fn from_model_dir( model_dir: &Path, eos_token_id: u32, supports_thinking: bool, model_type: &str, repo_root: Option<&Path>, disable_template_overrides: bool, ) -> Result<Self>

Source

pub fn inner(&self) -> &Tokenizer

2026-09-26: The underlying Hugging Face tokenizer.

Source

pub fn encode(&self, text: &str) -> Result<Vec<u32>>

Source

pub fn decode(&self, ids: &[u32]) -> Result<String>

Source

pub fn decode_with_special(&self, ids: &[u32]) -> Result<String>

2026-09-26: Decode without skipping special tokens; decode skips them.

Source

pub fn incremental_decode( &self, toks: &[u32], prefix_offset: &mut usize, read_offset: &mut usize, ) -> String

2026-09-26: Incremental detokenizer. Returns the text toks added since the last call and advances the offsets.

Each call decodes only toks[prefix_offset..read_offset] and toks[prefix_offset..] (with decode, so special tokens are skipped) and returns what the second adds to the first. It returns an empty string and leaves the offsets alone when the second decode is not longer, ends in U+FFFD, or does not split at a char boundary. Offsets that no longer fit toks are reset to 0 first.

Source

pub fn streaming_decoder( &self, skip_special_tokens: bool, ) -> StreamingDecoder<'_>

2026-09-26: A new StreamingDecoder over this tokenizer.

Source

pub fn apply_chat_template_jinja( &self, messages: &[Value], tools: Option<&[Value]>, enable_thinking: bool, disable_tool_steering: bool, ) -> Result<Vec<u32>>

2026-09-26: apply_chat_template_jinja_with_effort with no reasoning effort and preserve_thinking unset.

Source

pub fn apply_chat_template_jinja_with_effort( &self, messages: &[Value], tools: Option<&[Value]>, enable_thinking: bool, disable_tool_steering: bool, reasoning_effort: Option<&str>, preserve_thinking: Option<bool>, ) -> Result<Vec<u32>>

Source

pub fn apply_chat_template_openai( &self, messages: &[Value], tools: Option<&[Value]>, enable_thinking: bool, disable_tool_steering: bool, ) -> Result<Vec<u32>>

2026-09-26: apply_chat_template_openai_with_effort with no reasoning effort and preserve_thinking unset.

Source

pub fn apply_chat_template_openai_with_effort( &self, messages: &[Value], tools: Option<&[Value]>, enable_thinking: bool, disable_tool_steering: bool, reasoning_effort: Option<&str>, preserve_thinking: Option<bool>, ) -> Result<Vec<u32>>

Source

pub fn apply_chat_template( &self, messages: &[(String, String)], enable_thinking: bool, _image_pad_counts: &[usize], ) -> Result<Vec<u32>>

2026-09-26: Render (role, content) pairs through apply_chat_template_jinja, with no tools; _image_pad_counts is unused.

Source

pub fn eos_token_id(&self) -> u32

Source

pub fn think_end_token_id(&self) -> Option<u32>

Source

pub fn supports_thinking(&self) -> bool

Source

pub fn uses_deepseek_v4_encoding(&self) -> bool

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,