Archived
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:
1 parent
81be3cb63d
commit
da7b911c64
10 files changed
+246
-12
No files matched your search
@@ -7085,6 +7085,121 @@ TEST(media_rows_are_staged_by_chunk_at_the_tokens_that_take_them) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================== runs read both ways */
|
||||
/* A picture whose placeholders the model reads both ways (RadEncoderDecl::bidirectional) is never
|
||||
* cut by a chunk: the chunk ends before it on the quantum (64 here, the linear group's chunk), or,
|
||||
* starting at it, runs past its end, and the pass names the run's rows and the keys they see
|
||||
* (RadBatch::n_bidi). Tokens 200..299 here; without the flag the first chunk would end at the
|
||||
* checkpoint interval (256), inside the picture. A run longer than any step is cut where its chunk
|
||||
* falls, and its rows then see the run up to the cut. An audio clip is read causally and cut
|
||||
* anywhere. */
|
||||
namespace {
|
||||
|
||||
std::unique_ptr<Request> with_run(Fixture& f, int n_prompt, int tok, int n, mm::Kind kind) {
|
||||
auto item = std::make_shared<mm::Item>();
|
||||
item->kind = kind;
|
||||
item->n_seg = 1;
|
||||
item->seg_rows = n;
|
||||
item->encoded = true;
|
||||
item->embd.assign((size_t)n * 4, 0);
|
||||
auto req = f.request(n_prompt, 4);
|
||||
req->media = std::make_shared<mm::PromptMedia>();
|
||||
req->media->items.push_back(mm::Placed{ item, tok - 1 });
|
||||
mm::RopeLayout::Run run;
|
||||
run.tok = tok; run.n = n; run.w = n; run.base = tok; run.shift = 0; run.item = 0; run.flat = true;
|
||||
req->media->rope.runs.push_back(run);
|
||||
return req;
|
||||
}
|
||||
|
||||
void media_fixture(Fixture& f, int64_t max_tok, int32_t bidi) {
|
||||
f.build(/*blocks=*/4096, /*states=*/64, max_tok);
|
||||
f.prog.encoder.modalities = RAD_MM_IMAGE;
|
||||
f.prog.encoder.n_embd = 4;
|
||||
f.prog.encoder.patch_dim = 4;
|
||||
f.prog.encoder.merge = 1;
|
||||
f.prog.encoder.max_patches = 1024;
|
||||
f.prog.encoder.bidirectional = bidi;
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
TEST(a_run_read_both_ways_is_never_cut_by_a_chunk) {
|
||||
Fixture f;
|
||||
media_fixture(f, 256, 1);
|
||||
CHECK_OK(f.start());
|
||||
f.add(with_run(f, 400, 200, 100, mm::Kind::Image));
|
||||
const RadBatch* b = f.sch.step();
|
||||
REQUIRE(b != nullptr);
|
||||
CHECK_EQ(b->n_tok, (int64_t)192);
|
||||
CHECK_EQ(b->n_bidi, (int64_t)0);
|
||||
f.commit_plain();
|
||||
b = f.sch.step();
|
||||
REQUIRE(b != nullptr);
|
||||
CHECK_EQ(b->n_tok, (int64_t)128); /* 192 .. 319, past the run's end */
|
||||
REQUIRE_EQ(b->n_bidi, (int64_t)1);
|
||||
CHECK_EQ(b->bidi_row[0], 8);
|
||||
CHECK_EQ(b->bidi_n[0], 100);
|
||||
CHECK_EQ(b->bidi_seq[0], 0);
|
||||
CHECK_EQ(b->bidi_used[0], 300);
|
||||
CHECK_EQ(b->n_mm_rows, (int64_t)100);
|
||||
f.commit_plain();
|
||||
b = f.sch.step();
|
||||
REQUIRE(b != nullptr);
|
||||
CHECK_EQ(b->n_tok, (int64_t)64); /* to the tail checkpoint, text only */
|
||||
CHECK_EQ(b->n_bidi, (int64_t)0);
|
||||
|
||||
/* bidi_fit itself: inside the run, from before it, from its start, and with too small a
|
||||
* budget (wait) or a run no step holds (cut as it falls). */
|
||||
auto r = with_run(f, 400, 200, 100, mm::Kind::Image);
|
||||
CHECK_EQ(f.sch.bidi_fit(*r, 0, 400, 256, 256), 192);
|
||||
CHECK_EQ(f.sch.bidi_fit(*r, 0, 400, 192, 256), 192);
|
||||
CHECK_EQ(f.sch.bidi_fit(*r, 192, 400, 64, 256), 128);
|
||||
CHECK_EQ(f.sch.bidi_fit(*r, 192, 400, 64, 100), 0);
|
||||
CHECK_EQ(f.sch.bidi_fit(*r, 0, 250, 250, 256), 250); /* the sequence ends inside it */
|
||||
auto big = with_run(f, 800, 200, 400, mm::Kind::Image);
|
||||
CHECK_EQ(f.sch.bidi_fit(*big, 192, 800, 64, 256), 64);
|
||||
/* Two video frames, <eoi><boi> apart: back past both, or on past both. */
|
||||
auto vid = with_run(f, 400, 100, 70, mm::Kind::Video);
|
||||
mm::RopeLayout::Run second = vid->media->rope.runs[0];
|
||||
second.tok = 172;
|
||||
vid->media->rope.runs.push_back(second);
|
||||
CHECK_EQ(f.sch.bidi_fit(*vid, 0, 400, 200, 256), 64);
|
||||
CHECK_EQ(f.sch.bidi_fit(*vid, 64, 400, 64, 256), 192);
|
||||
CHECK_EQ(f.sch.bidi_fit(*vid, 64, 400, 64, 128), 0);
|
||||
}
|
||||
|
||||
TEST(a_run_longer_than_a_step_is_cut_and_reads_up_to_the_cut) {
|
||||
Fixture f;
|
||||
media_fixture(f, 256, 1);
|
||||
CHECK_OK(f.start());
|
||||
f.add(with_run(f, 800, 200, 400, mm::Kind::Image));
|
||||
const RadBatch* b = f.sch.step();
|
||||
REQUIRE(b != nullptr);
|
||||
CHECK_EQ(b->n_tok, (int64_t)192);
|
||||
f.commit_plain();
|
||||
b = f.sch.step();
|
||||
REQUIRE(b != nullptr);
|
||||
CHECK_EQ(b->n_tok, (int64_t)64);
|
||||
REQUIRE_EQ(b->n_bidi, (int64_t)1);
|
||||
CHECK_EQ(b->bidi_row[0], 8);
|
||||
CHECK_EQ(b->bidi_n[0], 56);
|
||||
CHECK_EQ(b->bidi_used[0], 256);
|
||||
}
|
||||
|
||||
TEST(runs_are_cut_anywhere_without_the_flag_and_for_audio) {
|
||||
for (int k = 0; k < 2; ++k) {
|
||||
Fixture f;
|
||||
media_fixture(f, 256, k == 0 ? 0 : 1);
|
||||
CHECK_OK(f.start());
|
||||
f.add(with_run(f, 400, 200, 100, k == 0 ? mm::Kind::Image : mm::Kind::Audio));
|
||||
const RadBatch* b = f.sch.step();
|
||||
REQUIRE(b != nullptr);
|
||||
CHECK_EQ(b->n_tok, (int64_t)256);
|
||||
CHECK_EQ(b->n_bidi, (int64_t)0);
|
||||
CHECK_EQ(b->n_mm_rows, (int64_t)56);
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================== scored rows (KL mode) */
|
||||
/* In KL mode a scored prompt names a logits row at every position it prefills, after the
|
||||
* sampler's rows and in entry order, which is the order Engine::score_rows maps back. A row
|
||||
|
||||
Reference in new issue
Block a user