pub struct PromptLayout {
pub image_token: String,
pub fake_token: String,
pub global_token: String,
pub row_col_fmt: fn(usize, usize) -> String,
pub tokens_per_tile: usize,
}Expand description
The pieces of the layout that vary by checkpoint, read from config.json
and the processor rather than hard-coded.
Fields§
§image_token: StringRepeated tokens_per_tile times per image block.
fake_token: StringWraps every image block and closes the run.
global_token: StringMarks the global thumbnail’s block.
row_col_fmt: fn(usize, usize) -> String<row_{r}_col_{c}>, 1-based.
tokens_per_tile: usize(image_size / patch_size)^2 / scale_factor^2 — 64 for SmolVLM-256M.
Implementations§
Source§impl PromptLayout
impl PromptLayout
Sourcepub const fn with_geometry(
self,
image_size: usize,
patch_size: usize,
scale_factor: usize,
) -> Self
pub const fn with_geometry( self, image_size: usize, patch_size: usize, scale_factor: usize, ) -> Self
Derive tokens_per_tile from the vision geometry.
Computed rather than constant: it is
(image_size / patch_size)^2 / scale_factor^2, so a different SmolVLM
size changes it and a hard-coded 64 would be silently wrong there — the
same class of defect this whole module is guarding against.
Sourcepub fn image_block(&self, rows: usize, cols: usize) -> String
pub fn image_block(&self, rows: usize, cols: usize) -> String
The image-block run: 16 tiles row-major, then \n\n, then the global
thumbnail, then a closing fake token.
rows/cols describe the tile grid the preprocessor chose. rows == 0
means the image was small enough that only the thumbnail exists — the
reference emits just the global block then, with no grid and no \n\n.
Sourcepub fn user_turn(&self, question: &str, rows: usize, cols: usize) -> String
pub fn user_turn(&self, question: &str, rows: usize, cols: usize) -> String
The full user turn, chat template included.
The template is SmolVLM’s own — <|im_start|>User: … Assistant: — and
it is written here only because the tokenizer’s Jinja template is not
available to this crate. It is checked against the reference’s own
output, which is the only thing that makes writing it acceptable at all.
Trait Implementations§
Source§impl Clone for PromptLayout
impl Clone for PromptLayout
Source§fn clone(&self) -> PromptLayout
fn clone(&self) -> PromptLayout
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PromptLayout
impl Debug for PromptLayout
Auto Trait Implementations§
impl Freeze for PromptLayout
impl RefUnwindSafe for PromptLayout
impl Send for PromptLayout
impl Sync for PromptLayout
impl Unpin for PromptLayout
impl UnsafeUnpin for PromptLayout
impl UnwindSafe for PromptLayout
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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