Skip to main content

Int8Model

Struct Int8Model 

Source
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: usize

Positions 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

Source

pub fn from_json(j: &Value) -> Result<Int8Model, String>

The model scripts/train_tiny_transformer.py exports (benchmarks/silicon/tiny_transformer.json).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Clone for Int8Model

Source§

fn clone(&self) -> Int8Model

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Int8Model

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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,

§

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