pub struct ActiveSequence { /* private fields */ }Expand description
A sequence that is actively being built, with the ability to add tokens and commit to hashes TODO: reuse tokens
Implementations§
Source§impl ActiveSequence
Auto-generated by derive_getters::Getters.
impl ActiveSequence
Auto-generated by derive_getters::Getters.
Sourcepub fn unique_blocks(&self) -> &Vec<UniqueBlock>
pub fn unique_blocks(&self) -> &Vec<UniqueBlock>
Get field unique_blocks from instance of ActiveSequence.
Sourcepub fn block_hashes(&self) -> &Vec<BlockHash> ⓘ
pub fn block_hashes(&self) -> &Vec<BlockHash> ⓘ
Get field block_hashes from instance of ActiveSequence.
Sourcepub fn plhs(&self) -> &Vec<PositionalLineageHash>
pub fn plhs(&self) -> &Vec<PositionalLineageHash>
Get field plhs from instance of ActiveSequence.
Sourcepub fn block_size(&self) -> usize
pub fn block_size(&self) -> usize
Get field block_size from instance of ActiveSequence.
Sourcepub fn max_output_tokens(&self) -> usize
pub fn max_output_tokens(&self) -> usize
Get field max_output_tokens from instance of ActiveSequence.
Sourcepub fn generated_tokens(&self) -> usize
pub fn generated_tokens(&self) -> usize
Get field generated_tokens from instance of ActiveSequence.
Sourcepub fn planned_output_ids(&self) -> &Option<Vec<u32>>
pub fn planned_output_ids(&self) -> &Option<Vec<u32>>
Get field planned_output_ids from instance of ActiveSequence.
Sourcepub fn num_input_tokens(&self) -> usize
pub fn num_input_tokens(&self) -> usize
Get field num_input_tokens from instance of ActiveSequence.
Sourcepub fn num_allocated_tokens(&self) -> usize
pub fn num_allocated_tokens(&self) -> usize
Get field num_allocated_tokens from instance of ActiveSequence.
Sourcepub fn enable_prefix_caching(&self) -> bool
pub fn enable_prefix_caching(&self) -> bool
Get field enable_prefix_caching from instance of ActiveSequence.
Sourcepub fn emit_token_ids(&self) -> bool
pub fn emit_token_ids(&self) -> bool
Get field emit_token_ids from instance of ActiveSequence.
Source§impl ActiveSequence
impl ActiveSequence
Sourcepub fn new(
tokens: Vec<u32>,
max_output_tokens: usize,
block_size: Option<usize>,
enable_prefix_caching: bool,
emit_token_ids: bool,
) -> Self
pub fn new( tokens: Vec<u32>, max_output_tokens: usize, block_size: Option<usize>, enable_prefix_caching: bool, emit_token_ids: bool, ) -> Self
Create a new ActiveSequence instance with the provided tokens
pub fn new_with_planned_output_ids( tokens: Vec<u32>, max_output_tokens: usize, block_size: Option<usize>, enable_prefix_caching: bool, emit_token_ids: bool, planned_output_ids: Option<Vec<u32>>, ) -> Self
pub fn extra_tokens(&self) -> u32
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn prepare_allocation(&self, cumulative_tokens: usize) -> Option<MoveBlock>
pub fn prepare_allocation(&self, cumulative_tokens: usize) -> Option<MoveBlock>
Build a MoveBlock::Use signal for blocks up to cumulative_tokens
without updating internal state. Returns None if no new blocks are needed.
Call commit_allocation after the signal is successfully processed.
Sourcepub fn positional_lineage_hashes(&self) -> &[PositionalLineageHash]
pub fn positional_lineage_hashes(&self) -> &[PositionalLineageHash]
Positional lineage hashes for all fully-tokenised blocks in the sequence.
Mirrors block_hashes() but returns the PLH identity used by kvbm-logical.
Sourcepub fn block_token_ids(&self) -> Vec<Vec<u32>>
pub fn block_token_ids(&self) -> Vec<Vec<u32>>
Materialize every complete block’s token IDs.
§Panics
Panics for native flat sequences that were created without token-ID event emission, because those sequences intentionally discard completed prompt and decode blocks.
Sourcepub fn commit_allocation(&mut self, cumulative_tokens: usize)
pub fn commit_allocation(&mut self, cumulative_tokens: usize)
Commit a successful allocation by advancing num_allocated_tokens.
Sourcepub fn allocate_blocks_for_chunk(
&mut self,
cumulative_tokens: usize,
) -> Option<MoveBlock>
pub fn allocate_blocks_for_chunk( &mut self, cumulative_tokens: usize, ) -> Option<MoveBlock>
Prepare + commit in one call (convenience for paths where failure is impossible).
Sourcepub fn take_creation_signal(&mut self) -> Option<MoveBlock>
pub fn take_creation_signal(&mut self) -> Option<MoveBlock>
Allocate all remaining blocks at once (backward compat).
Sourcepub fn new_with_signal(
tokens: Vec<u32>,
max_output_tokens: usize,
block_size: Option<usize>,
enable_prefix_caching: bool,
) -> (Self, Option<MoveBlock>)
pub fn new_with_signal( tokens: Vec<u32>, max_output_tokens: usize, block_size: Option<usize>, enable_prefix_caching: bool, ) -> (Self, Option<MoveBlock>)
Create a new ActiveSequence instance and return the creation signal
Sourcepub fn generate(&mut self) -> Vec<MoveBlock>
pub fn generate(&mut self) -> Vec<MoveBlock>
Generate a random token, push it to the sequence, and increment generation count.
This function:
- Generates a random token and adds it to the current sequence
- Acquires a new partial block if needed or promotes an existing partial block to a full block
- Returns appropriate signals for the G1 manager to process
§Panics
Calling this function when max_output_tokens has already been reached will cause a panic.
Always check generated_tokens < max_output_tokens before calling this method.
Sourcepub fn generate_token(&mut self) -> (u32, Vec<MoveBlock>)
pub fn generate_token(&mut self) -> (u32, Vec<MoveBlock>)
Generate the next output token, push it to the sequence, and return the token alongside any KV movement signals.
Sourcepub fn free_signal(&self) -> Vec<MoveBlock>
pub fn free_signal(&self) -> Vec<MoveBlock>
Free the currently active allocation footprint.
Sourcepub fn reset_with_signal(&mut self) -> Vec<MoveBlock>
pub fn reset_with_signal(&mut self) -> Vec<MoveBlock>
Move the request to a preempted state and return the free signals from freeing current blocks.
Upon preemption, the sequence retains the tokens generated during the decode phase (if any).
Resets num_allocated_tokens so re-admission will re-allocate from scratch.
Sourcepub fn pop(&mut self)
pub fn pop(&mut self)
Pops the last token in the sequence.
This is only used to undo a freshly generated decode token after a failed
allocation/preemption path. Under that invariant, the token being removed
must be in the current partial block, so we only need to drop the trailing
partial UniqueBlock when the sequence length returns to an exact block
boundary. Using this to unwind arbitrary prompt history would be incorrect.
If this contract is violated in release builds, legacy token storage preserves its historical no-op on an empty buffer, while flat storage panics to surface the invalid rollback.