Skip to main content

CachedStateFeatures

Struct CachedStateFeatures 

Source
pub struct CachedStateFeatures {
    pub hash_key: u64,
    pub shape: Vec<usize>,
    pub payload: CachedTensorPayload,
    pub byte_size: usize,
    pub compression_mode: CacheCompressionMode,
    pub state_mask: Vec<i64>,
    pub state_text: Option<String>,
}
Expand description

キャッシュに格納される State 中間特徴量エントリ。

Fields§

§hash_key: u64

xxHash3 (64-bit) によるキー。

§shape: Vec<usize>

テンソル形状 ([batch_size, seq_len, hidden_size])。

§payload: CachedTensorPayload

テンソル実体ペイロード。

§byte_size: usize

テンソルが占有する実メモリバイト数(moka の weigher に使用)。

§compression_mode: CacheCompressionMode

採用された圧縮モード。

§state_mask: Vec<i64>

State の有効トークンアテンションマスク列 ([batch_size, seq_len])。

§state_text: Option<String>

キャッシュされた State 原文テキスト(または先頭抜粋)。 State-Offloading 時に System 2 へのエスカレーションプロンプト生成で活用される。

Implementations§

Source§

impl CachedStateFeatures

Source

pub fn new_raw( hash_key: u64, shape: Vec<usize>, ort_value: Value, byte_size: usize, state_mask: Vec<i64>, ) -> Self

非圧縮の生 Value からキャッシュエントリを生成する。

§引数
  • hash_key: 64-bitハッシュキー。
  • shape: テンソル形状。
  • ort_value: ONNX Runtimeの出力 Value。
  • byte_size: 占有バイト数。
  • state_mask: State 有効トークンマスク列。空の場合は全トークン有効 (1) として補完される。
Source

pub fn new_raw_with_text( hash_key: u64, shape: Vec<usize>, ort_value: Value, byte_size: usize, state_mask: Vec<i64>, state_text: Option<String>, ) -> Self

非圧縮の生 Value と State 原文テキストからキャッシュエントリを生成する。

Source

pub fn new_compressed( hash_key: u64, shape: Vec<usize>, raw_slice: &[f32], mode: CacheCompressionMode, state_mask: Vec<i64>, ) -> Result<Self>

f32 スライスを指定された圧縮モードで変換してキャッシュエントリを生成する。

§引数
  • hash_key: 64-bitハッシュキー。
  • shape: テンソル形状 ([batch_size, seq_len, hidden_size])。
  • raw_slice: 展開済み f32 スライス。
  • mode: 圧縮モード。
  • state_mask: State 有効トークンマスク列。空の場合は全トークン有効 (1) として補完される。
Source

pub fn new_compressed_with_text( hash_key: u64, shape: Vec<usize>, raw_slice: &[f32], mode: CacheCompressionMode, state_mask: Vec<i64>, state_text: Option<String>, ) -> Result<Self>

f32 スライスと State 原文テキストを指定された圧縮モードで変換してキャッシュエントリを生成する。

Source

pub fn with_state_text(self, text: Option<String>) -> Self

State 原文テキストを設定するビルダーメソッド。

Source

pub fn as_ort_value(&self) -> Result<Arc<Value>>

推論入力としてバインド可能な Arc<Value> を取得する。

非圧縮時は保持している Arc<Value> をそのままゼロコピーで返却し、 圧縮時はオンザフライで ONNX Runtime のアロケータメモリへ直接デコードを展開してテンソルを生成する。

Source

pub fn as_ort_value_for_batch(&self, target_batch: usize) -> Result<Arc<Value>>

指定されたバッチサイズに合わせてバインド可能な Arc<Value> を取得する。

target_batch == 1 かつ自身のバッチサイズが 1 の場合はゼロコピー返却する。 target_batch > 1 の場合は、単一サンプルの特徴量データを target_batch 回リピートした テンソル ([target_batch, seq_len, hidden_size]) を ONNX Runtime アロケータメモリへ直接構築して返却する。 中間ベクタのヒープ確保と再アロケーションを回避し、64バイトアライメントを維持する。

Source

pub fn batch_size(&self) -> usize

バッチサイズを取得する。

Source

pub fn seq_len(&self) -> usize

系列長(トークン数)を取得する。

Source

pub fn hidden_size(&self) -> usize

隠れ層次元数を取得する。

Source

pub fn state_mask_for_batch(&self, target_batch: usize) -> Vec<i64>

指定されたバッチサイズに合わせて複製された state_mask を取得する。

キャッシュされた単一 State のマスク列 ([state_seq_len]) を target_batch 回リピートした テンソル用フラットベクタ ([target_batch * state_seq_len]) を生成する。

Trait Implementations§

Source§

impl Debug for CachedStateFeatures

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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
§

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,

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
§

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

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