Skip to content

Commit 79fe024

Browse files
author
Zhuoming Chen
committed
comments and docs
1 parent c79c8dc commit 79fe024

4 files changed

Lines changed: 114 additions & 72 deletions

File tree

docs/_static/custom.css

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
/* ===========================================================================
2-
Vortex docs theme — light pink-purple background + structured op blocks.
2+
Vortex docs theme — light pink + white background + structured op blocks.
33
=========================================================================== */
44

5-
/* ---- 1. Light pink-purple page background (furo CSS variables) ----------
6-
Set on both ``body`` and the more-specific light selector furo uses, so the
5+
/* ---- 1. Light pink + white page background (furo CSS variables) ---------
6+
Set on both ``body`` and the more-specific light selector furo uses so the
77
override reliably wins in light / auto modes. */
88
body,
99
body:not([data-theme="dark"]) {
10-
--color-background-primary: #fdf7fe; /* main content surface */
11-
--color-background-secondary: #f6ecfb; /* sidebars / secondary surface */
12-
--color-sidebar-background: #f4e9fb;
13-
--color-code-background: #f3e8fb; /* inline / block code */
14-
--color-api-background: #f6ecfb;
10+
--color-background-primary: #fff7fb; /* main content surface (near-white pink) */
11+
--color-background-secondary: #ffeef5; /* sidebars / secondary surface (light pink) */
12+
--color-sidebar-background: #ffe9f1;
13+
--color-code-background: #fdeef4; /* inline / block code */
14+
--color-api-background: #ffeef5;
1515
}
1616

17-
/* Dark mode: keep it readable with a deep plum instead of pink. */
17+
/* Dark mode: a muted rose-tinted dark so text stays legible. */
1818
@media (prefers-color-scheme: dark) {
1919
body:not([data-theme="light"]) {
20-
--color-background-primary: #17111e;
21-
--color-background-secondary: #20172a;
22-
--color-sidebar-background: #20172a;
23-
--color-code-background: #241a30;
24-
--color-api-background: #20172a;
20+
--color-background-primary: #1c151a;
21+
--color-background-secondary: #261b22;
22+
--color-sidebar-background: #261b22;
23+
--color-code-background: #2a1d25;
24+
--color-api-background: #261b22;
2525
}
2626
}
2727
body[data-theme="dark"] {
28-
--color-background-primary: #17111e;
29-
--color-background-secondary: #20172a;
30-
--color-sidebar-background: #20172a;
31-
--color-code-background: #241a30;
32-
--color-api-background: #20172a;
28+
--color-background-primary: #1c151a;
29+
--color-background-secondary: #261b22;
30+
--color-sidebar-background: #261b22;
31+
--color-code-background: #2a1d25;
32+
--color-api-background: #261b22;
3333
}
3434

3535
/* ---- 2. Class / method signatures: compact (not oversized) -------------- */
@@ -42,11 +42,10 @@ dl.py.class .sig-name { font-weight: 700; font-size: 1em; }
4242
dl.py.method > dt.sig { font-size: 0.85em; }
4343
dl.py.method > dt.sig .sig-name { font-weight: 600; }
4444

45-
/* ---- 3. Structured colored blocks for the op field lists ----------------
45+
/* ---- 3. Structured pink-on-white blocks for the op field lists ----------
4646
Each op docstring is a field list (:Math: / :__init__: / :__call__: / :Note:).
47-
Render every field as a stacked block: a colored label "pill" above a
48-
tinted card with a matching accent border. The region order is always
49-
Math, __init__, __call__, Note, so :nth-of-type gives a stable accent. */
47+
Render every field as a stacked block: a pink label "pill" above a white
48+
card with a pink accent border. */
5049
dl.field-list {
5150
display: block;
5251
margin: 0.6rem 0 0.4rem 0;
@@ -58,7 +57,7 @@ dl.field-list > dt { /* the region label (Math / __init__ / …) */
5857
font-size: 0.82em;
5958
letter-spacing: 0.02em;
6059
color: #ffffff;
61-
background: #7c3aed;
60+
background: #db2777; /* pink */
6261
padding: 0.08rem 0.55rem;
6362
border-radius: 0.4rem;
6463
margin: 0.55rem 0 0 0;
@@ -68,19 +67,16 @@ dl.field-list > dd { /* the region body card */
6867
display: block;
6968
margin: 0.2rem 0 0.1rem 0;
7069
padding: 0.4rem 0.75rem;
71-
border-left: 3px solid #7c3aed;
72-
background: rgba(124, 58, 237, 0.07);
70+
border: 1px solid #f6c9dd;
71+
border-left: 3px solid #db2777;
72+
background: #ffffff; /* white card */
7373
border-radius: 0 0.45rem 0.45rem 0;
7474
}
7575
dl.field-list > dd > p { margin: 0; }
7676

77-
/* per-region accents (Math → violet, __init__ → pink, __call__ → indigo,
78-
Note → amber) */
79-
dl.field-list > dt:nth-of-type(1) { background: #7c3aed; }
80-
dl.field-list > dd:nth-of-type(1) { border-left-color: #7c3aed; background: rgba(124, 58, 237, 0.07); }
81-
dl.field-list > dt:nth-of-type(2) { background: #db2777; }
82-
dl.field-list > dd:nth-of-type(2) { border-left-color: #db2777; background: rgba(219, 39, 119, 0.07); }
83-
dl.field-list > dt:nth-of-type(3) { background: #4f46e5; }
84-
dl.field-list > dd:nth-of-type(3) { border-left-color: #4f46e5; background: rgba(79, 70, 229, 0.07); }
85-
dl.field-list > dt:nth-of-type(4) { background: #b45309; }
86-
dl.field-list > dd:nth-of-type(4) { border-left-color: #b45309; background: rgba(180, 83, 9, 0.08); }
77+
/* Subtle alternation in pink shades so adjacent blocks read as separate. */
78+
dl.field-list > dt:nth-of-type(even) { background: #ec4899; }
79+
dl.field-list > dd:nth-of-type(even) { border-left-color: #ec4899; background: #fff6fa; }
80+
81+
/* Display equations inside a Math block sit flush-left, not centered. */
82+
dl.field-list > dd div.math { text-align: left; margin: 0.1rem 0; }

vortex_torch/indexer/matmul.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ class GeMV(vOp):
99
r"""
1010
Per-request batched matrix–vector product, :math:`O = Y X^{\top}`.
1111
12-
:Math: with a batched query :math:`X\in\mathbb{R}^{B\times 1\times D}` and
13-
packed pages :math:`Y\in\mathbb{R}^{S\times 1\times D}`, each page
14-
:math:`s` of request :math:`i` scores as
15-
:math:`O[s]=\langle Y[s],\,X[i]\rangle`, giving
16-
:math:`O\in\mathbb{R}^{S\times 1\times 1}`.
12+
:Math:
13+
Batched query :math:`X\in\mathbb{R}^{B\times 1\times D}`, packed pages
14+
:math:`Y\in\mathbb{R}^{S\times 1\times D}`; for page :math:`s` in
15+
request :math:`i(s)`,
16+
17+
.. math::
18+
19+
O_{s,0,0} = \sum_{d=0}^{D-1} Y_{s,0,d}\,X_{i(s),0,d}
20+
= \langle Y_s,\, X_{i(s)} \rangle,
21+
\qquad O\in\mathbb{R}^{S\times 1\times 1}.
1722
:__init__: ``GeMV()`` — no arguments.
1823
:__call__: ``o = op(x, y, ctx=ctx)`` — ``x`` is ``[B, 1, D]``, ``y`` is
1924
``[S, 1, D]`` (matching ``D``); returns ``o`` ``[S, 1, 1]``. Output is
@@ -77,11 +82,15 @@ class GeMM(vOp):
7782
r"""
7883
Per-page matrix–matrix product, :math:`O[s] = Y[s]\,X[s]^{\top}`.
7984
80-
:Math: with :math:`Y\in\mathbb{R}^{S\times N_y\times K}` and
81-
:math:`X\in\mathbb{R}^{(B\,\text{or}\,S)\times N_x\times K}`, per page
82-
:math:`s`:
83-
:math:`O[s]=Y[s]\,X[s]^{\top}\in\mathbb{R}^{N_y\times N_x}` — i.e.
84-
``GeMM(x, y) = y xᵀ``. Output :math:`O\in\mathbb{R}^{S\times N_y\times N_x}`.
85+
:Math:
86+
:math:`Y\in\mathbb{R}^{S\times N_y\times K}`,
87+
:math:`X\in\mathbb{R}^{(B\text{ or }S)\times N_x\times K}`; per page
88+
:math:`s` this is :math:`O_s = Y_s X_s^{\top}` (i.e. ``GeMM(x, y) = y xᵀ``):
89+
90+
.. math::
91+
92+
O_{s,a,b} = \sum_{k=0}^{K-1} Y_{s,a,k}\,X_{s,b,k},
93+
\qquad O\in\mathbb{R}^{S\times N_y\times N_x}.
8594
:__init__: ``GeMM()`` — no arguments.
8695
:__call__: ``o = op(x, y, ctx=ctx)`` — ``x`` is ``[B|S, N_x, K]``, ``y`` is
8796
``[S, N_y, K]`` (matching ``K``); returns ``o`` ``[S, N_y, N_x]``.

vortex_torch/indexer/output_func.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ class topK(vOp):
1111
The terminal op of a ``forward_indexer``: it turns per-page scores into the
1212
sparse set of pages each request attends to.
1313
14-
:Math: for each request's packed score segment
15-
:math:`X\in\mathbb{R}^{S\times 1\times 1}`, the selected page set is the
16-
first ``block_reserved_bos`` pages, the last ``block_reserved_eos``
17-
pages, and the ``topk_val`` highest-scoring of the remaining pages.
14+
:Math:
15+
For a request's per-page scores :math:`X_p` (:math:`p=0,\dots,S-1`),
16+
with reserved prefix :math:`\mathcal{B}=\{0,\dots,n_{\mathrm{bos}}-1\}`
17+
and suffix :math:`\mathcal{E}=\{S-n_{\mathrm{eos}},\dots,S-1\}`, the
18+
selected page set is
19+
20+
.. math::
21+
22+
\mathcal{S} = \mathcal{B}\,\cup\,\mathcal{E}\,\cup\,
23+
\operatorname*{top\text{-}k}_{\,p\,\notin\,\mathcal{B}\cup\mathcal{E}} X_p,
24+
\qquad k = \texttt{topk\_val}.
1825
:__init__: ``topK()`` — no arguments; the budget ``topk_val`` and the
1926
reserved BOS/EOS counts are read from :class:`Context` at runtime.
2027
:__call__: ``op(score, o, ctx=ctx)`` — ``score`` is ``[S, 1, 1]`` (one
@@ -84,11 +91,17 @@ class approxTopK(topK):
8491
r"""
8592
Approximate :class:`topK` — faster adaptive 8-bit radix selection.
8693
87-
:Math: same selection as :class:`topK` (reserved BOS/EOS pages +
88-
``topk_val`` by score), but the top-``topk_val`` set is found with an
89-
adaptive 8-bit radix kernel that stops early once the slots still owed
90-
by the threshold bin fall within ``tolerate_ratio`` of the target,
91-
filling any remainder in arrival order.
94+
:Math:
95+
The selected set :math:`\mathcal{S}` matches :class:`topK`, but the
96+
top-:math:`k` search over the non-reserved pages stops at the first
97+
radix round whose count :math:`r` still owed by the threshold bin
98+
satisfies
99+
100+
.. math::
101+
102+
r \;\le\; \texttt{tolerate\_ratio}\cdot k,
103+
104+
with any remaining slots filled in arrival order.
92105
:__init__: ``approxTopK(tolerate_ratio=0.0)`` — approximation budget in
93106
``[0, 1]``: ``0.0`` = exact (all radix rounds run), higher = cheaper
94107
but looser (typical throughput sweet spot ``0.05–0.15``).

vortex_torch/indexer/reduce.py

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ class Reduce(vOp):
1010
1111
:Math:
1212
For input :math:`X\in\mathbb{R}^{N\times D_0\times D_1}` and a
13-
reduction :math:`\rho` (mean / max / min / L2-norm / sum, fixed by the
14-
subclass): ``dim=1`` →
15-
:math:`\text{out}[n,0,d_1]=\rho_{d_0}\,X[n,d_0,d_1]` (shape
16-
``[N, 1, D_1]``); ``dim=2`` →
17-
:math:`\text{out}[n,d_0,0]=\rho_{d_1}\,X[n,d_0,d_1]` (shape
18-
``[N, D_0, 1]``); ``dim=0`` collapses the packed leading axis to one
19-
row per ``(batch, kv_head)``.
13+
per-axis reduction :math:`\rho` (mean / max / min / L2-norm / sum,
14+
fixed by the subclass):
15+
16+
.. math::
17+
18+
Y_{n,0,d} = \rho_{\,0 \le i < D_0}\, X_{n,i,d}\ \ (\text{dim}=1),
19+
\qquad
20+
Y_{n,d,0} = \rho_{\,0 \le j < D_1}\, X_{n,d,j}\ \ (\text{dim}=2).
21+
22+
``dim=0`` collapses the packed leading axis to one row per
23+
``(batch, kv\_head)``.
2024
:__init__:
2125
``Reduce(dim=1)`` — logical axis to reduce, one of ``0`` / ``1`` / ``2``.
2226
:__call__:
@@ -101,8 +105,12 @@ class Max(Reduce):
101105
r"""
102106
Max reduction over one logical axis (a :class:`Reduce`).
103107
104-
:Math: ``dim=1``: :math:`\text{out}[n,0,d_1]=\max_{d_0}X[n,d_0,d_1]`;
105-
``dim=2``: :math:`\text{out}[n,d_0,0]=\max_{d_1}X[n,d_0,d_1]`.
108+
:Math:
109+
.. math::
110+
111+
Y_{n,0,d} = \max_{0 \le i < D_0} X_{n,i,d}\ \ (\text{dim}=1),
112+
\qquad
113+
Y_{n,d,0} = \max_{0 \le j < D_1} X_{n,d,j}\ \ (\text{dim}=2).
106114
:__init__: ``Max(dim=1)`` — axis to reduce (``1`` → :math:`D_0`,
107115
``2`` → :math:`D_1`).
108116
:__call__: ``y = op(x, ctx=ctx)`` — ``[N, D_0, D_1]`` → ``[N, 1, D_1]``
@@ -117,8 +125,12 @@ class Min(Reduce):
117125
r"""
118126
Min reduction over one logical axis (a :class:`Reduce`).
119127
120-
:Math: ``dim=1``: :math:`\text{out}[n,0,d_1]=\min_{d_0}X[n,d_0,d_1]`;
121-
``dim=2``: :math:`\text{out}[n,d_0,0]=\min_{d_1}X[n,d_0,d_1]`.
128+
:Math:
129+
.. math::
130+
131+
Y_{n,0,d} = \min_{0 \le i < D_0} X_{n,i,d}\ \ (\text{dim}=1),
132+
\qquad
133+
Y_{n,d,0} = \min_{0 \le j < D_1} X_{n,d,j}\ \ (\text{dim}=2).
122134
:__init__: ``Min(dim=1)`` — axis to reduce (``1`` → :math:`D_0`,
123135
``2`` → :math:`D_1`).
124136
:__call__: ``y = op(x, ctx=ctx)`` — ``[N, D_0, D_1]`` → ``[N, 1, D_1]``
@@ -133,8 +145,12 @@ class Mean(Reduce):
133145
r"""
134146
Mean reduction over one logical axis (a :class:`Reduce`).
135147
136-
:Math: ``dim=1``: :math:`\text{out}[n,0,d_1]=\frac{1}{D_0}\sum_{d_0}X[n,d_0,d_1]`;
137-
``dim=2``: :math:`\text{out}[n,d_0,0]=\frac{1}{D_1}\sum_{d_1}X[n,d_0,d_1]`.
148+
:Math:
149+
.. math::
150+
151+
Y_{n,0,d} = \frac{1}{D_0}\sum_{i=0}^{D_0-1} X_{n,i,d}\ \ (\text{dim}=1),
152+
\qquad
153+
Y_{n,d,0} = \frac{1}{D_1}\sum_{j=0}^{D_1-1} X_{n,d,j}\ \ (\text{dim}=2).
138154
:__init__: ``Mean(dim=1)`` — axis to reduce (``1`` → :math:`D_0`,
139155
``2`` → :math:`D_1`).
140156
:__call__: ``y = op(x, ctx=ctx)`` — ``[N, D_0, D_1]`` → ``[N, 1, D_1]``
@@ -149,8 +165,12 @@ class L2Norm(Reduce):
149165
r"""
150166
L2-norm reduction over one logical axis (a :class:`Reduce`).
151167
152-
:Math: ``dim=1``: :math:`\text{out}[n,0,d_1]=\sqrt{\sum_{d_0}X[n,d_0,d_1]^2}`;
153-
``dim=2``: :math:`\text{out}[n,d_0,0]=\sqrt{\sum_{d_1}X[n,d_0,d_1]^2}`.
168+
:Math:
169+
.. math::
170+
171+
Y_{n,0,d} = \Big(\sum_{i=0}^{D_0-1} X_{n,i,d}^2\Big)^{1/2}\ \ (\text{dim}=1),
172+
\qquad
173+
Y_{n,d,0} = \Big(\sum_{j=0}^{D_1-1} X_{n,d,j}^2\Big)^{1/2}\ \ (\text{dim}=2).
154174
:__init__: ``L2Norm(dim=1)`` — axis to reduce (``1`` → :math:`D_0`,
155175
``2`` → :math:`D_1`).
156176
:__call__: ``y = op(x, ctx=ctx)`` — ``[N, D_0, D_1]`` → ``[N, 1, D_1]``
@@ -165,8 +185,12 @@ class Sum(Reduce):
165185
r"""
166186
Sum reduction over one logical axis (a :class:`Reduce`).
167187
168-
:Math: ``dim=1``: :math:`\text{out}[n,0,d_1]=\sum_{d_0}X[n,d_0,d_1]`;
169-
``dim=2``: :math:`\text{out}[n,d_0,0]=\sum_{d_1}X[n,d_0,d_1]`.
188+
:Math:
189+
.. math::
190+
191+
Y_{n,0,d} = \sum_{i=0}^{D_0-1} X_{n,i,d}\ \ (\text{dim}=1),
192+
\qquad
193+
Y_{n,d,0} = \sum_{j=0}^{D_1-1} X_{n,d,j}\ \ (\text{dim}=2).
170194
:__init__: ``Sum(dim=1)`` — axis to reduce (``1`` → :math:`D_0`,
171195
``2`` → :math:`D_1`).
172196
:__call__: ``y = op(x, ctx=ctx)`` — ``[N, D_0, D_1]`` → ``[N, 1, D_1]``

0 commit comments

Comments
 (0)