Standalone LaTeX/TikZ skill for non-tensor paper figures: node/edge macros, lint-on-warning build, golden examples, and negative fixtures.
47 lines
1.6 KiB
TeX
47 lines
1.6 KiB
TeX
% superfig golden example 3 -- a state/time flow.
|
|
% One decode step: previous KV plus a new token produce the next state
|
|
% and the emitted token. The callout is an aside on the finished state band.
|
|
% ../scripts/build.sh state-flow.tex
|
|
\documentclass[border=10pt]{standalone}
|
|
\usepackage[cjk]{superfig}
|
|
|
|
\sfsetrole{state}{sfTeal}
|
|
\sfsetrole{step}{sfOrange}
|
|
\sfsetrole{tok}{sfViolet}
|
|
|
|
\begin{document}
|
|
\begin{tikzpicture}
|
|
|
|
\sfstage{S}{解码一步:旧状态 + 新 token}
|
|
\sfvgap{26mm}
|
|
\sfrow{R1}{14mm}
|
|
\sfnode[role=state]{kv}{KV$_t$}{16mm}{11mm}
|
|
\sfconn{c1}{读}
|
|
\sfnode[role=step]{dec}{解码}{16mm}{11mm}
|
|
\sfconn{c2}{追加}
|
|
\sfnode[role=state]{kv2}{KV$_{t+1}$}{18mm}{11mm}
|
|
\sfrowend
|
|
\sflane{R1}
|
|
\sfcaption{kv}{KV$_t$}{已缓存键值}
|
|
\sfcaption{dec}{一步}{读 KV,写新列}
|
|
\sfcaption{kv2}{KV$_{t+1}$}{状态推进}
|
|
\sfcallout{N1}{38mm}{R1}{为何保留 KV}{%
|
|
下一步只读已有列、只追加 $x_t$ 这一列。重算前缀是另一条路径,这张图不画。}
|
|
|
|
% Tokens enter from above so the caption lane below the state row stays clear.
|
|
\sfnode[role=tok, at={($(dec.north west)+(-4mm,14mm)$)}]{xt}{$x_t$}{14mm}{10mm}
|
|
\sfnode[role=tok, at={($(dec.north east)+(4mm,14mm)$)}]{yt}{$y_t$}{14mm}{10mm}
|
|
\sfarrow{xt.south}{dec.north}
|
|
\sfarrow{dec.north}{yt.south}
|
|
|
|
\sfbbox{all}
|
|
\sftopformula{F}{%
|
|
$(\mathrm{KV}_{t+1},\, y_t) = \mathrm{Decode}(\mathrm{KV}_t,\, x_t)$}
|
|
\sfmeaningbox{mb}{108mm}{all}
|
|
{自回归一步:状态沿时间推进}
|
|
{缓存 KV、解码算子、本步 token}
|
|
{解码读 $\mathrm{KV}_t$ 与 $x_t$,写出 $y_t$,并把新列追加为 $\mathrm{KV}_{t+1}$}
|
|
|
|
\end{tikzpicture}
|
|
\end{document}
|