Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/BATCHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ same server): its numbers, what a slot costs and where setup recommends it are i
## The strata-poly models

`"parallel": N` in the model's config (`strata-<model>.json`), or `--parallel N` when you run setup, works for
GLM 5.3 Flash, DeepSeek V4 Flash, LFM2.5, Flint, Qwen3.6, Ornith 1.5, Gemma 4, Tiel Coder and MiniCPM-V too, up to
8. The server drives it the way it drives the Strata project's engine (below), with the same lines:
GLM 5.3 Flash, DeepSeek V4 Flash, LFM2.5, Flint, Qwen3.6, Ornith 1.5, Gemma 4, Tiel Coder, MiniCPM-V and Inkling 2
Mini (not on a Mac yet) too, up to 8. The server drives it the way it drives the Strata project's engine (below), with the same lines:

- A request alone writes on its own and guesses ahead as always, so one user sees no change.
- When a second one comes, the first goes on in a batch slot from where it was, nothing read again, and the two
Expand Down
7 changes: 4 additions & 3 deletions docs/models/inkling.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Back to [README.md](../../README.md)

**Inkling 2 Mini** by Thinking Machines: a file of 9 to 18 GB. It is experimental here. It has run on Linux with an
RTX 5090, on Windows with an 8 GB laptop card and on a Mac with an M5 Ultra (a beta there), one request at a time. It
RTX 5090, on Windows with an 8 GB laptop card and on a Mac with an M5 Ultra (a beta there). It
reads pictures too. Its 24 layers of weights run as 48: the twelve in the middle run three
times for every token. Forty of the 48 look back 1,024 tokens only, so a long conversation takes little VRAM:
32,768 bytes a token.
Expand Down Expand Up @@ -97,8 +97,9 @@ rows took 3.4 s.
Not run yet: an AMD card, two cards (`--expert-gpu`, built but not run), UD-Q4_K_XL on the 8 GB card and UD-Q4_K_XL
on a Mac. Pictures go through Unsloth's mmproj-F16.gguf, read on the CPU (`--vision cpu`) or the card; on a Mac, on
the CPU. The draft file is an
option (`--draft-model`). The engine takes one request at a time
for this model, and the installer writes `"parallel": 1`. Its license is Apache 2.0.
option (`--draft-model`). Several requests at once (`"parallel"`, see [BATCHING.md](../BATCHING.md)) are
opt-in on an NVIDIA card, not with the draft file; on a Mac the engine takes one request at a time for this model,
and the installer writes `"parallel": 1` there. Its license is Apache 2.0.

## Install

Expand Down
214 changes: 193 additions & 21 deletions engine/src/poly/engine.cpp

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions engine/src/poly/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ struct Layer {
std::vector<void*> card_moe; ///< the routed experts, routed on the card (moe_card())
/// the head of step()'s rows in one call (Engine::batch_heads()): by the rows, their sequences and head keys
std::map<std::vector<int>, void*> rows_heads;
/// the tail of step()'s rows in one call, where it reads them too (Engine::tail_by_rows()): by the rows, their
/// sequences and the tail key
std::map<std::vector<int>, void*> rows_tails;
};

/// A routed expert is run from the VRAM cache or on the CPU when tokens come a few at a time, as an answer's do
Expand Down Expand Up @@ -601,6 +604,10 @@ class Engine {
/// state and attention rows from its own sequence (rows_of_, seq_state(), seq_buf()), its position from at_.
/// Otherwise step() runs the head a row at a time, with the row's sequence bound.
virtual bool batch_heads() const { return false; }
/// With batch_heads(): layer_tail() takes step()'s rows too (rows_of_ set), for a recurrent state of each row's
/// own sequence after the experts (Inkling 2's convolution of the experts' sum). step() then records a tail by
/// its rows' sequences, as a head, and does not split the rows into halves.
virtual bool tail_by_rows() const { return false; }
/// The architecture's step() rows leave the recurrent state after a row at Row::snap (step() with guesses).
virtual bool rows_snaps() const { return false; }
/// While step() runs a head in one call: each row's sequence and position, row after row; else null. snap: for
Expand Down Expand Up @@ -701,6 +708,13 @@ class Engine {
void moe_add(int n);
template <class F>
void* record(F&& work);
// step()'s recordings where the tails take the rows (tail_by_rows(): Inkling 2). They are keyed by the rows'
// sequences and rooms, so slots that come and go make more of them for as long as the engine runs: they are held
// to a VRAM budget, the least recently launched dropped first (trim_step_graphs()), and a recording the card has
// no memory for runs unrecorded (record_step()). The other families' step() records as before.
bool step_replay(std::map<std::vector<int>, void*>& in, const std::vector<int>& key, const std::function<void()>& work);
void* record_step(const std::function<void()>& work);
void trim_step_graphs(size_t target);
void moe_rows(Layer& L, int il, int n);
void stage(const Layer& L, const int32_t* experts, int m, void* stream, bool alone = false);
void stage_rest(const Layer& L, const int32_t* experts, const std::vector<int>& which, int m, void* stream,
Expand Down Expand Up @@ -907,6 +921,13 @@ class Engine {
///< every layer's head_key()
/// step()'s layers and logits recorded as one: by its rows, each row's sequence, guess and head_key()s
std::map<std::vector<int>, void*> step_passes_;
/// step_replay()'s recordings: the step that last launched each one (step_no_)
std::map<void*, uint64_t> step_used_;
uint64_t step_no_ = 0; ///< step()s so far
uint64_t step_rec_retry_ = 0; ///< after a recording the card had no memory for: none before this step
size_t step_bytes_ = 0; ///< the VRAM step_used_'s recordings took (cudaMemGetInfo() around each)
size_t step_budget_ = 0; ///< and the most they may take (STRATA_POLY_STEP_GRAPH_MIB; 0 until the first)
size_t step_dropped_ = 0, step_logged_ = 0;
void* tail_ = nullptr; ///< one token's launches from the last layer to the logits, recorded
void* tail_picks_ = nullptr; ///< the same, the most likely token in place of the logits (eval_picks())
// A recorded launch cannot be given the position as an argument: it reads it here when it runs. eval() writes
Expand Down Expand Up @@ -1107,6 +1128,9 @@ class Engine {
int32_t* d_ids_ = nullptr; ///< a batch's experts and weights when it routes on the card
float* d_wts_ = nullptr;
int32_t* h_ids_ = nullptr; ///< pinned: the experts, back from the card
float* h_wts_ = nullptr; ///< pinned: their weights, for step()'s rows (bells(), --batch)
/// While moe() takes step()'s rows: their picks from the card (h_ids_, h_wts_), as a token alone routes there
const int32_t* step_ids_ = nullptr;
void** d_slots_ = nullptr; ///< every layer's L.slot on the card, n_expert_ a layer (moe_card())
std::vector<void*> h_slots_; ///< what d_slots_ holds
// card_far_: with most experts cached, a few tokens route on the card even so (card_moe()), and a call's experts
Expand Down
Loading
Loading