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: u64xxHash3 (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
impl CachedStateFeatures
Sourcepub fn new_raw(
hash_key: u64,
shape: Vec<usize>,
ort_value: Value,
byte_size: usize,
state_mask: Vec<i64>,
) -> Self
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) として補完される。
Sourcepub 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
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 原文テキストからキャッシュエントリを生成する。
Sourcepub fn new_compressed(
hash_key: u64,
shape: Vec<usize>,
raw_slice: &[f32],
mode: CacheCompressionMode,
state_mask: Vec<i64>,
) -> Result<Self>
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) として補完される。
Sourcepub 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>
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 原文テキストを指定された圧縮モードで変換してキャッシュエントリを生成する。
Sourcepub fn with_state_text(self, text: Option<String>) -> Self
pub fn with_state_text(self, text: Option<String>) -> Self
State 原文テキストを設定するビルダーメソッド。
Sourcepub fn as_ort_value(&self) -> Result<Arc<Value>>
pub fn as_ort_value(&self) -> Result<Arc<Value>>
推論入力としてバインド可能な Arc<Value> を取得する。
非圧縮時は保持している Arc<Value> をそのままゼロコピーで返却し、
圧縮時はオンザフライで ONNX Runtime のアロケータメモリへ直接デコードを展開してテンソルを生成する。
Sourcepub fn as_ort_value_for_batch(&self, target_batch: usize) -> Result<Arc<Value>>
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バイトアライメントを維持する。
Sourcepub fn batch_size(&self) -> usize
pub fn batch_size(&self) -> usize
バッチサイズを取得する。
隠れ層次元数を取得する。
Sourcepub fn state_mask_for_batch(&self, target_batch: usize) -> Vec<i64>
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§
Auto Trait Implementations§
impl !RefUnwindSafe for CachedStateFeatures
impl !UnwindSafe for CachedStateFeatures
impl Freeze for CachedStateFeatures
impl Send for CachedStateFeatures
impl Sync for CachedStateFeatures
impl Unpin for CachedStateFeatures
impl UnsafeUnpin for CachedStateFeatures
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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