abi, sched: placeholder runs read both ways

An encoder states that the language model reads a picture's or video
frame's placeholders both ways (RadEncoderDecl::bidirectional). The
scheduler then ends no prefill chunk inside such a run, and a trunk
pass names its runs and the keys their rows see (RadBatch::n_bidi).
Fields appended; such a pass is not recorded.
This commit is contained in:
keptn42 committed 2026-11-04 07:20:43 +01:00
1 parent 81be3cb63d
commit da7b911c64
10 files changed
+246 -12

No files matched your search

+6
View File
@@ -99,6 +99,11 @@ ABI_FIELD(RadBatch, plugin_cu_h)
ABI_FIELD(RadBatch, sgen_b)
ABI_FIELD(RadBatch, kv_used_max_h)
ABI_FIELD(RadBatch, positions_h)
ABI_FIELD(RadBatch, n_bidi)
ABI_FIELD(RadBatch, bidi_row)
ABI_FIELD(RadBatch, bidi_n)
ABI_FIELD(RadBatch, bidi_seq)
ABI_FIELD(RadBatch, bidi_used)
ABI_STRUCT(RadBufDecl)
ABI_FIELD(RadBufDecl, dtype)
ABI_FIELD(RadBufDecl, rank)
@@ -317,6 +322,7 @@ ABI_FIELD(RadEncoderDecl, max_patches)
ABI_FIELD(RadEncoderDecl, n_embd)
ABI_FIELD(RadEncoderDecl, out)
ABI_FIELD(RadEncoderDecl, one_grid)
ABI_FIELD(RadEncoderDecl, bidirectional)
ABI_STRUCT(RadEncoding)
ABI_FIELD(RadEncoding, scheme)
ABI_FIELD(RadEncoding, transform)
+7
View File
@@ -886,6 +886,13 @@ typedef struct RadEncoderDecl {
* position tables or kernels are per geometry; the core ends a pass where the grid changes.
* 0 packs segments of any grid into a pass. */
int32_t one_grid;
/* ---- appended in ABI 32 (runs the language model reads both ways) */
/* 1: the language model attends the placeholders of one picture or video frame to each other
* both ways (Gemma 4's use_bidirectional_attention "vision"), text before and after them
* causally. The core then ends no prefill chunk inside such a run and states each trunk pass's
* runs (RadBatch::n_bidi). 0 for an audio encoder. */
int32_t bidirectional;
} RadEncoderDecl;
int rad_declare_encoder(RadBuilder* b, const RadEncoderDecl* d);
+17
View File
@@ -339,6 +339,23 @@ typedef struct RadBatch {
/* ABI 35: host mirror of positions, for a one-sequence prefill op whose exact KV bound is the
* position immediately after its first query piece. Valid through the batch's issue pass. */
const int32_t* positions_h;
/* ---- appended in ABI 35 (runs read both ways) */
/* The runs of a trunk pass whose rows attend to each other both ways
* (RadEncoderDecl::bidirectional): a picture's or a video frame's placeholders inside one
* sequence's chunk. The pass attends them causally like every other row; the plugin attends a
* run's rows again without the causal bound, over the keys before `bidi_used` (the position
* after the run's last token), in place of that result. The scheduler ends no chunk inside such
* a run, so its keys are this pass's or, after a prefix hit, the cache's; a run longer than any
* step is cut where its chunk ends, and that chunk's rows see the run up to the cut.
*
* host: n_bidi and, per run, its first row in this pass, its rows and the index of its sequence
* in the per-sequence arrays; device: [n_bidi] the keys a run's rows see. 0 runs on every other
* pass. */
int64_t n_bidi;
const int32_t* bidi_row; /* host */
const int32_t* bidi_n; /* host */
const int32_t* bidi_seq; /* host */
const int32_t* bidi_used; /* device */
} RadBatch;
/* What a generator pass carries beside the step batch's own fields, which keep their meanings: