mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-04 15:28:40 +00:00
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
repository paths inside tests.
engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.
No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
46 lines
2.8 KiB
C++
46 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
namespace strata::program {
|
|
|
|
// --serve: is the live conversation's tail past `resume` only the reply this prompt replaces?
|
|
//
|
|
// A request that resumes from a checkpoint (not from the live session) parks the live branch first, so a later request
|
|
// can come back to it. When the checkpoint is the live branch's own turn checkpoint - the history before its last
|
|
// assistant turn - and the prompt opens an assistant turn at that same place again, the client has re-sent the history
|
|
// with that reply dropped, edited or about to be regenerated (an OpenAI-style client sends every earlier reply back
|
|
// without its reasoning, so this is every next turn of such a client). The branch it leaves holds nothing but that one
|
|
// reply, which no request of the same client sends back as it was: parking it copies the whole conversation to host
|
|
// memory on the request's path (~130-290 ms on an R9700) for a copy that only ever gets dropped as superseded.
|
|
//
|
|
// True when all of these hold:
|
|
// - `live` continues past `resume` (live[resume] exists) with a turn opening there (live[resume] == turn_token) and
|
|
// no other turn after it: what follows is one assistant turn, its header and the reply generated after it;
|
|
// - the prompt opens a turn at the same place with the same role token (ids[resume] == turn_token,
|
|
// ids[resume + 1] == live[resume + 1]): the same assistant turn, re-sent or opened again;
|
|
// - live and the prompt agree on [0, resume) (the caller resumes from a checkpoint of exactly those tokens; checked
|
|
// here again so the rule stands alone).
|
|
// - the live branch has no picture at or past `resume` (`live_pictures`: where each of its pictures starts): a branch
|
|
// whose tail holds a picture is parked as before (a chat request's reply holds none, so this is a guard).
|
|
template<class LiveTok, class PromptTok>
|
|
bool live_tail_is_replaced_reply(const std::vector<LiveTok>& live, const std::vector<PromptTok>& ids, int64_t resume,
|
|
int64_t turn_token, const std::vector<int64_t>& live_pictures = {}) {
|
|
if (turn_token < 0 || resume < 1) return false;
|
|
for (const int64_t at : live_pictures)
|
|
if (at >= resume) return false;
|
|
const auto r = static_cast<std::size_t>(resume);
|
|
if (live.size() < r + 2 || ids.size() < r + 2) return false;
|
|
if (static_cast<int64_t>(live[r]) != turn_token || static_cast<int64_t>(ids[r]) != turn_token) return false;
|
|
if (static_cast<int64_t>(live[r + 1]) != static_cast<int64_t>(ids[r + 1])) return false;
|
|
for (std::size_t i = r + 1; i < live.size(); ++i)
|
|
if (static_cast<int64_t>(live[i]) == turn_token) return false;
|
|
for (std::size_t i = 0; i < r; ++i)
|
|
if (static_cast<int64_t>(live[i]) != static_cast<int64_t>(ids[i])) return false;
|
|
return true;
|
|
}
|
|
|
|
} // namespace strata::program
|