pub struct Int8Model {
pub d: usize,
pub heads: usize,
pub d_ff: usize,
pub vocab: usize,
pub ctx: usize,
pub requant: BTreeMap<String, (i64, u32)>,
pub weights: BTreeMap<String, Vec<i64>>,
pub embed: Vec<i64>,
pub positions: Vec<i64>,
pub exp_lut: Vec<i64>,
}Expand description
A one-layer int8 transformer: its shapes, its requant pairs, its tables.
Fields§
§d: usize§heads: usize§d_ff: usize§vocab: usize§ctx: usizePositions the cache holds — the positional table’s rows.
requant: BTreeMap<String, (i64, u32)>Each requant’s (M, S), by its name in the model (r_qkv, M_q, M_score, …).
weights: BTreeMap<String, Vec<i64>>The int8 weights, row-major, by name: Wq Wk Wv Wo (d × d), W1 (d × d_ff), W2 (d_ff × d), Eq
(vocab × d, the tied embedding the head multiplies by its transpose).
embed: Vec<i64>The token embedding as the stream reads it (vocab × d).
positions: Vec<i64>The positional embedding (ctx × d).
exp_lut: Vec<i64>The softmax’s exp table, indexed by the requanted distance from the row’s maximum.
Implementations§
Source§impl Int8Model
impl Int8Model
Sourcepub fn from_json(j: &Value) -> Result<Int8Model, String>
pub fn from_json(j: &Value) -> Result<Int8Model, String>
The model scripts/train_tiny_transformer.py exports (benchmarks/silicon/tiny_transformer.json).
Sourcepub fn step_reads() -> BTreeSet<String>
pub fn step_reads() -> BTreeSet<String>
What a decode step’s host reads, besides the caches the step carries: next, the token it feeds back as the next
step’s tok. A step lowered returning these (crate::spatial::pipeline::compile_program_to_spatial_returning)
forwards every other value only its next statement reads.
Sourcepub fn reference_cuda(
&self,
prompt: &[i64],
generated: usize,
) -> Result<String, String>
pub fn reference_cuda( &self, prompt: &[i64], generated: usize, ) -> Result<String, String>
The hand-written CUDA reference of the decode step: one warp generating every token of the trace for prompt on the
device in one launch, the generated tokens past the prompt printed (GEN i token), then the whole trace repeated
(its first argument’s count, 2,000 by default) between two events and the time per token printed (US_PER_TOKEN).
The GPU’s best for this model: the kernel written for the part by hand.
Sourcepub fn prompt_next_tokens(
&self,
prompt: &[usize],
target: &SpatialTarget,
) -> Result<Vec<usize>, String>
pub fn prompt_next_tokens( &self, prompt: &[usize], target: &SpatialTarget, ) -> Result<Vec<usize>, String>
The next token, 0-based, each step over prompt predicts on target: the decode step at each position lowered
and run on the spatial evaluator, the cache each step writes carried into the next. What a board stepped through
the prompt replies, and the token after the prompt’s last is the trainer’s first generated one.
Sourcepub fn decode_step_lg(
&self,
tok: usize,
pos: usize,
kc: &[i64],
vc: &[i64],
) -> String
pub fn decode_step_lg( &self, tok: usize, pos: usize, kc: &[i64], vc: &[i64], ) -> String
The decode step for token tok at position pos (both 0-based), the cache holding the key and value rows of
positions 0..pos (pos · d values each, row-major). The step binds logits (1 × vocab) and next, the
1-based index of the first maximal logit, and writes this token’s rows into Kc and Vc as row pos + 1.
Sourcepub fn decode_step_tp_lg(
&self,
tok: usize,
pos: usize,
kc: &[i64],
vc: &[i64],
tp: usize,
) -> Result<(String, TpManifest), String>
pub fn decode_step_tp_lg( &self, tok: usize, pos: usize, kc: &[i64], vc: &[i64], tp: usize, ) -> Result<(String, TpManifest), String>
The decode step of Int8Model::decode_step_lg split over tp chips, Megatron’s way, as one program and the
manifest of where each of its tensors lives.
Chip c owns heads c·H/tp .. whole: its columns of Wq, Wk, Wv and of the KV cache, its heads’ rows of
Wo, an exp table of its own, and FFN columns c·d_ff/tp .. of W1 with their rows of W2. Every chip-local
table is named <table>_c<chip> and is a TpSlice of the model’s. A chip’s output projection is a partial
accumulator (o_a_c<chip>, f_a_c<chip>), and an all-reduce, spelled as the fold of plus it means, sums the
partials before the requant, so the step is the unsplit step bit for bit. The embedding, the residuals and the
head are the replicated spine. On one chip the accumulators are whole and nothing is all-reduced.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Int8Model
impl RefUnwindSafe for Int8Model
impl Send for Int8Model
impl Sync for Int8Model
impl Unpin for Int8Model
impl UnsafeUnpin for Int8Model
impl UnwindSafe for Int8Model
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.