Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

feat(server): serve TopK-Embed-V1 multi-vector models (0.8B and 2B) (#417)

Filip Makraduli36c612915a4c
diff --git a/README.md b/README.md
index db9c6bc27..95cf77b2e 100644
--- a/README.md
+++ b/README.md
@@ -69,7 +69,7 @@ docker run --gpus all -p 8080:8080 \
-v sie-hf-cache:/app/.cache/huggingface \
ghcr.io/superlinked/sie-server:latest-cuda12-default
-# Linux, NVIDIA GPU: Transformers 5 models (LightOnOCR, GLM-OCR, and the GLiNER2.5-Decide models)
+# Linux, NVIDIA GPU: Transformers 5 models (LightOnOCR, GLM-OCR, GLiNER2.5-Decide, and TopK-Embed-V1)
docker run --gpus all -p 8080:8080 \
-v sie-hf-cache:/app/.cache/huggingface \
ghcr.io/superlinked/sie-server:latest-cuda12-transformers5
@@ -87,8 +87,8 @@ docker run -p 8080:8080 \
Docker images are bundle-specific so dependency-incompatible model families stay isolated. Use the
`sglang-vision-extract` image for LightOnOCR, GLM-OCR, and PaddleOCR-VL, or the `transformers5` image for the
-`:transformers` profiles of LightOnOCR and GLM-OCR and for the GLiNER2.5-Decide models; the `default` image
-intentionally does not advertise them.
+`:transformers` profiles of LightOnOCR and GLM-OCR, the GLiNER2.5-Decide models, and the TopK-Embed-V1 models; the
+`default` image intentionally does not advertise them.
```bash
# in a second terminal
diff --git a/deploy/helm/sie-cluster/templates/_otel-collector-config.tpl b/deploy/helm/sie-cluster/templates/_otel-collector-config.tpl
index d513ef6f9..a08b69a92 100644
--- a/deploy/helm/sie-cluster/templates/_otel-collector-config.tpl
+++ b/deploy/helm/sie-cluster/templates/_otel-collector-config.tpl
@@ -586,7 +586,7 @@ processors:
- set(attributes["admission_outcome"], cache["admission_outcome"]) where cache["admission_outcome"] != nil
# Canonical release domains are rechecked at the collector boundary
# so malformed producer values cannot become vendor dimensions.
- - 'set(attributes["model"], "other") where attributes["event.schema.version"] == "2" and not IsMatch(attributes["model"], "^(BAAI/bge-m3|IDEA-Research/grounding-dino-base|Qwen/Qwen3-Embedding-4B|Qwen/Qwen3-Reranker-0[.]6B|Qwen/Qwen3-Reranker-4B|Qwen/Qwen3-VL-Reranker-2B|Qwen/Qwen3[.]5-4B|Qwen/Qwen3[.]6-27B|Snowflake/snowflake-arctic-embed-l-v2[.]0|docling|fastino/gliguard-LLMGuardrails-300M|fastino/gliner2-base-v1|fastino/gliner2-large-v1|google/owlv2-base-patch16-ensemble|google/siglip-so400m-patch14-384|google/siglip2-base-patch16-224|ibm-granite/granite-guardian-3[.]0-2b|knowledgator/gliclass-large-v3[.]0|lightonai/GTE-ModernColBERT-v1|lightonai/LightOnOCR-2-1B|numind/NuNER_Zero|openai/whisper-large-v3-turbo|other|prithivida/Splade_PP_en_v2|tencent/R3-embedding-0[.]6b|tencent/R3-rerank-0[.]6b|urchade/gliner_multi-v2[.]1|urchade/gliner_multi_pii-v1)$")'
+ - 'set(attributes["model"], "other") where attributes["event.schema.version"] == "2" and not IsMatch(attributes["model"], "^(BAAI/bge-m3|IDEA-Research/grounding-dino-base|Qwen/Qwen3-Embedding-4B|Qwen/Qwen3-Reranker-0[.]6B|Qwen/Qwen3-Reranker-4B|Qwen/Qwen3-VL-Reranker-2B|Qwen/Qwen3[.]5-4B|Qwen/Qwen3[.]6-27B|Snowflake/snowflake-arctic-embed-l-v2[.]0|docling|fastino/gliguard-LLMGuardrails-300M|fastino/gliner2-base-v1|fastino/gliner2-large-v1|google/owlv2-base-patch16-ensemble|google/siglip-so400m-patch14-384|google/siglip2-base-patch16-224|ibm-granite/granite-guardian-3[.]0-2b|knowledgator/gliclass-large-v3[.]0|lightonai/GTE-ModernColBERT-v1|lightonai/LightOnOCR-2-1B|numind/NuNER_Zero|openai/whisper-large-v3-turbo|other|prithivida/Splade_PP_en_v2|tencent/R3-embedding-0[.]6b|tencent/R3-rerank-0[.]6b|topk-io/topk-embed-v1-small|topk-io/topk-embed-v1-xsmall|urchade/gliner_multi-v2[.]1|urchade/gliner_multi_pii-v1)$")'
- 'set(attributes["machine_profile"], "other") where attributes["event.schema.version"] == "2" and not IsMatch(attributes["machine_profile"], "^(a10|a100-40gb|a100-80gb|cpu|h100|l4|l4-spot|other|sglang-cu130|t4)$")'
- set(attributes["event.name"], "inference.request.completed")
- set(body, "inference.request.completed")
diff --git a/packages/sie_server/README.md b/packages/sie_server/README.md
index 5fb18f50e..bd302c7b8 100644
--- a/packages/sie_server/README.md
+++ b/packages/sie_server/README.md
@@ -26,11 +26,11 @@ pip install sie-server
pip install sie-server "transformers<5"
```
-- **Transformers 5 bundle** (LightOnOCR, GLM-OCR, GLiGuard, and the GLiNER2.5-Decide models) — requires
- `transformers` 5.x, and is served with `-b transformers5`. The GLiNER2.5-Decide models also need `gliner2`
- 2.x. `sie-server` itself asks for `gliner2<2`, which the default bundle's GLiNER2 models need, so pip
- reports that conflict when the second command below installs 2.x; the transformers5 bundle's GLiNER2
- models are verified on 2.0.0:
+- **Transformers 5 bundle** (LightOnOCR, GLM-OCR, GLiGuard, the GLiNER2.5-Decide models, and the TopK-Embed-V1
+ multi-vector models) — requires `transformers` 5.x, and is served with `-b transformers5`. The GLiNER2.5-Decide
+ models also need `gliner2` 2.x. `sie-server` itself asks for `gliner2<2`, which the default bundle's GLiNER2
+ models need, so pip reports that conflict when the second command below installs 2.x; the transformers5
+ bundle's GLiNER2 models are verified on 2.0.0:
```bash
pip install sie-server "transformers>=5,<6"
diff --git a/packages/sie_server/bundles/transformers5.yaml b/packages/sie_server/bundles/transformers5.yaml
index 640340965..eabd27b5c 100644
--- a/packages/sie_server/bundles/transformers5.yaml
+++ b/packages/sie_server/bundles/transformers5.yaml
@@ -9,6 +9,8 @@ adapters:
- sie_server.adapters.gliner2.classification
- sie_server.adapters.gliner2.decide
- sie_server.adapters.st_sparse_vision.adapter
+# TopK-Embed-V1 multi-vector text + page-image models (Qwen3.5 backbone, transformers>=5.2).
+- sie_server.adapters.topk_embed.adapter
deps:
# Transformers 5.x for models requiring newer architecture support
# (e.g., LightOnOCR-2-1B needs LightOnOcrForConditionalGeneration,
@@ -38,3 +40,17 @@ deps:
# 2.0 declares transformers<5 only for its `local` extra, which is not used;
# the multilingual and 1B Decide checkpoints were saved with transformers 5.
gliner2: '==2.0.0'
+ # TopK-Embed-V1 packed path (adapters/topk_embed/packed.py): the Gated
+ # DeltaNet chunked delta rule and causal conv (flash-linear-attention's
+ # Triton kernels) and FlashAttention's varlen attention. CUDA only; without
+ # them the adapter runs every input as its own padded row. fla-core, not the
+ # flash-linear-attention meta-package, which registers extra AutoConfig
+ # model types on import. Its only base dependency is einops; torch and
+ # triton come from the shared venv.
+ fla-core:
+ version: '==0.5.2'
+ marker: sys_platform == 'linux'
+ # The prebuilt wheel the default bundle uses (torch 2.9, CUDA 12.9, cp312).
+ flash-attn:
+ url: https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.7.11/flash_attn-2.7.4+cu129torch2.9-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
+ marker: sys_platform == 'linux'
diff --git a/packages/sie_server/models/topk-io__topk-embed-v1-small.yaml b/packages/sie_server/models/topk-io__topk-embed-v1-small.yaml
new file mode 100644
index 000000000..58675296e
--- /dev/null
+++ b/packages/sie_server/models/topk-io__topk-embed-v1-small.yaml
@@ -0,0 +1,56 @@
+sie_id: topk-io/topk-embed-v1-small
+hf_id: topk-io/topk-embed-v1-small
+hf_revision: 33b15d544d74f29d04cdb97adeb9fd0e52da5fb7
+inputs:
+ # Text queries; text or page-image documents (one image per document).
+ text: true
+ image: true
+ audio: false
+ video: false
+tasks:
+ encode:
+ dense: null
+ sparse: null
+ multivector:
+ dim: 2048
+ score: null
+ extract: null
+# Document cap. The checkpoint allows 8192 tokens (sentence_bert_config.json
+# document_length), but on the cluster path one item's result must serialize
+# under 16 MiB (sidecar MAX_CHUNKED_RESULT_BYTES, gateway per-item limit): at
+# 2048 float16 numbers a token that is 4096 tokens, so 4000 keeps each document
+# at 15.6 MiB with room for the envelope. float32 responses take twice as much.
+# The adapter caps queries at query_length (1024) and each image at 1280 merged
+# patches (5 MiB).
+max_sequence_length: 4000
+profiles:
+ default:
+ max_batch_tokens: 8192
+ compute_precision: bfloat16
+ adapter_path: sie_server.adapters.topk_embed.adapter:TopkEmbedAdapter
+ adapter_options:
+ loadtime:
+ # CUDA graphs for small text batches (queries) on the packed CUDA path;
+ # anything else runs eagerly. See adapters/topk_embed/graphs.py.
+ cuda_graphs: bucketed
+ text_batch_tokens: 8192
+ muvera_config:
+ num_repetitions: 40
+ num_simhash_projections: 6
+ projection_dim: null
+ final_projection_dim: 10240
+ runtime:
+ normalize: true
+ # The model computes in bf16, so float16 loses nothing and halves the
+ # payload (a page is ~1230 token vectors). Clients can ask for float32.
+ output_dtype: float16
+ muvera:
+ extends: default
+ adapter_options:
+ runtime:
+ normalize: true
+ output_types:
+ - dense
+ output_similarity:
+ dense: dot
+ muvera: {}
diff --git a/packages/sie_server/models/topk-io__topk-embed-v1-xsmall.yaml b/packages/sie_server/models/topk-io__topk-embed-v1-xsmall.yaml
new file mode 100644
index 000000000..1872dfa66
--- /dev/null
+++ b/packages/sie_server/models/topk-io__topk-embed-v1-xsmall.yaml
@@ -0,0 +1,58 @@
+sie_id: topk-io/topk-embed-v1-xsmall
+hf_id: topk-io/topk-embed-v1-xsmall
+hf_revision: d09d8a7a8cdd6c287f792b3c4d7b41233d46e66a
+inputs:
+ # Text queries; text or page-image documents (one image per document).
+ text: true
+ image: true
+ audio: false
+ video: false
+tasks:
+ encode:
+ dense: null
+ sparse: null
+ multivector:
+ dim: 1024
+ score: null
+ extract: null
+# Document cap. The checkpoint allows 8192 tokens (sentence_bert_config.json
+# document_length), but on the cluster path one item's result must serialize
+# under 16 MiB (sidecar MAX_CHUNKED_RESULT_BYTES, gateway per-item limit): at
+# 1024 float16 numbers a token that is 8192 tokens before the envelope, so 8000
+# keeps each document at 15.6 MiB. float32 responses take twice as much. The
+# adapter caps queries at query_length (1024) and each image at 1280 merged
+# patches (2.5 MiB).
+max_sequence_length: 8000
+profiles:
+ default:
+ max_batch_tokens: 16384
+ compute_precision: bfloat16
+ adapter_path: sie_server.adapters.topk_embed.adapter:TopkEmbedAdapter
+ adapter_options:
+ loadtime:
+ # CUDA graphs for small text batches (queries) on the packed CUDA path;
+ # anything else runs eagerly. See adapters/topk_embed/graphs.py.
+ cuda_graphs: bucketed
+ # Tokens per packed forward: 8192 beat 16384 and 32768 by 5 to 17% on an
+ # L40S at every document length (the server's batches still take 16384).
+ text_batch_tokens: 8192
+ muvera_config:
+ num_repetitions: 40
+ num_simhash_projections: 6
+ projection_dim: null
+ final_projection_dim: 10240
+ runtime:
+ normalize: true
+ # The model computes in bf16, so float16 loses nothing and halves the
+ # payload (a page is ~1230 token vectors). Clients can ask for float32.
+ output_dtype: float16
+ muvera:
+ extends: default
+ adapter_options:
+ runtime:
+ normalize: true
+ output_types:
+ - dense
+ output_similarity:
+ dense: dot
+ muvera: {}
diff --git a/packages/sie_server/scripts/generate_topk_embed_goldens.py b/packages/sie_server/scripts/generate_topk_embed_goldens.py
new file mode 100644
index 000000000..a0b681353
--- /dev/null
+++ b/packages/sie_server/scripts/generate_topk_embed_goldens.py
@@ -0,0 +1,220 @@
+r"""Generate parity goldens for the TopK-Embed-V1 adapter from TopK's own pipeline.
+
+Runs the checkpoint's sentence-transformers stack (``MultiVectorEncoder`` with its
+remote code) on fixed queries, text documents and synthetic pages, without any SIE
+code, and writes per-input token counts, token ids, per-token projections onto
+fixed random directions, and the MaxSim score matrices to
+``tests/adapters/goldens/topk_embed/<org>__<name>.json``.
+
+The pipeline's backbone (``hf_backbone.py``) needs CUDA-only kernels:
+flash-linear-attention's ``causal_conv1d`` and ``chunk_gated_delta_rule`` over
+packed sequences, and ``torch.compile``'d flex attention. On CUDA the script runs
+it unchanged (install ``flash-linear-attention``). With ``--device cpu`` it swaps
+those three for reference implementations with the same math: a depthwise causal
+conv per packed segment, transformers' torch ``chunk_gated_delta_rule`` per
+segment, and eager flex attention with the same document mask. Everything else,
+preprocessing included, is TopK's code.
+
+Run with the checkpoint's own requirements (``requirements.txt`` in the model
+repo; transformers 5.9 and sentence-transformers 6.0):
+
+ uv run --no-project --python 3.12 \\
+ --with torch==2.9.1 --with torchvision==0.24.1 --with transformers==5.9.0 \\
+ --with sentence-transformers==6.0.1 --with safetensors --with pillow \\
+ python packages/sie_server/scripts/generate_topk_embed_goldens.py --device cpu
+"""
+
+from __future__ import annotations
+
+import argparse
+import importlib.machinery
+import importlib.metadata
+import itertools
+import json
+import re
+import sys
+import types
+from pathlib import Path
+from typing import Any
+
+import numpy as np
+import torch
+import torch.nn.functional as F
+from PIL import Image
+
+MODELS = {
+ "topk-io/topk-embed-v1-xsmall": "d09d8a7a8cdd6c287f792b3c4d7b41233d46e66a",
+ "topk-io/topk-embed-v1-small": "33b15d544d74f29d04cdb97adeb9fd0e52da5fb7",
+}
+QUERIES = [
+ "how does photosynthesis work?",
+ " what was the Q3 revenue ",
+ "",
+]
+DOCUMENTS = [
+ "Plants convert light energy into chemical energy stored as glucose.",
+ "",
+ "!!! ... ??? --- (( )) <|im_end|> <|endoftext|>",
+ " ".join(f"Section {i}: revenue grew in region {i % 5}, driven by renewals (table {i})." for i in range(12)),
+]
+# Synthetic pages: dark "text line" bars on a light background, from a fixed seed.
+PAGES = [
+ {"name": "letter", "width": 850, "height": 1100, "seed": 1},
+ {"name": "portrait", "width": 480, "height": 640, "seed": 2},
+ {"name": "small", "width": 300, "height": 200, "seed": 3},
+]
+# Per-token vectors are stored as projections onto these directions (unit, seeded).
+N_DIRECTIONS = 4
+GOLDENS_DIR = Path(__file__).resolve().parents[1] / "tests" / "adapters" / "goldens" / "topk_embed"
+
+
+def render_page(spec: dict[str, Any]) -> Image.Image:
+ rng = np.random.default_rng(spec["seed"])
+ height, width = spec["height"], spec["width"]
+ page = np.full((height, width, 3), 245, dtype=np.uint8)
+ line_height = max(6, height // 40)
+ for top in range(height // 12, height - height // 12, line_height * 2):
+ length = int(width * rng.uniform(0.3, 0.8))
+ shade = int(rng.integers(10, 60))
+ page[top : top + line_height, width // 10 : width // 10 + length] = shade
+ return Image.fromarray(page)
+
+
+def directions(dim: int) -> np.ndarray:
+ matrix = np.random.default_rng(0).standard_normal((N_DIRECTIONS, dim))
+ return matrix / np.linalg.norm(matrix, axis=1, keepdims=True)
+
+
+def install_cpu_kernels() -> None:
+ """Provide the flash-linear-attention symbols hf_backbone.py imports, as torch code."""
+
+ def causal_conv1d(x, weight, bias=None, activation=None, cu_seqlens=None, **_):
+ bounds = [0, x.shape[1]] if cu_seqlens is None else cu_seqlens.tolist()
+ outs = []
+ for start, end in itertools.pairwise(bounds):
+ segment = F.pad(x[:, start:end].transpose(1, 2), (weight.shape[-1] - 1, 0))
+ y = F.conv1d(segment, weight.unsqueeze(1), bias, groups=x.shape[-1])
+ outs.append((F.silu(y) if activation in ("silu", "swish") else y).transpose(1, 2))
+ return torch.cat(outs, dim=1), None
+
+ def module(name: str, *, package: bool = False) -> types.ModuleType:
+ stub = types.ModuleType(name)
+ # transformers probes installed packages with importlib.util.find_spec.
+ stub.__spec__ = importlib.machinery.ModuleSpec(name, loader=None, is_package=package)
+ return stub
+
+ fla = module("fla", package=True)
+ fla_utils = module("fla.utils")
+ fla_utils.FLA_DISABLE_TENSOR_CACHE = False # ty: ignore[unresolved-attribute]
+ fla_modules = module("fla.modules", package=True)
+ fla_convolution = module("fla.modules.convolution")
+ fla_convolution.causal_conv1d = causal_conv1d # ty: ignore[unresolved-attribute]
+ fla.utils = fla_utils # ty: ignore[unresolved-attribute]
+ fla.modules = fla_modules # ty: ignore[unresolved-attribute]
+ fla_modules.convolution = fla_convolution # ty: ignore[unresolved-attribute]
+ sys.modules.update(
+ {"fla": fla, "fla.utils": fla_utils, "fla.modules": fla_modules, "fla.modules.convolution": fla_convolution}
+ )
+
+
+def patch_cpu_model(model: Any) -> None:
+ """Eager flex attention, and the torch delta rule run once per packed segment."""
+ from torch.nn.attention.flex_attention import create_block_mask, flex_attention
+
+ backbone = next(module for name, module in sys.modules.items() if name.endswith("hf_backbone"))
+ backbone.compiled_flex_attention = flex_attention # ty: ignore[unresolved-attribute]
+ backbone.compiled_create_block_mask = create_block_mask # ty: ignore[unresolved-attribute]
+
+ def segmented(rule):
+ def run(query, key, value, *, g, beta, cu_seqlens=None, **kwargs):
+ bounds = [0, query.shape[1]] if cu_seqlens is None else cu_seqlens.tolist()
+ outs = [
+ rule(query[:, s:e], key[:, s:e], value[:, s:e], g=g[:, s:e], beta=beta[:, s:e], **kwargs)[0]
+ for s, e in itertools.pairwise(bounds)
+ ]
+ return torch.cat(outs, dim=1), None
+
+ return run
+
+ for layer in model[0].auto_model.model.language_model.layers:
+ if layer.layer_type == "linear_attention":
+ layer.linear_attn.chunk_gated_delta_rule = segmented(layer.linear_attn.chunk_gated_delta_rule)
+
+
+def dumps(golden: dict[str, Any]) -> str:
+ """Indented JSON with every list of numbers on one line."""
+ text = json.dumps(golden, indent=1)
+ return re.sub(r"\[([^\[\]{}\"]*)\]", lambda m: "[" + " ".join(m.group(1).split()) + "]", text) + "\n"
+
+
+def maxsim(queries: list[np.ndarray], documents: list[np.ndarray]) -> list[list[float]]:
+ return [[float((q @ d.T).max(axis=1).sum()) for d in documents] for q in queries]
+
+
+def generate(model_id: str, revision: str, device: str) -> dict[str, Any]:
+ from sentence_transformers import MultiVectorEncoder # ty: ignore[unresolved-import]
+
+ model = MultiVectorEncoder(model_id, revision=revision, trust_remote_code=True, device=device)
+ if device == "cpu":
+ patch_cpu_model(model)
+ module = model[0]
+ pages = [render_page(spec) for spec in PAGES]
+ with torch.inference_mode():
+ queries = [t.float().cpu().numpy() for t in model.encode_query(QUERIES)]
+ documents = [t.float().cpu().numpy() for t in model.encode_document(DOCUMENTS)]
+ images = [model.encode_document([page])[0].float().cpu().numpy() for page in pages]
+ basis = directions(queries[0].shape[1])
+
+ def entry(vectors: np.ndarray, **extra: Any) -> dict[str, Any]:
+ # One row per direction, one value per token.
+ return {"tokens": len(vectors), "projections": np.round(basis @ vectors.T, 5).tolist(), **extra}
+
+ query_ids = module.preprocess(QUERIES, task="query")
+ doc_ids = module.preprocess(DOCUMENTS, task="document")
+ return {
+ "model": model_id,
+ "revision": revision,
+ "generated_with": {
+ "pipeline": "sentence_transformers.MultiVectorEncoder + the checkpoint's remote code",
+ "device": device,
+ "kernels": "reference torch/eager stand-ins (see script)" if device == "cpu" else "native",
+ "torch": torch.__version__,
+ "transformers": importlib.metadata.version("transformers"),
+ "sentence_transformers": importlib.metadata.version("sentence-transformers"),
+ "directions": {"seed": 0, "count": N_DIRECTIONS, "distribution": "standard normal, unit rows"},
+ },
+ "queries": [
+ entry(v, text=t, input_ids=row[mask].tolist())
+ for v, t, row, mask in zip(
+ queries, QUERIES, query_ids["input_ids"], query_ids["attention_mask"], strict=True
+ )
+ ],
+ "documents": [
+ entry(v, text=t, input_ids=row[mask].tolist())
+ for v, t, row, mask in zip(
+ documents, DOCUMENTS, doc_ids["input_ids"], doc_ids["attention_mask"], strict=True
+ )
+ ],
+ "pages": [entry(v, **spec) for v, spec in zip(images, PAGES, strict=True)],
+ "text_scores": maxsim(queries, documents),
+ "page_scores": maxsim(queries, images),
+ }
+
+
+def main() -> None:
+ parser = argparse.ArgumentParser(description="Generate parity goldens for the TopK-Embed-V1 adapter.")
+ parser.add_argument("--device", default="cuda" if torch.cuda.is_available() else "cpu")
+ parser.add_argument("--model", choices=sorted(MODELS), action="append")
+ args = parser.parse_args()
+ if args.device == "cpu":
+ install_cpu_kernels()
+ GOLDENS_DIR.mkdir(parents=True, exist_ok=True)
+ for model_id in args.model or list(MODELS):
+ golden = generate(model_id, MODELS[model_id], args.device)
+ path = GOLDENS_DIR / f"{model_id.replace('/', '__')}.json"
+ path.write_text(dumps(golden), encoding="utf-8")
+ print(f"wrote {path}")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/packages/sie_server/src/sie_server/adapters/_cuda_graphs.py b/packages/sie_server/src/sie_server/adapters/_cuda_graphs.py
index 3479dcd68..32204b19e 100644
--- a/packages/sie_server/src/sie_server/adapters/_cuda_graphs.py
+++ b/packages/sie_server/src/sie_server/adapters/_cuda_graphs.py
@@ -1,9 +1,10 @@
"""Process-wide pieces shared by the CUDA graph runners.
A runner records the kernel launches of a forward once per input shape and
-replays them with one call. Two runners exist: the GLiClass DeBERTa encoder
-(``gliclass/cuda_graphs.py``) and the ModernBERT flash-attention varlen
-encoders (``_modernbert_flash_graphs.py``). They record different forwards,
+replays them with one call. Three runners exist: the GLiClass DeBERTa encoder
+(``gliclass/cuda_graphs.py``), the ModernBERT flash-attention varlen encoders
+(``_modernbert_flash_graphs.py``) and TopK-Embed's text model
+(``topk_embed/graphs.py``). They record different forwards,
but they share one device and one caching allocator, so these rules hold
across every runner in the process:
diff --git a/packages/sie_server/src/sie_server/adapters/topk_embed/__init__.py b/packages/sie_server/src/sie_server/adapters/topk_embed/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/packages/sie_server/src/sie_server/adapters/topk_embed/_vision_rotary_kernel.py b/packages/sie_server/src/sie_server/adapters/topk_embed/_vision_rotary_kernel.py
new file mode 100644
index 000000000..36967c683
--- /dev/null
+++ b/packages/sie_server/src/sie_server/adapters/topk_embed/_vision_rotary_kernel.py
@@ -0,0 +1,47 @@
+"""Triton kernel of ``vision_rotary.py`` (imported only where Triton is installed)."""
+
+# Triton reads a kernel's parameter annotations itself, so the kernel's pointer and stride
+# arguments stay unannotated.
+# ruff: noqa: ANN001, ANN202
+
+from __future__ import annotations
+
+import triton # ty: ignore[unresolved-import]
+import triton.language as tl # ty: ignore[unresolved-import]
+
+
+def rotate_kernel(
+ x_ptr,
+ cos_ptr,
+ sin_ptr,
+ out_ptr,
+ n_heads,
+ stride_xt,
+ stride_xh,
+ stride_ct,
+ stride_ot,
+ stride_oh,
+ half: tl.constexpr,
+ block_h: tl.constexpr,
+ block_d: tl.constexpr,
+):
+ t = tl.program_id(0).to(tl.int64)
+ heads = tl.arange(0, block_h)
+ # Triton ranges are powers of two: block_d covers half the head size, masked past it.
+ dims = tl.arange(0, block_d)
+ in_dims = dims < half
+ in_heads = (heads < n_heads)[:, None] & in_dims[None, :]
+ cos1 = tl.load(cos_ptr + t * stride_ct + dims, mask=in_dims).to(tl.float32)[None, :]
+ cos2 = tl.load(cos_ptr + t * stride_ct + half + dims, mask=in_dims).to(tl.float32)[None, :]
+ sin1 = tl.load(sin_ptr + t * stride_ct + dims, mask=in_dims).to(tl.float32)[None, :]
+ sin2 = tl.load(sin_ptr + t * stride_ct + half + dims, mask=in_dims).to(tl.float32)[None, :]
+ rows = x_ptr + t * stride_xt + heads[:, None] * stride_xh
+ x1 = tl.load(rows + dims[None, :], mask=in_heads).to(tl.float32)
+ x2 = tl.load(rows + half + dims[None, :], mask=in_heads).to(tl.float32)
+ # rotate_half(x) is cat(-x2, x1): the same products and sums as the PyTorch chain.
+ out1 = x1 * cos1 + (-x2) * sin1
+ out2 = x2 * cos2 + x1 * sin2
+ out = out_ptr + t * stride_ot + heads[:, None] * stride_oh
+ tl.store(out + dims[None, :], out1.to(out_ptr.dtype.element_ty), mask=in_heads)
+ tl.store(out + half + dims[None, :], out2.to(out_ptr.dtype.element_ty), mask=in_heads)
diff --git a/packages/sie_server/src/sie_server/adapters/topk_embed/adapter.py b/packages/sie_server/src/sie_server/adapters/topk_embed/adapter.py
new file mode 100644
index 000000000..f557df1e0
--- /dev/null
+++ b/packages/sie_server/src/sie_server/adapters/topk_embed/adapter.py
@@ -0,0 +1,1077 @@
+"""Multi-vector text and page-image embeddings for the TopK-Embed-V1 family.
+
+Serves ``topk-io/topk-embed-v1-xsmall`` (Qwen3.5-0.8B backbone, 1024-dim tokens)
+and ``topk-io/topk-embed-v1-small`` (Qwen3.5-2B backbone, 2048-dim tokens). Every
+token becomes a vector; a query scores a document with MaxSim.
+
+The checkpoints ship a sentence-transformers 6 module stack whose backbone packs a
+batch into one sequence and runs flash-linear-attention and compiled flex-attention
+kernels (CUDA only). This adapter reproduces the same recipe on the stock
+``transformers.models.qwen3_5`` classes, one right-padded row per input, so it needs
+neither ``trust_remote_code`` nor sentence-transformers 6:
+
+* query: ``"Query: " + text.strip()``, capped at ``query_length`` tokens, every
+ token scored;
+* text document: ``("Document: " + text).strip()``, capped at ``document_length``
+ tokens, tokens in ``scoring_skip_ids`` (punctuation, special tokens) not scored;
+* image document: the chat template with one image placeholder, expanded to the
+ image's merged patches after ``smart_resize`` to at most ``image_token_budget``
+ of them; only those patch tokens are scored.
+
+On CUDA with flash-linear-attention installed, each batch runs packed (see
+``packed.py``): one sequence, no padding, variable-length kernels, as the
+reference pipeline runs, with fused kernels for the per-token work (RMSNorm with
+the residual add, gated RMSNorm, SwiGLU). Otherwise every input is its own
+right-padded row.
+
+Numerics follow the reference stack (transformers 5.9): rotary tables built from
+bf16 ``inv_freq``, vision rotary phases in the weight dtype, pixel normalisation in
+the weight dtype, and bidirectional full-attention layers. The vision tower is run
+here from the checkpoint's own sub-modules, so the result does not depend on how a
+transformers release builds the vision rotary table (5.17 changed it).
+"""
+
+from __future__ import annotations
+
+import io
+import json
+import logging
+import math
+import threading
+import time
+from collections import OrderedDict
+from collections.abc import Callable
+from concurrent.futures import ThreadPoolExecutor
+from dataclasses import dataclass
+from pathlib import Path
+from typing import TYPE_CHECKING, Any, cast
+
+import numpy as np
+import torch
+from torch.nn import functional as F
+
+from sie_server.adapters._base_adapter import BaseAdapter
+from sie_server.adapters._multivector import maxsim_scores_batched
+from sie_server.adapters._spec import AdapterSpec
+from sie_server.adapters._types import ComputePrecision
+from sie_server.adapters._utils import grouped_score_pairs, validate_output_types
+from sie_server.adapters.topk_embed import vision_rotary
+from sie_server.adapters.topk_embed.graphs import GRAPH_MODES, GraphMode, GraphRunner, default_max_tokens
+from sie_server.adapters.topk_embed.packed import PackedTextModel, Packing, resolve_kernels, to_device
+from sie_server.core.inference_output import EncodeOutput
+from sie_server.core.oom import is_oom_error
+from sie_server.core.postprocessor import MuveraConfig, MuveraPostprocessor
+from sie_server.types.inputs import ImageInput, InvalidInputError, Item, decode_image
+
+if TYPE_CHECKING:
+ from PIL import Image as PILImage
+
+ from sie_server.core.inference_output import ScoreOutput
+
+logger = logging.getLogger(__name__)
+
+_ERR_NO_INPUT = "TopkEmbedAdapter requires text or image input per item"
+_ERR_IMAGE_QUERY = "TopK-Embed queries must be text; images can only be encoded as documents"
+_ERR_INSTRUCTION = "TopK-Embed applies its own 'Query: ' and 'Document: ' templates; instructions are not supported"
+
+# Files the adapter reads; the repos also carry the sentence-transformers remote code and plots.
+_CHECKPOINT_FILES = [
+ "config.json",
+ "model.safetensors",
+ "model.safetensors.index.json",
+ "model-*.safetensors",
+ "tokenizer.json",
+ "tokenizer_config.json",
+ "processor_config.json",
+ "chat_template.jinja",
+ "sentence_bert_config.json",
+]
+# TopK-specific keys in config.json that Qwen3_5Config does not own.
+_TOPK_CONFIG_KEYS = (
+ "dim",
+ "output_dim",
+ "normalize",
+ "query_template",
+ "document_prompt",
+ "image_token_budget",
+ "scoring_skip_ids",
+)
+_REMOTE_CODE_CONFIG_KEYS = ("architectures", "auto_map", "model_type", "transformers_version")
+_IMAGE_MESSAGE = [{"role": "user", "content": [{"type": "image"}]}]
+# theta of transformers 5.9's Qwen3_5VisionRotaryEmbedding, the table the checkpoints were trained on.
+_VISION_ROPE_THETA = 10000.0
+# Page grids whose vision position inputs stay cached (up to about 280 KB each):
+# pages of repeated sizes hit the cache, and the least recently used grid goes first.
+_GRID_CACHE_SIZE = 256
+# Threads decoding, resizing and patchifying the pages of one request.
+_PREPROCESS_WORKERS = 4
+# flash-linear-attention tunes some kernels again as a batch grows: its short convolution
+# for every 1,024 tokens, its RMSNorm of narrow rows for every 2,048 rows. The attention
+# layers' per-head norms take one row per head, so theirs moves every 2,048 / heads tokens
+# (256 for TopK-Embed's 8 query heads). The warm-up runs one batch per step.
+_CONV_TUNING_TOKENS = 1024
+_NORM_TUNING_ROWS = 2048
+
+
+@dataclass
+class _ImageRow:
+ input_ids: torch.Tensor
+ pixel_values: torch.Tensor
+ grid_thw: tuple[int, int, int]
+
+
+@dataclass
+class _Launched:
+ """A forward whose vectors are on their way to the host.
+
+ On CUDA the copy runs asynchronously into pinned memory and ``copied`` marks its
+ end, so the host can launch the next batch before this one is unpacked.
+ """
+
+ vectors: torch.Tensor
+ copied: Any
+ split: Callable[[torch.Tensor], list[torch.Tensor]]
+
+ def rows(self) -> list[torch.Tensor]:
+ """One ``[len, dim]`` host tensor per input row; waits for the copy."""
+ if self.copied is not None:
+ self.copied.synchronize()
+ return self.split(self.vectors)
+
+
+class TopkEmbedAdapter(BaseAdapter):
+ """Late-interaction encoder for TopK-Embed-V1: text queries; text or page-image documents."""
+
+ spec = AdapterSpec(
+ inputs=("text", "image"),
+ outputs=("multivector", "score"),
+ # Discovered at load: the head width, or ``token_dim`` when set.
+ multivector_dim=None,
+ unload_fields=("_model", "_head", "_processor", "_tokenizer"),
+ default_preprocessor="image",
+ )
+
+ def __init__(
+ self,
+ model_name_or_path: str | Path,
+ *,
+ compute_precision: ComputePrecision = "bfloat16",
+ revision: str | None = None,
+ max_seq_length: int | None = None,
+ normalize: bool = True,
+ token_dim: int | None = None,
+ query_max_length: int | None = None,
+ image_token_budget: int | None = None,
+ text_batch_tokens: int = 16384,
+ image_batch_size: int = 4,
+ muvera_config: dict[str, Any] | None = None,
+ attn_implementation: str | None = None,
+ packed: bool | None = None,
+ cuda_graphs: str | bool = "off",
+ cuda_graph_tokens: int | None = None,
+ ) -> None:
+ """Initialize the adapter.
+
+ Args:
+ model_name_or_path: HuggingFace model ID or local checkpoint directory.
+ compute_precision: Weight and activation dtype. The checkpoints are bf16.
+ revision: HuggingFace revision to download (pin a commit SHA).
+ max_seq_length: Upper bound on the document cap (``document_length``).
+ normalize: L2-normalize each token vector (MaxSim expects unit vectors).
+ token_dim: Keep only the leading ``token_dim`` dimensions of each vector
+ (Matryoshka), truncated before normalizing. Defaults to the head width.
+ query_max_length: Query token cap. Defaults to ``query_length`` in
+ ``sentence_bert_config.json``.
+ image_token_budget: Most merged patches per image. Defaults to the
+ checkpoint's ``image_token_budget``.
+ text_batch_tokens: Padded tokens per text forward pass.
+ image_batch_size: Images per vision forward pass.
+ muvera_config: Optional MUVERA configuration (passed to postprocessor).
+ attn_implementation: Attention kernel for the full-attention layers of
+ the row-per-input path (``sdpa`` when unset).
+ packed: Run each batch as one packed sequence with variable-length
+ kernels. ``None`` packs on CUDA when flash-linear-attention is
+ installed; ``True`` always packs (PyTorch reference kernels where
+ the fast ones are missing); ``False`` never packs.
+ cuda_graphs: CUDA graphs for small text batches on the packed CUDA path
+ (see ``graphs.py``): ``"off"`` or ``"bucketed"``. An operator setting,
+ fixed at load.
+ cuda_graph_tokens: Most tokens (rows times padded length) one graph holds.
+ Defaults to 2,048 at a hidden size of 768, proportionally fewer for
+ wider models.
+ """
+ self._model_name_or_path = str(model_name_or_path)
+ self._compute_precision = compute_precision
+ self._revision = revision
+ self._max_seq_length = max_seq_length
+ self._normalize = normalize
+ self._token_dim_opt = token_dim
+ self._query_max_length_opt = query_max_length
+ self._image_token_budget_opt = image_token_budget
+ self._text_batch_tokens = max(1, int(text_batch_tokens))
+ self._image_batch_size = max(1, int(image_batch_size))
+ self._muvera_config = muvera_config
+ self._attn_implementation = attn_implementation
+ self._packed = packed
+ self._packed_text: PackedTextModel | None = None
+ mode = "off" if cuda_graphs is False else cuda_graphs
+ if mode not in GRAPH_MODES:
+ msg = f"cuda_graphs must be one of {', '.join(GRAPH_MODES)}, got {cuda_graphs!r}"
+ raise ValueError(msg)
+ self._cuda_graphs = cast("GraphMode", mode)
+ self._cuda_graph_tokens = cuda_graph_tokens
+ self._graphs: GraphRunner | None = None
+ self._preprocess_pool: ThreadPoolExecutor | None = None
+ self._preprocess_pool_lock = threading.Lock()
+
+ self._model: Any = None
+ self._head: Any = None
+ self._processor: Any = None
+ self._tokenizer: Any = None
+ self._device: str | None = None
+ self._dtype: torch.dtype = torch.bfloat16
+ self._multivector_dim: int | None = token_dim
+ self._query_template = "Query: "
+ self._document_prompt = "Document: "
+ self._query_max_length = 1024
+ self._doc_max_length = max_seq_length or 8192
+ self._image_token_id = 0
+ self._attention_heads = 1
+ self._skip_ids = torch.empty(0, dtype=torch.long)
+ self._image_prefix = torch.empty(0, dtype=torch.long)
+ self._image_suffix = torch.empty(0, dtype=torch.long)
+ self._vision_inv_freq: torch.Tensor | None = None
+ self._patch_size = 16
+ self._merge_size = 2
+ self._temporal_patch_size = 2
+ self._min_pixels = 0
+ self._max_pixels = 0
+ self._pixel_scale = 1.0
+ self._pixel_bias = 0.0
+ self._num_grid_per_side = 0
+ self._grid_cache: OrderedDict[tuple[int, int, int], tuple[torch.Tensor, torch.Tensor, torch.Tensor]] = (
+ OrderedDict()
+ )
+ # transformers' output recorder patches module forwards during each call;
+ # serialize forwards so concurrent requests cannot race it.
+ self._forward_lock = threading.Lock()
+
+ # ------------------------------------------------------------------
+ # Load
+ # ------------------------------------------------------------------
+
+ def load(self, device: str) -> None:
+ """Load the backbone, projection head and processor onto ``device``."""
+ # transformers >= 5.2 (the transformers5 bundle): the default bundle's 4.57 has no qwen3_5.
+ from transformers import Qwen3VLProcessor
+ from transformers.models.qwen3_5 import Qwen3_5Config, Qwen3_5Model # ty: ignore[unresolved-import]
+
+ self._device = device
+ self._dtype = self._resolve_compute_dtype()
+ path = self._resolve_checkpoint_dir()
+ raw = json.loads((path / "config.json").read_text(encoding="utf-8"))
+ topk = {key: raw.pop(key) for key in _TOPK_CONFIG_KEYS if key in raw}
+ for key in _REMOTE_CODE_CONFIG_KEYS:
+ raw.pop(key, None)
+ config = Qwen3_5Config(**raw)
+ # Bidirectional full-attention layers; the linear-attention layers stay causal recurrences.
+ config.text_config.is_causal = False
+ self._attention_heads = int(config.text_config.num_attention_heads)
+ config.text_config.use_cache = False
+
+ attn_impl = self._attn_implementation or "sdpa"
+ logger.info(
+ "Loading TopK-Embed %s on device=%s with dtype=%s, attn=%s",
+ self._model_name_or_path,
+ device,
+ self._dtype,
+ attn_impl,
+ )
+ model, loading = Qwen3_5Model.from_pretrained(
+ path,
+ config=config,
+ dtype=self._dtype,
+ attn_implementation=attn_impl,
+ device_map=device,
+ output_loading_info=True,
+ )
+ # The checkpoint is the reference wrapper: ``model.*`` (this backbone) plus ``head.weight``.
+ unexpected = set(loading.get("unexpected_keys", [])) - {"head.weight"}
+ if loading.get("missing_keys") or loading.get("mismatched_keys") or unexpected:
+ msg = (
+ f"TopK-Embed checkpoint does not match Qwen3_5Model: missing={loading.get('missing_keys')} "
+ f"mismatched={loading.get('mismatched_keys')} unexpected={sorted(unexpected)}"
+ )
+ raise RuntimeError(msg)
+ self._model = model.eval()
+ # An unpadded batch drops the key-padding mask, and sdpa then falls back to
+ # module.is_causal; clear it so that fallback is bidirectional as well.
+ for layer in self._model.language_model.layers:
+ if hasattr(layer, "self_attn"):
+ layer.self_attn.is_causal = False
+ # Rotary tables are rebuilt in float32 at load; the weights were trained against bf16 ones.
+ for module in self._model.modules():
+ inv_freq = getattr(module, "inv_freq", None)
+ if isinstance(inv_freq, torch.Tensor) and inv_freq.is_floating_point():
+ module.inv_freq = inv_freq.to(torch.bfloat16).to(self._dtype)
+ kernels = resolve_kernels(device, mode=self._packed)
+ self._packed_text = PackedTextModel(self._model.language_model, kernels) if kernels else None
+ logger.info("TopK-Embed text path: %s", kernels.names if kernels else "row per input (padded)")
+ vision = config.vision_config
+ rotary_dim = vision.hidden_size // vision.num_heads // 2
+ inv_freq = 1.0 / (_VISION_ROPE_THETA ** (torch.arange(0, rotary_dim, 2, dtype=torch.float) / rotary_dim))
+ self._vision_inv_freq = inv_freq.to(torch.bfloat16).to(device=device, dtype=self._dtype)
+ self._num_grid_per_side = int(vision.num_position_embeddings**0.5)
+
+ self._head = self._load_head(path).to(device=device, dtype=self._dtype).eval()
+ width = self._head.out_features
+ token_dim = int(self._token_dim_opt or topk.get("output_dim") or width)
+ if not 0 < token_dim <= width:
+ msg = f"token_dim must be in 1..{width}, got {token_dim}"
+ raise ValueError(msg)
+ self._multivector_dim = token_dim
+ self._query_template = topk.get("query_template", self._query_template)
+ self._document_prompt = topk.get("document_prompt", self._document_prompt)
+ self._skip_ids = torch.tensor(topk.get("scoring_skip_ids") or [], dtype=torch.long)
+ self._image_token_id = int(config.image_token_id)
+
+ st_config = self._read_json(path / "sentence_bert_config.json")
+ text_cap = int(config.text_config.max_position_embeddings)
+ self._query_max_length = min(int(self._query_max_length_opt or st_config.get("query_length", 1024)), text_cap)
+ doc_cap = int(st_config.get("document_length", 8192))
+ if self._max_seq_length:
+ doc_cap = min(doc_cap, self._max_seq_length)
+ self._doc_max_length = min(doc_cap, text_cap)
+
+ # The repo's auto_map points at its remote code; the stock processor needs none of it.
+ processor = cast("Any", Qwen3VLProcessor.from_pretrained(path, trust_remote_code=False))
+ self._processor = processor
+ self._tokenizer = processor.tokenizer
+ # Pads come after real tokens: the linear-attention layers are causal recurrences.
+ self._tokenizer.padding_side = "right"
+ image_processor = processor.image_processor
+ self._patch_size = int(image_processor.patch_size)
+ self._merge_size = int(image_processor.merge_size)
+ self._temporal_patch_size = int(image_processor.temporal_patch_size)
+ self._min_pixels = int(image_processor.size.shortest_edge)
+ budget = int(self._image_token_budget_opt or topk.get("image_token_budget", 1280))
+ self._max_pixels = budget * (self._patch_size * self._merge_size) ** 2
+ self._pixel_scale = image_processor.rescale_factor / image_processor.image_std[0]
+ self._pixel_bias = -image_processor.image_mean[0] / image_processor.image_std[0]
+ template = self._processor.apply_chat_template(_IMAGE_MESSAGE, tokenize=False, add_generation_prompt=False)
+ ids = self._tokenizer(template)["input_ids"]
+ split = ids.index(self._image_token_id)
+ self._image_prefix = torch.tensor(ids[:split], dtype=torch.long)
+ self._image_suffix = torch.tensor(ids[split + 1 :], dtype=torch.long)
+ self._grid_cache.clear()
+ self._graphs = self._graph_runner(device)
+
+ def _graph_runner(self, device: str) -> GraphRunner | None:
+ """The CUDA graph runner for small text batches, when configured and possible."""
+ if self._cuda_graphs == "off":
+ return None
+ text = self._packed_text
+ if not str(device).startswith("cuda"):
+ reason = "they need a CUDA device"
+ elif text is None or text.kernels.names.get("delta_rule") != "fla chunk":
+ reason = "they need the packed path with flash-linear-attention"
+ else:
+ embed = self._model.get_input_embeddings()
+ max_tokens = int(self._cuda_graph_tokens or default_max_tokens(int(embed.weight.shape[1])))
+ logger.info("TopK-Embed CUDA graphs: bucketed, up to %d tokens per graph", max_tokens)
+ return GraphRunner(
+ text,
+ embed,
+ pad_token_id=int(self._tokenizer.pad_token_id),
+ max_tokens=max_tokens,
+ name=self._model_name_or_path,
+ )
+ logger.info("TopK-Embed CUDA graphs off: %s", reason)
+ return None
+
+ def warmup(self) -> None:
+ """Compile and tune the GPU kernels before the model takes traffic.
+
+ flash-linear-attention's Triton kernels compile and autotune on first use, and
+ some tune again as a batch grows (see ``_NORM_TUNING_ROWS``). On a fresh machine
+ the first requests would stall, for seconds to over a minute, at every new batch
+ size. So one packed batch per tuning step, up to the largest batch the adapter
+ builds, runs here, then the CUDA graphs' padded forward at each size it tunes
+ for, a query and a page (the vision tower's kernels). Off CUDA or off the packed
+ path there is nothing to compile.
+ """
+ if self._packed_text is None or not str(self._device).startswith("cuda"):
+ return
+ started = time.perf_counter()
+ token = int(self._tokenizer.pad_token_id)
+ step = max(1, min(_CONV_TUNING_TOKENS, _NORM_TUNING_ROWS // self._attention_heads))
+ largest = self._largest_batch_tokens()
+ for total in range(step, largest + step, step):
+ full, rest = divmod(total, self._doc_max_length)
+ lengths = [self._doc_max_length] * full + ([rest] if rest else [])
+ rows = [torch.full((n,), token, dtype=torch.long) for n in lengths]
+ try:
+ self._forward_packed(rows, images=None, normalize=True, dtype=torch.float16, graphs=False).rows()
+ except Exception as exc:
+ if not is_oom_error(exc):
+ raise
+ # A GPU shared with other models: serving splits what does not fit, so load anyway.
+ torch.cuda.empty_cache()
+ logger.warning("TopK-Embed warm-up stopped at %d tokens per batch: out of GPU memory", total)
+ break
+ if self._graphs is not None:
+ with self._forward_lock, torch.inference_mode():
+ self._graphs.warm_up(_CONV_TUNING_TOKENS)
+ options = {"output_dtype": "float16"}
+ self.encode([Item(text="warm up")], ["multivector"], is_query=True, options=options)
+ self.encode([Item(images=[_warmup_page()])], ["multivector"], options=options)
+ logger.info(
+ "TopK-Embed warm-up: batches up to %d tokens in steps of %d, a query and a page in %.1f s",
+ largest,
+ step,
+ time.perf_counter() - started,
+ )
+
+ def _largest_batch_tokens(self) -> int:
+ """Most tokens one packed forward holds: a text batch, one capped document, or a batch of pages."""
+ page = self._max_pixels // (self._patch_size * self._merge_size) ** 2
+ page += len(self._image_prefix) + len(self._image_suffix)
+ return max(self._text_batch_tokens, self._doc_max_length, self._image_batch_size * page)
+
+ def _resolve_compute_dtype(self) -> torch.dtype:
+ # Honoured on every device: the reference runs bf16 on CPU too.
+ dtype_map = {"bfloat16": torch.bfloat16, "float16": torch.float16, "float32": torch.float32}
+ return dtype_map.get(self._compute_precision, torch.bfloat16)
+
+ def _resolve_checkpoint_dir(self) -> Path:
+ local = Path(self._model_name_or_path)
+ if local.is_dir():
+ return local
+ from huggingface_hub import snapshot_download
+
+ return Path(
+ snapshot_download(self._model_name_or_path, revision=self._revision, allow_patterns=_CHECKPOINT_FILES)
+ )
+
+ @staticmethod
+ def _read_json(path: Path) -> dict[str, Any]:
+ return json.loads(path.read_text(encoding="utf-8")) if path.is_file() else {}
+
+ @staticmethod
+ def _load_head(path: Path) -> torch.nn.Linear:
+ from safetensors import safe_open
+
+ shard = "model.safetensors"
+ index = path / "model.safetensors.index.json"
+ if index.is_file():
+ shard = json.loads(index.read_text(encoding="utf-8"))["weight_map"]["head.weight"]
+ with safe_open(str(path / shard), framework="pt") as handle:
+ weight = handle.get_tensor("head.weight")
+ head = torch.nn.Linear(weight.shape[1], weight.shape[0], bias=False, dtype=weight.dtype)
+ head.load_state_dict({"weight": weight})
+ return head
+
+ # ------------------------------------------------------------------
+ # Encode
+ # ------------------------------------------------------------------
+
+ def encode(
+ self,
+ items: list[Item],
+ output_types: list[str],
+ *,
+ instruction: str | None = None,
+ is_query: bool = False,
+ prepared_items: Any = None,
+ options: dict[str, Any] | None = None,
+ ) -> EncodeOutput:
+ self._check_loaded()
+ validate_output_types(output_types, {"multivector"}, type(self).__name__)
+ if instruction:
+ raise InvalidInputError(_ERR_INSTRUCTION)
+ opts = options or {}
+ normalize = bool(opts.get("normalize", self._normalize))
+ # Vectors cross to the host in 16 bits when the response is 16-bit anyway and nothing
+ # after the adapter reads them at full precision (the MUVERA postprocessor does).
+ half = opts.get("output_dtype") == "float16" and opts.get("muvera") is None
+ dtype = torch.float16 if half else torch.float32
+
+ # Items route by modality: a batch of the reference model carries one modality,
+ # so text and image items run as separate forward passes. An item with images
+ # is a page-image document (its text is not encoded); several images on one
+ # item are concatenated into one multi-vector.
+ results: list[np.ndarray | None] = [None] * len(items)
+ token_counts = [0] * len(items)
+ text_slots: list[int] = []
+ texts: list[str] = []
+ image_slots: list[tuple[int, int]] = []
+ images: list[PILImage.Image] = []
+ for idx, item in enumerate(items):
+ if item.images:
+ if is_query:
+ raise InvalidInputError(_ERR_IMAGE_QUERY)
+ decoded = [decode_image(image, item_index=idx, image_index=j) for j, image in enumerate(item.images)]
+ image_slots.append((idx, len(decoded)))
+ images.extend(decoded)
+ elif item.text is not None:
+ text_slots.append(idx)
+ texts.append(item.text)
+ else:
+ raise InvalidInputError(_ERR_NO_INPUT)
+
+ if texts:
+ vectors, lengths = self._encode_texts(texts, is_query=is_query, normalize=normalize, dtype=dtype)
+ for idx, vector, length in zip(text_slots, vectors, lengths, strict=True):
+ results[idx] = vector
+ token_counts[idx] = length
+ if images:
+ per_image = self._encode_images(images, normalize=normalize, dtype=dtype)
+ cursor = 0
+ for idx, count in image_slots:
+ segment = per_image[cursor : cursor + count]
+ cursor += count
+ results[idx] = segment[0] if count == 1 else np.concatenate(segment, axis=0)
+
+ multivector = [vector for vector in results if vector is not None]
+ assert len(multivector) == len(items)
+ output = EncodeOutput(
+ multivector=multivector,
+ batch_size=len(items),
+ is_query=is_query,
+ multivector_token_dim=self._multivector_dim,
+ )
+ # Unit-meter seam (§7.3): the tokens each text item actually ran, template and
+ # truncation included. Image items bill through ``images`` and count 0 here.
+ if texts:
+ output.extra["input_token_counts"] = token_counts
+ return output
+
+ def _encode_texts(
+ self, texts: list[str], *, is_query: bool, normalize: bool, dtype: torch.dtype = torch.float32
+ ) -> tuple[list[np.ndarray], list[int]]:
+ if is_query:
+ payloads = [self._query_template + (text or "").strip() for text in texts]
+ cap = self._query_max_length
+ else:
+ fallback = self._tokenizer.eos_token or "."
+ payloads = [(self._document_prompt + (text or "")).strip() or fallback for text in texts]
+ cap = self._doc_max_length
+ with self._tokenizer_guard():
+ encoded = self._tokenizer(payloads, truncation=True, max_length=cap)["input_ids"]
+ rows = [torch.tensor(ids, dtype=torch.long) for ids in encoded]
+ keeps = [
+ torch.ones_like(row, dtype=torch.bool) if is_query else ~torch.isin(row, self._skip_ids) for row in rows
+ ]
+
+ vectors: list[np.ndarray | None] = [None] * len(rows)
+
+ def deliver(batch: list[int], launched: _Launched) -> None:
+ for output, i in zip(launched.rows(), batch, strict=True):
+ vectors[i] = output[keeps[i]].numpy()
+
+ batches = [
+ (batch, [rows[i] for i in batch], None) for batch in self._plan_text_batches([len(row) for row in rows])
+ ]
+ self._run_batches(batches, normalize=normalize, dtype=dtype, deliver=deliver)
+ return [vector for vector in vectors if vector is not None], [len(row) for row in rows]
+
+ def _plan_text_batches(self, lengths: list[int]) -> list[list[int]]:
+ """Group rows by length so each batch stays within ``text_batch_tokens``.
+
+ A padded batch costs its row count times its longest row; a packed batch
+ costs the sum of its rows.
+ """
+ order = sorted(range(len(lengths)), key=lambda i: lengths[i])
+ batches: list[list[int]] = []
+ current: list[int] = []
+ tokens = 0
+ for i in order:
+ # ``order`` is ascending, so row i sets the padded width of the batch.
+ cost = tokens + lengths[i] if self._packed_text is not None else (len(current) + 1) * lengths[i]
+ if current and cost > self._text_batch_tokens:
+ batches.append(current)
+ current, tokens = [], 0
+ current.append(i)
+ tokens += lengths[i]
+ if current:
+ batches.append(current)
+ return batches
+
+ def _encode_images(
+ self, images: list[PILImage.Image], *, normalize: bool, dtype: torch.dtype = torch.float32
+ ) -> list[np.ndarray]:
+ rows = self._image_rows(images)
+ order = sorted(range(len(rows)), key=lambda i: len(rows[i].input_ids))
+ vectors: list[np.ndarray | None] = [None] * len(rows)
+
+ def deliver(batch: list[int], launched: _Launched) -> None:
+ for output, i in zip(launched.rows(), batch, strict=True):
+ vectors[i] = output[rows[i].input_ids == self._image_token_id].numpy()
+
+ batches = []
+ for start in range(0, len(order), self._image_batch_size):
+ batch = order[start : start + self._image_batch_size]
+ batches.append((batch, [rows[i].input_ids for i in batch], [rows[i] for i in batch]))
+ self._run_batches(batches, normalize=normalize, dtype=dtype, deliver=deliver)
+ # Page batches vary in size; hand the cached blocks back once the request is done.
+ if self._device and str(self._device).startswith("cuda"):
+ torch.cuda.empty_cache()
+ return [vector for vector in vectors if vector is not None]
+
+ # ------------------------------------------------------------------
+ # Forward
+ # ------------------------------------------------------------------
+
+ def _run_batches(
+ self,
+ batches: list[tuple[list[int], list[torch.Tensor], list[_ImageRow] | None]],
+ *,
+ normalize: bool,
+ dtype: torch.dtype,
+ deliver: Callable[[list[int], _Launched], None],
+ ) -> None:
+ """Run ``(indices, rows, images)`` batches back to back.
+
+ Each batch is launched before the previous one is unpacked, so on a GPU the host
+ prepares and unpacks batches while the device computes.
+ """
+ pending: tuple[list[int], _Launched] | None = None
+ for indices, rows, images in batches:
+ launched = self._launch(rows, images=images, normalize=normalize, dtype=dtype)
+ if pending is not None:
+ deliver(*pending)
+ pending = (indices, launched)
+ if pending is not None:
+ deliver(*pending)
+
+ def _launch(
+ self,
+ rows: list[torch.Tensor],
+ *,
+ images: list[_ImageRow] | None = None,
+ normalize: bool,
+ dtype: torch.dtype = torch.float32,
+ ) -> _Launched:
+ """Run rows through the backbone and head; the vectors come back as ``dtype`` on the host."""
+ assert self._model is not None
+ assert self._head is not None
+ try:
+ if self._packed_text is not None:
+ return self._forward_packed(rows, images=images, normalize=normalize, dtype=dtype)
+ return self._forward_padded(rows, images=images, normalize=normalize, dtype=dtype)
+ except Exception as exc:
+ if self._graphs is not None and is_oom_error(exc):
+ # Give the graphs' memory back before the worker's out-of-memory recovery retries.
+ with self._forward_lock:
+ self._graphs.clear()
+ torch.cuda.empty_cache()
+ raise
+
+ def _forward_padded(
+ self, rows: list[torch.Tensor], *, images: list[_ImageRow] | None, normalize: bool, dtype: torch.dtype
+ ) -> _Launched:
+ device = self._device or "cpu"
+ width = max(len(row) for row in rows)
+ pad_id = self._tokenizer.pad_token_id
+ input_ids = torch.full((len(rows), width), pad_id, dtype=torch.long)
+ attention_mask = torch.zeros((len(rows), width), dtype=torch.long)
+ for i, row in enumerate(rows):
+ input_ids[i, : len(row)] = row
+ attention_mask[i, : len(row)] = 1
+ input_ids = input_ids.to(device)
+ attention_mask = attention_mask.to(device)
+
+ with self._forward_lock, torch.inference_mode():
+ inputs_embeds = self._model.get_input_embeddings()(input_ids)
+ position_ids = None
+ if images:
+ image_hidden = self._vision_forward(images)
+ image_positions = input_ids == self._image_token_id
+ inputs_embeds[image_positions] = image_hidden.to(inputs_embeds.dtype)
+ position_ids = self._image_position_ids(images, width).to(device)
+ hidden = self._model.language_model(
+ inputs_embeds=inputs_embeds,
+ attention_mask=attention_mask,
+ position_ids=position_ids,
+ use_cache=False,
+ ).last_hidden_state
+ vectors = self._project(hidden, normalize=normalize, dtype=dtype).cpu()
+ return _Launched(vectors, None, lambda host: [host[i, : len(row)] for i, row in enumerate(rows)])
+
+ def _forward_packed(
+ self,
+ rows: list[torch.Tensor],
+ *,
+ images: list[_ImageRow] | None,
+ normalize: bool,
+ dtype: torch.dtype,
+ graphs: bool = True,
+ ) -> _Launched:
+ packed_text = self._packed_text
+ assert packed_text is not None
+ device = self._device or "cpu"
+ lengths = [len(row) for row in rows]
+ with self._forward_lock, torch.inference_mode():
+ if not images and graphs and self._graphs is not None:
+ hidden = self._graphs.run(rows)
+ if hidden is not None:
+ # Rows come back right-padded to the graph's length.
+ vectors = self._project(hidden, normalize=normalize, dtype=dtype)
+ return self._to_host(vectors, lambda host: [host[i, :n] for i, n in enumerate(lengths)])
+ ids = torch.cat(rows)
+ # Host-to-device copies do not wait for the previous batch still on the GPU.
+ input_ids = to_device(ids, device).unsqueeze(0)
+ packing = Packing.from_lengths(lengths, device)
+ if images:
+ positions = torch.cat([self._image_position_ids([row], len(row.input_ids)) for row in images], dim=2)
+ else:
+ # Text: every packed input restarts at position 0 on all three rotary axes.
+ positions = torch.cat([torch.arange(n) for n in lengths]).view(1, 1, -1).expand(3, 1, -1).contiguous()
+ embeds = self._model.get_input_embeddings()(input_ids)
+ if images:
+ image_hidden = self._vision_forward(images)
+ # Positions found on the host: a boolean mask on the device would wait for the GPU.
+ slots = to_device((ids == self._image_token_id).nonzero().squeeze(1), device)
+ embeds[0].index_copy_(0, slots, image_hidden.to(embeds.dtype))
+ hidden = packed_text(embeds, to_device(positions, device), packing)
+ vectors = self._project(hidden, normalize=normalize, dtype=dtype)[0]
+ return self._to_host(vectors, lambda host: list(host.split(lengths)))
+
+ def _project(self, hidden: torch.Tensor, *, normalize: bool, dtype: torch.dtype) -> torch.Tensor:
+ """Head, truncation to the token dim, L2 normalization in float32, then ``dtype``; on the device."""
+ vectors = self._head(hidden).float()
+ vectors = vectors[..., : self._multivector_dim]
+ if normalize:
+ vectors = F.normalize(vectors, p=2, dim=-1)
+ return vectors.to(dtype)
+
+ @staticmethod
+ def _to_host(vectors: torch.Tensor, split: Callable[[torch.Tensor], list[torch.Tensor]]) -> _Launched:
+ """Start copying ``vectors`` to the host: asynchronously into pinned memory on CUDA."""
+ if vectors.device.type != "cuda":
+ return _Launched(vectors.cpu(), None, split)
+ host = torch.empty(vectors.shape, dtype=vectors.dtype, pin_memory=True)
+ host.copy_(vectors, non_blocking=True)
+ copied = torch.cuda.Event()
+ copied.record()
+ return _Launched(host, copied, split)
+
+ def _vision_forward(self, images: list[_ImageRow]) -> torch.Tensor:
+ """The reference's packed vision tower: every image in one sequence, attention kept per image."""
+ visual = self._model.visual
+ device = self._device or "cpu"
+ weight = visual.patch_embed.proj.weight
+ pixel_values = to_device(torch.cat([row.pixel_values for row in images]), device)
+ # The patch-embed Conv3d has kernel == stride over pre-patched input: one matmul.
+ hidden = F.linear(pixel_values.to(weight.dtype), weight.view(weight.shape[0], -1), visual.patch_embed.proj.bias)
+
+ per_grid = [self._grid_inputs(row.grid_thw) for row in images]
+ pos_index = to_device(torch.cat([grid[0] for grid in per_grid], dim=1), device)
+ pos_weight = to_device(torch.cat([grid[1] for grid in per_grid], dim=1), device)
+ rot_pos = to_device(torch.cat([grid[2] for grid in per_grid]), device)
+ hidden = hidden + (visual.pos_embed(pos_index) * pos_weight.unsqueeze(-1)).sum(0)
+
+ inv_freq = self._vision_inv_freq
+ assert inv_freq is not None
+ max_hw = max(max(row.grid_thw[1:]) for row in images)
+ # transformers 5.9 Qwen3_5VisionRotaryEmbedding: phases in the (bf16) inv_freq dtype.
+ freqs = (torch.arange(max_hw, device=device).unsqueeze(-1) * inv_freq).flatten(1)
+ freqs = freqs[rot_pos].flatten(1)
+ emb = torch.cat((freqs, freqs), dim=-1)
+ cos, sin = emb.cos(), emb.sin()
+
+ # Attention stays within each image: images are padded to the longest and padded keys
+ # masked, the reference's own sdpa call. Page vectors are sensitive to the attention
+ # kernel's rounding: FlashAttention's varlen kernel, exact enough on its own, moved some
+ # page tokens far from the reference on an L4 (worst cosine 0.28); this call matches it.
+ lengths = torch.tensor([math.prod(row.grid_thw) for row in images], dtype=torch.long)
+ max_len = int(lengths.max())
+ seq_idx = torch.repeat_interleave(torch.arange(len(images)), lengths)
+ within = torch.arange(int(lengths.sum())) - torch.repeat_interleave(lengths.cumsum(0) - lengths, lengths)
+ pad_index = to_device(seq_idx * max_len + within, device)
+ key_mask = to_device((torch.arange(max_len) < lengths[:, None])[:, None, None, :].contiguous(), device)
+ for block in visual.blocks:
+ attended = _vision_attention(
+ block.attn, block.norm1(hidden), cos, sin, pad_index=pad_index, key_mask=key_mask, max_len=max_len
+ )
+ hidden = hidden + attended
+ hidden = hidden + block.mlp(block.norm2(hidden))
+ return visual.merger(hidden)
+
+ # ------------------------------------------------------------------
+ # Image preprocessing (topk_embed_st.py in the model repo)
+ # ------------------------------------------------------------------
+
+ def _image_rows(self, images: list[PILImage.Image]) -> list[_ImageRow]:
+ """Preprocess the pages of a request in parallel (decode, resize, patchify)."""
+ if len(images) == 1:
+ return [self._image_row(images[0])]
+ with self._preprocess_pool_lock:
+ if self._preprocess_pool is None:
+ self._preprocess_pool = ThreadPoolExecutor(
+ max_workers=_PREPROCESS_WORKERS, thread_name_prefix="topk-embed-preprocess"
+ )
+ pool = self._preprocess_pool
+ return list(pool.map(self._image_row, images))
+
+ def _image_row(self, image: PILImage.Image) -> _ImageRow:
+ from torchvision.transforms.v2 import InterpolationMode
+ from torchvision.transforms.v2.functional import pil_to_tensor, resize
+
+ pixels = pil_to_tensor(image.convert("RGB"))
+ _, height, width = pixels.shape
+ height, width = smart_resize(
+ height,
+ width,
+ factor=self._patch_size * self._merge_size,
+ min_pixels=self._min_pixels,
+ max_pixels=self._max_pixels,
+ )
+ pixels = resize(pixels, [height, width], interpolation=InterpolationMode.BICUBIC, antialias=True)
+ grid = (1, height // self._patch_size, width // self._patch_size)
+ count = grid[1] * grid[2] // self._merge_size**2
+ input_ids = torch.cat(
+ [self._image_prefix, torch.full((count,), self._image_token_id, dtype=torch.long), self._image_suffix]
+ )
+ return _ImageRow(input_ids=input_ids, pixel_values=self._patchify(pixels), grid_thw=grid)
+
+ def _patchify(self, pixels: torch.Tensor) -> torch.Tensor:
+ """uint8 [C, H, W] -> normalized patches [H/p * W/p, C * T * p * p] in merge-block order."""
+ channel, height, width = pixels.shape
+ patch, merge, temporal = self._patch_size, self._merge_size, self._temporal_patch_size
+ grid_h, grid_w = height // patch, width // patch
+ patches = pixels.unsqueeze(0).expand(temporal, channel, height, width)
+ patches = patches.reshape(temporal, channel, grid_h // merge, merge, patch, grid_w // merge, merge, patch)
+ patches = patches.permute(2, 5, 3, 6, 1, 0, 4, 7)
+ flat = patches.reshape(grid_h * grid_w, channel * temporal * patch * patch)
+ # Normalized in the weight dtype, as the reference does.
+ return flat.to(self._dtype).mul_(self._pixel_scale).add_(self._pixel_bias)
+
+ def _grid_inputs(self, thw: tuple[int, int, int]) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
+ """Bilinear position-embedding indices and weights, and rotary (row, col) per patch."""
+ cached = self._grid_cache.get(thw)
+ if cached is not None:
+ self._grid_cache.move_to_end(thw)
+ return cached
+ t, h, w = thw
+ merge, side = self._merge_size, self._num_grid_per_side
+ h_idxs, w_idxs = torch.linspace(0, side - 1, h), torch.linspace(0, side - 1, w)
+ h_floor, w_floor = h_idxs.int(), w_idxs.int()
+ h_ceil, w_ceil = (h_floor + 1).clip(max=side - 1), (w_floor + 1).clip(max=side - 1)
+ dh, dw = h_idxs - h_floor, w_idxs - w_floor
+ index = torch.stack(
+ [
+ ((h_floor * side)[:, None] + w_floor[None]).flatten(),
+ ((h_floor * side)[:, None] + w_ceil[None]).flatten(),
+ ((h_ceil * side)[:, None] + w_floor[None]).flatten(),
+ ((h_ceil * side)[:, None] + w_ceil[None]).flatten(),
+ ]
+ ).to(torch.int64)
+ weight = torch.stack(
+ [
+ ((1 - dh)[:, None] * (1 - dw)[None]).flatten(),
+ ((1 - dh)[:, None] * dw[None]).flatten(),
+ (dh[:, None] * (1 - dw)[None]).flatten(),
+ (dh[:, None] * dw[None]).flatten(),
+ ]
+ )
+ perm = torch.arange(t * h * w).view(t, h // merge, merge, w // merge, merge).permute(0, 1, 3, 2, 4).reshape(
+ -1
+ ) % (h * w)
+ row = (
+ (torch.arange(h // merge)[:, None, None, None] * merge + torch.arange(merge)[None, None, :, None])
+ .expand(h // merge, w // merge, merge, merge)
+ .reshape(-1)
+ )
+ col = (
+ (torch.arange(w // merge)[None, :, None, None] * merge + torch.arange(merge)[None, None, None, :])
+ .expand(h // merge, w // merge, merge, merge)
+ .reshape(-1)
+ )
+ entry = (index[:, perm], weight[:, perm].to(self._dtype), torch.stack((row, col), dim=-1).repeat(t, 1))
+ if len(self._grid_cache) >= _GRID_CACHE_SIZE:
+ self._grid_cache.popitem(last=False)
+ self._grid_cache[thw] = entry
+ return entry
+
+ def _image_position_ids(self, images: list[_ImageRow], width: int) -> torch.Tensor:
+ """3D (temporal, height, width) rotary positions per row, right-padded to ``width``."""
+ prefix = len(self._image_prefix)
+ positions = torch.zeros((3, len(images), width), dtype=torch.long)
+ for i, row in enumerate(images):
+ within = torch.arange(len(row.input_ids))
+ grid_h, grid_w = row.grid_thw[1] // self._merge_size, row.grid_thw[2] // self._merge_size
+ count = grid_h * grid_w
+ image = (within >= prefix) & (within < prefix + count)
+ j = within - prefix
+ # Text after the image resumes at prefix + max(grid_h, grid_w).
+ sequential = within + torch.where(within >= prefix + count, max(grid_h, grid_w) - count, 0)
+ positions[0, i, : len(within)] = torch.where(image, torch.full_like(within, prefix), sequential)
+ positions[1, i, : len(within)] = torch.where(image, prefix + j // grid_w, sequential)
+ positions[2, i, : len(within)] = torch.where(image, prefix + j % grid_w, sequential)
+ return positions
+
+ # ------------------------------------------------------------------
+ # Scoring
+ # ------------------------------------------------------------------
+
+ def score(
+ self,
+ query: Item,
+ items: list[Item],
+ *,
+ instruction: str | None = None,
+ options: dict[str, Any] | None = None,
+ ) -> list[float]:
+ """Score documents (text or page images) against a text query with MaxSim."""
+ self._check_loaded()
+ # MaxSim runs here on the host in float32, whatever the response dtype.
+ options = {key: value for key, value in (options or {}).items() if key != "output_dtype"}
+ query_output = self.encode([query], ["multivector"], instruction=instruction, is_query=True, options=options)
+ doc_output = self.encode(items, ["multivector"], instruction=instruction, is_query=False, options=options)
+ if query_output.multivector is None or doc_output.multivector is None:
+ raise RuntimeError("TopkEmbedAdapter: encode returned no multivector output")
+ query_tensor = torch.from_numpy(query_output.multivector[0])
+ return maxsim_scores_batched(query_tensor, [torch.from_numpy(doc) for doc in doc_output.multivector])
+
+ def score_pairs(
+ self,
+ queries: list[Item],
+ docs: list[Item],
+ *,
+ instruction: str | None = None,
+ options: dict[str, Any] | None = None,
+ ) -> ScoreOutput:
+ def score_with_options(query: Item, items: list[Item], *, instruction: str | None = None) -> list[float]:
+ return self.score(query, items, instruction=instruction, options=options)
+
+ return grouped_score_pairs(score_with_options, queries, docs, instruction=instruction)
+
+ # ------------------------------------------------------------------
+ # Metering and pipeline hooks
+ # ------------------------------------------------------------------
+
+ def count_input_tokens(self, items: list[Item]) -> list[int] | None:
+ """Per-item text-token counts that survive a mixed text and image batch.
+
+ Image items run the vision tower (billed through ``images``) and count 0
+ text tokens, like ``qwen3_vl_embedding``.
+ """
+ tokenizer = self._metering_tokenizer()
+ if tokenizer is None:
+ return None
+ positions = [i for i, item in enumerate(items) if not item.images and isinstance(item.text, str)]
+ counts = [0] * len(items)
+ if not positions:
+ return counts
+ with self._tokenizer_guard():
+ measured = self._token_counts_or_none(
+ tokenizer, [items[i].text or "" for i in positions], expected_len=len(positions)
+ )
+ if measured is None:
+ return None
+ for i, count in zip(positions, measured, strict=True):
+ counts[i] = count
+ return counts
+
+ def _metering_max_length(self) -> int | None:
+ return self._doc_max_length
+
+ def unload(self) -> None:
+ with self._preprocess_pool_lock:
+ pool, self._preprocess_pool = self._preprocess_pool, None
+ if pool is not None:
+ pool.shutdown(wait=False)
+ if self._graphs is not None:
+ self._graphs.clear()
+ self._graphs = None
+ self._packed_text = None
+ super().unload()
+
+ def get_postprocessors(self) -> dict[str, Any]:
+ """Return the configured MUVERA multivector-to-dense postprocessor."""
+ config = MuveraConfig(**self._muvera_config) if self._muvera_config else MuveraConfig()
+ return {"muvera": MuveraPostprocessor(token_dim=self._multivector_dim or 1024, config=config)}
+
+ def get_preprocessor(self) -> Any:
+ # The adapter owns tokenization and image preprocessing. The base
+ # CharCountPreprocessor (cost-only) keeps text requests on the batched
+ # ModelWorker path; image batches reach the worker through the pipeline's
+ # passthrough (ColQwen3 does the same).
+ return super().get_preprocessor()
+
+
+def smart_resize(height: int, width: int, *, factor: int, min_pixels: int, max_pixels: int) -> tuple[int, int]:
+ """Qwen2-VL ``smart_resize`` (transformers 5.9): sides divisible by ``factor``, area in bounds."""
+ if max(height, width) / min(height, width) > 200:
+ msg = f"absolute aspect ratio must be smaller than 200, got {max(height, width) / min(height, width)}"
+ raise InvalidInputError(msg)
+ h_bar = round(height / factor) * factor
+ w_bar = round(width / factor) * factor
+ if h_bar * w_bar > max_pixels:
+ beta = math.sqrt((height * width) / max_pixels)
+ h_bar = max(factor, math.floor(height / beta / factor) * factor)
+ w_bar = max(factor, math.floor(width / beta / factor) * factor)
+ elif h_bar * w_bar < min_pixels:
+ beta = math.sqrt(min_pixels / (height * width))
+ h_bar = math.ceil(height * beta / factor) * factor
+ w_bar = math.ceil(width * beta / factor) * factor
+ return h_bar, w_bar
+
+
+def _vision_attention(
+ attn: Any,
+ hidden: torch.Tensor,
+ cos: torch.Tensor,
+ sin: torch.Tensor,
+ *,
+ pad_index: torch.Tensor,
+ key_mask: torch.Tensor,
+ max_len: int,
+) -> torch.Tensor:
+ """One vision attention layer over packed patches, attending only within each image."""
+ seq_length = hidden.shape[0]
+ query, key, value = attn.qkv(hidden).reshape(seq_length, 3, attn.num_heads, -1).permute(1, 0, 2, 3).unbind(0)
+ query, key = _apply_rotary_pos_emb_vision(query, key, cos, sin)
+ n_images = key_mask.shape[0]
+
+ def padded(x: torch.Tensor) -> torch.Tensor:
+ out = x.new_zeros((n_images * max_len, *x.shape[1:]))
+ out.index_copy_(0, pad_index, x)
+ return out.view(n_images, max_len, *x.shape[1:]).transpose(1, 2)
+
+ out = F.scaled_dot_product_attention(padded(query), padded(key), padded(value), attn_mask=key_mask)
+ out = out.transpose(1, 2)
+ out = out.reshape(-1, *out.shape[2:]).index_select(0, pad_index)
+ return attn.proj(out.reshape(seq_length, -1))
+
+
+def _apply_rotary_pos_emb_vision(
+ query: torch.Tensor, key: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor
+) -> tuple[torch.Tensor, torch.Tensor]:
+ """Rotate in float32 and return the input dtype, as transformers' ``apply_rotary_pos_emb_vision`` does.
+
+ On CUDA one fused kernel does it with bit-identical results (``vision_rotary.py``).
+ """
+ if vision_rotary.available(query):
+ return vision_rotary.rotate(query, cos, sin), vision_rotary.rotate(key, cos, sin)
+ q, k = query.float(), key.float()
+ cos, sin = cos.unsqueeze(-2).float(), sin.unsqueeze(-2).float()
+ q_embed = (q * cos) + (_rotate_half(q) * sin)
+ k_embed = (k * cos) + (_rotate_half(k) * sin)
+ return q_embed.to(query.dtype), k_embed.to(key.dtype)
+
+
+def _rotate_half(x: torch.Tensor) -> torch.Tensor:
+ x1 = x[..., : x.shape[-1] // 2]
+ x2 = x[..., x.shape[-1] // 2 :]
+ return torch.cat((-x2, x1), dim=-1)
+
+
+def _warmup_page() -> ImageInput:
+ """A small blank page: its size does not matter to the kernels the warm-up compiles."""
+ from PIL import Image
+
+ buffer = io.BytesIO()
+ Image.new("RGB", (256, 256), "white").save(buffer, "PNG")
+ return ImageInput(data=buffer.getvalue(), format="png")
diff --git a/packages/sie_server/src/sie_server/adapters/topk_embed/graphs.py b/packages/sie_server/src/sie_server/adapters/topk_embed/graphs.py
new file mode 100644
index 000000000..b886ee119
--- /dev/null
+++ b/packages/sie_server/src/sie_server/adapters/topk_embed/graphs.py
@@ -0,0 +1,466 @@
+"""CUDA graphs for TopK-Embed-V1's small text batches.
+
+A forward over a few short inputs (one query, a handful of queries) launches about
+a thousand small kernels, so the GPU waits on the CPU that launches them. A CUDA
+graph records the launches of one input shape once and replays them with a single
+call.
+
+Graphs are an operator setting, fixed when the model loads
+(``adapter_options.loadtime.cuda_graphs``: ``off`` or ``bucketed``). They apply on
+the packed CUDA path only (flash-linear-attention installed); images and anything
+larger than a graph run packed and eagerly, as before.
+
+What a graph holds. The embedding lookup and the backbone, in the ``Padded``
+layout of ``packed.py``: every input is its own row, right-padded to the graph's
+length. The Gated DeltaNet layers read each row left to right, so padding after
+an input never reaches it, and attention masks the padded keys, so a replay gives
+each input the hidden states the packed forward gives it, up to kernel rounding.
+The head and normalisation run eagerly on the replayed hidden states.
+
+Shapes (``bucketed``). A graph's length is the longest input rounded up: to a
+multiple of 16 tokens up to 128, of 64 up to 512, of 256 past that. Its rows are
+the batch rounded up to a power of two, or to the most rows that fit the token
+bound at that length. A graph holds at most ``max_tokens`` tokens (rows times
+length): by default 2,048 at a hidden size of 768 and proportionally fewer for
+wider models (1,536 for the 0.8B model, 768 for the 2B). Past about that, the GPU,
+not kernel launches, bounds a forward.
+
+Recording follows the GLiClass runner's rules. One recording at a time in the
+process (``sie_server.adapters._cuda_graphs``, shared with the GLiClass and ModernBERT
+runners); none while less than a tenth
+of the device's memory is free; at most 16 recordings at once, then one per 2
+seconds; the graphs' memory is held to 4% of the device's, past which the shapes
+not yet recorded run eagerly. A shape that fails to record runs eagerly from then
+on, and after three such shapes graphs turn off for the process. Running out of
+memory while recording drops every graph and pauses recording for a minute. The
+forward that records a graph is answered by its first replay. Graphs share one
+memory pool and one hidden-state buffer sized for the token bound; replays never
+overlap (the adapter's forward lock), and each replay's hidden states are read
+before the next.
+"""
+
+from __future__ import annotations
+
+import contextlib
+import logging
+import math
+import time
+from collections.abc import Callable
+from dataclasses import dataclass, field
+from typing import Any, Literal
+
+import torch
+
+from sie_server.adapters._cuda_graphs import MEMORY_BUDGET_SHARE, RECORDING_HEADROOM, RECORDING_LOCK
+from sie_server.adapters.topk_embed.packed import PackedTextModel, Padded
+from sie_server.core.oom import is_oom_error
+
+logger = logging.getLogger(__name__)
+
+GraphMode = Literal["off", "bucketed"]
+GRAPH_MODES: tuple[GraphMode, ...] = ("off", "bucketed")
+# A graph of a model with this hidden size holds this many tokens; wider models
+# spend proportionally more GPU time per token, so their graphs hold fewer.
+_BASE_GRAPH_TOKENS = 2048
+_BASE_HIDDEN_SIZE = 768
+# Length buckets: (up to this length, round up to a multiple of this).
+_LENGTH_STEPS = ((128, 16), (512, 64))
+_LONG_LENGTH_STEP = 256
+# A runner may record this many graphs at once, then one per this many seconds.
+_RECORDING_BURST = 16
+_SECONDS_PER_RECORDING = 2.0
+# After a recording runs out of memory, the runner records nothing for this long.
+_OOM_COOL_DOWN_SECONDS = 60.0
+# Shapes that may fail to record, for reasons other than memory, before graphs turn off.
+_MAX_RECORDING_FAILURES = 3
+# A runner serving forwards logs its counters this often.
+_SUMMARY_SECONDS = 600.0
+
+# (rows, padded length)
+Key = tuple[int, int]
+# Why a forward the runner was offered ran eagerly.
+EagerReason = Literal[
+ "too_large", # past the token bound
+ "disabled", # graphs turned off for the process after recording failures
+ "failed_shape", # the shape failed to record before
+ "budget_full", # the memory budget holds no more graphs
+ "recording_paused", # out of recording credit, or cooling down after an out-of-memory error
+ "no_headroom", # too little free device memory to record
+ "busy", # another model's runner is recording
+ "recording_failed", # this forward's recording failed
+]
+
+
+def default_max_tokens(hidden_size: int) -> int:
+ """Tokens a graph holds by default for a model with this hidden size (a multiple of 16)."""
+ tokens = _BASE_GRAPH_TOKENS * _BASE_HIDDEN_SIZE // max(hidden_size, _BASE_HIDDEN_SIZE)
+ return max(16, tokens // 16 * 16)
+
+
+def bucket_length(length: int) -> int:
+ """A graph's padded length for inputs up to ``length`` tokens."""
+ for limit, step in _LENGTH_STEPS:
+ if length <= limit:
+ return max(step, math.ceil(length / step) * step)
+ return math.ceil(length / _LONG_LENGTH_STEP) * _LONG_LENGTH_STEP
+
+
+def row_buckets(length: int, max_tokens: int) -> tuple[int, ...]:
+ """Row counts of the graphs of this padded length: powers of two, and the most that fit."""
+ largest = max_tokens // length
+ sizes = [1 << power for power in range(largest.bit_length())]
+ if largest and sizes[-1] != largest:
+ sizes.append(largest)
+ return tuple(sizes)
+
+
+def graph_key(rows: int, length: int, max_tokens: int) -> Key | None:
+ """The graph a batch of ``rows`` inputs, the longest ``length`` tokens, replays; None when too large."""
+ padded = bucket_length(length)
+ size = next((size for size in row_buckets(padded, max_tokens) if size >= rows), None)
+ return None if size is None else (size, padded)
+
+
+def bucketed_shapes(max_tokens: int) -> frozenset[Key]:
+ """Every shape a runner with this token bound can record."""
+ lengths = {bucket_length(length) for length in range(1, max_tokens + 1)}
+ return frozenset((rows, length) for length in lengths for rows in row_buckets(length, max_tokens))
+
+
+@dataclass
+class GraphStats:
+ """Counters of the forwards a runner was offered since the model loaded.
+
+ Each forward counts once: ``replayed`` (a recorded graph served it),
+ ``recorded`` (it recorded a graph and was answered by the first replay), or
+ under ``eager`` by why it ran eagerly. ``recording_failures`` counts shapes that
+ failed to record for reasons other than memory; ``drops`` counts the times every
+ graph was dropped.
+ """
+
+ replayed: int = 0
+ recorded: int = 0
+ eager: dict[str, int] = field(default_factory=dict)
+ recording_failures: int = 0
+ drops: int = 0
+
+ @property
+ def forwards(self) -> int:
+ return self.replayed + self.recorded + sum(self.eager.values())
+
+
+class _RecordingOutOfMemoryError(Exception):
+ """Recording a graph ran out of device memory."""
+
+
+@dataclass
+class _Graph:
+ graph: Any
+ input_ids: torch.Tensor
+ mask: torch.Tensor
+ # Device memory the recording took: pool growth and the recorded graph.
+ device_bytes: int = 0
+
+
+class GraphRunner:
+ """Records and replays TopK-Embed's embeddings and backbone per (rows, padded length)."""
+
+ def __init__(
+ self,
+ text_model: PackedTextModel,
+ embed: Any,
+ *,
+ pad_token_id: int,
+ max_tokens: int,
+ name: str = "",
+ clock: Callable[[], float] = time.monotonic,
+ ) -> None:
+ self._text_model = text_model
+ self._embed = embed
+ self._pad_token_id = pad_token_id
+ self._max_tokens = max_tokens
+ self._name = name
+ self._clock = clock
+ self._hidden_size = int(embed.weight.shape[1])
+ self._dtype = embed.weight.dtype
+ self._graphs: dict[Key, _Graph] = {}
+ self._failed: set[Key] = set()
+ self._disabled = False
+ # Set when the memory budget holds no more graphs.
+ self._full = False
+ self._device_bytes = 0
+ self._recording_credit = float(_RECORDING_BURST)
+ self._credited_at = clock()
+ self._pool: Any = None
+ self._stream: Any = None
+ # The hidden states every graph writes, sized for the token bound.
+ self._hidden: torch.Tensor | None = None
+ self.stats = GraphStats()
+ self._summary_at = clock()
+ self._summary_forwards = 0
+ self._summary_replayed = 0
+
+ @property
+ def max_tokens(self) -> int:
+ return self._max_tokens
+
+ @property
+ def graph_count(self) -> int:
+ return len(self._graphs)
+
+ @property
+ def disabled(self) -> bool:
+ return self._disabled
+
+ @property
+ def held_bytes(self) -> int:
+ """Device memory the runner counts against its budget."""
+ buffers = sum(entry.input_ids.nbytes + entry.mask.nbytes for entry in self._graphs.values())
+ hidden = self._hidden.nbytes if self._hidden is not None else 0
+ return self._device_bytes + buffers + hidden
+
+ # -- entry point -------------------------------------------------------
+
+ def run(self, rows: list[torch.Tensor]) -> torch.Tensor | None:
+ """Hidden states for token-id ``rows`` from a graph, or None to run them eagerly.
+
+ The result is ``[len(rows), L, H]``: each input right-padded to the graph's
+ length ``L``. It is a view of the runner's shared buffer, so read it before
+ the next ``run``.
+ """
+ hidden, reason = self._run(rows)
+ if reason is not None:
+ self.stats.eager[reason] = self.stats.eager.get(reason, 0) + 1
+ self._log_summary()
+ return hidden
+
+ def _run(self, rows: list[torch.Tensor]) -> tuple[torch.Tensor | None, EagerReason | None]:
+ if self._disabled:
+ return None, "disabled"
+ key = graph_key(len(rows), max(len(row) for row in rows), self._max_tokens)
+ if key is None:
+ return None, "too_large"
+ now = self._clock()
+ elapsed, self._credited_at = now - self._credited_at, now
+ self._recording_credit = min(float(_RECORDING_BURST), self._recording_credit + elapsed / _SECONDS_PER_RECORDING)
+ entry = self._graphs.get(key)
+ if entry is not None:
+ self.stats.replayed += 1
+ return self._replay(key, entry, rows), None
+ reason = self._why_not_record(key)
+ if reason is not None:
+ return None, reason
+ if not RECORDING_LOCK.acquire(blocking=False):
+ return None, "busy" # another model is recording
+ try:
+ self._recording_credit -= 1
+ try:
+ entry = self._record(key)
+ except Exception as exc: # noqa: BLE001 -- any failure to record runs the forward eagerly
+ self._recording_failed(key, exc)
+ return None, "recording_failed"
+ # The graph answers the forward that recorded it. Its first replay is
+ # part of recording it: a failure other than memory runs the forward
+ # eagerly and the graph is not kept.
+ try:
+ hidden = self._replay(key, entry, rows)
+ except Exception as exc:
+ if is_oom_error(exc):
+ raise
+ self._recording_failed(key, exc)
+ return None, "recording_failed"
+ self._keep(key, entry)
+ self.stats.recorded += 1
+ finally:
+ RECORDING_LOCK.release()
+ return hidden, None
+
+ def _why_not_record(self, key: Key) -> EagerReason | None:
+ if key in self._failed:
+ return "failed_shape"
+ if self._full:
+ return "budget_full"
+ if self._recording_credit < 1:
+ return "recording_paused"
+ if self._free_memory() < RECORDING_HEADROOM * self._total_memory():
+ return "no_headroom"
+ return None
+
+ def _keep(self, key: Key, entry: _Graph) -> None:
+ """Cache a new graph; past the memory budget, record no more (the shapes are a fixed set)."""
+ self._graphs[key] = entry
+ self._device_bytes += entry.device_bytes
+ held = self.held_bytes
+ if held > MEMORY_BUDGET_SHARE * self._total_memory():
+ self._full = True
+ logger.warning(
+ "TopK-Embed CUDA graphs for %s took %d MB, their memory budget, with %d graphs recorded; "
+ "the other shapes run eagerly",
+ self._name,
+ held // 2**20,
+ len(self._graphs),
+ )
+
+ def _recording_failed(self, key: Key, exc: BaseException) -> None:
+ if isinstance(exc, _RecordingOutOfMemoryError) or is_oom_error(exc):
+ # Release the graphs; the forward runs eagerly, and recording pauses.
+ self.clear()
+ self.stats.drops += 1
+ self._recording_credit = 1 - _OOM_COOL_DOWN_SECONDS / _SECONDS_PER_RECORDING
+ logger.info(
+ "TopK-Embed CUDA graph recording for %s ran out of memory; graphs dropped, recording paused for %d s",
+ self._name,
+ _OOM_COOL_DOWN_SECONDS,
+ )
+ return
+ self._failed.add(key)
+ self.stats.recording_failures += 1
+ logger.warning(
+ "TopK-Embed CUDA graph recording for %s failed for %d rows of %d tokens; that shape runs eagerly",
+ self._name,
+ key[0],
+ key[1],
+ exc_info=exc,
+ )
+ if len(self._failed) >= _MAX_RECORDING_FAILURES:
+ self._disabled = True
+ self.clear()
+ logger.error(
+ "TopK-Embed CUDA graphs for %s are off for this process after %d shapes failed to record",
+ self._name,
+ len(self._failed),
+ )
+
+ def clear(self) -> None:
+ """Drop every graph and its memory."""
+ self._graphs.clear()
+ self._hidden = None
+ self._pool = None
+ self._device_bytes = 0
+ self._full = False
+
+ def _log_summary(self) -> None:
+ now = self._clock()
+ if now - self._summary_at < _SUMMARY_SECONDS:
+ return
+ stats = self.stats
+ forwards = stats.forwards - self._summary_forwards
+ replayed = stats.replayed - self._summary_replayed
+ interval = now - self._summary_at
+ self._summary_at, self._summary_forwards, self._summary_replayed = now, stats.forwards, stats.replayed
+ if not forwards:
+ return
+ logger.info(
+ "TopK-Embed CUDA graphs for %s: %d forwards in the last %d s, %.1f%% replayed; since load: "
+ "%d replayed, %d recorded, eager %s, %d recording failures, %d drops; %d graphs, %d MB%s",
+ self._name,
+ forwards,
+ round(interval),
+ 100.0 * replayed / forwards,
+ stats.replayed,
+ stats.recorded,
+ dict(sorted(stats.eager.items())),
+ stats.recording_failures,
+ stats.drops,
+ len(self._graphs),
+ self.held_bytes // 2**20,
+ ", off for this process" if self._disabled else "",
+ )
+
+ # -- recording and replay ---------------------------------------------
+
+ def _device(self) -> torch.device:
+ return self._embed.weight.device
+
+ def _free_memory(self) -> int:
+ return torch.cuda.mem_get_info(self._device())[0]
+
+ def _total_memory(self) -> int:
+ return torch.cuda.mem_get_info(self._device())[1]
+
+ def warm_up(self, step: int) -> None:
+ """Run the recorded computation eagerly at each ``step`` of tokens a graph can hold.
+
+ Its kernels are the padded variants of the packed path's, tuned on their own; the
+ adapter's warm-up calls this so a first recording does not tune them.
+ """
+ device = self._embed.weight.device
+ for tokens in range(step, self._max_tokens + step, step):
+ ids = torch.full((1, min(tokens, self._max_tokens)), self._pad_token_id, dtype=torch.long, device=device)
+ self._forward(ids, torch.ones_like(ids, dtype=torch.bool))
+
+ def _forward(self, input_ids: torch.Tensor, mask: torch.Tensor) -> torch.Tensor:
+ """The recorded computation: embeddings and backbone over right-padded rows."""
+ rows, length = input_ids.shape
+ positions = torch.arange(length, device=input_ids.device).view(1, 1, -1).expand(3, rows, -1)
+ return self._text_model(self._embed(input_ids), positions, Padded(mask))
+
+ def _hidden_states(self, key: Key) -> torch.Tensor:
+ """The shared hidden-state buffer, viewed as this shape's ``[rows, length, hidden]`` tensor."""
+ rows, length = key
+ if self._hidden is None:
+ # Recorded graphs write here, so it lives as long as they do: only clear() drops it.
+ self._hidden = torch.empty(self._max_tokens * self._hidden_size, dtype=self._dtype, device=self._device())
+ return self._hidden[: rows * length * self._hidden_size].view(rows, length, self._hidden_size)
+
+ def _record(self, key: Key) -> _Graph:
+ """Record the graph for ``key``; raises ``_RecordingOutOfMemoryError`` when memory runs out."""
+ try:
+ return self._capture(key)
+ except Exception as exc:
+ if is_oom_error(exc):
+ raise _RecordingOutOfMemoryError(str(exc)) from exc
+ raise
+
+ def _capture(self, key: Key) -> _Graph:
+ """Record ``key`` on the runner's own stream, into the runner's memory pool.
+
+ One eager forward of the shape runs on that stream first: Triton compiles and
+ autotunes kernels for new shapes, and the stream's first use creates cuBLAS
+ state, and neither can happen while recording. Recording launches no kernels;
+ the caller replays the graph to answer the forward.
+ """
+ rows, length = key
+ device = self._device()
+ input_ids = torch.full((rows, length), self._pad_token_id, dtype=torch.long, device=device)
+ mask = torch.ones((rows, length), dtype=torch.bool, device=device)
+ hidden = self._hidden_states(key)
+ current = torch.cuda.current_stream(device)
+ stream = self._stream or torch.cuda.Stream(device=device)
+ if self._pool is None:
+ self._pool = torch.cuda.graph_pool_handle()
+ graph = torch.cuda.CUDAGraph()
+ stream.wait_stream(current)
+ try:
+ with torch.inference_mode(), torch.cuda.stream(stream):
+ self._forward(input_ids, mask)
+ self._stream = stream
+ free_before = self._free_memory()
+ graph.capture_begin(pool=self._pool, capture_error_mode="thread_local")
+ try:
+ hidden.copy_(self._forward(input_ids, mask))
+ except BaseException:
+ # End the recording without hiding why it failed.
+ with contextlib.suppress(Exception):
+ graph.capture_end()
+ raise
+ graph.capture_end()
+ device_bytes = max(0, free_before - self._free_memory())
+ finally:
+ current.wait_stream(stream)
+ return _Graph(graph=graph, input_ids=input_ids, mask=mask, device_bytes=device_bytes)
+
+ def _replay(self, key: Key, entry: _Graph, rows: list[torch.Tensor]) -> torch.Tensor:
+ """Replay ``entry`` on ``rows``; the hidden states of the real rows."""
+ size, length = key
+ input_ids = torch.full((size, length), self._pad_token_id, dtype=torch.long)
+ mask = torch.zeros((size, length), dtype=torch.bool)
+ for i, row in enumerate(rows):
+ input_ids[i, : len(row)] = row
+ mask[i, : len(row)] = True
+ # Rows past the batch attend to their first position, so no attention row is empty.
+ mask[len(rows) :, 0] = True
+ entry.input_ids.copy_(input_ids)
+ entry.mask.copy_(mask)
+ entry.graph.replay()
+ return self._hidden_states(key)[: len(rows)]
diff --git a/packages/sie_server/src/sie_server/adapters/topk_embed/packed.py b/packages/sie_server/src/sie_server/adapters/topk_embed/packed.py
new file mode 100644
index 000000000..e4d481156
--- /dev/null
+++ b/packages/sie_server/src/sie_server/adapters/topk_embed/packed.py
@@ -0,0 +1,463 @@
+"""Packed (variable-length) execution for TopK-Embed-V1.
+
+A batch runs as one sequence: the inputs are concatenated with no padding, and
+cumulative sequence lengths (``cu_seqlens``) keep them apart in every layer. This
+is how TopK's own pipeline runs the backbone (``hf_backbone.py`` in the model
+repo), and it avoids the padding the row-per-input path computes on.
+
+On CUDA the kernels are flash-linear-attention's and FlashAttention's:
+
+* the Gated DeltaNet chunked delta rule (decay gate computed in the kernel) and
+ causal conv, both variable-length;
+* FlashAttention's variable-length attention for the full-attention layers;
+* fused RMSNorm (with the residual add), gated RMSNorm and SwiGLU, each one pass
+ over the activations where the stock modules run a chain of float32 element-wise
+ ops. The Gated DeltaNet norm is the one TopK's stack (transformers 5.9 with
+ flash-linear-attention) already fuses.
+
+The reference kernels run the same math in PyTorch, one sequence at a time where a
+kernel mixes positions. They back the CPU tests and are never chosen automatically.
+
+``PackedTextModel`` reuses the loaded ``transformers.models.qwen3_5`` modules'
+weights and mirrors their forward passes, minus the KV cache and padding masks
+that a packed, cache-free encoder does not need. It also runs a fixed-size
+layout, right-padded rows (``Padded``), which is what a CUDA graph records
+(``graphs.py``): the Gated DeltaNet layers read each row left to right, so the
+padding after an input never reaches it, and attention masks the padded keys.
+"""
+
+from __future__ import annotations
+
+import inspect
+import itertools
+import logging
+from collections.abc import Callable, Sequence
+from dataclasses import dataclass, field
+from typing import Any
+
+import torch
+from torch.nn import functional as F
+
+logger = logging.getLogger(__name__)
+
+
+def to_device(tensor: torch.Tensor, device: str | torch.device) -> torch.Tensor:
+ """Copy a host tensor to ``device``; on CUDA from pinned memory, without waiting for queued GPU work."""
+ if torch.device(device).type != "cuda":
+ return tensor.to(device)
+ return tensor.pin_memory().to(device, non_blocking=True)
+
+
+@dataclass(frozen=True)
+class Packing:
+ """Where each input of a packed batch starts and ends.
+
+ ``cu_seqlens`` holds the ``N + 1`` int64 offsets on the model's device;
+ ``cu_seqlens_cpu`` holds the same offsets on the host, so kernels can plan
+ without a device sync; ``cu_seqlens_int32`` is the device copy FlashAttention
+ takes. ``max_len`` is the longest input.
+ """
+
+ cu_seqlens: torch.Tensor
+ cu_seqlens_cpu: torch.Tensor
+ cu_seqlens_int32: torch.Tensor
+ max_len: int
+
+ @classmethod
+ def from_lengths(cls, lengths: Sequence[int], device: str | torch.device) -> Packing:
+ offsets = torch.tensor([0, *itertools.accumulate(lengths)], dtype=torch.long)
+ return cls(
+ cu_seqlens=to_device(offsets, device),
+ cu_seqlens_cpu=offsets,
+ cu_seqlens_int32=to_device(offsets.to(torch.int32), device),
+ max_len=max(lengths),
+ )
+
+ def segments(self) -> list[tuple[int, int]]:
+ """``(start, end)`` of each packed input."""
+ return list(itertools.pairwise(self.cu_seqlens_cpu.tolist()))
+
+
+@dataclass(frozen=True)
+class Padded:
+ """Inputs as rows of one length, each right-padded: ``mask`` is ``[B, L]``, True on real tokens."""
+
+ mask: torch.Tensor
+
+
+Layout = Packing | Padded
+
+
+@dataclass(frozen=True)
+class PackedKernels:
+ """The kernels the packed forward needs.
+
+ Sequence mixers, which see the packing (``packing=None``: every row of the
+ batch is one input, as in the ``Padded`` layout):
+
+ * ``delta_rule(q, k, v, *, a, beta, a_log, dt_bias, packing)`` returns
+ ``[B, T, HV, V]``. The decay is ``-exp(a_log) * softplus(a + dt_bias)`` in
+ float32, as the stock layer computes it.
+ * ``causal_conv(x, weight, bias, activation, packing)`` maps ``[B, T, D]`` to
+ ``[B, T, D]``.
+ * ``attention(q, k, v, packing, scale)`` takes ``[T, H, d]`` queries and
+ ``[T, H_kv, d]`` keys and values of a packed batch (bidirectional).
+
+ Per-token ops, computed in float32 and returned in the input dtype:
+
+ * ``rms_norm(x, scale, eps, residual)`` returns ``(rms(s) * scale, s)`` with
+ ``s = x + residual`` (``s = x`` without a residual).
+ * ``gated_rms_norm(x, gate, weight, eps)`` returns ``rms(x) * weight * silu(gate)``.
+ * ``swiglu(gate, up)`` returns ``silu(gate) * up``.
+ """
+
+ delta_rule: Callable[..., torch.Tensor]
+ causal_conv: Callable[..., torch.Tensor]
+ attention: Callable[..., torch.Tensor]
+ rms_norm: Callable[..., tuple[torch.Tensor, torch.Tensor]]
+ gated_rms_norm: Callable[..., torch.Tensor]
+ swiglu: Callable[..., torch.Tensor]
+ names: dict[str, str] = field(default_factory=dict)
+
+
+def resolve_kernels(device: str, *, mode: bool | None) -> PackedKernels | None:
+ """Pick the packed kernels for ``device``.
+
+ ``mode=None`` (auto) packs only on CUDA with flash-linear-attention importable;
+ otherwise it returns ``None`` and the caller keeps its row-per-input path.
+ ``mode=True`` always packs, with the reference kernels where the fast ones are
+ missing. ``mode=False`` never packs.
+ """
+ if mode is False:
+ return None
+ fast = _fast_kernels() if str(device).startswith("cuda") else None
+ if fast is not None:
+ return fast
+ if mode is None:
+ return None
+ return reference_kernels()
+
+
+def reference_kernels() -> PackedKernels:
+ return PackedKernels(
+ delta_rule=reference_delta_rule,
+ causal_conv=reference_causal_conv,
+ attention=reference_attention,
+ rms_norm=reference_rms_norm,
+ gated_rms_norm=reference_gated_rms_norm,
+ swiglu=reference_swiglu,
+ names={"delta_rule": "reference", "causal_conv": "reference", "attention": "reference", "norms": "reference"},
+ )
+
+
+def _fast_kernels() -> PackedKernels | None:
+ try:
+ from fla.modules.activations import swiglu # ty: ignore[unresolved-import]
+ from fla.modules.convolution import causal_conv1d # ty: ignore[unresolved-import]
+ from fla.modules.fused_norm_gate import rms_norm_gated # ty: ignore[unresolved-import]
+ from fla.modules.layernorm import rms_norm # ty: ignore[unresolved-import]
+ from fla.ops.gated_delta_rule import chunk_gated_delta_rule # ty: ignore[unresolved-import]
+ except Exception: # noqa: BLE001 - fla missing or unusable (no Triton): not packing
+ logger.info("flash-linear-attention unavailable; TopK-Embed keeps the row-per-input path")
+ return None
+
+ def delta_rule(
+ q: torch.Tensor,
+ k: torch.Tensor,
+ v: torch.Tensor,
+ *,
+ a: torch.Tensor,
+ beta: torch.Tensor,
+ a_log: torch.Tensor,
+ dt_bias: torch.Tensor,
+ packing: Packing | None,
+ ) -> torch.Tensor:
+ out, _ = chunk_gated_delta_rule(
+ q,
+ k,
+ v,
+ g=a,
+ beta=beta,
+ initial_state=None,
+ output_final_state=False,
+ use_qk_l2norm_in_kernel=True,
+ use_gate_in_kernel=True,
+ A_log=a_log,
+ dt_bias=dt_bias,
+ **_offsets(packing),
+ )
+ return out
+
+ def causal_conv(
+ x: torch.Tensor,
+ weight: torch.Tensor,
+ bias: torch.Tensor | None,
+ activation: str | None,
+ packing: Packing | None,
+ ) -> torch.Tensor:
+ out, _ = causal_conv1d(x=x, weight=weight, bias=bias, activation=activation, **_offsets(packing))
+ return out
+
+ def fused_rms_norm(
+ x: torch.Tensor, scale: torch.Tensor, eps: float, residual: torch.Tensor | None = None
+ ) -> tuple[torch.Tensor, torch.Tensor]:
+ return rms_norm(x, scale, None, residual=residual, eps=eps, prenorm=True)
+
+ def fused_gated_rms_norm(x: torch.Tensor, gate: torch.Tensor, weight: torch.Tensor, eps: float) -> torch.Tensor:
+ return rms_norm_gated(x, gate, weight, None, activation="swish", eps=eps)
+
+ attention, attention_name = reference_attention, "sdpa per sequence"
+ try:
+ from flash_attn import flash_attn_varlen_func # ty: ignore[unresolved-import]
+
+ def attention(
+ q: torch.Tensor, k: torch.Tensor, v: torch.Tensor, packing: Packing, scale: float
+ ) -> torch.Tensor:
+ cu = packing.cu_seqlens_int32
+ return flash_attn_varlen_func(
+ q, k, v, cu, cu, packing.max_len, packing.max_len, softmax_scale=scale, causal=False
+ )
+
+ attention_name = "flash_attn varlen"
+ except ImportError:
+ logger.info("flash_attn unavailable; TopK-Embed packs attention with per-sequence sdpa")
+ return PackedKernels(
+ delta_rule=delta_rule,
+ causal_conv=causal_conv,
+ attention=attention,
+ rms_norm=fused_rms_norm,
+ gated_rms_norm=fused_gated_rms_norm,
+ swiglu=swiglu,
+ names={"delta_rule": "fla chunk", "causal_conv": "fla", "attention": attention_name, "norms": "fla fused"},
+ )
+
+
+def _offsets(packing: Packing | None) -> dict[str, torch.Tensor]:
+ """Fla's variable-length arguments for ``packing``; none for fixed rows."""
+ if packing is None:
+ return {}
+ return {"cu_seqlens": packing.cu_seqlens, "cu_seqlens_cpu": packing.cu_seqlens_cpu}
+
+
+# ---------------------------------------------------------------------------
+# Reference kernels (PyTorch)
+# ---------------------------------------------------------------------------
+
+
+def reference_delta_rule(
+ q: torch.Tensor,
+ k: torch.Tensor,
+ v: torch.Tensor,
+ *,
+ a: torch.Tensor,
+ beta: torch.Tensor,
+ a_log: torch.Tensor,
+ dt_bias: torch.Tensor,
+ packing: Packing | None,
+) -> torch.Tensor:
+ """The PyTorch chunked delta rule from transformers, run per packed sequence (or per row)."""
+ from transformers.models.qwen3_5 import modeling_qwen3_5 # ty: ignore[unresolved-import]
+
+ rule = inspect.unwrap(modeling_qwen3_5.torch_chunk_gated_delta_rule)
+ g = -a_log.float().exp() * F.softplus(a.float() + dt_bias)
+ spans = packing.segments() if packing is not None else [(0, q.shape[1])]
+ outs = [
+ rule(
+ q[:, s:e],
+ k[:, s:e],
+ v[:, s:e],
+ g=g[:, s:e],
+ beta=beta[:, s:e],
+ initial_state=None,
+ output_final_state=False,
+ use_qk_l2norm_in_kernel=True,
+ )[0]
+ for s, e in spans
+ ]
+ return torch.cat(outs, dim=1)
+
+
+def reference_causal_conv(
+ x: torch.Tensor, weight: torch.Tensor, bias: torch.Tensor | None, activation: str | None, packing: Packing | None
+) -> torch.Tensor:
+ """Depthwise causal conv per packed sequence (or per row): left-pad by ``width - 1``, then activate."""
+ width = weight.shape[-1]
+ outs = []
+ spans = packing.segments() if packing is not None else [(0, x.shape[1])]
+ for s, e in spans:
+ seq = F.pad(x[:, s:e].transpose(1, 2), (width - 1, 0))
+ out = F.conv1d(seq, weight.unsqueeze(1), bias, groups=x.shape[-1])
+ outs.append(F.silu(out) if activation in ("silu", "swish") else out)
+ return torch.cat(outs, dim=2).transpose(1, 2)
+
+
+def reference_attention(
+ q: torch.Tensor, k: torch.Tensor, v: torch.Tensor, packing: Packing, scale: float
+) -> torch.Tensor:
+ """Bidirectional attention per packed sequence (``[T, H, d]`` in and out)."""
+ outs = []
+ for s, e in packing.segments():
+ out = F.scaled_dot_product_attention(
+ q[s:e].transpose(0, 1).unsqueeze(0),
+ k[s:e].transpose(0, 1).unsqueeze(0),
+ v[s:e].transpose(0, 1).unsqueeze(0),
+ scale=scale,
+ enable_gqa=True,
+ )
+ outs.append(out[0].transpose(0, 1))
+ return torch.cat(outs, dim=0)
+
+
+def padded_attention(
+ q: torch.Tensor, k: torch.Tensor, v: torch.Tensor, mask: torch.Tensor, scale: float
+) -> torch.Tensor:
+ """Bidirectional attention over right-padded rows (``[B, H, L, d]``); padded keys are masked.
+
+ Keys and values repeat to the query heads rather than using sdpa's grouped-query
+ mode, which not every sdpa backend takes together with a mask.
+ """
+ repeats = q.shape[1] // k.shape[1]
+ if repeats > 1:
+ k = k.repeat_interleave(repeats, dim=1)
+ v = v.repeat_interleave(repeats, dim=1)
+ return F.scaled_dot_product_attention(q, k, v, attn_mask=mask[:, None, None, :], scale=scale)
+
+
+def reference_rms_norm(
+ x: torch.Tensor, scale: torch.Tensor, eps: float, residual: torch.Tensor | None = None
+) -> tuple[torch.Tensor, torch.Tensor]:
+ """RMSNorm of ``x + residual``, summed and normalised in float32 as the fused kernel does."""
+ total = x.float() if residual is None else x.float() + residual.float()
+ normed = total * torch.rsqrt(total.pow(2).mean(-1, keepdim=True) + eps) * scale
+ return normed.to(x.dtype), x if residual is None else total.to(residual.dtype)
+
+
+def reference_gated_rms_norm(x: torch.Tensor, gate: torch.Tensor, weight: torch.Tensor, eps: float) -> torch.Tensor:
+ """``rms(x) * weight * silu(gate)`` in float32 (flash-linear-attention's ``FusedRMSNormGated``)."""
+ xf = x.float()
+ normed = xf * torch.rsqrt(xf.pow(2).mean(-1, keepdim=True) + eps) * weight.float()
+ return (normed * F.silu(gate.float())).to(x.dtype)
+
+
+def reference_swiglu(gate: torch.Tensor, up: torch.Tensor) -> torch.Tensor:
+ """``silu(gate) * up`` in float32."""
+ return (F.silu(gate.float()) * up.float()).to(gate.dtype)
+
+
+# ---------------------------------------------------------------------------
+# Packed forward over the stock Qwen3.5 modules
+# ---------------------------------------------------------------------------
+
+
+class PackedTextModel:
+ """``Qwen3_5TextModel.forward`` over one packed sequence, on the loaded model's weights.
+
+ Each RMSNorm also performs the residual add that precedes it. The residual stream
+ is summed in float32 and stored in the model dtype, which rounds it exactly as
+ the stock bf16 add does; only the normalised values skip that rounding.
+ """
+
+ def __init__(self, language_model: Any, kernels: PackedKernels) -> None:
+ if language_model.config.hidden_act not in ("silu", "swish"):
+ msg = f"packed TopK-Embed needs a SiLU MLP, got {language_model.config.hidden_act!r}"
+ raise ValueError(msg)
+ self.model = language_model
+ self.kernels = kernels
+ self.layers = list(language_model.layers[: language_model.config.num_hidden_layers])
+ # Qwen3.5's RMSNorm multiplies by ``1 + weight`` in float32; the kernels take that factor.
+ norms = [language_model.norm]
+ for layer in self.layers:
+ norms += [layer.input_layernorm, layer.post_attention_layernorm]
+ if hasattr(layer, "self_attn"):
+ norms += [layer.self_attn.q_norm, layer.self_attn.k_norm]
+ self._scales = {norm: 1.0 + norm.weight.detach().float() for norm in norms}
+
+ def __call__(self, embeds: torch.Tensor, position_ids: torch.Tensor, layout: Layout) -> torch.Tensor:
+ """Final hidden states ``[B, T, H]`` for ``embeds`` ``[B, T, H]``.
+
+ With ``Packing``, ``B`` is 1 and the inputs are packed along ``T``; with
+ ``Padded``, each of the ``B`` rows is one right-padded input. ``position_ids``
+ are ``[3, B, T]`` (temporal, height, width), restarting per input.
+ """
+ position_embeddings = self.model.rotary_emb(embeds, position_ids)
+ packing = layout if isinstance(layout, Packing) else None
+ hidden, residual = embeds, None
+ for layer in self.layers:
+ normed, residual = self._norm(layer.input_layernorm, hidden, residual)
+ if hasattr(layer, "linear_attn"):
+ hidden = self._gated_delta_net(layer.linear_attn, normed, packing)
+ else:
+ hidden = self._attention(layer.self_attn, normed, position_embeddings, layout)
+ normed, residual = self._norm(layer.post_attention_layernorm, hidden, residual)
+ hidden = self._mlp(layer.mlp, normed)
+ return self._norm(self.model.norm, hidden, residual)[0]
+
+ def _norm(
+ self, norm: Any, x: torch.Tensor, residual: torch.Tensor | None = None
+ ) -> tuple[torch.Tensor, torch.Tensor]:
+ return self.kernels.rms_norm(x, self._scales[norm], norm.eps, residual)
+
+ def _gated_delta_net(self, attn: Any, hidden: torch.Tensor, packing: Packing | None) -> torch.Tensor:
+ """``Qwen3_5GatedDeltaNet.forward`` without the cache."""
+ batch, length, _ = hidden.shape
+ mixed = attn.in_proj_qkv(hidden)
+ z = attn.in_proj_z(hidden)
+ b = attn.in_proj_b(hidden)
+ a = attn.in_proj_a(hidden)
+ mixed = self.kernels.causal_conv(
+ mixed, attn.conv1d.weight.squeeze(1), attn.conv1d.bias, attn.activation, packing
+ )
+ query, key, value = torch.split(mixed, [attn.key_dim, attn.key_dim, attn.value_dim], dim=-1)
+ query = query.reshape(batch, length, -1, attn.head_k_dim)
+ key = key.reshape(batch, length, -1, attn.head_k_dim)
+ value = value.reshape(batch, length, -1, attn.head_v_dim)
+ repeats = attn.num_v_heads // attn.num_k_heads
+ if repeats > 1:
+ query = query.repeat_interleave(repeats, dim=2)
+ key = key.repeat_interleave(repeats, dim=2)
+ out = self.kernels.delta_rule(
+ query, key, value, a=a, beta=b.sigmoid(), a_log=attn.A_log, dt_bias=attn.dt_bias, packing=packing
+ )
+ out = self.kernels.gated_rms_norm(
+ out.reshape(-1, attn.head_v_dim),
+ z.reshape(-1, attn.head_v_dim),
+ attn.norm.weight,
+ attn.norm.variance_epsilon,
+ )
+ return attn.out_proj(out.reshape(batch, length, -1))
+
+ def _attention(
+ self,
+ attn: Any,
+ hidden: torch.Tensor,
+ position_embeddings: tuple[torch.Tensor, torch.Tensor],
+ layout: Layout,
+ ) -> torch.Tensor:
+ """``Qwen3_5Attention.forward`` (gated output, partial rotary), bidirectional per input."""
+ from transformers.models.qwen3_5.modeling_qwen3_5 import apply_rotary_pos_emb # ty: ignore[unresolved-import]
+
+ input_shape = hidden.shape[:-1]
+ hidden_shape = (*input_shape, -1, attn.head_dim)
+ query, gate = torch.chunk(attn.q_proj(hidden).view(*input_shape, -1, attn.head_dim * 2), 2, dim=-1)
+ gate = gate.reshape(*input_shape, -1)
+ query = self._norm(attn.q_norm, query.reshape(hidden_shape))[0].transpose(1, 2)
+ key = self._norm(attn.k_norm, attn.k_proj(hidden).view(hidden_shape))[0].transpose(1, 2)
+ value = attn.v_proj(hidden).view(hidden_shape).transpose(1, 2)
+ cos, sin = position_embeddings
+ query, key = apply_rotary_pos_emb(query, key, cos, sin)
+ if isinstance(layout, Packing):
+ out = self.kernels.attention(
+ query[0].transpose(0, 1).contiguous(),
+ key[0].transpose(0, 1).contiguous(),
+ value[0].transpose(0, 1).contiguous(),
+ layout,
+ attn.scaling,
+ )
+ else:
+ out = padded_attention(query, key, value, layout.mask, attn.scaling).transpose(1, 2)
+ out = out.reshape(*input_shape, -1) * torch.sigmoid(gate)
+ return attn.o_proj(out)
+
+ def _mlp(self, mlp: Any, hidden: torch.Tensor) -> torch.Tensor:
+ """``Qwen3_5MLP.forward``: ``down(silu(gate(x)) * up(x))``."""
+ return mlp.down_proj(self.kernels.swiglu(mlp.gate_proj(hidden), mlp.up_proj(hidden)))
diff --git a/packages/sie_server/src/sie_server/adapters/topk_embed/vision_rotary.py b/packages/sie_server/src/sie_server/adapters/topk_embed/vision_rotary.py
new file mode 100644
index 000000000..acfa3cd1d
--- /dev/null
+++ b/packages/sie_server/src/sie_server/adapters/topk_embed/vision_rotary.py
@@ -0,0 +1,74 @@
+"""The vision tower's rotary embedding as one GPU kernel, bit-identical to the PyTorch ops it replaces.
+
+In PyTorch the rotation of a query or key tensor is a chain of element-wise kernels:
+two upcasts to float32, the half rotation (a concatenation), two multiplies, an add and
+a downcast. On a page image (about 5,000 patches) that chain is about a fifth of the
+vision tower's GPU time. The kernel below reads each tensor once and does the same
+three rounded float32 operations per element (``x * cos``, ``rotate_half(x) * sin``,
+their sum), then rounds to the input dtype. Fused multiply-add is turned off, so the
+compiler cannot merge a multiply and the add into one rounding: the result is
+bit-identical to the PyTorch chain, and the page vectors cannot move.
+
+Only used on CUDA with Triton importable; anything else keeps the PyTorch chain.
+"""
+
+from __future__ import annotations
+
+from typing import Any
+
+import torch
+
+
+def _load_kernel() -> Any:
+ """The jitted kernel, or ``None`` on CPU-only installs (no Triton).
+
+ Typed ``Any``: a Triton kernel takes plain ints for its constexpr parameters, and compiler
+ options such as ``enable_fp_fusion``, at launch, which its Python signature does not describe.
+ """
+ try:
+ from sie_server.adapters.topk_embed._vision_rotary_kernel import rotate_kernel
+ except ImportError: # CPU-only installs: no Triton
+ return None
+ return rotate_kernel
+
+
+_kernel: Any = _load_kernel()
+
+
+def available(tensor: torch.Tensor) -> bool:
+ """Whether the kernel can rotate ``tensor`` (CUDA, Triton importable, an even head size)."""
+ return _kernel is not None and tensor.is_cuda and tensor.shape[-1] % 2 == 0
+
+
+def _next_power_of_2(n: int) -> int:
+ return 1 << (n - 1).bit_length()
+
+
+def rotate(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor) -> torch.Tensor:
+ """Rotate ``x`` (``[tokens, heads, dim]``) by ``cos``/``sin`` (``[tokens, dim]``); same dtype out."""
+ kernel = _kernel
+ if kernel is None:
+ msg = "the fused vision rotary kernel needs Triton"
+ raise RuntimeError(msg)
+ tokens, heads, dim = x.shape
+ if x.stride(-1) != 1:
+ x = x.contiguous()
+ cos, sin = cos.contiguous(), sin.contiguous()
+ out = torch.empty((tokens, heads, dim), dtype=x.dtype, device=x.device)
+ kernel[(tokens,)](
+ x,
+ cos,
+ sin,
+ out,
+ heads,
+ x.stride(0),
+ x.stride(1),
+ cos.stride(0),
+ out.stride(0),
+ out.stride(1),
+ half=dim // 2,
+ block_h=_next_power_of_2(heads),
+ block_d=_next_power_of_2(dim // 2),
+ enable_fp_fusion=False,
+ )
+ return out
diff --git a/packages/sie_server/src/sie_server/bundle_requirements.py b/packages/sie_server/src/sie_server/bundle_requirements.py
index 48b36cf60..4f329db9c 100644
--- a/packages/sie_server/src/sie_server/bundle_requirements.py
+++ b/packages/sie_server/src/sie_server/bundle_requirements.py
@@ -11,7 +11,7 @@ from collections.abc import Mapping
from hashlib import sha256
from typing import cast
-_CUDA_ONLY_PACKAGES = frozenset({"flash-attn", "xformers"})
+_CUDA_ONLY_PACKAGES = frozenset({"fla-core", "flash-attn", "xformers"})
def resolve_bundle_requirements(
diff --git a/packages/sie_server/tests/adapters/goldens/topk_embed/topk-io__topk-embed-v1-small.json b/packages/sie_server/tests/adapters/goldens/topk_embed/topk-io__topk-embed-v1-small.json
new file mode 100644
index 000000000..e62053461
--- /dev/null
+++ b/packages/sie_server/tests/adapters/goldens/topk_embed/topk-io__topk-embed-v1-small.json
@@ -0,0 +1,149 @@
+{
+ "model": "topk-io/topk-embed-v1-small",
+ "revision": "33b15d544d74f29d04cdb97adeb9fd0e52da5fb7",
+ "generated_with": {
+ "pipeline": "sentence_transformers.MultiVectorEncoder + the checkpoint's remote code",
+ "device": "cpu",
+ "kernels": "reference torch/eager stand-ins (see script)",
+ "torch": "2.9.1",
+ "transformers": "5.9.0",
+ "sentence_transformers": "6.0.1",
+ "directions": {
+ "seed": 0,
+ "count": 4,
+ "distribution": "standard normal, unit rows"
+ }
+ },
+ "queries": [
+ {
+ "tokens": 8,
+ "projections": [
+ [-0.02699, -0.04283, 0.01202, -0.01509, -0.03973, -0.05007, 0.00673, -0.02584],
+ [0.01439, 0.03373, 0.00429, 0.01006, 0.02512, 0.01103, -0.02767, 0.00896],
+ [0.0016, -0.00652, -0.02958, -0.0027, 0.0175, -0.00626, 0.01132, -0.0351],
+ [-0.0213, -0.02231, -0.01078, -0.00602, -0.00494, 0.00799, -0.00293, 0.03123]
+ ],
+ "text": "how does photosynthesis work?",
+ "input_ids": [2766, 25, 1204, 1503, 7022, 71163, 944, 30]
+ },
+ {
+ "tokens": 8,
+ "projections": [
+ [-0.02174, -0.01558, -0.0151, -0.01285, -0.00528, -0.001, 0.00342, -0.01144],
+ [0.03733, 0.0329, 0.01582, 0.03212, 0.0293, 0.03348, 0.03011, 0.01697],
+ [-0.04359, -0.02584, -0.04777, -0.03784, -0.03595, -0.02899, -0.0167, -0.03716],
+ [-0.00043, -0.00684, 0.01958, 0.00797, 0.01506, -0.00101, 0.01305, 0.01878]
+ ],
+ "text": " what was the Q3 revenue ",
+ "input_ids": [2766, 25, 1092, 557, 279, 1167, 18, 12585]
+ },
+ {
+ "tokens": 3,
+ "projections": [
+ [-0.02058, -0.03242, -0.0005],
+ [-0.00129, 0.01461, 0.01415],
+ [-0.03071, -0.03895, -0.03602],
+ [0.0059, -0.00526, -0.05022]
+ ],
+ "text": "",
+ "input_ids": [2766, 25, 220]
+ }
+ ],
+ "documents": [
+ {
+ "tokens": 11,
+ "projections": [
+ [-0.03568, -0.01007, -0.01811, 0.00996, 0.00747, -0.00993, 0.008, -0.00207, 0.04088, -0.00841, 0.01341],
+ [0.02132, 0.01922, -0.01014, -0.01817, -0.02688, -0.00727, -0.012, -0.01704, -0.02349, 0.02023, 0.02153],
+ [0.01525, 0.00301, -0.032, 0.03626, -0.01921, -0.02626, -0.0195, -0.03158, -0.0249, -0.01553, -0.00702],
+ [-0.00388, -0.0034, 0.00866, -0.00343, 0.00613, -0.00573, 0.0052, -0.00506, 0.00068, -0.01199, -0.00834]
+ ],
+ "text": "Plants convert light energy into chemical energy stored as glucose.",
+ "input_ids": [7288, 25, 47544, 5335, 3000, 4649, 1083, 11153, 4649, 9476, 430, 32120, 13]
+ },
+ {
+ "tokens": 1,
+ "projections": [
+ [-0.03301],
+ [0.00354],
+ [-0.00595],
+ [0.0071]
+ ],
+ "text": "",
+ "input_ids": [7288, 25]
+ },
+ {
+ "tokens": 9,
+ "projections": [
+ [-0.03138, 0.01174, -0.0122, 0.01463, -0.00717, -0.00056, -0.01608, -0.00127, 0.00389],
+ [0.01087, 0.01016, 0.00917, -0.00266, 0.00633, -0.00395, -0.00138, -0.00566, 0.00804],
+ [0.01363, -0.02788, -0.03287, -0.04225, -0.04108, -0.01209, -0.02909, -0.01988, -0.00435],
+ [0.0017, 0.01617, -0.01273, 0.01806, -0.01171, 0.02461, -0.00143, 0.01, -7e-05]
+ ],
+ "text": "!!! ... ??? --- (( )) <|im_end|> <|endoftext|>",
+ "input_ids": [7288, 25, 31780, 2423, 49591, 12091, 1718, 11644, 220, 248046, 220, 248044]
+ },
+ {
+ "tokens": 221,
+ "projections": [
+ [-0.01236, 0.0145, 0.01696, 0.01221, 0.00101, 0.01472, 0.00882, 0.02336, 0.01444, 0.00716, 0.02104, 0.02207, 0.00544, -0.01062, 0.0442, 0.05152, 0.04153, 0.01558, 0.04874, 0.02087, 0.02473, 0.03034, 0.01287, 0.0202, 0.02602, 0.03827, 0.05534, 0.02805, 0.02108, 0.02243, 0.00526, 0.00606, 0.0644, 0.04818, 0.04178, 0.04404, 0.05164, 0.01806, -0.00197, 0.03392, 0.01385, 0.02568, 0.02883, 0.04668, 0.02537, 0.03766, 0.02304, 0.02252, 0.00525, 0.02231, 0.05241, 0.0508, 0.01694, 0.04832, 0.0515, 0.0221, 0.03145, 0.04766, 0.01675, 0.02893, 0.03242, 0.05162, 0.02938, 0.03711, 0.02243, 0.02548, 0.0076, 0.03087, 0.05312, 0.0542, 0.00293, 0.05384, 0.05234, 0.02522, 0.03195, 0.03892, 0.01811, 0.02737, 0.03321, 0.05243, 0.0308, 0.03427, 0.02498, 0.02897, 0.01243, 0.03512, 0.04789, 0.05168, 0.00446, 0.0436, 0.04802, 0.02191, 0.03216, 0.02693, 0.01808, 0.02823, 0.03193, 0.05363, 0.03439, 0.01019, 0.02763, 0.02778, 0.01322, 0.03032, 0.04494, 0.04872, 0.00456, 0.03867, 0.04678, 0.02154, 0.03128, 0.02018, 0.01717, 0.02476, 0.029, 0.04985, 0.03097, 0.02395, 0.0267, 0.02805, 0.01376, 0.02798, 0.05086, 0.04764, 0.00324, 0.03764, 0.04568, 0.02354, 0.03095, 0.0349, 0.01821, 0.02567, 0.03078, 0.05218, 0.01712, 0.04146, 0.02596, 0.02729, 0.01533, 0.03286, 0.058, 0.04633, 0.00216, 0.05008, 0.04873, 0.02912, 0.03827, 0.02059, 0.01881, 0.02639, 0.03243, 0.05565, 0.0311, 0.05241, 0.02757, 0.02411, 0.01583, 0.03523, 0.06222, 0.04814, 0.00191, 0.03864, 0.04692, 0.02706, 0.04092, 0.03439, 0.02007, 0.02726, 0.03494, 0.05719, 0.02797, 0.04219, 0.03415, 0.04151, 0.0242, 0.0377, 0.05016, 0.04765, 0.00013, 0.03852, 0.04908, 0.02992, 0.04206, 0.01011, 0.01151, 0.02226, 0.0295, 0.03403, 0.0569, 0.0108, 0.01881, 0.03989, 0.03902, 0.02292, 0.03842, 0.03812, 0.04425, 0.00329, 0.02467, 0.03042, 0.04466, 0.02771, 0.02783, 0.03268, 0.03303, 0.0185, 0.02653, 0.03252, 0.05067, 0.02096, 0.02994, 0.03504, 0.05282, 0.02057, 0.034, 0.05159, 0.04713, 0.00154, 0.03001, 0.04819, 0.03961],
+ [0.03985, 0.02473, 0.00997, -0.01365, -0.00957, -0.01979, -0.01675, 0.0028, -0.0205, -0.02895, -0.02161, -0.05305, -0.01143, -0.03049, -0.01076, 0.00054, -0.00387, -0.0301, 0.0134, 0.03337, -0.02439, 0.02826, -0.01288, -0.02673, -0.02325, 0.00426, 0.02615, 0.0073, -0.02189, -0.05318, -0.00929, -0.03119, 0.03467, 0.01605, -0.00239, 0.01219, 0.01992, 0.03508, -0.01584, 0.02822, -0.01703, -0.02902, -0.02034, -0.00683, -0.01646, 0.01491, -0.01504, -0.04852, -0.01279, -0.03143, 0.03493, 0.0167, -0.01339, 0.01625, 0.0246, 0.03341, -0.01034, 0.01658, -0.01638, -0.02772, -0.01501, -0.00606, -0.02303, -0.00017, -0.00741, -0.04341, -0.01452, -0.02647, 0.02922, 0.0194, -0.0006, 0.00802, 0.02055, 0.0337, 0.02268, 0.0048, -0.01716, -0.02564, -0.0176, -0.00609, -0.02564, -0.00694, -0.00865, -0.037, -0.01603, -0.02181, 0.01998, 0.01862, 0.00209, -0.00229, 0.01281, 0.03281, 0.01545, 0.00393, -0.01762, -0.02521, -0.01883, -0.00804, -0.0286, -0.02275, -0.00824, -0.03095, -0.01838, -0.02271, 0.02101, 0.01583, 0.00332, 0.00284, 0.01533, 0.03269, 0.03326, 0.00974, -0.01624, -0.0228, -0.01873, -0.00837, -0.01956, 0.00851, -0.01426, -0.03716, -0.01479, -0.0262, 0.02562, 0.01844, 0.00253, 0.01754, 0.00192, 0.03646, 0.03147, 0.0102, -0.01679, -0.02285, -0.01849, -0.00573, 0.00154, 0.01376, -0.00456, -0.02703, -0.018, -0.02646, 0.0335, 0.01895, 0.00325, 0.01393, 0.01066, 0.03554, 0.03907, -0.00405, -0.01746, -0.02331, -0.01634, -0.01, -0.01298, 0.00848, 0.00276, -0.01029, -0.02041, -0.0257, 0.02377, 0.02185, 0.00654, -0.00805, 0.00189, 0.03044, 0.03209, -0.00147, -0.01992, -0.02029, -0.01432, -0.0148, 0.00291, -0.00677, 0.00559, 0.00487, -0.02511, -0.01936, 0.01591, 0.02182, 0.00414, -0.00996, 0.00205, 0.02963, 0.03384, 0.00203, 0.00769, -0.01935, -0.0205, -0.01732, -0.01578, 0.02088, -0.0171, 0.01194, 0.00218, -0.02187, -0.0112, 0.02076, 0.01867, 0.00757, 0.00861, 0.02079, 0.01725, 0.03197, 0.04457, 0.02656, 0.02841, -0.02081, -0.01853, -0.01911, -0.01154, -0.00164, 0.00479, 0.00348, 0.00595, -0.01993, -0.01861, 0.0172, 0.02055, 0.00647, 0.01459, 0.03637, 0.01084],
+ [0.01358, -0.04975, -0.04501, -0.04768, -0.02133, 0.0034, 0.00087, -0.01132, -0.00256, -0.02167, 0.00387, 0.01943, 0.0134, 0.03299, -0.00962, -0.00403, -0.02298, -0.03198, -0.04549, -0.04547, 0.01169, -0.03146, -0.01803, 0.00553, 0.00695, -0.01548, -0.02971, 0.0125, 0.00726, 0.02358, 0.01876, 0.0258, -0.0444, -0.00819, -0.01865, -0.01047, -0.03995, -0.04684, 0.00569, -0.04815, -0.01583, 0.00619, 0.00276, -0.01201, 0.00607, -0.03219, 0.00636, 0.02384, 0.01769, 0.01722, -0.05691, -0.006, -0.00197, -0.04532, -0.05087, -0.05147, -0.01219, -0.05402, -0.01638, 0.0047, -0.0044, -0.01567, 0.01326, -0.0267, 0.00309, 0.02196, 0.01592, 0.01516, -0.05887, -0.00556, -0.00532, -0.04169, -0.05384, -0.05411, -0.04482, -0.04345, -0.01368, 0.0045, -0.005, -0.01596, 0.01628, -0.02376, 0.00168, 0.02052, 0.01425, 0.01319, -0.06131, -0.00329, -0.00395, -0.03423, -0.0556, -0.05604, -0.04447, -0.07489, -0.01194, 0.00685, -0.00324, -0.01564, -0.00403, -0.01097, 0.00104, 0.01318, 0.0169, 0.01384, -0.04548, -0.00209, -0.00495, -0.06335, -0.04042, -0.05605, -0.04413, -0.08308, -0.01282, 0.00374, -0.00181, -0.01378, 0.00467, 0.01713, 0.00435, 0.02034, 0.01734, 0.0171, -0.05047, -0.00234, -0.00115, -0.07526, -0.03903, -0.05867, -0.05181, -0.07407, -0.01157, 0.00364, -0.00037, -0.01501, -0.01586, -0.02602, -0.0006, 0.01397, 0.01741, 0.01721, -0.06288, -0.00304, -0.00222, -0.07248, -0.05502, -0.06612, -0.05239, -0.07386, -0.01127, 0.00458, -0.00332, -0.01631, -0.00338, -0.02931, -0.00416, -0.00316, 0.01843, 0.01714, -0.06467, -0.00691, -0.0032, -0.07526, -0.0522, -0.06253, -0.05497, -0.0669, -0.00856, 0.00455, -0.00576, -0.01189, -0.02495, -0.01828, -0.00826, -0.01343, 0.0168, 0.01166, -0.05949, -0.01126, 0.00248, -0.06544, -0.04288, -0.05506, -0.0436, -0.04312, -0.06669, -0.00845, 0.00461, -0.00315, -0.01239, -0.01527, -0.00834, -0.01504, -0.01509, 0.01645, 0.00372, -0.0435, -0.01026, -0.00292, -0.04005, -0.06809, -0.04122, -0.04704, -0.04038, -0.03463, -0.03412, -0.00875, 0.00391, 0.00199, -0.00897, -0.01488, 0.01221, -0.00648, -0.01773, 0.01734, 0.0121, -0.04752, -0.00485, -0.00173, -0.04029, -0.04629, -0.0363],
+ [-0.01464, -0.00105, -0.01346, -0.01946, 0.00317, -0.0051, -0.01664, 0.01118, -0.00796, -0.01064, -0.01082, -0.0108, 0.01584, 0.0048, -0.0113, -0.00264, -0.01546, -0.02094, -0.01815, -0.0027, -0.0102, 5e-05, 0.00898, -0.00891, -0.01988, 0.01686, -0.00763, 0.01505, -0.00271, -0.0047, 0.00734, 0.01124, -0.00232, -0.0083, -0.0375, -0.00754, -0.00828, -0.00767, -0.0345, -0.01261, 0.01154, -0.0098, -0.01099, 0.01125, -0.01865, -0.01012, 0.00432, 0.00505, 0.00954, 0.00746, 0.00173, -0.00672, -0.02604, -0.01993, -0.01678, -0.00074, -0.02936, -0.02916, 0.012, -0.0154, -0.00927, 0.00319, -0.00567, -0.03216, 0.00431, 0.00172, 0.00816, -0.00588, -0.00976, -0.00783, -0.03956, -0.03299, -0.0273, -0.00239, -0.01677, -0.02379, 0.0087, -0.01779, -0.00937, -0.00198, 0.00032, -0.02111, 0.00768, 0.00054, 0.01027, -0.01463, -0.01221, -0.00851, -0.04098, -0.0274, -0.02627, -5e-05, -0.00871, -0.00185, 0.00795, -0.01824, -0.00816, -0.00173, -0.01081, -0.00916, 0.00802, -0.00911, 0.01337, -0.01035, -0.01424, -0.00606, -0.04133, -0.00254, -0.01922, -0.00572, -0.01462, -0.01551, 0.00768, -0.01829, -0.00375, 0.00037, -0.01156, 0.02064, 0.0099, 0.00185, 0.01193, -0.00019, -0.0044, -0.00778, -0.04332, -0.0064, -0.0164, -0.00604, -0.00716, -0.03314, 0.00601, -0.01979, -0.00179, -0.00158, -0.03633, -0.00126, 0.01244, -0.00131, 0.01194, -0.00355, 0.00135, -0.00752, -0.04165, -0.03017, -0.02058, -0.01041, -0.00724, -0.03596, 0.00718, -0.01991, -0.00598, -0.00367, -0.02063, -0.0182, 0.01191, -0.01813, 0.00922, -0.00519, -0.01304, -0.00899, -0.0391, -0.03429, -0.0259, -0.01113, -0.00733, -0.03227, 0.00511, -0.02066, -0.00452, -0.00433, -0.03657, -0.01311, 0.01666, -0.01504, 0.0137, -0.00779, -0.01388, -0.00881, -0.04077, -0.03056, -0.01726, -0.00817, -0.00898, -0.01552, -0.02584, 0.00931, -0.0194, -0.00333, -0.00059, -0.03597, -0.00688, 0.01994, -0.02345, 0.01467, -0.00533, -0.01091, -0.00542, -0.04038, -0.00829, -0.01464, -0.01644, -0.00957, -0.02601, -0.00945, -0.01047, 0.00458, -0.0186, 0.00087, 0.00405, -0.03351, 0.01786, 0.01858, -0.00523, 0.0175, -0.00649, -0.00744, -0.00466, -0.0409, -0.00282, -0.00028, -0.02283]
+ ],
+ "text": "Section 0: revenue grew in region 0, driven by renewals (table 0). Section 1: revenue grew in region 1, driven by renewals (table 1). Section 2: revenue grew in region 2, driven by renewals (table 2). Section 3: revenue grew in region 3, driven by renewals (table 3). Section 4: revenue grew in region 4, driven by renewals (table 4). Section 5: revenue grew in region 0, driven by renewals (table 5). Section 6: revenue grew in region 1, driven by renewals (table 6). Section 7: revenue grew in region 2, driven by renewals (table 7). Section 8: revenue grew in region 3, driven by renewals (table 8). Section 9: revenue grew in region 4, driven by renewals (table 9). Section 10: revenue grew in region 0, driven by renewals (table 10). Section 11: revenue grew in region 1, driven by renewals (table 11).",
+ "input_ids": [7288, 25, 10790, 220, 15, 25, 12585, 13538, 303, 5364, 220, 15, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 15, 553, 10790, 220, 16, 25, 12585, 13538, 303, 5364, 220, 16, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 16, 553, 10790, 220, 17, 25, 12585, 13538, 303, 5364, 220, 17, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 17, 553, 10790, 220, 18, 25, 12585, 13538, 303, 5364, 220, 18, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 18, 553, 10790, 220, 19, 25, 12585, 13538, 303, 5364, 220, 19, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 19, 553, 10790, 220, 20, 25, 12585, 13538, 303, 5364, 220, 15, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 20, 553, 10790, 220, 21, 25, 12585, 13538, 303, 5364, 220, 16, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 21, 553, 10790, 220, 22, 25, 12585, 13538, 303, 5364, 220, 17, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 22, 553, 10790, 220, 23, 25, 12585, 13538, 303, 5364, 220, 18, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 23, 553, 10790, 220, 24, 25, 12585, 13538, 303, 5364, 220, 19, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 24, 553, 10790, 220, 16, 15, 25, 12585, 13538, 303, 5364, 220, 15, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 16, 15, 553, 10790, 220, 16, 16, 25, 12585, 13538, 303, 5364, 220, 16, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 16, 16, 553]
+ }
+ ],
+ "pages": [
+ {
+ "tokens": 918,
+ "projections": [
+ [-0.02402, 0.01022, -0.01897, -0.02999, -0.02332, 0.00595, -0.00026, -0.0078, -0.01083, -0.03267, -0.02411, -0.02921, 0.00947, -0.00741, -0.01329, -0.02764, -0.03857, -0.0317, -0.00297, 0.00616, -0.01745, -0.03825, -0.02773, -0.01178, 0.00057, -0.01751, -0.01603, -0.00153, -0.02507, -0.03648, -0.00554, -0.00217, 0.00958, -0.01901, -0.00388, -0.01457, -0.03198, -0.01356, 0.00161, -0.00382, 0.00344, -0.04274, 0.0142, 0.00398, 0.01747, -0.02035, 0.0069, -0.00659, -0.02527, -0.01838, 0.04205, -0.04416, -0.02087, -0.01955, -0.04539, 0.00023, -0.05531, -0.03697, -0.01171, -0.02556, -0.02064, -0.02559, -0.01962, -0.03081, -0.00257, -0.0033, 0.02217, 0.03803, -0.02462, -0.04346, -0.03044, -0.03313, 0.0068, 0.02135, -0.02872, -0.00291, 0.00313, 0.03961, -0.03832, -0.02544, 0.00095, -0.03004, 0.00278, -0.04742, -0.03456, -0.01082, -0.00624, -0.01391, -0.01446, -0.02908, -0.03325, -0.02553, 0.0308, 0.01395, 0.01694, -0.00438, -0.02518, -0.02048, -0.03029, -0.00413, 0.02242, 0.04493, -0.00409, 0.00527, -0.00435, -0.00398, -0.02644, -0.00408, -0.02147, 0.01402, -0.04134, -0.03392, -0.01901, -0.00942, -0.00134, 0.00122, 0.006, 0.00946, -0.00563, -0.012, 0.00411, 0.00476, 0.02152, 0.02048, -0.01489, -0.00387, -0.01128, -0.04629, 0.00841, 0.01501, 0.0101, 0.01622, -0.02367, 0.00945, -0.05497, -0.02295, 0.01571, -0.0364, -0.03618, -0.02067, -0.01437, 0.00221, 0.00112, 0.01015, 0.01956, -0.02307, -0.02316, -0.01429, 0.0138, 0.01677, 0.02199, -0.03804, 0.00096, 0.01208, 0.01311, 0.00396, -0.01576, -0.02154, -0.00724, 0.01544, 0.01521, -0.04975, -0.0124, 0.00436, -0.03741, -0.0287, -0.0051, -0.00775, -0.03131, -0.01518, -0.01348, -0.02112, -0.02231, -0.03315, -0.03701, -0.0263, -0.01645, 0.00687, 0.01754, 0.01966, 0.02042, -0.00247, -0.01484, -0.00895, -0.00374, -0.01052, -0.00139, 0.00843, 0.006, 0.00521, 0.01656, -0.05889, -0.05657, -0.01565, -0.01288, -0.01226, -0.02077, -0.04058, -0.03607, -0.00844, -0.04099, -0.04057, -0.03825, -0.01416, -0.0461, -0.06486, 0.0137, 0.02502, -0.01096, -0.00863, 0.00331, 0.01994, 0.00361, 0.02128, 0.02203, -0.02185, -0.02131, 0.01429, -0.04428, -0.03549, -0.01605, -0.02538, -0.01898, -0.01369, -0.03021, -0.02996, 0.00316, 0.00665, 0.02323, -0.03759, -0.01901, -0.0354, -0.05232, 0.00039, 0.01821, -0.01235, 0.02067, 0.00597, -0.00136, -0.00137, -0.04115, -0.00408, -0.01831, 0.00326, -0.00509, -0.04343, -0.02922, -0.00603, -0.02203, -0.0192, -0.00353, -0.00944, -0.02858, -0.03014, -0.03344, -0.03523, -0.01491, -0.00866, 0.01302, -0.02198, 0.02172, -0.00507, -0.00795, -0.01369, -0.02814, -0.00169, 0.00168, 0.01249, 0.01618, -0.00627, 0.00353, 0.01219, -0.03344, -0.02565, 0.00085, -0.01647, -0.01914, -0.0037, -0.01552, -0.02829, -0.03046, -0.03412, -0.04305, -0.02296, 0.00078, 0.0247, 0.01105, -0.03228, -0.05085, -0.01144, 0.00236, -0.0183, -0.01979, 0.00942, -0.01195, -0.01658, 0.0049, -0.00805, 0.01776, -0.04053, -0.03881, -0.00949, -0.01869, -0.01903, -0.02541, -0.00734, -0.03801, -0.03102, 0.00201, -0.00338, 0.02091, -0.00237, -0.01608, -0.01588, -0.01791, 0.00249, 0.01329, 0.01542, 0.01153, 0.01409, 0.00324, 0.00943, 0.02217, 0.00471, -0.00658, -0.01209, -0.05666, -0.03694, -0.02116, -0.01512, -0.00599, -0.01616, -0.01994, -0.02604, -0.02179, -0.02379, 0.00083, -0.00777, 0.00766, -0.01524, -0.0118, -0.00194, -0.0102, 0.00756, -0.01728, 0.00064, -0.00335, -0.04149, 0.01963, 0.00767, -0.0294, -0.00616, -0.01056, -0.02885, -0.03789, -0.00273, -0.01536, -0.00804, 0.0203, 0.0133, -0.01865, -0.02244, 0.0071, 0.01066, -0.01163, 0.02407, -0.00014, 0.00991, -0.02733, -0.01681, 0.02259, 0.00879, 0.00203, -0.01354, 0.00215, 0.01926, 0.00721, 0.01183, -0.00666, 0.0116, -0.03057, -0.0198, -0.0045, -0.00067, -0.00649, -0.00874, -0.00379, -0.02805, -0.0312, 0.01102, 0.00086, 0.01721, 0.00768, -0.01742, -0.0299, -0.01425, 0.01247, 0.01754, 0.00745, 0.014, 0.01766, 0.01432, 0.01375, 0.02251, 0.02562, -0.01325, 0.00825, -0.02268, -0.01813, -0.00775, -0.01117, 0.00245, 0.00171, -0.00752, -0.02962, -0.02437, 0.01753, 0.02214, 0.00583, -0.02832, -0.0036, -0.01494, -0.0012, 0.00034, 0.02229, -0.00774, 0.02063, -0.02087, 0.00731, 0.00152, -0.02402, -0.0225, 0.01216, 0.01566, -0.03192, -0.0155, -0.00033, -0.01591, -0.01664, -0.03373, -0.038, -0.00962, 0.00757, 0.02427, -0.00715, 0.00452, -0.00498, 0.00769, -0.00187, 0.01651, -0.0152, -0.01711, -0.00492, 0.001, -0.00814, -0.00632, 0.01255, 0.02076, -0.0242, -0.01028, -0.01618, -0.03978, -0.03448, -0.02218, -0.02051, -0.02032, -0.03618, -0.03155, 0.02047, 0.01569, 0.02589, 0.00797, -0.00736, 0.00368, -0.00091, -0.00121, 0.00871, 0.02104, -0.0029, 0.00034, 0.00838, 0.01654, 0.03687, 0.00033, -0.01204, -0.05246, -0.03567, -0.02221, -0.04495, -0.03249, -0.02174, -0.0176, -0.0078, -0.02299, -0.02131, 0.01486, 0.00297, 0.00776, -0.00816, -0.0417, -0.01244, -0.00545, -0.02655, -0.02617, -0.03542, -0.00399, 0.00547, 0.00273, -8e-05, -0.00909, 0.00198, 0.00052, 0.02094, -0.02366, -0.03241, -0.04101, -0.02541, -0.01416, -0.0275, -0.02731, -0.01005, -0.03291, -0.02872, 0.00122, 0.01656, 0.01985, 0.0017, -0.01158, -0.01622, -0.01924, -0.00406, -0.01044, 0.01487, -0.01114, -6e-05, 0.00063, 0.00471, 0.00989, -0.00958, 0.00132, -0.01278, -0.00391, -0.03526, -0.02638, -0.01408, -0.01339, -0.00109, -0.00388, -0.02858, -0.0324, -0.00431, 0.01999, 0.00885, -0.00303, -0.02221, -0.02728, -0.02038, -0.01688, 0.01055, 0.01944, -0.00933, 0.01978, -0.01038, -0.00143, -0.00988, 0.01977, -0.01118, -0.02197, -0.02831, -0.04404, -0.03334, -0.02878, -0.02547, -0.01447, -0.02251, -0.0412, -0.03013, -0.01591, -0.04038, 0.00139, -0.02586, -0.02988, -0.07344, -0.07522, -0.00781, 0.00566, 0.0019, -0.03054, 0.00208, -0.03048, -0.01272, -0.00126, 0.00266, 0.01333, -0.0126, 0.01151, -0.0613, -0.04721, -0.01135, -0.03, -0.02162, -0.01639, -0.02637, -0.02909, -0.00114, -0.0174, -0.00974, -0.00338, -0.00624, -0.0405, -0.05838, 0.00132, -0.00645, 0.01457, 0.0141, 0.0044, 0.00164, 0.00035, 0.01941, -0.00442, -0.01805, 0.01124, -0.01931, -0.05097, -0.04181, -0.01112, -0.00754, 0.01199, 0.01803, 0.01252, 0.01775, -0.01372, -0.00976, 0.00108, 0.0082, 0.00032, 0.01272, -0.01452, -0.04432, -0.02537, 0.00118, -0.02456, -0.02646, 0.02173, 0.02803, 0.00736, 0.01009, -0.00212, -0.00652, -0.00024, -0.0458, -0.02757, -0.01101, -0.00777, -0.00664, -0.01274, -0.01473, -0.02668, -0.01983, -0.01916, -0.01957, -0.02447, 0.01293, 0.01814, -0.01822, -0.01927, -0.03181, -0.05187, -0.02702, -0.00998, -0.00383, -0.00618, 0.01482, 0.01304, -0.02471, -0.01359, 0.0121, -0.03094, -0.0221, -0.00178, -0.01596, -0.005, -0.00301, -0.00672, -0.00392, -0.00689, -0.02552, -0.01601, -0.00072, -0.02306, 0.00449, 0.00683, -0.01442, -0.01949, -0.0337, -0.01915, -0.01044, 0.01563, 0.02655, 0.03286, -0.04132, -0.00433, 0.00674, 0.00743, -0.03816, -0.0171, -0.00954, -0.02595, -0.02357, -0.03932, -0.03257, 0.00491, -0.01002, -0.01527, -0.0055, 0.00431, -0.02101, -0.00586, 0.00767, -0.00971, 0.01057, 0.00112, -0.02612, 0.00267, 0.01028, -0.00958, 0.01152, -0.01773, 0.01123, -0.02644, 0.02234, -0.0516, -0.02277, -0.01957, -0.03299, 0.00063, -0.00645, -0.00258, -0.00915, -0.00323, -0.03482, -0.03895, -0.00791, -0.03063, 0.02131, 0.00244, 0.00237, 0.00061, 0.01622, -0.00915, -0.01734, -0.00418, -0.01551, -0.01562, 0.03015, 0.01333, -0.0019, 0.00252, -0.04852, -0.03152, 0.00633, -0.00737, 0.01992, 0.02238, 0.02748, 0.0122, -0.01176, -0.03007, -0.0316, -0.02087, -0.01614, -0.00227, 0.02897, -0.00021, -0.02681, -0.00347, -0.01613, -0.00159, 0.01866, -0.02562, -0.00015, 0.01142, 0.0338, 0.01586, 0.03233, -0.04232, -0.02513, -0.00355, -0.00516, 0.00779, 0.00489, 0.01511, -0.00535, 0.00066, -0.03103, -0.03753, -0.03067, -0.00533, 0.00871, -0.00065, -0.00449, 0.00221, -0.00944, 0.01245, 0.01585, 0.02231, -0.02789, 0.00915, 0.02483, -0.03888, -0.02038, 0.00854, -0.03819, -0.02861, -0.01197, -0.0199, -0.03039, -0.00925, 0.00019, -0.00897, -0.02488, -0.04431, -0.04561, -0.04326, -0.00841, 0.00246, 0.00776, 0.03424, -0.00213, -0.02563, -0.02623, -0.00321, 0.01747, -0.02371, 0.01313, 0.00204, -0.03098, -0.04837, -0.03726, -0.02327, -0.01034, -0.00246, -0.02007, 0.03304, -0.03222, 0.00461, 0.01643, -0.00928, 0.00256, 0.02862, 0.00646, 0.02905, -0.00773, -0.00579, -0.01143, -0.01384, -0.00459, -0.01186, 0.04168, -0.00032, 0.00842, -0.00428, -0.01021, -0.03533, -0.00454, -0.02959, 0.00874, -0.00286, -0.01458, -0.01278, 0.03914, -0.02507, 0.02664, 0.03639, -0.0251, -0.0024, -0.01811, -0.00362, -0.00676, -0.00788, 0.00099, -0.02031, -0.01766, -0.016, -0.04258, 0.02272, -0.00138, 0.01868, -0.00594, -0.04385, -0.01745, -0.04577, -0.0206, 0.013, 0.00127, -0.01148, 0.02058, 0.0368, -0.04647, -0.00098, 0.01581, -0.00191, -0.01362, 0.00492, 0.00225, 0.00225, -0.00111, 0.02145, -0.01869, 0.00916, 0.01028, -0.05065, -0.00084, -0.02039, 0.0351, -0.00868, -0.0099, -0.04861],
+ [-0.00643, -0.00227, -0.02442, -0.01151, -0.01401, -0.03701, -0.02489, -0.02059, 0.00261, 0.00762, -0.00528, -0.01062, -0.01502, -0.02585, -0.02551, -0.02273, -0.014, -0.02491, -0.01146, -0.01438, -0.01489, -0.01593, -0.00077, -0.00619, -0.02327, -0.00733, 0.01554, -0.00835, -0.01337, -0.01555, -0.04135, 0.00338, -0.01419, -0.0179, 0.016, 0.00144, -0.01547, -0.03414, 0.00293, 0.00127, 0.01667, -0.01603, -0.01157, 0.01625, -0.01008, 0.00555, 0.04841, 0.04141, 0.01158, -0.00472, -0.01067, -0.01718, -0.00597, -0.00953, 0.01321, -0.04605, -0.03354, -0.03541, -0.06951, -0.06126, -0.03087, -0.01573, -0.0245, -0.0458, -0.00109, -0.05615, 0.01951, 0.00235, -0.07012, -0.08779, -0.04706, -0.00197, -0.01656, -0.00744, 0.01507, 0.0046, -0.00293, -0.01889, -0.01883, -0.01658, -0.00215, -0.00328, 0.01324, -0.02009, -0.02937, -0.05568, -0.04164, -0.03222, -0.01487, -0.02187, -0.02882, -0.01798, 0.01584, 0.01047, -0.01809, 0.00139, -0.05631, -0.04682, 0.00516, 0.018, 0.00174, 0.0029, 0.01657, -0.01413, -0.00457, 0.00589, 0.02728, -0.01325, -0.00266, -0.00605, -0.03554, -0.03531, -0.04689, -0.01265, -0.00574, 0.00235, 0.01249, -0.00023, -0.05973, -0.02527, 0.00744, 0.02116, -0.00118, -0.0018, -0.05276, -0.01413, 0.01372, 0.00729, 0.01695, 0.0126, 0.00158, -0.0043, 0.04023, 0.00971, 0.04144, 0.00137, 0.00577, -0.01029, -0.02648, -0.07097, -0.03668, -0.01838, -0.00804, -0.02264, 0.01685, -0.07626, -0.05063, -0.00237, 0.0382, 0.00811, 0.00664, 0.02218, -0.04924, 0.0058, 0.02001, 0.0014, -0.0544, -0.04571, 0.00013, -0.01671, 0.01404, 0.03816, 0.01465, 0.01981, -0.01535, -0.02114, -0.05517, -0.04715, -0.00026, 0.02554, 0.03384, 0.01545, 0.01696, 0.02578, 0.03385, 0.0301, 0.01928, 0.00237, 0.00184, -0.02272, -0.01233, 0.02964, -0.04198, -0.05069, -0.03451, -0.00492, 0.01842, 0.01096, -0.02978, 0.02082, -0.00326, -0.036, -0.03055, -0.05967, -0.03626, -0.01475, -0.00479, -0.01617, -0.01746, 0.00407, 0.02358, 0.0256, 0.0147, -0.05969, -0.01516, 0.01414, 0.02266, 0.01804, 0.00277, 0.01049, -0.03122, -0.01989, -0.00685, 0.00191, 0.00959, 0.00427, -0.00248, -0.00323, -0.0283, -0.029, -0.06898, -0.05783, -0.03057, -0.00571, -0.01468, -0.0172, -0.04751, -0.03296, 0.00033, 0.00141, -0.07763, -0.03794, 0.01858, 0.0266, 0.01764, 0.01354, -0.0082, -0.02504, -0.01165, 0.00287, 0.00023, -0.02708, 0.00505, 0.00834, 0.01023, -0.0197, -0.01815, -0.03662, 0.0025, 0.0098, 0.03529, 0.03878, 0.03248, 0.02938, 0.02606, 0.01772, -0.01703, 0.00384, -0.02527, -0.01123, -0.00216, -0.01745, -0.02484, -0.02064, -0.0065, 0.03244, 0.00818, 0.02006, 0.01455, 0.00575, 7e-05, 0.0139, -0.00034, -0.01434, -0.03156, -0.01262, -0.00437, 0.0281, 0.03949, 0.01627, 0.00787, 0.00821, 0.01602, -0.02247, 0.0005, 0.00221, -0.06268, -0.01905, 0.00282, -0.03792, -0.02177, -0.01119, 0.00157, -0.00615, 0.00451, 0.02615, 0.01138, -0.01278, 0.01514, -0.01851, -0.02223, -0.04658, -0.04417, -0.0226, -0.00643, -0.02159, -0.03741, -0.00762, -0.03011, -0.03949, -0.03452, 0.01902, -0.05841, -0.06416, -0.01737, 0.04041, 0.01649, 0.01243, 0.01526, 0.00032, 0.02771, 0.016, -0.01822, -0.04408, -0.01195, 0.01746, -0.01291, -0.00502, -0.02295, 0.01614, 0.03195, -0.02824, -0.03445, -0.03455, 0.01212, 0.00642, 0.01594, -0.03482, -0.039, -0.05185, -0.04048, -0.00404, 0.0045, 0.00085, 0.01413, 0.02395, 0.01003, -0.01209, -0.01537, -0.03085, 0.00687, -0.00692, 0.01945, -0.00927, -0.01959, -0.02881, 0.01245, 0.02688, 0.02575, -0.00105, -0.06078, -0.00705, 0.0249, 0.01993, 0.00782, 0.0344, 0.01266, -0.03055, -0.02635, 0.01454, 0.00727, -0.01575, -0.01821, -0.05709, 0.02144, -0.0014, 0.02411, 0.01149, 0.01016, -0.03437, -0.02417, -0.02237, -0.04734, -0.05005, -0.0241, -0.00196, -0.00719, -0.03759, -0.01768, -0.03633, -0.04799, -0.0216, -0.05389, -0.05564, -0.05043, 0.00171, 0.02335, 0.01989, -0.0151, 0.0011, -0.02349, -0.00616, 0.01261, -0.02173, -0.04267, -0.00051, -0.01124, 0.00776, -0.00404, -0.0326, -0.04039, -0.03495, -0.02072, -0.01895, -0.03866, -0.01791, -0.02476, -0.02403, -0.02397, -0.03163, -0.01234, -0.0465, 0.00304, 0.01069, 0.00994, 0.00983, -0.00382, 0.01892, -0.02242, 0.03042, -0.03274, 0.01265, 0.01251, 0.01902, -0.01746, -0.00707, -0.01495, -0.02168, -0.01362, 0.00357, -0.00442, -0.01752, -0.02626, -0.00275, -0.02512, -0.04917, -0.00471, -0.00125, -0.00105, -0.03147, -0.00586, 0.01104, -0.00552, -0.00053, -0.00442, 0.02164, 0.02369, -0.02494, 0.02508, 0.01878, -0.0068, -0.02094, -0.02005, -0.01868, -0.01046, 0.01145, 0.00366, 0.00226, -0.04733, -0.02134, -0.00751, -0.03821, -0.04382, -0.00975, -0.00141, -0.02355, 0.02686, 0.00548, -0.01043, -0.04737, -0.04209, 0.00176, -0.0021, 0.02408, -0.00867, 0.0044, 0.01872, 0.02198, -0.01557, -0.01351, -0.01994, -0.01498, -0.00364, -0.00367, -0.00688, -0.0275, -0.02365, -0.0048, -0.03692, -0.03379, 0.00952, 0.03163, -0.00756, 0.01149, -0.0002, 0.02194, -0.01101, 0.02098, 0.00633, 0.00818, -0.02479, 0.01169, -0.01152, 0.03885, 0.00742, -0.02265, -0.01993, -0.03107, -0.0454, -0.02217, -0.00732, -0.02177, -0.0312, -0.03451, -0.03231, -0.01946, -0.05555, -0.05943, -0.02801, -0.00596, 0.02527, 0.01954, 0.00135, 0.00678, -0.00535, 0.02352, 0.02276, 0.01887, 0.01091, 0.00913, 0.03681, -0.00213, -0.0068, -0.01229, -0.03634, -0.06578, -0.03721, -0.01312, -0.02258, -0.03054, -0.01633, 0.02607, -0.00587, -0.02632, -0.07071, -0.05211, -0.00504, -0.00643, 0.01927, -0.00551, 0.0145, 0.00788, -0.01273, -0.02346, 0.0151, -0.00352, 0.00378, 0.02426, -0.00728, -0.01196, -0.01276, -0.0262, -0.02701, -0.00344, 0.00871, -0.0123, -0.0189, -0.04642, -0.02057, -0.02129, -0.03559, -0.02941, 0.02959, 0.0225, 0.02593, -0.01278, -0.01817, -0.02217, 0.00411, -0.02642, 0.01603, 0.01826, -0.01552, 0.0034, 0.03181, -0.01572, -0.02035, -0.02234, -0.03021, -0.00605, 0.00251, 0.00868, -0.01652, -0.02485, -0.04049, -0.06505, -0.04275, 0.00761, -0.06052, 0.00045, 0.01595, 0.0129, 0.02719, -0.03628, 0.00367, -0.02974, -0.0427, -0.03962, 0.02981, -0.03613, 0.02305, 0.01353, -0.02103, -0.02649, -0.02544, -0.03382, -0.00192, -0.0033, -0.00111, 0.002, -0.01775, -0.00956, -0.06216, -0.03605, -0.0031, 0.02713, -0.01933, 0.01282, -0.00906, 0.00245, -0.01686, -0.0005, 0.01811, -0.01362, -0.00883, 0.00904, -0.03485, 0.0163, 0.01801, -0.00426, -0.01936, -0.01715, -0.03537, -0.00903, 0.01545, 0.03865, 0.03917, 0.03154, 0.03721, 0.03883, 0.01271, -0.01149, -0.03372, 0.00807, 0.01759, -0.0213, -0.03085, -0.04033, 0.01466, 0.02667, 0.00243, -0.00151, 0.0184, -0.01333, 0.00367, 0.02494, 0.00851, -0.0027, -0.01271, -0.04319, -0.01423, -0.00726, 0.02829, 0.03087, 0.01576, 0.02051, 0.02205, 0.00202, -0.06348, 0.02009, 0.00616, -0.01361, -0.04007, -0.04793, -0.02779, 0.01434, 0.05207, 0.01934, 0.03111, -0.01887, 0.01177, 0.02771, 0.01541, -0.00241, -0.02457, -0.02319, -0.04767, -0.01247, 1e-05, 0.00333, 0.01341, 0.02191, -0.01509, -0.02162, -0.04016, -0.05699, 0.01705, 0.01969, 0.00082, 0.01998, 0.0338, 0.01211, -0.02941, 0.017, 0.03405, 0.02052, 0.01281, 0.02116, 0.02092, 0.01694, -0.00025, -0.01632, -0.01727, -0.04973, -0.06037, -0.03084, 0.00655, 0.01485, -0.00774, -0.00769, 0.01485, -0.0114, -0.05553, 0.01929, 0.01719, -0.01804, -0.01071, 0.02858, 0.02607, 0.01015, -0.05913, -0.04136, -0.00086, -0.0102, 0.01497, -0.04108, 0.01024, 0.00515, -0.01239, -0.02015, -0.0477, -0.04475, -0.02087, 0.00587, 0.01233, -0.00311, 0.0105, 0.01294, 0.02468, 0.02735, 0.00287, 0.0226, -0.02298, -0.00136, 0.0035, 0.00458, -0.02926, -0.04238, -0.04263, -0.00707, 0.02949, 0.02772, -0.01484, -0.01256, 0.01536, -0.03385, -0.03166, -0.04206, -0.04059, -0.00795, 0.03166, 0.01522, -0.04081, -0.00501, 0.02093, 0.03164, 0.03103, -0.00223, 0.03029, 0.01741, 0.0055, 0.00489, 0.01994, -0.05026, -0.04472, -0.03117, -0.00682, 0.02432, 0.01544, 0.03977, 0.01143, 0.02368, -0.01868, -0.02062, -0.04749, -0.03478, -0.00916, 0.02494, -0.00068, -0.03965, -0.00351, 0.00747, 0.01974, 0.00924, -0.01866, 0.02293, 0.02119, -0.01267, -0.00508, 0.01056, -0.0365, -0.04969, -0.0368, -0.02014, 0.02865, -0.00701, -0.02031, 0.01216, -0.01902, -0.02922, -0.02537, -0.02499, 0.04166, -0.01842, -0.00447, 0.01867, 0.0204, -0.03101, 0.00998, -0.02246, 0.01565, 0.02736, -0.00109, 0.02116, 0.0124, 0.01129, 0.02779, 0.00806, 0.01459, 0.02086, -0.02339, 0.02601, -0.00693, -0.02227, 0.02395, 0.00118, 0.01383, -0.04131, -0.02885, 0.02032, -0.01011, 0.00665, -0.0347, -0.03209, -0.02195, 0.02752, -0.05759, 0.01961, 0.02081, 0.00489, -0.01883, 0.03186, -0.01626, -0.01472, 0.00641, -0.01352, 0.00615, -0.03308, 0.01836, -0.00557, 0.01565, 0.01055, 0.00839, 0.01756, -0.00985, -0.03945, -0.03745, 0.03636, -0.01242, 0.04599, 0.01926, 0.00851, -0.04193, 0.02164, -0.03362, 0.02909, 0.02492, -0.02211, -0.01999, 0.02055, -0.01052, -0.00806, 0.03401, -0.00576, -0.02208, 0.02119, 0.00225, 0.01141],
+ [0.00199, 0.03497, -0.03577, 0.00917, 0.02083, 0.01294, 0.00774, 0.00243, -0.03985, -0.01941, -0.00219, -0.00966, -0.00792, -0.00195, -0.03556, -0.0269, -0.02573, -0.04127, -0.05525, -0.04659, -0.04794, -0.05028, -0.02831, -0.02329, -0.00815, -0.03502, -0.03723, -0.03126, -0.00905, -0.0126, -0.0586, -0.0582, -0.00226, -0.01459, -0.02637, -0.01344, -0.01937, 0.00138, -0.01337, -0.0399, 0.00891, 0.01003, -0.0068, 0.00628, -0.05436, -0.02546, -0.0253, -0.01956, -0.02195, -0.0405, -0.07975, 0.00668, -0.02649, -0.04918, -0.00426, -0.07377, -0.01533, -0.02243, -0.04743, -0.04703, -0.03429, -0.03028, -0.03023, -0.01158, -0.03691, -0.05427, -0.07523, -0.07671, -0.05846, -0.02735, -0.0026, 0.00532, -0.03098, -0.07034, -0.03316, -0.03217, 0.01036, -0.07478, 0.01444, -0.01132, -0.01298, -0.04569, -0.00608, -0.0171, -0.02887, -0.03402, -0.01751, -0.00278, -0.03124, -0.01695, -0.0082, -0.03049, -0.08356, -0.05267, 0.00774, 0.01004, -0.01248, -0.01229, -0.00475, 0.00501, -0.0117, -0.09037, -0.00447, -0.06842, 0.012, 0.00302, -0.01705, -0.0212, -0.06007, -0.06316, -0.02026, -0.03224, -0.03167, 0.0193, 0.02941, 0.01625, -0.03121, 0.01337, 0.01547, -0.00883, 0.01397, 0.00265, -0.03473, 0.01048, -0.0156, -0.03452, -0.02833, 0.02256, -0.0554, 0.01249, 0.00829, -0.04496, -0.01713, 0.00893, -0.03057, -0.01418, 0.01017, -0.0094, -0.01361, 0.00219, 0.00959, 0.03045, 0.01853, -0.01525, -0.02276, 0.01695, 0.01943, 0.02055, -0.00362, -0.0506, 0.01073, -0.00936, -0.02863, -0.01058, -0.00173, -0.05548, -0.02433, -0.01666, -0.01294, -0.03808, -0.0437, -0.04141, -0.03639, 0.00192, -0.02282, -0.03602, -0.04121, -0.02284, -0.02367, -0.02562, -0.03456, -0.03445, -0.03188, -0.03326, -0.03175, -0.03663, -0.04301, -0.03671, -0.04807, -0.02608, -0.0007, -0.03151, -0.03219, -0.01612, -0.012, -0.0081, 0.00772, -0.02174, 0.02699, -0.0567, -0.06136, -0.0208, -0.02951, -0.05214, -0.04397, -0.05519, -0.03476, -0.02283, -0.02563, -0.02573, -0.03357, -0.03413, -0.03371, -0.03213, 0.00056, 0.01262, 0.00314, -0.05608, -0.05231, -0.02534, -0.02141, -0.00745, -0.00136, -0.01398, -0.05869, -0.0376, -0.00573, 0.00417, -0.00714, -0.00924, -0.0259, -0.0288, -0.04018, -0.04342, -0.02516, -0.02534, -0.03446, 0.02425, -0.05801, 0.00101, 0.00704, 0.03136, 0.0229, 0.01168, -0.05037, -0.04112, -0.0299, -0.02697, -0.02078, -0.01976, 0.02053, 0.02145, -0.03901, -0.02548, -0.02787, -0.02784, -0.0349, -0.04882, -0.03052, -0.02098, -0.02997, -0.04366, -0.03942, -0.00727, -0.0256, -0.023, -0.03644, -0.02754, -0.04654, -0.01557, 0.00669, 0.02957, -0.03217, -0.02354, -0.00226, 0.00801, -0.03957, 0.00432, -0.04941, -0.02332, -0.05465, 0.0007, -0.02101, -0.03596, -0.04189, -0.02462, -0.01708, -0.03462, -0.03585, -0.02021, -0.01244, -0.02197, -0.01909, -0.02517, -0.02277, -0.058, -0.03773, -0.01629, -0.03077, -0.01295, -0.0252, 0.01133, 0.00897, -0.04594, -0.02267, -0.01144, -0.01628, -0.01987, -0.00221, -0.02014, -0.04343, -0.0502, -0.02883, -0.01348, -0.01794, -0.02192, -0.01289, -0.03114, -0.04249, -0.02338, 0.01304, -0.04439, -0.03042, -0.02241, -0.03512, -0.0202, -0.00181, -0.04946, 0.01682, -0.03682, 0.00805, -0.00051, -0.05242, -0.04535, -0.0451, -0.04916, -0.02588, -0.03958, -0.03909, 0.00612, -0.00232, -0.00894, -0.02659, 0.00433, -0.03186, -0.02359, -0.03787, 0.00523, -0.03774, -0.01402, -0.02096, -0.02812, -0.03757, -0.0337, -0.00666, 0.00655, -0.01354, 0.00897, -0.04255, -0.05157, -0.02736, -0.03772, -0.03328, -0.01554, -0.03581, -0.04607, 0.0001, -0.00747, -0.04964, 0.01625, 0.00153, -0.0208, 0.00108, -0.00711, -0.02437, -0.05986, -0.00102, -0.04786, -0.01878, -0.02763, 0.00346, -0.03915, -0.05659, -0.01029, 0.00458, 0.00579, -0.05092, -0.04162, -0.02988, -0.02936, -0.01683, -0.0188, -0.03555, -0.0213, -0.02114, -0.02561, -0.03073, -0.01028, -0.02472, -0.03192, -0.04033, -0.04508, -0.03033, -0.02161, -0.00659, -0.03302, -0.00135, 0.00546, -0.03429, 0.01068, 0.01529, 0.02457, 0.00375, -0.06503, -0.03859, -0.02006, 0.00523, -0.01271, -0.02516, -0.02767, -0.0146, 0.00668, -0.00044, -0.01306, -0.00416, -0.0128, -0.04603, 0.01837, -0.02362, 0.00521, -0.00374, -0.00467, -0.03297, -0.03596, -0.0114, -0.01925, -0.00932, -0.02777, -0.0123, 0.00795, -0.01901, -0.05058, -0.03687, -0.02266, -0.02222, -0.04157, -0.04306, -0.01715, -0.02579, -0.01359, -0.01582, -0.02263, 0.03981, -0.00495, -0.0195, 0.01603, -0.03477, -0.02573, 0.01391, -0.01625, -0.03088, -0.00752, 0.02893, 0.01324, -0.04478, 0.00958, 0.01742, -0.00607, -0.04407, -0.02858, -0.04662, -0.00621, -0.00885, -0.02699, -0.03408, -0.02863, -0.00012, 0.00299, 0.01513, 0.00681, -0.00735, -0.00138, 0.01564, -0.03936, -0.0063, 0.00126, -0.04354, -0.04535, -0.02266, 0.01146, 0.00841, 0.006, -0.05489, 0.00199, -0.0323, -0.04343, -0.02249, -0.02925, -0.01138, -0.01912, -0.02957, -0.03163, -0.02689, 0.00102, -0.00281, -0.00024, 0.01338, 0.01908, -0.0024, 0.00426, -0.04409, 0.01317, -0.0306, -0.02884, 0.01616, -0.05207, -0.0448, 0.01115, -0.03114, -0.02709, 0.00013, 0.01192, 0.01133, -0.04807, -0.04534, -0.02045, -0.02524, -0.0416, -0.0389, -0.04426, -0.03469, -0.01239, -0.00339, -0.04205, -0.04635, 0.02163, -0.04278, -0.02548, -0.02522, 0.00673, 0.00873, -0.0499, 0.01998, -0.02966, -0.01845, 0.00572, 0.01211, 0.01383, -0.02275, -0.03595, -0.02022, 0.00534, -0.01192, -0.01538, -0.02265, -0.01, -0.00863, -0.02446, -0.02282, -0.01117, -0.02558, -0.04925, -0.01752, -0.03818, 0.00817, -0.00586, 0.02019, 0.01163, -0.0315, -0.05796, -0.02626, 0.01034, -0.04861, 0.01336, -0.04132, 0.0108, -0.05306, -0.02301, -0.04112, -0.01544, -0.02476, -0.03831, -0.0305, -0.02095, -0.0152, -0.01679, -0.0117, -0.03264, 0.00298, -0.04789, -0.02831, -0.03016, 0.02699, 0.0172, 0.0071, -0.03367, -0.00662, 0.0152, -0.02013, 0.02153, -0.02845, 0.01967, -0.02641, -0.05061, -0.03918, -0.02431, -0.02056, -0.02585, -0.0204, 0.00092, 0.02667, 0.0309, -0.00877, -0.01402, -0.01157, 0.03478, 0.01508, -0.01509, 0.00585, 0.0421, 0.03321, -0.01391, -0.0311, -0.00041, 0.00555, -0.02755, 0.00225, -0.00123, -0.06887, -0.02706, -0.05106, -0.0104, -0.03073, -0.01079, -0.01225, -0.00597, 0.00618, 0.0257, 0.02744, 0.00831, -0.04068, 0.03003, 0.03357, 0.01715, -0.00117, 0.0218, -0.03164, -0.02479, 0.01822, -0.0125, -0.02701, -0.03855, -0.05144, 0.01185, -0.04778, 0.01303, -0.03084, 0.02602, -0.03505, -0.04127, -0.01286, -0.0149, -0.03114, -0.01702, -0.01066, -0.00926, -0.04063, -0.0253, -0.01388, -0.02346, -0.03229, -0.03796, -0.05387, -0.01688, -0.03777, -0.02175, -0.00272, 0.00032, -0.03369, 0.0145, -0.04881, -0.02911, 0.01758, -0.04423, -0.02012, -0.06066, 0.01716, -0.00936, -0.01796, -0.04694, -0.03228, -0.02198, -0.02278, -0.03403, -0.00807, -0.01523, -0.02488, -0.03521, -0.0128, -0.03238, -0.045, -0.04802, -0.02983, -0.01624, -0.0233, -0.04371, -0.02217, -0.04142, -0.06386, 0.00483, 0.02311, -0.01808, -0.03763, -0.05621, -0.01729, -0.03785, -0.04417, -0.01161, -0.01083, 0.01548, -0.00065, -0.02773, -0.00474, 0.03439, 0.011, -0.01526, -0.02167, 0.01741, -0.02165, -0.02917, -0.04186, -0.03798, -0.0235, 0.01811, -0.05187, -0.03453, 0.01722, -0.00928, 0.01122, -0.0279, -0.06574, -0.01568, -0.01445, -0.02409, -0.03494, 0.00241, -0.02534, -0.02765, -0.02489, -0.02615, -0.04009, -0.0329, 0.00441, -0.00382, -0.04356, -0.0408, -0.04769, -0.03787, -0.02474, -0.02932, -0.00672, -0.00368, -0.00396, 0.00684, -0.04838, -0.03323, -0.05809, 0.01837, -0.01205, -0.01853, -0.02585, -0.03034, -0.01026, -0.02317, -0.02522, -0.02431, -0.02251, -0.03936, -0.04329, -0.03888, -0.02908, -0.0432, 0.01597, -0.02684, 0.01169, -0.0406, -0.03744, -0.02423, -0.00397, -0.00062, 0.01544, 0.00277, -0.01, -0.03435, -0.0541, -0.01761, -0.02509, -0.03824, -0.03457, -0.02754, -0.01449, -0.02993, -0.01988, -0.03298, -0.04082, -0.04014, -0.04862, -0.05678, -0.05475, -0.03244, -0.0313, -0.03574, -0.02257, -0.02606, 0.00566, -0.00168, 0.00974, 0.00923, -0.0536, -0.05548, -0.03051, 0.02337, -0.00729, -0.01247, -0.02795, -0.03008, -0.00882, -0.02699, -0.02753, -0.02775, -0.02555, -0.03031, -0.03182, -0.03626, -0.03381, -0.05165, -0.01507, 0.00764, -0.0246, -0.02531, -0.02835, -0.01424, -0.01337, 0.01832, 0.00984, 0.02503, 0.01499, -0.0682, -0.00305, -0.01699, -0.02491, -0.01787, -0.01856, -0.00311, 0.00618, 0.01846, 0.00772, -0.01881, -0.03174, 0.00685, -0.03463, -0.05529, -0.01679, 0.00742, -0.00337, 0.00017, -0.03417, -0.03025, -0.06561, 0.00979, -0.00275, 0.01187, -0.03401, -0.00873, -0.03224, -0.02952, 0.01367, -0.03047, -0.01159, -0.02842, 0.00115, -0.01827, 0.0208, 0.00848, -0.04647, 0.00499, 0.01438, 0.02418, 0.02534, 0.0115, 0.00447, -0.02146, 0.00527, -0.04062, 0.02478, -0.02612, -0.02263, -0.01641, -0.03913, 0.01144, -0.03527, -0.01473, -0.02663, 0.0132, -0.03286, -0.0102, -0.02374, -0.05645, -0.02827, -0.0281, 0.00963, -0.01269, 0.01184, 0.00298, 0.00707, -0.02952, 0.01656, -0.03479, -0.0573, -0.00054, -0.00391, 0.0094, -0.04592, -0.02389, 0.0076, -0.02928, -0.01727, -0.04278],
+ [0.01342, 0.02555, -0.00949, -0.00625, 0.01233, 0.02516, -0.00782, -0.01092, -0.00722, -0.01621, -0.0019, 0.01305, -0.02827, -0.05062, -0.03956, -0.014, 0.02058, 0.01895, -0.01058, -0.01845, -0.02851, -0.01276, 0.00026, 0.01093, 0.01021, -0.02213, -0.0107, 0.0323, -0.04178, -0.01878, -0.00744, 0.03917, 0.01192, -0.01367, 0.03002, 0.03235, -0.03015, -0.03289, -0.00107, 0.03958, 0.03264, -0.04195, 0.02126, 0.02101, 0.03005, 0.03443, -0.02091, -0.02523, 0.02158, -0.02877, 0.02524, -0.04185, -0.02381, -0.0272, -0.03446, -0.00198, -0.01617, -0.01047, -0.00318, 0.00225, 0.03427, 0.03818, 0.02094, 0.01232, 0.00524, -0.01234, 0.02774, 0.04456, -0.00177, 0.00894, -0.02146, -0.02106, -0.00829, 0.039, 0.02198, 0.01659, 0.01786, 0.02006, -0.03757, -0.03425, -0.0103, 0.03452, 0.02794, -0.00368, -0.00659, 0.01574, 0.01648, 0.01762, 0.04821, 0.02066, 0.00935, 0.01011, 0.04625, 0.03644, -0.00308, 0.01956, 0.01314, 0.00233, -0.01594, 0.00887, 0.00916, 0.03398, 0.0278, 0.03524, 0.01134, 0.00642, -0.02229, -0.01428, -0.02578, 0.01923, -0.01705, -0.01546, 0.00683, -0.00537, -0.01485, -0.02372, 0.00443, 0.00623, -0.01196, -0.0289, -0.01719, 0.03983, 0.0379, -0.00202, -0.01514, -0.017, 0.01873, -0.03748, 0.0349, 0.04686, 0.01178, 0.03098, -0.04163, 0.03331, -0.00874, -0.01931, 0.03916, -0.01117, -0.01118, -0.02285, -0.01186, -0.01201, -0.0237, -0.00301, 0.02122, -0.02542, -0.0376, -0.00764, 0.0286, 0.03792, 0.02992, -0.01715, 0.02742, 0.02756, 0.03387, 0.02545, 0.011, 0.00615, 0.00938, 0.00591, 0.03065, -0.00494, 0.02641, 0.04329, -0.01634, -0.0222, -0.00834, 0.0074, 0.00608, 0.02569, 0.01917, -0.00991, -0.02327, -0.00557, -0.00488, -0.0022, 0.00639, -0.01139, 0.0141, 0.00674, 0.0145, 0.01136, 0.00681, 0.01118, -0.01843, -0.00694, 0.02264, 0.02165, -0.00227, -0.02378, 0.01754, -0.00791, -0.01241, 0.00738, 0.0114, 0.02959, 0.00782, -0.01184, -0.02461, -0.01437, 0.00093, 0.00049, -0.00746, 0.00027, 0.01735, 0.00668, 0.05354, 0.0347, -0.00898, 0.03346, 0.01533, -0.00613, -0.01217, 0.00348, 0.02774, 0.00992, 0.00224, 0.04032, -0.00563, -0.01184, -0.0081, 0.00847, 0.01256, 0.00606, -0.0071, -0.01453, -3e-05, 0.01359, 0.01983, 0.00428, -0.00363, 0.01665, 0.01221, 0.04705, 0.0351, 0.0343, 0.03367, 0.00469, 0.01016, 0.01592, -0.0406, -0.00534, 0.0241, -0.00865, 0.0023, -0.01002, -0.01131, -0.0026, 0.02383, 0.01099, 0.02973, 0.01407, -0.00133, 0.0052, 0.0053, 0.00503, 0.01422, -0.01978, 0.00424, 0.01453, 0.00143, 0.01247, 0.02558, 0.01012, -0.01871, 0.04434, 0.0171, 0.04659, 0.03091, -0.00824, -0.02606, 0.03504, -0.01704, -0.0186, -0.01302, 0.01508, 0.02266, 0.02808, 0.01901, 0.00576, -0.00033, -0.00236, 0.00228, 0.01674, 6e-05, 0.01853, -0.01324, -0.00402, -0.01693, 0.00837, 0.00471, -0.01609, -0.01078, -0.0002, 0.01306, -0.02417, 0.02131, -0.01091, 0.04515, -0.01913, -0.02009, -0.01303, 0.02009, 0.03411, 0.04566, 0.03272, 0.02816, 0.03186, 0.03792, -0.00449, 0.00314, 0.03114, 0.01904, -0.01318, -0.04237, 0.00736, 0.0493, 0.03934, 0.05046, 0.00973, 0.03545, 0.03904, 0.01137, -0.00199, -0.00737, -0.01177, -0.0036, 0.00183, 0.02633, 0.00183, 0.00875, 0.02369, 0.01988, 0.01163, 0.00223, -0.00053, 0.03435, 0.01472, 0.01435, 0.02777, 0.00154, -0.0127, -0.03071, 0.00949, 0.02337, 0.03155, -0.01236, -0.04118, 0.00937, -0.00589, -0.02715, -0.02909, -0.01919, -0.00672, -0.00994, 0.0093, 0.01168, 0.00964, 0.03074, 0.00907, -0.01776, -0.00853, 0.03629, 0.03101, 0.02249, 0.02092, 0.04356, 0.00297, -0.01065, -0.00193, 0.01013, -0.01006, -0.00585, -0.02959, 0.03487, 0.00836, 0.0178, -0.01665, -0.00734, -0.0109, -0.02079, -0.01951, -0.00526, 0.02034, 0.03906, 0.03793, 0.02457, 0.01441, 0.00543, 0.0148, -0.00175, -0.00701, 0.01384, 0.02316, -0.00715, -0.03079, 0.03505, 0.04184, -0.001, 0.04429, 0.01433, 0.0041, 0.03406, 0.00398, -0.01325, -0.01976, 0.02527, -0.01821, -0.01416, -0.01067, 0.02502, 0.03306, 0.03751, 0.03185, 0.01849, 0.02492, -0.00568, -0.01444, -0.01624, -0.00928, 0.02044, 0.00342, -0.02153, -0.01327, 0.0307, 0.02193, -0.00256, 0.02492, -0.01502, 0.03644, -0.03162, -0.00068, -0.01423, 0.00824, -0.02099, -0.02579, -0.01578, -0.01541, 0.01384, -0.02247, -0.03658, -0.03196, 0.017, 0.0103, -0.02451, -0.03234, 0.00197, 0.01666, 0.01792, -0.00927, -0.00621, 0.02921, 0.0071, 0.00333, -0.01712, 0.01881, 0.04919, -0.00994, 0.00256, -0.00994, -0.00975, -0.01214, -0.01345, 0.00229, -0.0046, -0.0012, -0.0251, -0.04222, -0.02205, -0.00481, 0.02153, -0.00429, -0.02594, 0.00029, 0.00897, -0.01588, 0.03193, 0.01895, 0.0211, -0.0375, -0.03286, 0.006, 0.00316, 0.03857, 0.00799, -0.00427, 0.00937, -0.00211, -0.00541, -0.00986, -0.00291, -0.01138, -0.00022, -0.02757, -0.04013, -0.00263, 0.00973, 0.01937, -0.00047, -0.00991, 0.03115, 0.05216, -0.00997, 0.0001, -0.02989, 0.02322, -0.01019, 0.04889, 0.01084, 0.01672, -0.01721, 0.04082, 0.01322, -0.00991, -0.03231, -0.01737, -0.01982, -0.01397, 0.01153, 0.02763, 0.00845, -0.00047, -0.00852, -0.00561, 0.00045, -0.00269, -0.01581, 0.003, -0.01279, -0.03509, 0.03223, 0.00156, 0.00407, 0.03035, 0.00375, 0.03647, 0.03053, 0.04945, 0.0374, -0.02139, -0.02599, 0.01316, -0.01593, -0.01697, -0.00959, 0.01073, 0.02268, 0.01687, 0.00163, -0.00135, 0.01386, 0.02303, 0.02793, 0.00329, -0.00337, -0.00116, -0.04842, -0.03362, 0.02914, 0.00694, 0.03146, 0.03351, 0.00676, -0.0147, 0.02424, -0.00656, 0.00781, 0.00378, -0.00753, -0.01218, -0.01326, -0.00679, 0.00758, 0.03703, 0.02445, -0.01034, -0.02375, -0.00068, -0.01546, 0.01388, -0.00797, 0.00769, -0.00426, 0.00925, 0.05885, 0.00747, -0.00406, -0.01275, 0.0161, -0.01474, 0.02823, 0.05005, -0.01321, 0.0062, -0.02191, -0.01177, -0.0098, -0.01506, -0.01336, -0.01425, -0.00177, -0.02742, -0.02157, -0.022, -0.01095, -0.03774, -0.03924, 0.00071, -0.00621, 0.0101, 0.0046, 0.01785, 0.02527, -0.04006, 0.0162, 0.0051, 0.00827, 0.01492, 0.02947, 0.00198, -0.03389, -0.03453, -0.01903, -0.01118, -0.01852, -0.01775, -0.00134, -0.00214, -0.02491, -0.03008, 0.00648, 0.01239, -0.02219, -0.02623, -0.00067, 0.02611, -0.00243, 0.02183, -0.03642, 0.02704, 0.00714, 0.0117, 0.00812, 0.01069, 0.0028, 0.05034, -0.01479, 0.02931, -0.00684, -0.00934, -0.0171, -0.01786, -0.00055, 0.03235, 0.02557, 0.03636, 0.00602, -0.00322, 0.01744, 0.02868, 0.03131, 0.02002, -0.01452, 0.02111, -0.03081, 0.02331, 0.02295, -0.00868, 0.01702, 0.03429, -0.00344, 0.02951, 0.04766, -0.00385, -0.01653, 0.00031, 0.04307, -0.01698, -0.02063, -0.01274, 0.01737, 0.0315, 0.01696, 0.00939, 0.01378, 0.00973, 0.02585, 0.02664, -0.01846, 0.00146, 0.01271, 0.00406, -0.00424, 0.00454, -0.02148, 0.00425, 0.01728, -0.00207, 0.03428, 0.00569, -0.03012, 0.02061, -0.02964, -0.00866, -0.02015, -0.02157, -0.0026, -0.00583, 0.01014, -0.04022, -0.04587, -0.01559, 0.01871, 0.0016, -0.03282, -0.03179, -0.00609, 0.0584, 0.02141, 0.02547, 0.01952, 0.03489, -0.03194, 0.05365, 0.02383, 0.03564, 0.04672, -0.00903, 0.05038, 0.00862, 0.00166, -0.01637, -0.01812, 0.00366, 0.00171, -0.00615, 0.01199, 0.00885, -0.01248, -0.01881, -0.00887, 0.00049, -0.0192, -0.00609, 0.01581, -0.00825, -0.00324, 0.02357, 0.02232, 0.02287, 0.02579, 0.00555, -0.03007, -0.03326, 0.02877, -0.00246, -0.00677, 0.03163, -0.00674, -0.0168, -0.00729, -0.00336, 0.0072, 0.01074, -0.00535, -0.00908, -0.01735, 0.00301, -0.00328, -0.00467, -0.00821, 0.00787, 0.00748, 0.02772, 0.00921, 0.0357, -0.00111, 0.01504, -0.00713, -0.03392, 0.03181, 0.03234, 0.01398, -0.02654, 0.03482, -0.01673, -0.01604, 0.00054, 0.01689, 0.0216, 0.03435, 0.00876, -0.00467, -0.0144, -0.00141, 0.00202, 0.00345, 0.00853, 0.02421, 0.01007, 0.02699, 0.03669, 0.00427, 0.01573, 0.01699, -0.00422, -0.01112, 0.04077, 0.04139, -0.00445, 0.00874, 0.04841, -0.01291, -0.01454, -0.00861, 0.01604, 0.05988, 0.03279, 0.01834, -0.0058, -0.01433, -0.00043, 0.00191, -0.00745, 0.00758, 0.02811, 0.031, 0.01203, 0.02731, -0.02551, -0.00056, 0.0044, 0.00546, -0.00093, 0.04017, 0.01291, -0.01457, 0.0095, -0.03283, -0.00925, 0.0055, 0.0135, -0.02385, 0.01013, 0.00442, 0.04766, 0.05048, -0.01092, 0.01082, 0.01241, 0.01823, 0.04497, 0.0165, 0.03905, -0.00529, 0.00374, -0.00269, 0.03267, 0.03248, 0.03252, -0.00269, 0.03396, -0.03498, -0.02023, 0.0061, 0.02784, 0.04721, -0.01783, -0.01716, 0.02803, 0.01114, 0.02315, 0.00017, 0.00391, 0.0257, 0.03099, -0.05125, 0.02335, 0.03286, 0.01434, 0.02019, 0.00019, 0.0024, -0.03447, -0.03991, 0.01306, 0.03085, -0.01206, 0.02742, -0.04224, -0.02543, 0.0079, -0.03112, 0.05673, 0.0004, -0.00242, 0.04212, 0.03313, -0.02065, 0.01726, 0.04335, -0.01335, -0.04691, 0.03037, -0.02099, 0.02201, 0.04694, 0.01069, 0.00255, 0.03769, -0.01161, -0.03821, 0.04673, -0.03357, 0.00744, 0.02113, -0.01804, -0.01911]
+ ],
+ "name": "letter",
+ "width": 850,
+ "height": 1100,
+ "seed": 1
+ },
+ {
+ "tokens": 300,
+ "projections": [
+ [-0.02622, 0.00706, -0.02712, -0.03326, -0.02204, -0.01197, 0.00527, -0.02431, -0.0267, -0.03078, -0.0162, -0.00956, -0.0063, -0.02375, -0.0252, -0.00921, -0.02271, -0.02347, -0.03567, -0.03375, -0.01894, -0.0466, -0.03342, -0.02267, -0.017, -0.01527, -0.01448, -0.0075, -0.05091, -0.03038, -0.02521, -0.01898, -0.00988, -0.04848, -0.03707, -0.03176, -0.05003, -0.02889, -0.00123, 0.0141, -0.01634, -0.001, -0.01181, 0.00496, -0.01198, -0.02068, -0.01683, -0.0202, -0.03522, -0.0315, -0.02168, -0.02898, -0.00661, -0.02316, -0.01536, -0.00093, 0.00187, -0.00424, -0.01524, -0.00501, -0.00448, -0.02848, -0.02641, -0.04387, -0.04319, -0.00654, -0.03243, 0.00435, -0.01206, -0.00501, -0.0011, -0.03465, -0.01434, 0.00855, 0.00503, -0.01035, -0.01966, -0.02671, -0.02668, -0.02515, -0.00932, -0.01783, -0.02031, -0.02394, -0.02936, -0.0162, -0.03033, -0.01026, -0.01438, 0.00518, -0.02066, -0.02363, -0.03201, -0.02679, -0.03652, -0.0456, -0.02814, -0.04064, -0.01541, -0.01467, -0.02225, -0.02225, 0.00587, -0.00555, -0.02476, -0.00311, -0.02573, -0.02213, -0.04951, 0.00048, -0.0001, -0.03578, -0.03421, -0.02193, 0.0009, -0.01387, -0.01168, -0.05194, -0.00114, -0.02295, -0.00715, -0.01551, -0.01153, -0.02223, -0.02653, 0.00962, -0.01254, -0.00296, -0.0109, 0.00799, -0.01164, 0.00418, -0.00042, -0.00197, -0.00736, 0.00418, -0.01318, -0.00783, -0.03511, -0.0177, -0.03762, -0.01809, -0.00421, 0.0003, -0.00131, -0.01578, -0.00707, -0.00977, 0.00229, -0.00087, 0.00531, -0.0256, -0.01386, 0.01631, -0.01481, -0.00687, -0.02759, -0.02132, 0.00237, -0.00288, 0.00383, -0.01455, -0.01951, 0.00988, 0.00703, -0.00085, -0.02137, -0.01567, 0.00399, -0.0086, -0.00493, 0.01373, -0.01545, -0.01199, -0.00609, -0.01472, -0.00921, -0.03777, 0.01275, 0.02524, -0.0176, -0.01721, -0.00973, 0.00905, -0.00579, 0.01049, 0.0128, -0.0164, -0.00639, 0.00246, -0.016, -0.00531, -0.00742, -0.00659, -0.00295, -0.01048, -0.02383, -0.01881, -0.01249, -0.02161, -0.01292, 0.00839, -0.0367, -0.02429, -0.01097, 0.00263, -0.01638, -0.02553, -0.00688, -0.02918, -0.00753, -0.02473, -0.01804, -0.03254, -0.02886, -0.01684, -0.02633, -0.03928, -0.01674, -0.0059, 0.00158, 0.02042, -0.01917, -0.00493, 0.01627, -0.01582, -0.01863, -0.01521, -0.00344, -0.01563, -0.00524, -0.03216, -0.03843, -0.01911, -0.03793, -0.03357, -0.01128, 0.0221, -0.00655, 0.01197, -0.00214, -0.0281, -0.01854, 0.00147, -0.00799, -0.01085, -0.00512, -0.02513, 0.01161, -0.04816, 0.00077, -0.02116, -0.0079, 0.01895, -0.01718, -0.00458, -0.01067, -0.01621, -0.03309, -0.03391, 0.00185, -0.01555, -0.02859, -0.00909, -0.00243, -0.00047, -0.01286, 0.00426, 0.00351, 0.011, -0.0305, -0.01922, -0.02873, -0.01819, -0.03223, -0.03396, -0.03606, -0.0502, -0.03949, 0.0035, 0.00367, -0.05375, -0.02103, -0.0003, -0.0348, -0.03408, -0.02401, -0.00601, 0.00554, -0.01223, -0.03113, 0.01481, -0.01545, -0.01195, -0.01609, -0.01785, 0.01044, -0.01247, 0.0083, -0.03744],
+ [0.00682, -0.00469, -0.01595, -0.01195, -0.00979, -0.03423, -0.01945, 0.01044, 0.02068, 0.01998, -0.00883, -0.01815, -0.02371, -0.02807, 0.02171, -0.00157, -0.02761, -0.01973, -0.05366, 0.00396, -0.04763, -0.05246, -0.00752, 0.00592, 0.03015, -0.01303, 0.02079, 0.01303, 0.00648, 0.0079, 0.00715, -0.02269, -0.02696, -0.05208, -0.02529, -0.01785, -0.06752, -0.01037, 0.00276, 0.00678, -0.07254, -0.01203, 0.01421, 0.02124, 0.03164, -0.01408, -0.02875, -0.01145, -0.05158, -0.05755, -0.03861, 0.01826, 0.00488, -0.01204, -0.0303, -0.05722, -0.01983, 0.00018, 0.03016, 0.01863, 0.02126, -0.02919, -0.02306, -0.04241, -0.04485, -0.00182, 0.01294, -0.03701, 0.00112, -0.06657, -0.03031, 0.00173, -0.00617, -0.00294, 0.01331, 0.00991, -0.02524, -0.01831, -0.04263, -0.02284, -0.03747, 0.01021, 0.02366, 0.00234, -0.05438, -0.04309, -0.00729, -0.01974, 0.03174, -0.01521, 0.03136, -0.02507, 0.00128, -0.03767, -0.00632, -0.03665, -0.00513, 0.00507, 0.01479, 0.01296, -0.02168, -0.00036, -0.01959, -0.01318, 0.02977, 0.02821, -0.02808, -0.01464, -0.02478, -0.0172, -0.00221, -0.03899, -0.00558, -0.07632, -0.06063, -0.00376, -0.00021, -0.01214, -0.00576, 0.00457, 0.00682, -0.02969, -0.01872, -0.04018, -0.03226, 0.00478, 0.00696, 0.00434, -0.04284, -0.04296, -0.02084, 0.003, 0.01116, -0.01321, 0.0386, 0.01339, -0.02641, -0.00691, -0.02321, 0.00317, -0.03152, 0.02299, -0.06158, -0.0111, 0.00108, 0.01611, 0.01207, -0.01188, 0.02041, 0.00236, 0.00285, -0.03455, -0.01049, -0.03089, 0.0019, 0.0066, -0.04046, -0.0581, -0.01467, -0.00462, 0.0182, -0.0045, 0.01881, 0.01873, 0.01651, -0.00596, -0.02866, -0.02909, -0.06237, -0.01764, -0.00311, -0.00791, -0.05566, -0.00549, -0.07874, -0.01005, -0.00291, -0.00774, 0.00136, 0.03278, -0.00519, -0.01843, -0.00564, -0.0213, -0.01908, -0.01097, -0.00749, -0.02281, -0.06012, -0.02762, -0.00761, 0.01467, 0.03491, 0.03199, 0.02691, -0.01003, -0.03041, -0.01228, -0.04012, 0.00735, 0.01097, -0.02368, -0.02132, -0.0081, 0.01151, -0.04376, -0.00891, 0.00151, -0.01084, 0.01986, 0.0038, -0.03455, -0.0237, -0.03088, 0.0059, -0.00064, -0.02878, -0.00656, 0.00652, 0.0114, 0.02035, -0.03846, -0.00083, -0.00498, 0.02908, -0.01605, -0.02807, -0.0064, -0.0247, 0.00523, 0.00938, -0.0331, -0.0028, 0.00997, 0.00199, 0.00371, -0.02712, 0.03983, 0.05052, 0.03629, 0.01746, -0.03152, -0.01812, -0.04504, -0.01273, -0.01879, -0.00541, -0.04399, -0.02042, 0.00082, -0.04832, 0.01554, 0.01144, 0.03177, 0.039, 0.01431, -0.03057, -0.0161, -0.02052, 0.00618, -0.01016, -0.04484, -0.00605, 0.00631, 0.01864, -0.03383, 0.00186, 0.00542, 0.01215, -0.00203, 0.0089, -0.01621, 0.00146, -0.04396, 0.00399, -0.00619, -0.03545, 0.01007, 0.01082, 0.0164, -0.0037, -0.00035, 0.00717, 0.03505, -0.00196, 0.03916, -0.01474, 0.00035, 0.03872, 0.013, -0.04072, 0.00483, 0.00245, -0.0039, -0.00343, -0.00107, 0.0368, 0.04905, 0.00115, 0.01824],
+ [-0.0129, 0.04124, -0.02382, 0.00461, 0.00731, 0.02433, 0.00219, -0.0232, -0.04331, -0.0299, -0.01153, -0.01531, -0.01048, -0.01333, -0.02907, -0.04362, 0.03141, 0.00431, -0.02181, -0.02042, -0.03363, -0.00997, -0.03278, -0.00202, -0.02702, -0.03584, -0.02022, -0.05634, 0.02247, -0.01132, -0.04402, 0.02605, 0.00346, -0.00838, -0.01885, 0.00597, -0.00758, -0.0223, -0.03131, -0.07072, -0.01688, -0.00975, 0.00133, -0.03904, -0.02251, -0.03041, 0.02891, 0.00851, 0.01024, 0.01954, -0.00652, 0.02562, 0.00369, -0.03009, -0.03339, -0.00462, 0.00194, -0.0147, -0.01599, -0.01209, -0.04404, 0.00964, 0.00043, 0.01192, 0.01354, 0.02703, 0.02344, -0.00363, -0.04625, -0.02105, 0.00034, 0.01165, 0.00407, 0.00192, -0.03492, -0.02361, 0.0247, 0.0039, -0.01553, -0.00275, -0.02043, 0.01277, 0.01841, -0.00823, -0.00568, 0.01987, 0.00629, -0.02582, -0.01359, -0.02052, -0.03516, 0.01386, -0.00095, -0.00738, -0.01095, 0.00374, 0.01265, -0.02893, -0.00227, -0.03483, -0.02051, -0.0054, -0.02378, 0.0114, -0.02592, -0.04066, 0.01403, 0.00235, 0.00312, 0.01965, 0.03148, 0.01715, -0.02582, -0.0195, 0.00402, 0.01357, 0.00557, 0.02138, -0.03188, -0.02062, -0.0088, 0.02861, -0.00101, 0.00616, 0.01026, 0.02319, 0.01641, 0.01869, 0.01684, 0.03486, 0.02796, 0.02898, -0.03305, -0.02894, -0.00962, -0.01995, 0.02267, 0.00981, -0.00067, -0.00507, 0.00668, 0.01928, -0.00118, -0.00243, 0.01401, -0.03845, -0.02157, -0.02378, -0.00317, -0.02146, -0.03859, 0.02321, -0.00834, -0.01196, 0.00156, -0.00652, -0.01677, -0.01159, 0.00491, -0.00502, -0.04797, -0.02927, -0.04877, -0.00316, -0.04526, -0.02104, 0.01849, 0.02039, 0.00761, 0.03132, 0.03479, 0.01695, 0.00488, 0.00527, 0.01032, 0.0275, -0.00323, -0.02134, 0.00665, -0.01047, -0.04491, 0.01431, 0.01026, -0.01124, 0.03018, 0.04002, 0.0284, -0.01503, -0.00841, -0.00803, 0.03308, -0.00264, -0.0502, -0.01398, -0.02455, -0.03073, 0.02582, -0.0011, -0.00712, -0.00624, -0.00902, -0.01338, -0.008, -0.03434, -0.00318, -0.00988, -0.00737, -0.01507, -0.01941, -0.02648, -0.02693, 0.03076, -0.01062, 0.01357, -0.00275, -0.0086, -0.00032, 0.001, -0.03207, -0.03435, -0.03757, 0.01244, -0.00101, -0.02411, -0.06034, -0.01794, 0.02296, 0.00334, 0.00501, 0.01922, 0.0089, 0.01286, 0.00488, -0.03756, 0.01055, 0.01228, 0.01323, -0.0628, -0.01746, -0.03416, -0.05439, 0.01676, 0.02033, -0.0084, -0.00381, 0.01675, 0.01459, 0.00706, 0.00631, 0.01883, 0.01588, -0.02609, 0.00164, -0.04743, 0.00148, -0.00943, 0.03778, 0.00388, -0.00339, -0.01151, 0.02406, 0.00666, -0.01603, 0.00137, -0.02708, 0.01697, -0.01961, -0.02269, -0.0512, 0.0037, -0.02487, 0.03632, 0.01013, -0.01405, -0.01261, -0.01021, -0.01291, -0.02011, -0.01492, -0.04051, -0.03432, 0.03062, -0.01757, -0.01632, 0.00166, -0.04509, -0.0261, -0.02173, -0.01427, -0.0459, -0.00229, -0.03419, 0.00189, -0.0103, -0.00187, 0.00324, -0.00366, -0.00715, -0.01552, -0.0312],
+ [0.03001, 0.01019, -0.01912, -0.02548, -0.01663, -0.00401, -0.02684, -0.01954, -0.00917, -0.03519, -0.02903, -0.00481, -0.02796, -0.04284, -0.00635, 0.0242, -0.01249, -0.00578, 0.00843, 0.01072, 0.01473, 0.00232, 0.00318, -0.00026, -0.00624, 0.02985, 0.007, -0.01783, -0.02971, -0.01107, -0.03217, -0.0186, -0.00909, 0.00108, 0.00095, -0.03338, -0.00389, 0.00227, 0.01587, 0.02949, -0.03424, -0.0408, -0.01904, -0.00337, 0.00189, 0.01345, -0.009, 0.01511, 0.00011, 0.00537, -0.04315, 0.00884, -0.00381, 0.02984, -0.00664, -0.0515, -0.05466, -0.04804, -0.01509, 0.01728, -0.01177, -0.01863, -0.006, -0.0039, -0.005, -0.02436, -0.00979, -0.00454, 0.03102, -0.0192, -0.03309, -0.0303, 0.00692, 0.01361, 0.01537, -0.01697, -0.01398, 0.00468, 0.00058, 0.00675, 0.0047, -0.00569, 0.00481, 0.02619, -0.00095, -0.03274, -0.03456, 0.02918, -0.02747, 0.00959, 0.02219, -0.00443, 0.02552, 0.01709, 0.01516, -0.00614, -0.01423, 0.0257, 0.01368, 0.03686, 0.02601, 0.02249, 0.02473, 0.01204, -0.0017, -0.01428, -0.01053, -0.0056, -0.00455, -0.00103, -0.01754, 0.00186, 0.00419, -0.00232, -0.01904, -0.04681, 0.00226, -0.03653, 0.02397, -0.02485, -0.01066, -0.00905, 0.01673, 0.00936, 0.01003, -0.01299, 0.0103, 7e-05, -0.00735, -0.02487, -0.04275, -0.02702, 0.01235, 0.03283, 0.00659, 9e-05, -0.00843, 0.01299, 0.00277, 0.0217, -0.00717, 0.00563, 0.00203, 0.02012, 0.02002, 0.01641, -0.00231, 0.02061, 0.00315, -0.00299, -0.02156, -0.01475, -0.00153, -0.00502, 0.00838, 0.0121, 0.00878, 0.0022, 0.0177, 0.01427, 0.0267, 0.01571, 0.01201, 0.00856, 0.02721, -0.0225, -0.01357, -0.02131, 0.00181, -0.0083, -0.01747, -0.00312, 0.00019, 0.02156, -0.0097, -0.04671, 0.00683, 0.01453, 0.01354, 0.00929, -0.01749, -0.01664, -0.01831, -0.00976, -0.02077, -0.02852, -0.0282, 0.02576, -0.01008, -0.01923, -0.0419, -0.00772, -0.00017, -0.0026, 0.00194, -0.03048, -0.01559, 0.00167, 0.02061, 0.0076, 0.02181, -0.0321, 0.00698, 0.0229, 0.02004, -0.05267, -0.0096, 0.00528, 0.02026, -0.01302, -0.01584, -0.01703, 0.00508, 0.02732, 0.0105, 0.01444, 0.01337, 0.01201, 0.02486, 0.00057, 0.02081, 0.00557, 0.02623, 0.02652, 0.00803, -0.01516, -0.0108, 0.00865, 0.00917, -0.0056, -0.00307, 0.01246, 0.00045, 0.02741, 0.00425, -0.00796, 0.01288, 0.02707, -0.01895, 0.00596, -0.01018, -0.01062, -0.00988, -0.01686, -0.02034, -0.03244, -0.04579, 0.00053, -0.02877, -0.00439, -0.03002, -0.01962, -0.0008, 0.03105, -0.00612, -0.00404, -0.00322, 0.01378, 0.00017, 0.0062, -0.02997, -0.00247, 0.01294, 0.01358, 0.04445, -0.03126, -0.03497, -0.02952, 0.03158, 0.01172, 0.00368, -0.0052, -0.00829, 0.0252, 0.00713, 0.01784, 0.02395, 0.00505, 0.01591, 0.03167, 0.02761, -0.03384, 0.0008, 0.01451, -0.02942, -0.0147, 0.01395, 0.02491, -0.00493, -0.01131, -0.01518, 0.03563, 0.00292, 0.0144, 0.00092, 0.00029, -0.00292, -0.00813, 0.00606, 0.00319]
+ ],
+ "name": "portrait",
+ "width": 480,
+ "height": 640,
+ "seed": 2
+ },
+ {
+ "tokens": 70,
+ "projections": [
+ [-0.00749, -0.03237, -0.00348, -0.01485, -0.00207, -0.0003, -0.00944, -0.03861, -0.0007, -0.02405, 0.01094, -0.01122, 0.01779, -0.03343, -0.04301, 0.00831, 0.00465, -0.00474, -0.02237, -0.01926, 0.00876, -0.03291, 0.00753, -0.04378, 0.00576, -0.04202, -0.00594, -0.02222, -0.00582, -0.0118, 0.01039, -0.02729, -0.01513, -0.03852, 0.00801, -0.02242, -0.00682, -0.01673, -0.03065, -0.01872, 0.01348, -0.03177, -0.00786, -0.02525, -0.03509, 0.00682, 0.02578, -0.00702, -0.02831, -0.05879, 0.00599, -0.01547, 0.01223, -0.02197, -0.03825, 0.00716, -0.03819, -0.01328, -0.00509, -0.01772, -0.0054, -0.02447, -0.0133, -0.02026, 0.0082, -0.02748, -0.00078, -0.01076, 0.0013, 0.0052],
+ [-0.00099, 0.00397, -0.05967, -0.00191, 0.01332, 0.00831, -0.00224, -0.01006, 0.01512, -0.00823, -0.00204, -0.00013, -0.00531, -0.05714, -0.01665, -0.01486, 0.00404, 0.00999, 0.01538, -0.00322, -0.00523, -0.00474, -0.00517, -0.05366, -0.00185, -0.06585, 0.01579, -0.0103, 0.01871, 0.01373, 0.00047, -0.00567, -0.05643, -0.04027, -0.00776, -0.02896, 0.0167, -0.00807, 0.00954, 0.00741, 0.02908, 0.00332, -0.01922, -0.00779, -0.01095, -0.0173, 0.01079, 0.01368, 0.01966, -0.00011, 0.01235, 0.00246, 0.01524, -0.00699, -0.03633, -0.01035, 0.0041, 0.04888, 0.01144, -0.00504, 0.0385, 0.00526, -0.03786, -0.00185, -0.00592, -0.02819, -0.00175, 0.02297, 0.01056, -0.01114],
+ [-0.0389, 0.02645, -0.01729, -0.04616, -0.04825, -0.02157, -0.03889, -0.02821, -0.03426, -0.02198, -0.04324, -0.02292, -0.04693, 0.0004, -0.02665, -0.00102, -0.02338, -0.03932, -0.06341, -0.03601, -0.03216, 0.02617, -0.0581, -0.00351, -0.04593, -0.00654, -0.04057, -0.04821, -0.04834, -0.01341, -0.03883, 0.04262, -0.00342, -0.00246, -0.01984, -0.02744, -0.0316, -0.0252, -0.03015, -0.00552, -0.05767, 0.0181, -0.03344, -0.01248, -0.02412, -0.02832, -0.04915, -0.06343, -0.04864, 0.02157, -0.03663, 0.02501, -0.05454, -0.01316, 0.01308, -0.01154, -0.0517, -0.04874, -0.00914, -0.01489, -0.02729, 0.04021, -0.01827, -0.01548, -0.04879, 0.00817, -0.01428, -0.06366, -0.01125, -0.03036],
+ [0.00897, 0.01285, 0.0072, 0.01148, 0.01356, -0.01033, -0.00183, 0.02527, 0.02117, -0.02865, 0.00296, 0.0079, 0.02258, 0.02358, 0.01588, -0.00101, -0.00117, -0.00318, 0.00199, 0.02767, -0.02667, -0.00586, 0.01511, 0.00675, 0.02975, 0.01612, -0.01858, 0.00499, 5e-05, 0.01611, -0.00979, -0.00216, -0.00258, 0.0147, -0.00504, 0.01121, -0.00508, 0.01871, 0.00484, 0.01365, -0.01819, 0.01054, 0.00652, 0.02357, 0.02022, -0.02193, -0.01107, 0.00627, 0.00641, -0.04544, -0.01267, 0.0082, 0.0237, 0.02884, 0.0154, 0.01932, 0.00182, 0.0119, 0.02417, 0.01845, -0.02039, 0.0001, 0.00972, -0.00075, 0.01917, 0.01139, 0.00202, 0.02559, -0.00335, 0.01126]
+ ],
+ "name": "small",
+ "width": 300,
+ "height": 200,
+ "seed": 3
+ }
+ ],
+ "text_scores": [
+ [4.130899429321289, 1.4200189113616943, 2.6150436401367188, 1.8326287269592285],
+ [1.081325888633728, 1.4414055347442627, 2.0455217361450195, 3.3035502433776855],
+ [0.2888585031032562, 1.1402897834777832, 0.8297101259231567, 0.7210641503334045]
+ ],
+ "page_scores": [
+ [1.880713701248169, 1.9441338777542114, 1.5911884307861328],
+ [1.8951771259307861, 1.6807677745819092, 1.3565616607666016],
+ [0.8610867261886597, 0.7848396301269531, 0.7531245350837708]
+ ]
+}
diff --git a/packages/sie_server/tests/adapters/goldens/topk_embed/topk-io__topk-embed-v1-xsmall.json b/packages/sie_server/tests/adapters/goldens/topk_embed/topk-io__topk-embed-v1-xsmall.json
new file mode 100644
index 000000000..fe9d36681
--- /dev/null
+++ b/packages/sie_server/tests/adapters/goldens/topk_embed/topk-io__topk-embed-v1-xsmall.json
@@ -0,0 +1,149 @@
+{
+ "model": "topk-io/topk-embed-v1-xsmall",
+ "revision": "d09d8a7a8cdd6c287f792b3c4d7b41233d46e66a",
+ "generated_with": {
+ "pipeline": "sentence_transformers.MultiVectorEncoder + the checkpoint's remote code",
+ "device": "cpu",
+ "kernels": "reference torch/eager stand-ins (see script)",
+ "torch": "2.9.1",
+ "transformers": "5.9.0",
+ "sentence_transformers": "6.0.1",
+ "directions": {
+ "seed": 0,
+ "count": 4,
+ "distribution": "standard normal, unit rows"
+ }
+ },
+ "queries": [
+ {
+ "tokens": 8,
+ "projections": [
+ [0.06001, 0.08253, 0.03749, 0.06574, 0.06201, 0.06429, 0.0383, 0.01966],
+ [-0.02362, -0.02249, -0.03979, -0.03568, -0.04733, -0.0406, -0.02656, -0.00097],
+ [0.03424, 0.00375, -0.02974, 0.01318, 0.02131, 0.01553, 0.00323, 0.0217],
+ [-0.0091, -0.00697, -0.00628, -0.00774, -0.00674, -0.02349, -0.04059, 0.05074]
+ ],
+ "text": "how does photosynthesis work?",
+ "input_ids": [2766, 25, 1204, 1503, 7022, 71163, 944, 30]
+ },
+ {
+ "tokens": 8,
+ "projections": [
+ [0.03382, 0.02367, -0.01007, -0.00066, 0.03154, 0.01239, 0.01182, 0.01727],
+ [0.01896, -0.00035, -0.03739, -0.00424, -0.01291, 0.02545, 0.00866, -0.02079],
+ [0.002, 0.00028, -0.02807, -0.01229, 0.01947, 0.03554, 0.03209, -0.03375],
+ [0.00394, 0.00065, -0.01237, 0.00566, -0.01935, -0.01905, -0.03334, 0.03537]
+ ],
+ "text": " what was the Q3 revenue ",
+ "input_ids": [2766, 25, 1092, 557, 279, 1167, 18, 12585]
+ },
+ {
+ "tokens": 3,
+ "projections": [
+ [0.06639, 0.03504, 0.04513],
+ [0.00369, -0.02759, -0.02578],
+ [0.00937, -0.02854, -0.00911],
+ [0.01778, -0.02958, 0.02252]
+ ],
+ "text": "",
+ "input_ids": [2766, 25, 220]
+ }
+ ],
+ "documents": [
+ {
+ "tokens": 11,
+ "projections": [
+ [0.06216, 0.02354, 0.01303, 0.01258, 0.00089, 0.03035, 0.03155, 0.04348, -0.00113, 0.03801, 0.01064],
+ [-0.00046, -0.02796, -0.02462, 0.05247, -0.00218, -0.00394, 0.05029, -0.0038, 0.01486, 0.00369, 0.00598],
+ [0.01346, 0.00827, -0.05956, 0.08079, -0.02858, -0.04486, -0.09609, -0.05437, -0.07112, -0.03005, -0.05054],
+ [0.01823, -0.01287, -0.01848, 0.07913, 0.02827, 0.00509, 0.03812, 0.02316, -0.01556, 0.0054, 0.05674]
+ ],
+ "text": "Plants convert light energy into chemical energy stored as glucose.",
+ "input_ids": [7288, 25, 47544, 5335, 3000, 4649, 1083, 11153, 4649, 9476, 430, 32120, 13]
+ },
+ {
+ "tokens": 1,
+ "projections": [
+ [0.06959],
+ [0.01567],
+ [0.00264],
+ [-0.00115]
+ ],
+ "text": "",
+ "input_ids": [7288, 25]
+ },
+ {
+ "tokens": 9,
+ "projections": [
+ [0.06929, 0.0658, 0.05563, 0.04437, 0.05404, 0.03571, 0.03667, 0.05489, 0.05989],
+ [0.01503, 0.04328, 0.02591, 0.02706, 0.02289, 0.00955, 0.02423, 0.03882, 0.03117],
+ [0.01122, -0.04233, -0.03912, -0.05614, -0.04239, 0.00958, -0.00917, -0.03463, -0.03118],
+ [0.00121, 0.01164, -0.00274, 0.00916, 0.0017, 0.0336, 0.03352, 0.01996, 0.02765]
+ ],
+ "text": "!!! ... ??? --- (( )) <|im_end|> <|endoftext|>",
+ "input_ids": [7288, 25, 31780, 2423, 49591, 12091, 1718, 11644, 220, 248046, 220, 248044]
+ },
+ {
+ "tokens": 221,
+ "projections": [
+ [0.07089, -0.02285, -0.0011, 0.00392, 0.02934, 0.03972, 0.02755, -0.00763, -4e-05, -0.00479, -0.01828, -0.00532, -0.02012, -0.00746, -0.00684, -0.01148, 0.04356, -0.00679, 0.01896, -0.02418, 0.07615, 0.00806, 0.03139, 0.0392, 0.01909, -0.00613, 0.04159, 0.00721, -0.0243, 0.00644, -0.01469, -0.00622, 0.00249, -0.00913, 0.09861, -0.00379, 0.01063, -0.0158, 0.08175, -0.02163, 0.03506, 0.03702, 0.01654, -0.01075, 0.06379, -0.01319, -0.02377, 0.01442, -0.01764, -0.00229, 0.0073, -0.00624, 0.10109, -0.03148, 0.00325, -0.0222, 0.08378, -0.03152, 0.03389, 0.03464, 0.01472, -0.0176, 0.05025, -0.031, -0.02442, 0.01205, -0.01906, -0.00473, 0.01901, -0.01209, 0.1011, -0.04006, 0.00423, -0.02737, 0.08264, -0.01737, 0.03128, 0.03051, 0.01733, -0.01748, 0.04654, 1e-05, -0.02954, 0.00287, -0.02293, -0.00134, 0.02597, -0.01432, 0.1028, -0.03419, 0.00325, -0.02509, 0.08065, -0.04938, 0.03123, 0.03089, 0.0143, -0.01714, 0.06459, -0.01554, -0.02889, -0.00375, -0.02287, -0.00027, 0.01484, -0.0092, 0.09684, -0.05127, 0.01105, -0.02182, 0.08121, -0.04132, 0.0286, 0.02726, 0.00452, -0.01886, 0.06002, 0.00706, -0.02886, -0.00481, -0.02617, -0.01959, 0.01032, -0.02056, 0.09004, -0.03992, 0.00016, -0.02377, 0.07933, -0.02313, 0.02648, 0.02491, -0.00153, -0.02467, 0.04386, -0.0149, -0.03496, -0.01152, -0.03062, -0.02822, 0.01548, -0.02323, 0.09856, -0.02596, 0.02172, -0.02588, 0.0769, -0.0316, 0.02556, 0.02481, 0.00024, -0.02849, 0.02672, -0.03307, -0.03522, -0.00682, -0.02213, -0.01917, 0.01779, -0.02139, 0.09634, -0.02719, 0.01753, -0.02855, 0.07727, 0.00663, 0.0258, 0.02533, 0.00204, -0.02675, 0.03993, -0.00356, -0.03533, -0.00671, -0.02414, -0.0051, 0.02677, -0.0213, 0.09565, 0.00314, 0.02919, -0.02189, 0.07576, -0.01628, -0.00423, 0.02703, 0.02631, 0.00348, -0.02005, 0.07343, -0.01532, -0.03732, -0.01091, -0.02729, 0.00361, 0.01269, -0.02466, 0.09231, -0.01514, -0.00177, 0.03023, -0.01887, 0.07753, -0.02856, -0.02813, 0.02544, 0.02384, -0.01536, -0.02262, 0.06263, 0.0108, -0.03879, -0.01406, -0.03022, -0.02173, -0.00792, -0.0313, 0.09584, -0.02818, -0.02352, 0.03253],
+ [-0.01817, 0.01787, 0.01218, 0.01941, -0.01781, 0.00971, 0.0333, 0.01625, 0.02563, 0.02187, 0.02619, -0.01273, -0.00458, -0.0016, 0.00074, -0.02983, -0.00837, -0.00359, 0.01177, 0.00756, 0.02432, -0.00983, -0.0042, 0.01372, 0.03395, 0.01276, 0.01614, 0.01926, 0.02251, -0.00652, -0.00569, -0.01425, 0.01256, -0.03234, 0.01922, -0.02799, 0.00242, 0.00461, 0.02996, -0.01345, 0.00141, 0.01589, 0.02787, 0.02555, 0.01736, 0.02891, 0.01711, 0.00248, -0.01339, -0.01233, 0.01556, -0.03571, 0.0168, -0.03154, 0.007, 0.00773, 0.02993, 0.00314, 0.00014, 0.01313, 0.02937, 0.02869, 0.01557, 0.02732, 0.01352, 0.00239, -0.01724, -0.0085, 0.01985, -0.03677, 0.00906, -0.01827, 0.01046, 0.00739, 0.02878, 0.01297, -0.00238, 0.01088, 0.03159, 0.03154, 0.01508, 0.03178, 0.01219, -0.00129, -0.02048, -0.00587, 0.02413, -0.03737, 0.00835, -0.01122, 0.01036, 0.00823, 0.02712, -0.01273, -0.00164, 0.01132, 0.02888, 0.03209, 0.01742, 0.02374, 0.01302, -0.00397, -0.01995, -0.00589, 0.018, -0.03512, 0.01162, -0.01757, 0.00855, 0.00449, 0.02411, 0.0017, 0.00061, 0.01105, 0.02953, 0.03363, 0.01732, 0.01395, 0.0119, -0.00813, -0.02689, -0.01221, 0.01533, -0.03923, 0.00236, -0.00682, 0.00753, 0.00644, 0.02296, 0.01443, -0.0029, 0.00765, 0.02731, 0.0299, 0.01171, 0.01624, 0.00933, -0.01206, -0.02675, -0.01166, 0.02142, -0.04099, 0.00045, 0.00037, 0.00223, 0.00404, 0.0228, 0.02098, 0.0, 0.00871, 0.02926, 0.03138, 0.00643, 0.01963, 0.00717, -0.01209, -0.02898, -0.00706, 0.01909, -0.04189, 0.00282, 0.00774, 0.00093, -0.00032, 0.02249, -0.00727, -0.00074, 0.00847, 0.02719, 0.03101, 0.00117, 0.03151, 0.00561, -0.01022, -0.02859, -0.00165, 0.01841, -0.03785, 0.00249, -0.02807, 0.00537, 0.00308, 0.02364, -0.04319, -0.03921, 0.00123, 0.0102, 0.02481, 0.03215, 0.02104, 0.02257, 0.0075, -0.01072, -0.02629, -0.00472, 0.01254, -0.03621, -0.00338, -0.05158, -0.04474, 0.00152, 0.00439, 0.02487, -0.04036, -0.02185, -0.003, 0.00666, 0.01906, 0.02756, 0.01355, 0.01401, 0.01167, -0.01612, -0.03066, -0.01212, 0.01076, -0.04072, 0.0021, -0.04296, -0.02595, 0.00031],
+ [0.00551, -0.03722, -0.03882, -0.02702, -0.00919, 0.02477, -0.03633, -0.04038, -0.05841, -0.05032, 0.01348, 0.03569, 0.01279, 0.0308, -0.0068, -0.01949, -0.02013, -0.03339, -0.01413, -0.04859, 0.01655, -0.0446, -0.01516, 0.01446, -0.04658, -0.04641, -0.02312, -0.05873, 0.01312, 0.04389, 0.01667, 0.03051, -0.04531, -0.02103, 0.00354, -0.04126, -0.04603, -0.04323, 0.02285, -0.03298, -0.01156, 0.01066, -0.04046, -0.04763, -0.008, -0.04937, 0.01147, 0.04865, 0.02143, 0.02357, -0.0497, -0.00908, 0.00285, -0.02222, -0.0459, -0.03389, 0.02344, -0.04401, -0.01187, 0.0094, -0.03913, -0.04286, -0.01272, -0.05326, 0.00866, 0.05026, 0.02286, 0.01406, -0.03983, -0.00445, 0.00506, -0.02609, -0.0443, -0.03152, 0.02558, -0.013, -0.01055, 0.0078, -0.03765, -0.03925, -0.01161, -0.0279, 0.006, 0.05064, 0.01979, 0.00827, -0.03755, -0.00229, 0.00769, -0.00674, -0.04359, -0.02985, 0.02277, -0.0477, -0.01306, 0.00792, -0.03657, -0.04007, 0.0022, -0.05468, 0.0114, 0.04874, 0.02373, 0.00904, -0.03419, -0.00197, 0.00361, -0.03771, -0.04038, -0.02996, 0.02278, -0.04988, -0.01364, 0.01017, -0.04457, -0.04442, 0.00451, -0.06446, 0.00313, 0.04565, 0.02479, 0.01271, -0.03986, -0.00034, -0.00038, -0.04494, -0.0392, -0.03, 0.02226, -0.01678, -0.0119, 0.00856, -0.04318, -0.04355, 0.00012, -0.04502, 0.00301, 0.04346, 0.02179, 0.00805, -0.03382, -0.00142, 0.01019, -0.01615, -0.02084, -0.02567, 0.01946, -0.00124, -0.01137, 0.00791, -0.04111, -0.03861, -0.0054, -0.04144, 0.00328, 0.04442, 0.02281, 0.00477, -0.02679, 0.00445, 0.00824, -0.01126, -0.02199, -0.02142, 0.01492, -0.03067, -0.01202, 0.00804, -0.04457, -0.03367, 0.00338, -0.01774, 0.00361, 0.04687, 0.0229, -0.0022, -0.02754, 0.0072, 0.00577, -0.02515, -0.025, -0.02231, 0.01109, -0.01815, -0.01415, -0.01129, 0.00805, -0.04857, -0.03714, 0.00846, -0.05438, 0.00844, 0.04411, 0.02355, -0.00781, -0.02101, 0.00554, 0.01377, -0.01319, -0.00493, -0.0144, -0.01839, 0.01301, -0.01855, -0.02646, -0.00995, 0.00954, -0.05188, -0.04434, 0.00582, -0.06319, 0.00165, 0.04145, 0.02345, 0.00197, -0.03165, 0.00363, 0.01033, -0.02178, -0.01345, -0.0168],
+ [-0.018, -0.00616, 0.02924, 0.00954, 0.05167, 0.05259, 0.00578, -0.0096, -0.00978, -0.01347, -0.00253, -0.00611, 0.02171, -0.00369, 0.0177, 0.00749, 0.00753, 0.01139, 0.0154, -0.02128, -0.00646, -0.02559, 0.04967, 0.05719, 0.00067, -0.02864, 0.00528, -0.02421, -0.00301, -0.00446, 0.01713, -0.01297, 0.00708, -0.00647, 0.00045, -0.02924, 0.01246, -0.0456, -0.01391, -0.00492, 0.04607, 0.05147, 0.00365, -0.03031, -0.00032, -0.00909, -0.00242, -0.00666, 0.00833, 0.00222, -0.00544, -0.01719, 0.00219, -0.01409, -0.00292, -0.05012, -0.01018, -0.01802, 0.04137, 0.04727, 0.00114, -0.03069, -0.00576, -0.01219, 0.00021, -0.00944, 0.00187, 0.00107, -0.01042, -0.0238, 0.0008, -0.04752, -0.0112, -0.05236, -0.00767, -0.02736, 0.04137, 0.04367, -0.00519, -0.03184, -0.00803, -0.02253, 0.00035, -0.0121, 0.0001, 0.00121, -0.00976, -0.02677, 0.00221, -0.04082, -0.01186, -0.05027, -0.00376, -0.05205, 0.04062, 0.0474, -0.00136, -0.0332, -0.00805, -0.00964, 0.002, -0.00943, 0.00115, 0.00836, 0.00721, -0.02867, 0.00154, -0.05521, -0.00546, -0.05382, -0.00533, -0.02912, 0.04029, 0.04673, -0.00253, -0.03295, -0.0066, -0.03121, 0.0066, -0.00783, -0.00107, 0.00818, -0.00926, -0.03408, 0.00141, -0.04497, -0.01095, -0.04892, -0.00207, -0.01677, 0.03709, 0.04328, -0.00741, -0.03387, -0.01381, -0.01141, 0.00614, -0.01008, -0.00416, 0.00668, -0.01061, -0.02805, -0.00378, -0.02911, -0.00736, -0.0476, -0.00237, -0.02791, 0.03808, 0.0426, -0.00906, -0.03319, -0.01562, -0.01496, 0.00794, -0.0094, -0.00247, 0.0068, -0.00682, -0.03387, -0.0045, -0.04965, -0.00791, -0.05478, 0.00094, -0.02437, 0.03639, 0.04225, -0.01223, -0.03438, -0.01746, -0.0158, 0.00671, -0.01047, -0.00405, 0.01232, -0.00343, -0.03664, -0.00641, -0.04609, -0.00184, -0.05071, 0.00513, -0.02329, -0.00729, 0.03937, 0.04463, -0.0012, -0.03207, -0.0037, -0.01216, 0.00809, -0.00801, -0.0037, 0.02456, 0.01858, -0.04042, -0.00616, -0.0283, -0.02231, -0.00253, -0.04734, -0.00012, -0.01739, -0.00208, 0.03746, 0.04222, -0.01372, -0.03922, -0.00918, -0.03282, 0.00637, -0.00632, -0.0055, 0.01607, -0.01091, -0.03518, -0.00689, -0.02503, -0.00563, -0.0018]
+ ],
+ "text": "Section 0: revenue grew in region 0, driven by renewals (table 0). Section 1: revenue grew in region 1, driven by renewals (table 1). Section 2: revenue grew in region 2, driven by renewals (table 2). Section 3: revenue grew in region 3, driven by renewals (table 3). Section 4: revenue grew in region 4, driven by renewals (table 4). Section 5: revenue grew in region 0, driven by renewals (table 5). Section 6: revenue grew in region 1, driven by renewals (table 6). Section 7: revenue grew in region 2, driven by renewals (table 7). Section 8: revenue grew in region 3, driven by renewals (table 8). Section 9: revenue grew in region 4, driven by renewals (table 9). Section 10: revenue grew in region 0, driven by renewals (table 10). Section 11: revenue grew in region 1, driven by renewals (table 11).",
+ "input_ids": [7288, 25, 10790, 220, 15, 25, 12585, 13538, 303, 5364, 220, 15, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 15, 553, 10790, 220, 16, 25, 12585, 13538, 303, 5364, 220, 16, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 16, 553, 10790, 220, 17, 25, 12585, 13538, 303, 5364, 220, 17, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 17, 553, 10790, 220, 18, 25, 12585, 13538, 303, 5364, 220, 18, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 18, 553, 10790, 220, 19, 25, 12585, 13538, 303, 5364, 220, 19, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 19, 553, 10790, 220, 20, 25, 12585, 13538, 303, 5364, 220, 15, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 20, 553, 10790, 220, 21, 25, 12585, 13538, 303, 5364, 220, 16, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 21, 553, 10790, 220, 22, 25, 12585, 13538, 303, 5364, 220, 17, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 22, 553, 10790, 220, 23, 25, 12585, 13538, 303, 5364, 220, 18, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 23, 553, 10790, 220, 24, 25, 12585, 13538, 303, 5364, 220, 19, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 24, 553, 10790, 220, 16, 15, 25, 12585, 13538, 303, 5364, 220, 15, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 16, 15, 553, 10790, 220, 16, 16, 25, 12585, 13538, 303, 5364, 220, 16, 11, 15749, 539, 13474, 1091, 318, 1938, 220, 16, 16, 553]
+ }
+ ],
+ "pages": [
+ {
+ "tokens": 918,
+ "projections": [
+ [0.07034, 0.00391, -0.01303, -0.00122, 0.03179, -0.00244, -0.00236, 0.01325, 0.00853, 0.03063, 0.01415, -0.01453, -0.00987, -0.00135, 0.01413, 0.01945, -0.00889, -0.00267, -0.00083, -0.00914, -0.03019, -0.02718, -0.02993, 0.01394, 0.00534, 0.0017, -0.00856, -0.03706, -0.03704, -0.00906, -0.03469, 0.02968, 0.00427, -0.00114, 0.03193, -0.05609, -0.02127, 0.04497, -0.05165, -0.02473, -0.05528, -0.01784, -0.01437, 0.0058, -0.02458, 0.00129, 0.01428, -0.0009, -0.00838, 0.00831, 0.01089, -0.03618, -0.00302, 0.02249, -0.02409, -0.0707, 0.01963, 0.0245, 0.00163, -0.00863, -0.00115, -0.00672, -0.00077, -0.01007, -0.00897, -0.02397, -0.02762, -0.04407, -0.00393, 0.0031, -0.00589, -0.00633, -0.0338, -0.01017, -0.03794, 0.02891, -0.04289, -0.05496, 0.02105, 0.0209, 0.00187, 0.0113, -0.06285, -0.00145, 0.00353, -0.02751, -0.03175, -0.02428, -0.02741, -0.01682, -0.02594, -0.02301, -0.01441, -0.03003, -0.01702, -0.03535, -0.04067, -0.02347, -0.04414, -0.05077, -0.05024, -0.07399, -0.07252, -0.05881, -0.04961, -0.06858, -0.0145, 0.01368, -0.00018, -0.07433, -0.01008, 0.00265, 0.01512, -0.02371, -0.04469, -0.04201, -0.02394, -0.00362, -0.01778, -0.00192, 0.00736, -0.03506, -0.06425, -0.01857, -0.03424, -0.03042, -0.01436, -0.03981, 0.03196, -0.04427, -0.04629, 0.02057, 0.02387, -0.01034, -0.02559, -0.0517, -0.06389, -0.00384, 0.02261, -0.01673, -0.02566, -0.04136, -0.04271, -0.01179, -0.00231, -0.00941, -0.01853, -0.00608, -0.02087, -0.03507, -0.04901, 0.01055, 0.03367, -0.04929, -0.01911, -0.02321, -0.02352, -0.03068, -0.05534, -0.05682, -0.05096, -0.01414, -0.02099, -0.08566, -0.01515, 0.00312, -0.03758, -0.04093, -0.03658, -0.04599, -0.03119, -0.02187, -0.02049, -0.02071, -0.01767, -0.02016, -0.02693, -0.04123, -0.05789, -0.09563, -0.02815, -0.02036, -0.0349, -0.03826, -0.03809, -0.03365, -0.05916, -0.06601, 0.00704, 0.00927, -0.09662, -0.00122, 0.00906, -0.01344, -0.01883, -0.01188, -0.01981, -0.00945, -0.02071, -0.03562, -0.03156, -0.02705, -0.01889, -0.01476, -0.02206, -0.0201, -0.06829, -0.03064, -0.02128, -0.03987, -0.03939, -0.05746, -0.07309, -0.05565, -0.02163, -0.02767, -0.00263, -0.06068, -0.00836, 0.0079, -0.02627, -0.02201, -0.01803, -0.02934, -0.02447, -0.03201, -0.01943, -0.03741, -0.07214, -0.0101, -0.00914, -0.02361, -0.04876, -0.04918, -0.00977, 0.01865, 0.00494, -0.00373, -0.02848, 0.04227, -0.07011, -0.04691, -0.02499, 0.01221, -0.09296, -0.00143, 0.00504, -0.0272, -0.03301, -0.03775, -0.05205, -0.03413, -0.01476, -0.02097, -0.0189, -0.02713, -0.02441, -0.03018, -0.07029, -0.0708, -0.02687, -0.02386, -0.03302, -0.01738, 0.03404, -0.04668, -0.06396, -0.10642, -0.06249, -0.018, -0.03585, -0.06539, -0.06482, -0.00576, -0.04477, -0.04506, -0.03705, -0.04586, -0.04765, -0.03412, -0.03231, -0.02512, -0.03453, -0.01434, -0.01072, -0.01523, -0.03139, -0.03036, 0.01337, -0.03758, -0.02535, -0.00489, -0.01477, 0.01374, -0.06248, -0.06785, -0.07735, -0.01214, -0.05486, 0.00089, 0.01977, -0.02088, -0.02578, -0.01561, -0.00713, -0.00573, -0.00392, -0.00501, -0.03282, -0.02874, -0.02057, -0.02082, -0.01471, -0.00372, 0.01434, -0.04207, -0.04329, -0.03571, -0.00863, 0.03054, -0.0555, -0.0596, -0.03577, -0.02326, 0.02694, -0.07958, 0.00425, 0.01942, 0.0137, -0.00942, -0.01353, -0.01387, -0.00783, 0.00339, -0.04381, -0.06292, -0.05109, -0.03198, -0.03116, -0.02951, -0.01975, 0.00474, 0.01627, -0.02243, -0.07512, -0.06184, -0.03177, -0.06767, -0.07154, -0.02663, -0.02398, -0.04239, -0.06547, -0.02376, -0.00733, -0.00587, 0.00121, -0.01045, -0.0059, -0.01522, -0.01314, -0.04685, -0.03791, -0.05479, 0.0059, 0.02559, 0.01346, -0.0408, -0.02476, -0.04094, -0.05531, -0.03987, -0.06736, -0.03127, -0.06346, -0.07253, 0.03199, -0.04492, -0.00073, -0.08441, -0.01553, 0.00395, -0.01707, -0.02709, -0.03084, -0.02251, -0.0078, -0.01281, -0.02206, -0.02242, -0.06284, -0.02454, -0.0178, -0.02684, -0.01452, 0.00904, -0.05308, -0.05107, -0.03615, -0.06839, -0.02191, -0.06065, -0.07486, -0.0757, -0.01932, -0.05736, -0.06173, -0.07033, -0.00486, -0.03063, -0.04184, -0.03597, -0.02943, -0.02201, -0.02532, -0.02867, -0.03674, -0.06322, -0.03391, -0.04062, -0.01748, -0.01707, 0.00044, -0.02244, -0.05631, -0.05614, -0.07277, 0.02346, -0.03518, -0.05879, -0.08391, 0.01883, -0.04107, -0.06639, -0.00923, 0.01069, -0.02288, -0.02219, -0.00849, -0.0167, -0.01416, -0.01902, -0.03232, -0.00276, -0.0235, -0.02526, -0.0008, -0.05729, -0.05126, -0.03155, -0.01364, 0.00518, -0.07512, -0.07092, -0.01021, -0.00499, -0.05713, 0.01417, -0.03045, -0.01544, -0.06924, -0.01034, -0.00362, -0.02034, -0.02121, -0.039, -0.02445, -0.03259, -0.03293, -0.03164, -0.03567, -0.03041, -0.02547, -0.01138, -0.0248, -0.0453, 0.01749, -0.0625, -0.02404, -0.07004, -0.07387, -0.02744, -0.03156, -0.05533, -0.05121, -0.00689, -0.04428, -0.07768, -0.09461, -0.01059, -0.01716, -0.02953, -0.03201, -0.03096, -0.03882, -0.04102, -0.03939, -0.02681, -0.0372, -0.0298, -0.03048, -0.05301, -0.05331, -0.04939, -0.01486, 0.03494, -0.063, -0.07688, -0.04708, -0.05914, -0.05399, -0.06918, -0.01074, -0.02048, -0.08986, 0.00335, 0.00944, -0.0295, -0.02592, -0.01937, -0.02343, -0.01426, -0.01923, -0.01011, -0.05281, -0.01493, -0.02128, -0.02939, -0.02451, -0.02608, -0.0343, -0.04941, -0.04136, -0.0847, -0.07919, -0.05476, -0.06722, -0.05736, -0.03283, -0.02913, -0.05889, -0.0666, -0.0679, -0.01084, -0.05984, -0.05297, -0.02672, -0.02427, -0.02737, -0.02382, -0.02655, -0.06273, -0.03576, -0.04007, -0.05145, -0.0298, -0.04983, -0.0466, -0.0226, -0.04685, -0.07297, -0.06351, -0.00581, -0.06138, -0.03267, -0.03953, -0.02077, -0.03231, -0.0707, -0.00379, 0.01084, -0.03253, -0.0377, -0.01676, -0.02874, -0.02637, -0.02212, -0.02939, -0.0298, -0.01171, -0.03388, -0.02642, -0.04435, -0.05136, -0.0509, -0.03866, -0.06465, -0.08351, -0.07438, -0.05331, -0.03431, -0.01909, -0.05455, -0.0113, 0.01054, -0.07714, 0.01347, 0.02003, -0.02428, -0.02809, -0.05063, -0.04922, -0.03574, -0.02776, -0.02407, -0.02072, -0.02406, -0.02241, -0.04099, -0.06173, -0.05659, -0.06012, -0.04374, -0.00491, 0.02089, -0.08475, -0.05394, -0.06933, -0.04382, -0.05701, -0.02851, -0.06598, -0.06562, -0.07973, -0.00262, 0.00069, -0.04639, -0.05197, -0.05489, -0.05141, -0.0123, -0.02374, -0.02094, -0.03351, -0.02916, -0.03381, -0.05865, -0.02166, 0.0086, -0.06275, 0.00289, 0.00639, -0.01416, -0.05131, -0.05411, -0.075, 0.01991, -0.0189, -0.00129, -0.0729, -0.01524, -0.00624, -0.01384, -0.03016, -0.04343, -0.04907, -0.02832, -0.02243, -0.02129, -0.0267, -0.03945, -0.04775, -0.07286, -0.05285, -0.0341, -0.03395, -0.0265, 0.00259, -0.005, -0.05262, -0.05788, -0.0367, -0.10203, -0.00258, -0.02887, -0.03711, -0.07696, -0.07602, -7e-05, -0.05135, -0.051, -0.04846, -0.06229, -0.02913, -0.03035, -0.02699, -0.03669, -0.05094, -0.07519, -0.05043, -0.07461, -0.04127, -0.03261, -0.03024, -0.01025, -0.02965, -0.04866, -0.05494, -0.05563, 0.00785, 0.00858, -0.01398, -0.02498, -0.06985, -0.0057, 0.00232, -0.03398, -0.03563, -0.04288, -0.03165, -0.02455, -0.04927, -0.03664, -0.03958, -0.04931, -0.04928, -0.04325, -0.04782, -0.05017, -0.06218, -0.01413, -0.00988, -9e-05, -0.01535, -0.06666, -0.01217, -0.00745, -0.03114, -0.03372, -0.04137, -0.0796, -0.00076, 0.0022, -0.02574, -0.0621, -0.06034, -0.05107, -0.04917, -0.03993, -0.02807, -0.0256, -0.03408, -0.05729, -0.05446, -0.03111, -0.02487, -0.02774, -0.04978, -0.02724, -0.03182, -0.03299, -0.02899, -0.03052, -0.02878, -0.06466, 0.02496, -0.03842, -0.06971, -0.03626, -0.01549, -0.05053, -0.04488, -0.05638, -0.05468, -0.01304, -0.04655, -0.03121, -0.02823, -0.03026, -0.03499, -0.01633, -0.04453, -0.05778, -0.03392, -0.02212, -0.01368, -0.0407, -0.03919, -0.02684, -0.04781, -0.06722, -0.06745, 0.01793, -0.00571, -0.03293, -0.00339, 0.0169, 0.00166, -0.01641, -0.01741, -0.01071, 0.00829, -0.01513, -0.02529, -0.02314, -0.01363, 0.00321, -0.00693, -0.00667, -0.00346, -0.01342, -0.05413, 0.0069, 0.00403, 0.00141, -0.00691, -0.02511, -0.05056, -0.02163, 0.0163, -0.01078, -0.06881, 0.00338, 0.01413, -0.01162, -0.02807, -0.02844, -0.04832, -0.01231, -0.01819, -0.02334, -0.02465, -0.02008, 0.00362, -0.01473, -0.03391, -0.00542, -0.04787, -0.03141, -0.01318, -0.00995, -0.00594, -0.01707, -0.04427, -0.05064, -0.04154, 0.0309, -0.03023, -0.051, -0.00326, -0.02, -0.03262, -0.01419, 0.00418, -0.03629, 0.03217, -0.04785, -0.06748, 0.01081, 0.04435, -0.06327, -0.07621, -0.06118, -0.05814, -0.06531, -0.0194, -0.03133, -0.06172, -0.0413, -0.02098, -0.04572, -0.01397, 0.03767, -0.00141, -0.03826, -0.00202, -0.00904, -0.06452, -0.0684, -0.01728, -0.04079, -0.04224, 0.01171, 0.01009, -0.05834, -0.02174, -0.01893, -0.05084, -0.06604, -0.04019, -0.04728, -0.04026, -0.06794, 0.01249, -0.02559, -0.06688, -0.0349, -0.05105, -0.01749, 0.01804, -0.0, 0.00099, -0.00307, -0.07555, -0.03576, -0.02154, -0.04512, -0.00032, 0.04171, -0.00314, 0.0136, -0.03448, -0.05322, -0.04721, -0.06067, -0.06441, -0.06255, -0.05163, -0.06221, -0.04039, 0.03181, -0.02503, 0.00712, -0.01387, -0.02559, 0.0095, 0.00565, 0.03301],
+ [-0.02101, -0.04718, -0.03505, -0.06071, -0.01906, -0.03173, -0.02485, -0.02328, -0.05565, -0.05023, -0.02995, -0.01131, -0.0367, -0.0416, -0.02501, -0.02548, -0.0248, -0.02174, -0.05108, -0.03734, -0.00716, -0.00603, -0.01294, -0.02446, -0.0197, -0.02478, -0.06544, -0.01173, -0.03952, -0.01182, -0.01922, -0.01863, -0.02251, -0.04319, -0.0178, -0.01941, -0.00303, -0.02597, -0.01018, 0.00129, -0.02604, -0.00584, -0.0203, -0.02586, -0.03583, -0.02898, -0.03668, -0.03207, 0.01076, 0.01761, -0.03532, -0.02426, 0.00388, 0.01143, 0.00349, -0.02593, -0.00047, -0.01755, 0.03222, 0.03668, -0.00292, -0.00374, -0.00121, 0.0061, 0.00525, -0.0136, -0.01865, -0.00564, 0.02053, 0.01967, -0.03431, -0.019, -0.02261, -0.02097, -0.00825, -0.04455, -0.02553, -0.00747, 0.00072, -0.04909, 0.01143, 0.01903, -0.00484, -0.00408, -0.01444, 0.00397, 0.01957, 0.00059, 0.00285, 0.00599, 0.01381, 0.01205, 0.00146, -0.02203, 0.00148, 0.02122, -0.03298, -0.01246, -0.0193, -0.0174, -0.02403, -0.01053, -0.00124, -0.03797, -0.03236, -0.00372, -0.01432, -0.0202, 0.02744, -0.02814, -0.00825, -0.02369, -0.01319, -0.0124, -0.01618, -0.0144, -0.00964, 0.01121, 0.00159, -0.0179, 0.00833, -0.0344, -0.01338, -0.00429, -0.0446, -0.02199, -0.0328, -0.02152, -0.003, -0.03569, -0.0231, 0.00658, -0.00827, -0.0077, -0.02441, -0.02586, -0.02434, 0.00473, -0.00767, 0.01789, 0.00749, -0.01001, -0.00577, 0.00103, 0.02607, 0.02167, 0.01216, 0.02572, -0.03588, -0.00658, -0.01777, -0.05568, -0.02812, -0.02175, -0.04779, 0.00787, -0.01724, -0.04018, -0.06054, -0.06282, -0.01654, -0.02253, 0.03115, -0.03387, -0.01482, -0.02127, -0.01067, -0.01431, -0.01945, -0.01385, -0.04171, -0.04216, -0.02798, -0.0329, -0.05394, -0.05871, 0.00105, 0.00053, 0.01847, -0.02934, -0.01828, -0.00052, 0.00196, -0.00908, -0.05932, -0.06249, -0.04568, -0.01681, -0.03429, -0.0272, -0.04656, -0.02748, -0.04361, 0.00563, 0.0156, -0.01851, -0.01578, -0.01231, -0.01692, -0.04065, -0.04136, -0.05997, 0.00101, 0.00285, -0.00361, -0.00585, -0.05461, -0.0315, -0.01227, -0.00722, -0.01905, -0.05665, -0.03894, -0.04901, -0.01492, -0.04756, 0.02689, -0.03714, -0.00615, -0.01162, 0.02724, 0.01832, -0.00717, 0.00278, 0.00424, -0.00012, -0.0132, -0.00873, -0.0134, 0.02515, 0.01748, -0.01152, -0.03777, -0.04072, -0.04457, -0.02774, -0.02529, -0.00288, -0.05505, -0.00467, -0.02161, -0.03518, -0.02843, 0.022, -0.008, -0.02252, -0.03303, -0.02848, -0.01718, -0.03284, -0.02931, -0.05784, -0.0573, -0.04087, -0.04886, -0.05553, -0.05355, -0.01216, -0.02934, -0.03234, -0.0343, -0.00166, -0.0169, -0.02135, -0.01013, -0.04994, -0.05586, -0.03913, -0.02024, -0.0299, 0.01855, -0.04013, -0.04651, -0.02403, -0.01958, -0.01691, -0.03432, -0.01895, -0.05843, -0.05906, -0.04268, -0.04531, -0.05761, -0.0329, -0.01082, 0.00641, -0.00878, -0.04117, -0.0481, -0.01644, -0.01971, -0.003, -0.0229, -0.02099, -0.03087, -0.04294, -0.03633, 0.03134, -0.04868, -0.01314, -0.02737, 0.00867, 0.01351, -0.02312, -0.0264, -0.02662, -0.02526, -0.02567, -0.0209, -0.01459, -0.01476, 0.0065, 0.01803, -0.02045, -0.04141, -0.05405, -0.05254, -0.02295, -0.02354, -0.03803, -0.05267, -0.0268, 0.00347, 0.00463, -0.01721, 0.01314, -0.01262, -0.03756, -0.01771, -0.04154, -0.06049, -0.03181, -0.02089, -0.02927, -0.04314, -0.04457, -0.01332, -0.02334, 0.00589, 0.00904, -0.02656, -0.04338, -0.03995, 0.00257, -0.0325, 0.00835, -0.02805, -0.04944, 0.00574, -0.02438, -0.01499, -0.03227, -0.04238, -0.01701, -0.01782, 0.01439, -0.02071, -0.04398, -0.02857, 0.01208, -0.00415, -0.03137, -0.04121, -0.03625, -0.00334, -0.02109, -0.0297, -0.02459, -0.0572, -0.07749, -0.03286, -0.02199, -0.02104, -0.01691, -0.0284, -0.03315, -0.00292, -0.03106, 0.02226, -0.01671, -0.02151, -0.04088, -0.01533, 0.00226, -0.02589, -0.02609, -0.03278, -0.02345, -0.01958, -0.01242, -0.02793, -0.00448, -0.00017, -0.00674, -0.04502, -0.04377, -0.05879, -0.06602, -0.01508, 0.01024, -0.00554, -0.02092, -0.04848, -0.01505, 0.01065, 0.01045, -0.04676, -0.04937, -0.02232, -0.02671, -0.00911, -0.02384, -0.02221, -0.01747, -0.01521, -0.01274, -0.01992, -0.02624, 0.00659, 0.00091, 0.02897, -0.03515, -0.04377, -0.04182, -0.05925, -0.03542, -0.03374, -0.01903, -0.02487, -0.02722, -0.03363, -0.01512, 0.02673, -0.03246, -0.00351, -0.01367, -0.0051, -0.00292, -0.02417, -0.0155, -0.02334, -0.02317, -0.01852, 8e-05, 0.00394, -0.01204, -0.02297, -0.05556, -0.05015, -0.05389, -0.03424, -0.04499, -0.0181, -0.01061, 0.00554, -0.01879, -0.03702, -0.07003, -0.03343, -0.03098, -0.00469, -0.02562, -0.03463, 0.0032, -0.00385, -0.01854, -0.01665, -0.02438, -0.02455, -0.00951, 0.01433, -0.00767, -0.0105, 0.00754, -0.01236, 0.00632, -0.00817, -0.04419, -0.01994, -0.02171, -0.00547, 0.02274, -3e-05, -0.03651, -0.0177, 0.00913, 0.0178, -0.03515, -0.02293, -0.01162, -0.01225, -0.01829, -0.02105, -0.0181, -0.02514, -0.02305, -0.04418, -0.01491, -0.00905, -0.00886, 0.00833, -0.04017, -0.01236, -0.05353, -0.05646, -0.03815, -0.04547, -0.01286, -0.00104, -0.03084, -0.02728, -0.04212, -0.01971, 0.03385, 0.00592, -0.01695, -0.03588, 0.02474, 0.01854, -0.00963, 0.00011, 0.00501, -0.00197, -0.00646, -0.0266, -0.0019, 0.01743, 0.01043, -0.01434, -0.00925, -0.04285, -0.05361, -0.02332, -0.02229, -0.01476, -0.0138, -0.03112, -0.02045, -0.01681, -0.02038, -0.01722, -0.03432, -0.03265, -0.00736, 0.0035, 0.01283, -0.01126, 0.00742, 0.00867, 0.00169, 0.00674, -0.01885, 0.00713, 0.01005, -0.00428, -0.02208, -0.01993, -0.03036, -0.01171, -0.02327, -0.02519, -0.02276, -0.01329, -0.01825, 0.00139, -0.03463, 0.01162, 0.02915, -0.03332, -0.00416, -0.02192, -0.0216, -0.01471, -0.03558, -0.02156, -0.02179, -0.03557, -0.02258, -0.00809, -0.02191, -0.00141, -0.01691, 0.00512, -0.03498, -0.04507, -0.01913, -0.02653, -0.01589, -0.01662, -0.04249, -0.01301, -0.02582, -0.0318, 0.00106, -0.00959, -0.01675, -0.00367, -0.02478, 0.03949, 0.00532, -0.01175, -0.00374, -0.0121, -0.01708, 0.02838, 0.02686, 0.01043, -0.00989, -0.00148, 0.01452, 0.01191, -0.01506, -0.00544, -0.04861, 0.00539, 0.0058, -0.01121, -0.00355, 0.02402, -0.02726, -0.02699, 0.0281, -0.02873, -0.0294, -0.00884, 0.01235, -0.0102, -0.01151, -0.00991, -0.02126, 0.00188, 0.0063, -0.00395, -0.01148, -0.04309, -0.03781, 0.02336, -0.03232, -0.01124, -0.02064, -0.03365, -0.02583, -0.05215, -0.02923, -0.02859, -0.01573, -0.05572, -0.01438, 0.02256, 0.0245, -0.02017, -0.03327, -0.02468, -0.01111, -0.03398, -0.04355, -0.06817, -0.05613, -0.04718, -0.04296, -0.04656, -0.00926, -0.02906, -0.01759, -0.02261, 0.00225, -0.01051, -0.05523, -0.05178, -0.04381, -0.06292, -0.01456, -0.00738, -0.02545, -0.01179, 0.00177, -0.04096, -0.04345, -0.00792, 0.00794, 0.02232, -0.00147, -0.00918, -0.05048, -0.04228, -0.0337, -0.02938, -0.01517, -0.00994, 0.00082, -0.02307, 0.00199, 0.02636, 0.00955, -0.02015, -0.01797, -0.04007, -0.05505, -0.05194, -0.05619, -0.01834, -0.01196, 0.05314, -0.02938, -0.0125, -0.02951, 0.00553, 0.00977, -0.0124, -0.01074, -0.02394, 0.0116, 0.01399, 0.00938, 0.00572, -0.02592, -0.00786, -0.02941, 0.0273, -0.01576, -0.05851, -0.01881, -0.0291, -0.05222, 0.00984, -0.00213, -0.00239, -0.00301, -0.00214, 0.0069, -0.01691, -0.00478, -0.02827, 0.0072, 0.00221, -0.00932, -0.00479, -0.0185, -0.04649, -0.0258, -0.02416, -0.02444, -0.02081, -0.00083, -0.05165, -0.03811, -0.03235, -0.00906, 0.00149, 0.01095, 0.00247, -0.03511, -0.05494, -0.06038, -0.05102, 0.00747, 0.05728, -0.0337, -0.00392, -0.00628, 0.01831, 0.01661, 0.00629, -0.00714, -0.0376, -0.02866, -0.02118, -0.02039, -0.03106, -0.02186, -0.01167, 0.00479, -0.01358, 0.01041, -0.02357, -0.02896, 0.01288, 0.0051, -0.02775, -0.03884, -0.03656, -0.04484, -0.02548, 0.01696, 0.05544, -0.01681, -0.03843, -0.03516, -0.0195, -0.02808, -0.02163, -0.05549, -0.03961, -0.03051, -0.03194, -0.04466, -0.04123, -0.02622, -0.01824, -0.01863, -0.05152, -0.01746, -0.01872, -0.01189, -0.03398, -0.08241, -0.06401, -0.0413, 0.01533, -0.02218, 0.02876, -0.02264, -0.00478, -0.01483, -0.0195, -0.00594, -0.01936, 0.00902, -0.03946, -0.03747, -0.02644, -0.02149, -0.03938, -0.04626, -0.01992, -0.03683, -0.0447, -0.05491, -0.00343, -0.00694, 0.00337, -0.02866, -0.07272, -0.04875, -0.04107, -0.0122, -0.04455, 0.00727, -0.01853, -0.01241, -0.01668, -0.05141, -0.05871, -0.05728, -0.0188, -0.02223, -0.00834, -0.04087, -0.05533, -0.02817, -0.00885, -0.02803, -0.01996, -0.02468, -0.02, -0.03329, -0.033, -0.0319, -0.03886, -0.0862, -0.07284, -0.02144, -0.0754, -0.05437, 0.01088, -0.01637, -0.0276, 0.00896, -0.02927, -0.0035, 0.00103, -0.01706, -0.03259, 0.00029, -0.01793, -0.00416, 0.01376, -0.03824, -0.03657, -0.01034, -0.02985, -0.0256, -0.03153, -0.03549, -0.03452, -0.02851, -0.03256, -0.04712, -0.05528, -0.04026, -0.05083, -0.00307, -0.0104, -0.01819, 0.00295, -0.02992, -0.02356, -0.04259, -0.02444, -0.02898, -0.01693, -0.03358, -0.01899, -0.02102, -0.04945, -0.00897, -0.02526, -0.0276, -0.03806, -0.05041, 0.0012, -0.01978, -0.02284, -0.03556, -0.01798, -0.0119, -0.03826, 0.00109],
+ [0.01965, 0.02219, -0.00436, -0.02161, -0.00836, -0.02185, -0.01813, 0.00342, -0.01172, -0.0343, -0.02695, -0.04328, 0.0031, 0.00525, -0.04329, -0.03235, -0.00903, -0.02632, -0.01806, -0.01424, -0.01907, 0.00177, -0.00606, -0.01991, -0.01238, -0.00204, 0.01057, -0.02163, -0.01739, -0.01702, -0.0234, -0.02581, 0.00816, 0.01002, 0.04654, -0.01171, -0.01639, -0.02116, -0.03651, -0.05014, -0.04608, -0.00745, -0.03057, -0.00371, -0.0516, -0.01505, 0.04204, 0.00149, -0.02125, -0.00693, -0.05247, -0.02446, -0.03564, 0.00505, -0.02425, -0.02244, -0.01251, -0.02138, -0.08771, -0.09508, -0.10292, -0.10565, -0.10713, -0.10933, -0.10424, -0.00474, -0.01356, -0.06833, -0.09751, -0.09589, -0.06578, -0.02875, -0.05372, -0.00776, -0.01086, 0.06568, -0.00772, -0.02737, -0.02747, -0.04497, 0.0317, -0.00351, -0.04627, -0.02653, -0.03264, -0.09364, -0.09963, -0.10398, -0.1181, -0.12507, -0.12442, -0.11161, -0.10317, -0.00711, -0.09723, -0.09268, -0.04258, -0.08247, -0.04474, -0.05838, -0.01145, -0.02575, -0.0396, -0.04208, -0.03118, -0.03675, -0.002, -0.02478, 0.00222, -0.03018, 0.00047, 0.00413, -0.02802, -0.0026, -0.02639, -0.0377, -0.00808, -0.04117, -0.04561, -0.00781, 0.03611, -0.05384, 0.02106, -0.08537, -0.06968, -0.04404, -0.06062, -0.01487, 0.00521, -0.02783, -0.03608, 0.00489, 0.00771, -0.03391, -0.05234, -0.02172, -0.04564, -0.00711, -0.00428, -0.08056, -0.04507, -0.0324, -0.04602, -0.06588, -0.07994, -0.09446, -0.05944, 0.00409, -0.04847, -0.00134, -0.03955, 0.01688, 0.02081, -0.03941, -0.00326, -0.07882, -0.08729, -0.0797, -0.03296, -0.05393, -0.00631, -0.0392, -0.01534, -0.04594, -0.01754, -0.03261, -0.09468, -0.09224, -0.07857, -0.06501, -0.08656, -0.07844, -0.06649, -0.05712, -0.0536, -0.06766, -0.00591, -0.00921, -0.01021, -0.02571, -0.07694, -0.08683, -0.09764, -0.09454, -0.05452, -0.05014, -0.0555, -0.0107, -0.02513, 0.02282, -0.02603, -0.00719, -0.01073, -0.07291, -0.07178, -0.08886, -0.09507, -0.09873, -0.1, -0.07048, -0.05984, -0.05108, -0.07685, -0.08373, -0.09483, -0.08492, -0.02228, -0.06692, -0.0719, -0.08624, -0.08188, -0.05387, -0.04403, -0.0619, -0.00254, -0.04157, -0.01173, -0.0521, -0.00372, -0.00585, -0.09432, -0.09523, -0.09522, -0.09479, -0.10277, -0.09964, -0.04638, -0.0268, -0.01756, -0.09338, -0.0957, -0.09575, -0.07699, -0.06194, 0.01295, 0.00668, -0.01755, 0.01994, -0.01297, 0.02145, -0.04414, -0.04899, 0.00132, -0.00725, 0.00124, -0.01448, -0.01246, -0.07311, -0.07487, -0.08076, -0.06357, -0.07453, -0.08892, -0.08278, -0.08075, -0.07598, -0.06477, -0.00126, -0.0259, -0.02278, -0.05997, -0.06428, -0.07737, -0.03457, 0.04436, -0.05557, -0.03382, -0.03167, -0.05463, -0.01485, 0.00715, -0.03946, -0.032, -0.02104, -0.0856, -0.09112, -0.08448, -0.07869, -0.08692, -0.08809, -0.08623, -0.088, -0.08442, -0.04362, 0.01026, 0.01843, -0.03155, -0.02973, -0.0077, -0.08905, -0.0609, 0.03563, 0.0173, 0.01503, -0.03442, -0.00582, -0.04516, -0.00616, -0.04768, 0.00153, -0.00281, -0.0815, -0.09059, -0.09199, -0.10063, -0.1072, -0.1116, -0.10297, -0.01773, 0.01186, -0.08214, -0.09923, -0.09707, -0.0773, -0.02045, -0.05598, -0.04538, -0.00237, -0.00602, 0.02931, -0.02511, -0.03146, 0.00886, -0.00176, 0.02451, 0.01344, -0.01174, -0.01316, -0.04289, -0.00523, -0.00996, -0.00075, -0.04941, -0.05438, 0.00861, 0.02507, -0.07041, -0.065, -0.07682, -0.08987, -0.06477, -0.02084, -0.01556, -0.00372, -0.02886, -0.03431, -0.02561, -0.01736, -0.03148, -0.03074, -0.01941, -0.0179, -0.03046, 0.001, -0.00257, -0.08157, -0.0182, -0.01079, -0.01684, -0.08432, -0.05968, 0.01679, -0.04783, 0.01061, 0.02986, 0.01062, 0.00799, -0.03039, -0.05925, -0.03174, -0.04531, -0.04001, -0.04055, -0.03491, -0.04822, -0.02923, 0.03991, -0.04343, -0.00604, 0.01523, 0.00762, 0.01045, -0.08834, -0.09281, -0.08884, -0.11389, -0.11515, -0.11687, -0.10027, -0.07522, -0.00043, -0.07621, -0.09323, -0.10091, -0.07482, -0.02707, -0.05932, -0.04831, -0.01072, -0.0622, -0.08654, -0.02065, -0.02939, -0.00376, -0.00849, -0.00898, -0.03868, -0.03787, -0.02369, -0.08821, -0.10169, -0.09157, -0.1046, -0.11546, -0.12488, -0.10616, -0.07395, -0.06671, -0.03059, -0.07106, -0.00872, -0.08618, -0.04515, -0.05085, -0.04384, -0.03891, -0.03619, 0.00418, -0.02798, -0.04597, -0.01211, 0.00446, -0.03025, -0.03803, -0.00652, -0.01775, -0.06045, -0.04121, -0.03484, -0.04384, -0.04017, -0.02717, -0.00117, -0.05338, -0.06898, -0.06549, -0.01326, -0.04585, -0.04248, -0.045, 0.00445, 0.05931, -0.03582, -0.03822, 0.0039, -0.04139, -0.04252, -0.03274, -0.05683, 0.00226, -0.01743, 0.00302, 0.00231, -0.03871, -0.02654, -0.0537, -0.05698, -0.04768, -0.04538, -0.04025, -0.07311, -0.04915, -0.05697, 0.00421, -0.0084, -0.02033, 0.01766, -0.0252, -0.03062, -0.04537, -0.04056, -0.07812, -0.03798, -0.04595, 0.01516, -0.0292, -0.01741, -0.04408, -0.02053, -0.01771, -0.0697, -0.03653, -0.05508, -0.05075, -0.04336, -0.02663, -0.04716, -0.0343, -0.07399, -0.09473, -0.0511, -0.06765, -0.06377, -0.04782, 0.03022, 0.07416, -0.04009, -0.04341, -0.04629, -0.03073, -0.05772, -0.01216, 0.00288, -0.00297, 0.02058, 0.00425, 0.00899, -0.09933, -0.08779, -0.09029, -0.09059, -0.09642, -0.099, -0.08192, -0.01593, -0.0817, -0.08748, -0.08545, -0.0793, -0.07621, -0.06642, -0.03793, -0.01299, -0.03005, -0.02684, -0.02377, -0.04078, -0.07271, -0.07772, -0.04645, 0.00467, -0.03206, -0.03211, -0.01331, -0.10422, -0.10084, -0.09136, -0.09113, -0.09924, -0.09852, -0.09107, -0.01294, -0.09242, -0.10889, -0.10864, -0.10162, -0.08454, -0.07611, -0.02784, -0.04698, -0.02184, -0.03081, -0.03716, -0.03314, -0.10476, -0.05225, -0.01459, -0.00333, -0.04445, -0.01303, -0.02102, -0.05099, -0.05559, -0.05791, -0.06847, -0.07344, -0.06545, -0.00834, 0.0028, -0.06183, -0.07148, -0.058, -0.04552, -0.06896, -0.05749, 0.00646, -0.01886, -0.03577, -0.04226, -0.03554, -0.00693, -0.05008, -0.05443, -0.00781, 0.00511, -0.00164, -0.01447, -0.00151, -0.0497, -0.03159, -0.0254, -0.02953, -0.06852, -0.06919, -0.04903, -0.06668, -0.06759, -0.06105, -0.09272, -0.06262, -0.06564, -0.01383, -0.01138, 0.01389, 0.0018, -0.03796, -0.07379, -0.01066, -0.07486, -0.04678, -0.07839, 0.00813, -0.04323, -0.01232, 0.00245, -0.06327, -0.03752, -0.03339, -0.03255, -0.01732, 0.01261, -0.0687, -0.08752, -0.0817, -0.06865, -0.06562, -0.01472, -0.00228, -0.0004, -0.03725, -0.04165, 0.05222, 0.03841, -0.05811, -0.04728, -0.03598, -0.03451, -0.0331, -0.00398, 0.01467, -0.01106, -0.01257, -0.07399, -0.0733, -0.07364, -0.07607, -0.09387, -0.09564, -0.08768, -0.08159, -0.07689, -0.06623, -0.02225, -0.04046, -0.07167, -0.07804, -0.08824, -0.01027, 0.02784, -0.05559, -0.02775, 0.00517, -0.03473, 0.00215, -0.00219, -0.02469, -0.04641, -0.04653, -0.02135, -0.09578, -0.10413, -0.09437, -0.0757, -0.09555, -0.09521, -0.10051, -0.09243, -0.07848, -0.06352, -0.04528, -0.01467, -0.08571, -0.09218, -0.07959, -0.03195, 0.0214, -0.00512, -0.01644, -0.02173, 0.0317, -0.00146, -0.03996, -0.00737, -0.04606, -0.0147, -0.01374, -0.04765, -0.01309, -0.01736, -0.01576, -0.01065, -0.02617, -0.039, -0.03032, -0.04906, -0.06976, -0.04339, -0.06144, 0.00298, -0.04895, 0.006, -0.02802, 0.00843, -0.00571, -0.01977, -0.00216, -0.00348, -0.01539, -0.02171, -0.0342, -0.0198, -0.00558, -0.01032, -0.08412, -0.01995, -0.02977, -0.02953, -0.02363, -0.05791, -0.05048, -0.04551, -0.06978, -0.07934, -0.04176, -0.04569, -0.0474, -0.04671, -0.06724, -0.07204, -0.06373, -0.08515, -0.07953, -0.02734, -0.04277, -0.02075, 0.00541, -0.00439, -0.05103, -0.01204, -0.01976, -0.10452, -0.09924, -0.08684, -0.04853, -0.02825, -0.07756, -0.0743, -0.07339, -0.07892, -0.08308, -0.03641, -0.00922, -0.00674, -0.08329, -0.04609, -0.05063, -0.08154, -0.08535, -0.08803, -0.04644, -0.06086, -0.03602, -0.04912, 0.01406, -0.00452, -0.01075, -0.00458, -0.05674, -0.06558, -0.04942, -0.0523, -0.0292, -0.06168, -0.06075, -0.0576, -0.05963, -0.05567, -0.05232, -0.05844, -0.05837, -0.00867, -0.02091, -0.05131, -0.05984, -0.0607, -0.04869, -0.03534, -0.0604, 0.00046, -0.0438, 0.00208, -0.05689, -0.0099, -0.0188, -0.09819, -0.09397, -0.07353, -0.02212, -0.00467, -0.06297, -0.06911, -0.06992, -0.07166, -0.0684, -0.03109, -0.02851, -0.01382, -0.01704, -0.00431, -0.07422, -0.09459, -0.0936, -0.08015, -0.05779, -0.06394, -0.00258, -0.00606, -0.04421, -0.04078, -0.03137, -0.07778, -0.00634, 0.0271, 0.0262, -0.01459, 0.0693, 0.01649, -0.00098, 0.0297, 0.03504, -0.08338, -0.05675, -0.06984, -0.05343, -0.05465, 9e-05, -0.00582, -0.05462, -0.01827, -0.06871, -0.04276, 0.00033, -0.04174, -0.03984, -0.04903, 0.00117, -0.00329, -0.07115, -0.03515, -0.01244, -0.05093, 0.02021, 0.06336, -0.0439, -0.03998, -0.02935, 0.0092, -0.05382, -0.04781, -0.05173, -0.04873, -0.05958, -0.01321, 0.03455, -0.02866, -0.04271, -0.047, -0.03618, 0.00289, -0.02449, -0.01547, -0.03018, -0.01962, -0.03342, 0.00874, -0.03599, 0.02005, -0.00854, 0.03684, -0.05136, -0.04432, -0.05203, -0.03833, -0.04591, -0.05247, -0.05517, -0.04181, -0.08849, -0.04893, -0.01303, 0.00286, -0.02664, 0.0076, -0.04994, -0.0149, 0.00497, -0.03857, -0.00478],
+ [0.03736, -0.02242, -0.02667, 0.00283, -0.03083, -0.04209, -0.03089, -0.02379, -0.02584, -0.01668, -0.02829, -0.0553, -0.0387, -0.02241, -0.03232, -0.05211, -0.02943, -0.00883, -0.03504, -0.01483, -0.04203, -0.02159, -0.03103, -0.03104, 0.00734, -0.03446, -0.00813, -0.0162, -0.02446, -0.02589, -0.02218, -0.00194, 0.00029, -0.02472, -0.00867, 0.01531, -0.01888, 0.03171, -0.00896, -0.02701, 0.00408, 0.01295, 0.01648, 0.02485, 0.01502, 0.01529, -0.04175, -0.00175, 0.00813, 0.00659, 0.01695, 0.03723, 0.00574, 0.00574, -0.02331, -0.01604, -0.00866, -0.0179, 0.00299, -0.00963, -0.02215, -0.00113, 0.00229, 0.0001, 0.00053, 0.01174, 0.01084, -0.01919, -0.00375, 0.01219, 0.03762, 0.04784, 0.01679, 0.01882, 0.00554, -0.01184, -0.04307, 0.0228, 0.03344, 0.00244, -0.00645, -0.00816, 0.00951, -0.01298, -0.0193, -0.02366, -0.01078, -0.0157, -0.00378, -0.00316, -0.00299, 0.00236, -0.00976, 0.00549, 0.00045, 0.00932, 0.00449, 0.03503, 0.01993, 0.01515, 0.00021, 0.01079, 0.01218, 0.00365, -0.00725, 0.01347, 0.01421, 0.00713, -0.03368, -0.00184, 0.00853, -0.00563, -0.01129, -0.00718, -0.02462, -0.0337, 0.01193, 0.01038, 0.00819, 0.02263, 0.0059, 0.01929, 0.04936, 0.00323, 0.01683, 0.03813, 0.00215, -0.00369, -0.01876, 0.01138, 0.00912, 0.04143, -0.01763, 4e-05, 0.00492, -0.01087, 0.00468, -0.00119, -0.01518, -0.03839, -0.02498, -0.01901, -0.02618, -0.03225, -0.01257, -0.00601, 0.00347, -0.02262, 0.01576, -0.00458, -0.00615, -0.03374, -0.02183, 0.01194, -0.01538, 0.00361, 0.0029, 0.04541, 0.05115, 0.04084, 0.00894, -0.00824, -0.02596, 0.01474, -0.00756, -0.0291, -0.02755, -0.03734, -0.03173, -0.01818, -0.01326, -0.00506, -0.00774, -0.01346, -0.01439, -0.01519, 0.00711, 0.01077, 0.00765, 0.01539, -0.01008, 0.00363, 0.0025, 0.00034, 0.04123, 0.01482, 0.02842, 0.01783, 0.01175, -0.04832, -0.00061, -0.00647, -0.02552, -0.01278, -0.01284, -0.01706, -0.01602, -0.01563, -0.00014, -0.00582, -0.01068, -0.00579, -0.00215, -7e-05, 0.03233, 0.01936, 0.02015, 0.00073, 0.01424, -0.00191, -0.01289, 0.04329, 0.05616, 0.04042, 0.01338, 0.01363, -0.0289, 0.00627, 0.00587, -0.00333, -0.03493, -0.03077, -0.02992, -0.03098, -0.03022, -0.02087, 0.03154, 0.00399, 0.00209, -0.00795, -0.00357, 0.02648, 0.01223, 0.01061, -0.03057, 0.00406, 0.03499, 0.04517, 0.02393, -0.01995, 0.00945, 0.00928, -0.01138, -0.03441, -0.01635, -0.01128, -0.03647, -0.03883, -0.04127, -0.04059, -0.04179, -0.03121, 0.00026, -0.00374, -0.01275, -0.01166, -0.01725, -0.00095, 0.0025, -0.00025, -0.01841, -0.00457, -0.00604, 0.0249, 0.06363, 0.0153, 0.02063, -0.01125, 0.00209, -0.0151, -0.02662, 0.00868, -0.00434, -0.02198, -0.04293, -0.03671, -0.03665, -0.02386, -0.02356, -0.00529, -0.01454, -0.01986, -0.01007, 0.01927, 0.01104, 0.00599, 0.00095, 0.02049, 0.01452, 0.01098, 0.0333, 0.06214, 0.03487, -0.02041, 0.01283, -0.0292, -0.02469, -0.03564, 0.00544, -0.00162, -0.02807, -0.02469, -0.03723, -0.02497, -0.00318, 0.00401, -0.00036, 0.00709, 0.00013, -0.00098, -0.0161, -0.00671, -0.00243, 0.0033, 0.01552, 0.00307, 0.00586, -0.00925, 0.01798, -0.03871, -0.0087, 0.00193, 0.0114, -0.00183, -0.02747, -0.01754, -0.00694, -0.02242, -0.00998, 0.0273, 0.01291, 0.01891, 0.00921, 0.00102, 0.00576, 0.01055, -0.02375, -0.00583, -0.00348, -0.01748, -0.013, 0.00047, -0.00359, -0.00498, 0.00652, 0.02675, -0.00637, 0.02659, 0.01323, 0.01428, -0.01983, -0.02374, 0.00902, 0.01051, -0.00105, -0.01669, 0.02988, 0.00828, 0.02189, -0.00075, 0.018, 0.03453, 0.02078, 0.01804, -0.03436, -0.0231, -0.01753, 0.01719, 0.01727, 0.01003, -0.00597, 0.02297, 0.00944, -0.00055, 0.02441, 0.01033, -0.01184, -0.05212, -0.03287, -0.01275, 0.01923, -0.00934, -0.01041, -0.02221, -0.02016, 0.00374, 0.01329, 0.00803, 0.01615, -0.00187, 0.02009, -0.00914, -0.00662, -0.00242, 0.01798, 0.03593, 0.00903, 0.01581, -0.01035, 0.00396, -0.01543, 0.01163, 0.00397, -0.01468, -0.01502, -0.03063, -0.00122, -0.00961, -0.02278, -0.03487, -0.027, -0.02569, -0.01227, 0.00487, 0.00396, 0.00696, -0.01702, -0.01114, -0.01725, -0.00224, 0.00222, -0.00696, 0.03794, -0.00359, 0.0104, 0.00325, 0.00054, -0.01342, -0.01525, 0.00933, -0.00185, 0.00632, -0.03007, -0.00148, -0.00601, -0.0294, -0.02344, -0.0234, -0.02569, -0.02785, -0.03166, -0.01057, 0.03209, -0.00145, 0.01173, -0.00116, 0.00887, -0.00988, -0.01346, 0.00703, -0.04183, -0.01683, -0.00188, 0.00175, -0.0315, 0.01375, -0.01245, 0.00762, -0.02663, 0.01197, -0.01221, 0.0049, -0.01326, -0.01835, -0.00893, -0.00718, -0.0106, -0.0221, -0.00389, 0.0008, -0.00451, -0.00408, -0.00159, -0.00802, -0.00938, 0.00986, -0.03855, 0.008, 0.01174, -0.00251, 0.00815, 0.01177, 0.00675, -0.016, 0.01573, -0.01587, -0.01625, -0.01188, -0.0246, -0.00942, -0.03679, -0.02273, -0.02016, -0.0224, -0.02076, -0.02009, -0.00354, -0.01431, -0.00363, 0.02112, 0.01374, 0.00702, 0.0136, 0.00057, -0.0449, -0.00702, -0.02901, -0.00187, -0.0226, -0.00535, 0.00205, 0.00906, -0.0004, -0.0367, -0.03099, -0.00023, -0.02189, -0.00987, -0.02029, -0.02268, -0.00984, -0.00562, 0.00171, 0.00777, -0.01014, -0.01581, -0.0068, -0.00252, 0.00975, 0.0321, -0.00024, 0.00337, -0.02299, 0.00416, -0.0024, 0.00263, 0.02743, -0.00322, 0.011, -0.05554, 0.01413, -0.01793, -0.02032, -0.02721, -0.04066, -0.03434, -0.02532, -0.01301, -0.00945, -0.0019, -0.00217, 0.01768, -0.02729, -0.01238, -0.00938, 0.03826, 0.02833, -0.00303, 0.01397, 0.00228, -0.01359, -0.01314, 0.02114, 0.01808, -0.01982, -0.00249, -0.02195, -0.02598, 0.00161, -0.01332, -0.02973, -0.03272, -0.02929, -0.028, -0.03051, -0.02242, -0.00966, 0.05753, 0.05066, -0.01051, -0.02358, -0.03021, -0.02098, 0.00927, 0.01868, 0.04336, -0.00217, -0.00466, -0.00248, 0.00322, 0.04942, -0.01616, 0.00643, 0.01215, -0.03772, -0.01101, -0.00853, -0.02799, -0.02646, -0.0153, -0.00121, -0.00589, -0.03125, -0.01194, -0.01187, -0.01367, -0.00214, -0.01111, -0.00646, -0.00285, -0.00984, 0.01756, 0.05714, -0.03766, -0.01866, 0.01387, -0.01295, -0.00184, -0.0081, 0.00988, -0.01649, -0.01985, -0.00754, -0.01407, -0.00871, -0.03783, -0.01528, -0.00124, -0.00596, -0.00192, -0.00598, -0.00384, -0.00167, 0.00374, -0.00962, -0.00538, -0.00626, -0.0324, 0.00702, -0.02033, 0.02485, 0.01697, 0.02014, -0.00527, -0.00935, -0.00161, -0.01012, 0.00352, -0.03535, -0.01657, -0.00514, -0.02336, -0.043, -0.042, -0.04518, -0.04753, -0.01505, 0.00576, 0.00517, -0.00315, -0.01533, -0.04512, 0.01749, -0.01843, -0.026, -0.01399, -0.01027, 0.01372, 0.00983, 0.00266, 0.00988, -0.02414, -0.01876, -0.04018, -0.03399, -0.00195, -0.00207, -0.00317, -0.02847, -0.06092, -0.04996, -0.04793, -0.04353, -0.00953, -0.00941, -0.01497, -0.00269, -0.01557, 0.00823, 0.00281, 0.00302, -0.01656, -0.00511, -0.00276, 0.04613, 0.04119, 0.02411, 0.01266, 0.01113, -0.03993, -0.04787, -0.05139, -0.02097, 0.01187, -0.00726, -0.02531, -0.02473, -0.0161, -0.01725, -0.01103, -0.00775, -0.00476, -0.02101, 0.00895, -0.00568, -0.00199, -0.01576, 0.02027, 0.00717, 0.01152, -0.02425, 0.03936, 0.00622, 0.01505, 0.02088, 0.03109, 0.00406, -0.00531, 0.00028, -0.00999, -0.00636, -0.00761, -0.02039, -0.02467, -0.02498, -0.0201, -0.0199, -0.01226, -0.00455, -0.00798, -0.01271, -0.01484, -0.00028, -0.02311, -0.04069, -0.03462, -0.03441, -0.02897, -5e-05, 0.00492, 0.00864, 0.03509, 0.03654, 0.01568, 0.03659, -0.04389, -0.02747, 0.01606, -0.01063, -0.01815, -0.03323, -0.03383, -0.05067, -0.03024, -0.01566, -0.02561, -0.02391, -0.02864, -0.02308, -0.01359, -0.01054, -0.00822, -0.01425, -0.00748, 0.0139, 0.00675, -0.00161, -0.00176, 0.02868, 0.05112, 0.01935, 0.02716, -0.06603, -0.02907, -0.01623, -0.00321, -0.01899, -0.01782, -0.02063, -0.02423, -0.01343, -0.00494, -0.00284, -0.00587, -0.00787, -0.00025, 0.01471, 0.00851, 0.00571, -0.00191, -0.03518, 0.01427, -0.00111, 0.01489, 0.01266, 0.03745, 0.03987, 0.02761, -0.0133, -0.02449, -0.03061, 0.01438, -0.00827, -0.01723, -0.01969, -0.02442, -0.03207, 0.00256, -0.02967, -0.00131, -0.00585, -0.01316, -0.01031, 0.01197, 0.00141, 0.00015, -0.03751, -0.02664, 0.02634, 0.00206, 0.01954, 0.01, 0.03364, 0.0539, 0.01678, 0.00487, -0.0394, -0.01341, -0.0416, -0.01637, -0.00654, -0.0113, -0.02523, -0.03134, -0.00901, 0.00532, 0.01261, -0.00185, -0.03444, -0.00487, 0.01084, 5e-05, -0.00374, 0.01798, 0.01357, -0.01219, -0.02319, 0.00249, 0.01185, 0.0114, 0.02632, -0.0257, -0.00198, -0.043, -0.01684, 0.0051, -0.01563, -0.02782, 0.00752, 0.00137, -0.01851, 0.0017, 0.00189, 0.02033, 0.00841, 0.01281, -0.01296, -0.02233, 0.00676, -0.02856, 0.0008, -0.01279, -0.01716, -0.0304, 0.01304, 0.0176, 0.02037, 0.02207, -0.02752, -0.02628, -0.0456, 0.00082, 0.02051, -0.00358, 0.01811, -0.00549, -0.00014, -0.03957, -0.03624, -0.0045, -0.00825, -0.00984, 0.01207, 0.00677, 0.00237, 0.00896, -0.0117, 0.01056, 0.0021, -0.02478, -0.01451, 0.01958, -0.02055, 0.0109, 0.00839, -0.00322, 0.01152, 0.02838]
+ ],
+ "name": "letter",
+ "width": 850,
+ "height": 1100,
+ "seed": 1
+ },
+ {
+ "tokens": 300,
+ "projections": [
+ [0.06543, -0.01325, -0.02091, -0.00865, 0.01401, -0.0109, -0.01683, 0.00433, 0.01472, 0.00802, -0.00948, -0.01258, -0.00106, -0.00813, 0.01495, -0.03444, -0.03049, -0.02608, 0.03363, 0.01434, 0.02086, 0.02765, 0.01002, -0.0038, 0.03203, -0.03234, -0.01436, 0.0009, -0.00652, -0.05844, -0.02821, -0.03682, -0.03789, 0.00011, 0.0035, -0.05333, 0.00704, -0.01574, -0.00703, -0.01619, 0.00199, 0.04877, 0.0361, -0.0088, 0.01403, -0.04235, -0.02354, -0.03917, 0.00202, -0.00153, 0.00383, 0.01142, -0.00672, -0.02201, -0.01969, -0.00786, 0.04715, 0.02562, -0.03298, -0.0208, -0.02873, -0.03777, -0.04706, -0.0093, -0.00287, -0.04652, -0.00109, -0.04295, -0.02515, -0.01674, -0.0149, -0.02797, -0.0206, -0.01856, -0.03784, -0.04671, -0.02464, -0.04196, 0.01291, 0.00837, -0.03735, -0.01831, -0.0161, -0.01835, -0.01017, -0.01513, -0.04304, -0.02079, -0.05104, 0.00466, -0.02919, -0.02425, -0.03358, -0.00974, -0.0062, -0.01203, -0.02888, -0.01836, -0.0075, -0.02714, -0.01965, 0.02029, 0.02613, -0.01193, 0.0021, -0.03581, -0.03352, -0.04235, -0.00759, -0.00089, -0.02744, -0.0261, -0.04119, -0.00862, -0.00503, -0.06541, -0.0097, 0.00555, -0.01105, -0.03011, -0.04268, -0.03004, -0.03854, 0.01339, 0.00649, -0.02289, -0.00929, -0.00248, -0.02541, -0.01121, -0.0856, -0.0159, -0.0325, -0.03368, -0.01685, -0.03476, -0.04121, -0.05225, -0.00026, -0.00608, -0.0197, -0.03697, -0.0227, 0.00668, 0.00355, -0.02112, -0.01391, -0.03042, -0.00744, -0.0329, -0.05437, -0.03389, -0.051, -0.0228, -0.00308, -0.00417, -0.0352, -0.01367, 0.04344, -0.00505, -0.03744, 0.00093, -0.00481, 0.00581, -0.06881, -0.04962, -0.03821, -0.04748, -0.02469, -0.01155, -0.03952, -0.03874, -0.00345, 0.0634, -0.01142, -0.04505, -0.0095, -0.01505, -0.06278, -0.03528, -0.05378, -0.03909, -0.05014, -0.03747, -0.05345, -0.05415, -0.04294, -0.05594, -0.01344, -0.03855, -0.03225, -0.02058, -0.00977, -0.012, -0.00955, -0.06399, -0.0305, -0.04175, -0.01695, -0.00332, -0.00363, -0.05507, 0.00304, 0.04127, 0.01067, -0.04542, -0.01729, -0.01147, -0.04748, -0.03487, -0.03572, -0.02592, -0.02795, 0.00067, 0.00042, -0.00249, -0.0037, 0.01989, 0.01234, -0.00604, 0.00624, 0.00425, -0.00184, -0.05407, 0.002, -0.03913, -0.03368, -0.03784, -0.01762, -0.0086, -0.01386, 0.0255, 0.02138, -0.00654, -0.04038, -0.00588, -0.00497, -0.01424, -0.0116, -0.01098, -0.04744, -0.04489, -0.05584, -0.03343, -0.0006, -0.05682, -0.05245, -0.01918, -0.00428, -0.04852, -0.02653, 0.00818, -0.00802, -0.00214, -0.03782, -0.04483, -0.03825, -0.03462, 0.00793, 0.0017, 0.00364, 0.00227, 0.0167, 0.01123, -0.02374, 0.00179, -0.02545, -0.00483, -0.05189, -0.01768, -0.02738, -0.04944, -0.03736, -0.01485, -0.01008, -0.00952, -0.00343, -0.00091, -0.01683, -0.01501, -0.02466, -0.02059, -0.02034, -0.02572, -0.024, 0.01167, -0.02461, -0.00341, -0.01396, -0.01363, -0.01132, -0.01192, -0.02403, 0.02536, -0.00999, -0.02658, -0.03064, -0.0034, 0.00767, 0.0553],
+ [0.00258, -0.00758, -0.03193, -0.03703, -0.00571, -0.02024, -0.02557, -0.03109, -0.05846, -0.05498, 0.00693, 0.01206, -0.00093, -0.03386, -0.06478, -0.00845, -0.02901, -0.01218, 0.03205, 0.03079, 0.01908, -0.03039, -0.06256, -0.03827, -0.01166, -0.00116, -0.00046, -0.03757, -0.01325, 0.0177, -0.02269, -0.02274, -0.02117, 0.04127, 0.04638, -0.01384, -0.00619, -0.04517, -0.02444, 0.01069, 0.00252, -0.00876, -0.03527, -0.00591, 0.00738, -0.03318, -0.0238, 0.01119, 0.00744, 0.01145, -0.00128, -0.0041, -0.02518, 0.01293, 0.02539, 0.01191, 0.00602, -0.03494, 0.00057, -0.0082, -0.04217, -0.04942, -0.04433, 0.01636, 0.01499, -0.0506, 0.00582, -0.02578, 0.00115, -0.00962, -0.03697, -0.04838, -0.0384, 0.04389, -0.01676, -0.0547, -0.03622, -0.01243, 0.00609, 0.00404, -0.04597, -0.0388, -0.05254, 0.01305, -0.00767, -0.02625, -0.03914, -0.03954, -0.04478, -0.02114, -0.05523, -0.03055, -0.01411, 0.01424, 0.00905, 0.02295, -0.01657, -0.04777, -0.05554, 0.03401, -0.00893, 0.02134, -0.04654, -0.02777, -0.02137, -0.04641, -0.05168, -0.04285, 0.02388, 0.01605, -0.05247, 0.00141, -0.0582, -0.03711, -0.02277, -0.05167, -0.06822, -0.02911, -0.01672, -0.03504, -0.05458, -0.04182, -0.01941, -0.00761, -0.00406, -0.0497, -0.03057, -0.04979, 0.00566, -0.04622, -0.05353, -0.05998, -0.01222, -0.03629, -0.02609, -0.04834, -0.02849, -0.02301, 0.00243, -0.0382, -0.03175, -0.01196, -0.00328, -0.03567, -0.06236, -0.04521, -0.02711, -0.01384, -0.02478, -0.02062, -0.04478, -0.03616, -0.0229, 0.00521, -0.02049, -0.01668, 0.01477, -0.01039, -0.0205, -0.05497, 0.02197, 0.02866, -0.03192, -0.03623, -0.03438, -0.03683, -0.03251, -0.03076, 0.00198, -0.02062, -0.06197, -0.0563, -0.00915, -0.02858, -0.02822, -0.05669, -0.05001, -0.01284, -0.03581, 0.00088, -0.04356, -0.02304, -0.01926, -0.00529, -0.04088, -0.04942, -0.05216, -0.03924, 0.01053, -0.04115, -0.05267, -0.0648, 0.0115, -0.02594, -0.00871, -0.03642, -0.02698, -0.01644, 0.02231, -0.00204, 0.00931, -0.03751, -0.0112, -0.04518, -0.04004, -0.02489, -0.02978, -0.00248, -0.02381, -0.01817, -0.03361, -0.03673, -0.01838, 0.02452, -0.00103, 0.015, 0.02176, -0.02196, -0.05169, -0.04985, 0.02181, -0.02463, -0.02254, -0.02263, 0.01747, -0.04349, -0.0255, -0.00741, 0.00644, -0.00901, -0.04613, 0.00943, -0.01885, -0.03169, -0.018, -0.0488, -0.03149, 0.00175, -0.00603, -0.00046, -0.04759, -0.03362, -0.02975, -0.0084, -0.02029, -0.0337, -0.0319, 0.02394, -0.00775, -0.00527, -0.0422, -0.00188, -0.03004, 0.03084, -0.03573, -0.04833, -0.03735, -0.02707, 0.02436, 0.01467, 0.02884, -0.03252, -0.0846, -0.05985, 0.0051, -0.02105, -0.00432, -0.02661, -0.04061, -0.02869, -0.04878, -0.03051, -0.01816, 0.03118, 0.03989, 0.02754, 0.00253, -0.06441, -0.03142, -0.01975, -0.02446, 0.00773, -0.008, -0.03727, -0.02487, -0.03407, -0.02529, -0.00148, -0.03337, 0.00603, -0.01473, -0.02922, -0.0344, -0.05313, -0.02712, -0.03351, -0.00907, -0.06043, -0.04164, 0.00122],
+ [0.03886, -0.00054, -0.00787, -0.02794, -0.02403, -0.03799, -0.03071, -0.01624, -0.02855, -0.03098, -0.02686, -0.03543, -0.01235, -0.04085, 0.01264, -0.03146, -0.04274, -0.05763, -0.02884, -0.0082, -0.05612, -0.06016, -0.02237, -0.05172, 0.00708, -0.03766, -0.03417, 0.0036, -0.01237, -0.0081, -0.05028, -0.04762, -0.09039, -0.06522, -0.03226, -0.03991, -0.03985, -0.04146, -0.068, -0.07003, -0.06156, 0.05539, 0.00894, -0.03514, 0.0183, -0.03332, -0.04117, -0.06674, -0.02381, -0.03607, -0.02953, -0.01189, -0.02827, -0.09818, -0.09143, -0.06325, 0.04892, -0.00412, -0.03416, -0.0315, -0.02994, -0.03602, -0.07645, -0.03912, -0.06588, -0.01115, -0.01269, -0.05188, -0.06319, -0.05828, 0.03844, 0.05219, -0.0238, -0.03179, -0.03957, -0.03478, -0.03518, -0.07812, -0.03588, -0.01648, -0.0312, -0.06101, -0.07227, -0.08425, -0.05628, 0.0291, 0.03998, -0.03455, -0.00562, -0.02887, -0.0228, -0.04004, -0.06357, -0.03468, -0.02971, -0.08616, -0.06918, -0.05402, -0.07146, -0.00619, -0.0033, -0.00351, 0.03032, -0.00219, -0.01805, -0.01672, -0.03524, -0.06634, -0.06483, -0.03562, -0.04267, -0.04685, -0.03262, -0.06995, -0.06475, 0.02461, -0.02156, -0.00498, -0.02042, -0.02931, -0.0297, -0.03528, -0.08039, -0.02615, -0.01765, -0.03739, -0.0462, -0.05724, -0.08401, -0.03285, 0.00769, -0.02675, -0.04852, 0.00508, -0.02508, -0.02147, -0.04798, -0.08662, -0.03163, -0.0232, -0.03552, -0.05941, -0.06995, -0.01787, -0.03179, 0.00446, -0.02086, 0.00092, -0.02603, -0.00779, -0.02856, -0.03544, -0.06954, -0.06705, -0.02458, -0.02976, -0.09799, -0.06626, -0.01112, -0.04272, 0.01319, 0.01583, -0.0061, -0.00383, -0.04548, -0.03973, -0.03486, -0.07761, -0.07244, -0.04608, -0.03787, -0.02899, -0.06735, -0.01198, -0.05488, 0.00192, -0.00818, -0.04871, -0.02582, -0.01544, -0.01967, -0.04364, -0.08419, -0.07643, -0.01875, -0.04064, -0.02741, -0.05491, -0.07853, -0.00741, 0.00961, -0.01476, -0.0007, -0.0032, -0.01913, -0.01799, -0.02619, -0.05364, -0.05767, -0.03335, -0.02915, -0.05309, -0.05982, -0.00781, -0.02127, 0.01818, -3e-05, -0.03401, -0.02636, -0.02098, -0.03569, -0.02106, -0.05789, -0.05309, -0.02694, -0.02843, -0.08329, -0.05299, -0.05343, -0.0533, 0.01366, -0.0265, -0.02072, -0.01604, 0.01638, -0.02456, -0.04242, -0.08649, -0.07021, -0.04468, -0.03506, -0.06468, -0.0565, -0.06503, -0.04655, -0.03422, -0.01758, -0.01924, -0.01589, 0.00143, -0.02338, -0.05055, -0.09105, -0.0542, -0.04093, -0.0319, -0.02226, -0.09473, -0.06549, -0.03215, -0.04937, 0.05831, -0.02529, -0.01001, -0.06384, -0.04242, -0.0384, -0.07542, -0.04792, -0.02584, -0.02019, -0.0756, -0.03358, -0.05935, -0.08585, -0.04553, 0.05659, -0.02879, -0.00451, -0.0171, -0.04938, -0.05724, -0.09935, -0.11064, -0.04419, -0.05859, -0.10321, -0.04038, -0.06561, -0.05138, -0.0151, -0.02607, -0.03073, -0.05677, 0.008, -0.00916, -0.04069, -0.03993, -0.0419, -0.02573, -0.03907, -0.01446, -0.02683, -0.02028, -0.01924, -0.01543, -0.04914, -0.01018, -0.01495, -0.01386],
+ [0.01433, -0.04121, -0.03553, -0.02539, -0.03469, -0.03501, -0.01779, -0.03067, -0.03379, -0.02603, -0.0429, -0.03116, -0.03275, -0.00446, 0.02957, -0.02252, 0.00108, 0.01897, 0.03261, 0.04735, 0.04712, 0.05441, 0.03245, -0.00535, -0.01436, 0.01214, 0.0105, -0.02797, 0.00829, -0.00513, -0.02931, -0.00707, 0.00263, -0.00646, 0.03964, -0.00036, 0.03336, 0.03717, -0.01045, 0.01594, 0.02428, 0.04286, 0.00354, -0.0149, -0.00919, -0.02823, -0.00631, -0.0041, -0.00192, 0.00213, 0.01175, -0.01831, -0.01595, -0.00017, 0.00966, 0.01874, 0.03838, 0.00013, 0.01703, -0.01665, -0.02759, -0.0051, 0.01476, 0.00584, 0.01575, -0.00211, -0.01248, -0.00525, 0.00269, 0.01859, 0.04921, 0.03816, -0.00802, -0.0161, 0.01327, -0.03551, -0.01039, 0.00564, 0.01326, 0.01055, -0.00228, 0.00138, -0.01817, 0.00825, 0.00841, 0.02981, 0.03283, -0.01681, -0.03449, 0.00055, -0.02299, 0.0029, 0.00598, 0.01459, 0.03757, 0.02004, 0.02497, 0.0299, -0.01186, -0.03002, -0.02004, -0.00968, -0.02297, -0.01872, 0.00488, -0.03516, -0.00677, 0.01319, 0.00717, 0.02665, -0.00843, 0.03755, 0.03804, -0.00659, 0.02419, 0.02474, -0.00805, -0.02799, -0.02033, 0.01824, -0.03792, -0.01124, 0.00266, 0.00875, 0.00657, 0.01408, -0.01478, -0.01181, -0.00523, 0.01893, 0.02356, -0.02596, 0.02551, -0.0329, -0.01191, -0.02951, -0.01451, -0.00952, 0.01059, 0.03669, 0.02263, -0.00748, 0.00138, -0.01118, -0.06255, -0.03851, -0.02655, -0.01455, -0.01016, -0.00518, -0.03504, -0.01146, -0.0036, -0.02504, 0.03479, 0.03343, -0.00478, 0.00867, -0.0282, -0.03623, -0.02466, -0.02783, -0.01924, -0.02274, -0.01445, -0.04443, -0.01084, 0.00119, -0.01005, 0.02253, -0.01632, -0.01319, -0.00063, -0.04066, 0.02366, 0.00063, -0.00947, 0.01946, -0.03703, -0.01377, -0.0227, -0.00741, 0.00506, -0.01356, -0.00076, -0.01567, -0.02493, -0.01414, 0.00336, 0.03173, 0.02721, -0.01634, -0.03676, -0.0049, 0.00766, -0.0203, -0.00542, 0.01202, 0.00056, 0.03808, 0.04155, -2e-05, 0.02976, 0.01697, -0.00701, 0.08547, 0.00111, 0.02263, -0.01208, 0.00418, -0.03747, -0.02014, 0.00044, 0.00565, 0.03743, 0.02876, -0.00102, 0.01869, -0.02015, -0.0236, -0.03467, -0.02054, -0.01598, -0.03372, -0.00076, -0.02307, -0.01396, 0.00249, -0.00525, 0.04181, 0.01138, 0.01101, 0.0262, -0.03486, -0.05258, -0.03661, -0.02713, -0.00767, -0.02304, 0.00333, -0.0216, -0.00628, 0.00928, -0.01034, 0.02103, -0.01272, -0.02633, 0.00111, 0.01097, -0.05523, 0.00827, 0.0699, 0.01705, -0.03035, -0.02007, -0.0358, -0.02295, 0.00075, 0.01996, 0.04557, 0.03533, 0.03237, 0.03503, -0.00794, 0.01439, 0.05892, 0.05231, 0.00347, -0.03383, -0.00225, -0.03418, -0.02455, -0.00799, -0.00997, 0.02744, -0.00659, 0.02916, 0.02979, -0.02431, -0.02513, -0.0029, 0.00068, -0.01768, 0.01521, 0.0074, -0.01328, 0.00448, -0.01734, -0.0362, 0.00222, 0.00616, -0.02735, -0.01824, -0.03425, -0.01276, -0.0119, 0.01378, -0.01626, 0.01044, 0.00635]
+ ],
+ "name": "portrait",
+ "width": 480,
+ "height": 640,
+ "seed": 2
+ },
+ {
+ "tokens": 70,
+ "projections": [
+ [0.05348, 0.00772, 0.05891, 0.02824, 0.01061, 0.0119, 0.00872, 0.0114, -0.00856, 0.00447, -0.02679, -0.01731, 0.0271, 0.03168, 0.01393, 0.02087, 0.00859, -0.02332, -0.01558, -0.08793, -0.03021, -0.00454, 4e-05, 0.01062, 0.01018, 0.01153, -0.00018, -0.04034, -0.03461, -0.05197, -0.04651, -0.02495, 0.0157, 0.00748, -0.01828, -0.00621, 0.00651, -0.03059, 0.05839, -0.02387, -0.043, -0.04474, -0.00972, -0.00854, -0.02107, 0.00825, 0.00948, -0.02909, -0.0231, -0.03801, -0.04329, -0.04065, -0.00668, 0.01329, 0.0065, -0.02087, -0.01599, -0.00881, -0.05857, 0.00465, -0.04799, -0.03222, 0.04148, -0.00558, -0.0098, -0.01133, -0.04157, -0.02079, 0.00866, 0.00378],
+ [0.00931, -0.02439, -0.02562, -0.03733, 0.01195, -0.01399, -0.03108, -0.06153, -0.04054, -0.04003, -0.00266, -0.00741, -0.00699, 0.03888, -0.00159, 0.01373, 0.01661, 0.02921, -0.00938, 0.03003, 0.01206, 0.01865, 0.02141, 0.00354, 0.03633, 0.03367, 0.03719, -0.0285, 0.01184, 0.01729, -0.00108, 0.01295, -0.02421, -0.00616, 0.01154, 0.02273, 0.03328, -0.01474, -0.01341, -0.02683, -0.00017, -0.01689, -0.02418, -0.01362, -0.00437, 0.00922, 0.02868, 0.00643, -0.03248, -0.02339, -0.00405, 0.00988, -0.00043, 0.01511, 0.01518, 0.00228, 0.00715, 0.03851, -0.02162, -0.01116, -0.0001, -0.00375, -0.00165, -0.0083, 0.02032, -0.04433, -0.01881, 0.00786, -0.01625, -0.00808],
+ [0.06317, -0.02395, -0.04746, -0.02494, 0.00869, 0.02206, 0.01536, -0.02619, -0.00946, -0.00678, -0.03014, -0.04881, -0.05841, -0.01364, -0.06545, 0.00177, -0.02785, -0.01891, -0.04136, -0.01616, -0.05627, -0.04876, -0.07031, -0.03675, -0.03124, 0.0044, -0.01094, -0.05635, -0.004, -0.01335, -0.05001, -0.05257, -0.05535, -0.05926, 0.02325, -0.01863, -0.0182, -0.05235, 0.00339, -0.01619, -0.05559, -0.05459, -0.06602, -0.05689, -0.06768, -0.01528, -0.03061, -0.0385, -0.02372, -0.04588, -0.047, -0.06495, -0.07202, -0.04809, -0.04727, -0.06865, -0.04214, -0.04083, -0.0589, -0.05144, -0.05005, -0.05451, -0.05257, -0.03318, -0.00485, -0.05794, -0.05003, -0.0283, -0.01546, -0.01171],
+ [-0.00168, -0.01058, -0.00378, -0.02103, -0.04967, 0.00969, -0.01904, 0.03714, -0.02235, 0.0174, -0.03181, -0.01663, -0.02175, -0.01299, 0.00943, 0.00552, -0.00816, -0.0289, 0.01857, -0.01248, -0.04053, -0.00239, -0.0077, 0.00631, 0.00254, -0.00652, -0.02561, -0.00288, -0.06425, 0.00282, -0.04176, -0.01219, -0.01356, -0.01308, -0.06807, 0.0185, -0.01506, 0.03165, -0.01349, -0.01473, -0.03922, -0.0022, -0.05053, -0.0264, 0.02794, -0.02534, -0.04518, -0.00675, -0.03153, 0.00388, -0.06067, -0.02328, -0.05366, 0.0213, 0.01089, -0.03826, -0.01414, -0.0314, 0.00926, -0.00665, -0.04201, -0.0204, -0.0205, -0.03862, -0.08584, 0.02133, 0.0147, -0.03858, -0.00443, -0.01227]
+ ],
+ "name": "small",
+ "width": 300,
+ "height": 200,
+ "seed": 3
+ }
+ ],
+ "text_scores": [
+ [4.513365745544434, 2.0302014350891113, 2.7454798221588135, 1.8960669040679932],
+ [0.8605532646179199, 2.0196194648742676, 2.248322010040283, 3.2044801712036133],
+ [0.9925262928009033, 1.4315824508666992, 1.4432010650634766, 1.1922258138656616]
+ ],
+ "page_scores": [
+ [1.7586665153503418, 1.725450038909912, 1.860370397567749],
+ [1.4318137168884277, 1.2242709398269653, 1.4365534782409668],
+ [0.7521970272064209, 0.6419405937194824, 0.7512259483337402]
+ ]
+}
diff --git a/packages/sie_server/tests/adapters/test_topk_embed.py b/packages/sie_server/tests/adapters/test_topk_embed.py
new file mode 100644
index 000000000..11d5edafe
--- /dev/null
+++ b/packages/sie_server/tests/adapters/test_topk_embed.py
@@ -0,0 +1,407 @@
+"""Unit tests for TopkEmbedAdapter with a stand-in backbone and tokenizer.
+
+The real backbone needs transformers >= 5.2 (the transformers5 bundle), so these
+tests exercise everything around it: templates, truncation, scoring masks,
+modality routing, batching, the head (truncate, then normalize), image
+preprocessing and positions, scoring and metering. Parity with TopK's reference
+pipeline on the real checkpoints lives in ``test_topk_embed_parity.py``.
+"""
+
+from __future__ import annotations
+
+import io
+from pathlib import Path
+from types import SimpleNamespace
+from typing import Any
+from unittest.mock import patch
+
+import numpy as np
+import pytest
+import torch
+import yaml
+from PIL import Image
+from sie_server.adapters.topk_embed.adapter import TopkEmbedAdapter, _ImageRow, smart_resize
+from sie_server.types.inputs import ImageInput, InvalidInputError, Item
+
+REV = "d09d8a7a8cdd6c287f792b3c4d7b41233d46e66a"
+HIDDEN = 8
+HEAD_WIDTH = 6
+PAD_ID = 0
+IMAGE_TOKEN_ID = 99
+# Punctuation ids of the stand-in tokenizer, all in the scoring skip list.
+PUNCT = {":": 25, ",": 11, ".": 13, "!": 0}
+PREFIX = [90, 91, 92]
+SUFFIX = [93, 94]
+
+
+class FakeTokenizer:
+ """Whitespace words plus single-character punctuation, deterministic ids."""
+
+ eos_token = "<|im_end|>" # noqa: S105 -- a special token, not a secret
+ pad_token_id = PAD_ID
+
+ def __init__(self) -> None:
+ self.calls: list[dict[str, Any]] = []
+
+ def encode_one(self, text: str) -> list[int]:
+ ids: list[int] = []
+ word = ""
+ for char in text:
+ if char in PUNCT or char.isspace():
+ if word:
+ ids.append(self._word_id(word))
+ word = ""
+ if char in PUNCT:
+ ids.append(PUNCT[char])
+ else:
+ word += char
+ if word:
+ ids.append(self._word_id(word))
+ return ids
+
+ @staticmethod
+ def _word_id(word: str) -> int:
+ return 100 + sum(ord(c) for c in word) % 900
+
+ def __call__(self, texts: Any, truncation: bool = False, max_length: int | None = None) -> dict[str, Any]:
+ self.calls.append({"texts": texts, "truncation": truncation, "max_length": max_length})
+ if isinstance(texts, str):
+ return {"input_ids": self.encode_one(texts)}
+ rows = [self.encode_one(text) for text in texts]
+ if truncation and max_length is not None:
+ rows = [row[:max_length] for row in rows]
+ return {"input_ids": rows}
+
+
+class FakeLanguageModel:
+ """Identity text tower that records what it was called with."""
+
+ def __init__(self) -> None:
+ self.calls: list[dict[str, Any]] = []
+
+ def __call__(self, *, inputs_embeds, attention_mask, position_ids, use_cache):
+ self.calls.append(
+ {"shape": tuple(inputs_embeds.shape), "attention_mask": attention_mask, "position_ids": position_ids}
+ )
+ return SimpleNamespace(last_hidden_state=inputs_embeds)
+
+
+class FakeBackbone:
+ def __init__(self) -> None:
+ torch.manual_seed(0)
+ self.embed = torch.nn.Embedding(1000, HIDDEN)
+ self.language_model = FakeLanguageModel()
+
+ def get_input_embeddings(self) -> torch.nn.Embedding:
+ return self.embed
+
+
+def _png(color: str = "white", size: tuple[int, int] = (64, 64)) -> ImageInput:
+ buf = io.BytesIO()
+ Image.new("RGB", size, color).save(buf, "PNG")
+ return ImageInput(data=buf.getvalue(), format="png")
+
+
+def adapter() -> TopkEmbedAdapter:
+ return make_adapter()
+
+
+def make_adapter(**kwargs: Any) -> TopkEmbedAdapter:
+ """An adapter in the state ``load()`` leaves it, around stand-in modules."""
+ adapter = TopkEmbedAdapter("topk-io/topk-embed-v1-xsmall", revision=REV, max_seq_length=64, **kwargs)
+ torch.manual_seed(1)
+ adapter._model = FakeBackbone()
+ adapter._head = torch.nn.Linear(HIDDEN, HEAD_WIDTH, bias=False)
+ adapter._tokenizer = FakeTokenizer()
+ adapter._device = "cpu"
+ adapter._dtype = torch.float32
+ adapter._multivector_dim = HEAD_WIDTH
+ adapter._query_max_length = 16
+ adapter._doc_max_length = 64
+ adapter._image_token_id = IMAGE_TOKEN_ID
+ adapter._skip_ids = torch.tensor(sorted(PUNCT.values()))
+ adapter._image_prefix = torch.tensor(PREFIX)
+ adapter._image_suffix = torch.tensor(SUFFIX)
+ adapter._patch_size = 4
+ adapter._merge_size = 2
+ adapter._temporal_patch_size = 2
+ adapter._min_pixels = 16 * 16
+ adapter._max_pixels = 16 * (4 * 2) ** 2
+ adapter._pixel_scale = 1 / 127.5
+ adapter._pixel_bias = -1.0
+ adapter._num_grid_per_side = 8
+ return adapter
+
+
+def _image_tokens(row: _ImageRow) -> int:
+ return int((row.input_ids == IMAGE_TOKEN_ID).sum())
+
+
+def _fake_vision(adapter: TopkEmbedAdapter):
+ def vision(images: list[_ImageRow]) -> torch.Tensor:
+ count = sum(_image_tokens(row) for row in images)
+ return torch.arange(count * HIDDEN, dtype=torch.float32).reshape(count, HIDDEN) / 100.0
+
+ return patch.object(adapter, "_vision_forward", side_effect=vision)
+
+
+class TestSpec:
+ def test_capabilities(self) -> None:
+ adapter = TopkEmbedAdapter("topk-io/topk-embed-v1-xsmall")
+ assert adapter.capabilities.inputs == ["text", "image"]
+ assert adapter.capabilities.outputs == ["multivector", "score"]
+
+ def test_dims_before_load(self) -> None:
+ assert TopkEmbedAdapter("m").dims.multivector is None
+ assert TopkEmbedAdapter("m", token_dim=128).dims.multivector == 128
+
+ def test_encode_before_load_raises(self) -> None:
+ with pytest.raises(RuntimeError):
+ TopkEmbedAdapter("m").encode([Item(text="x")], ["multivector"])
+
+ def test_unload_clears_modules(self, adapter: TopkEmbedAdapter) -> None:
+ adapter.unload()
+ assert adapter._model is None
+ assert adapter._head is None
+ assert adapter._tokenizer is None
+
+
+class TestText:
+ def test_query_template_strips_and_keeps_every_token(self, adapter: TopkEmbedAdapter) -> None:
+ out = adapter.encode([Item(text=" what is up? ")], ["multivector"], is_query=True)
+ texts = adapter._tokenizer.calls[-1]["texts"]
+ assert texts == ["Query: what is up?"]
+ expected = adapter._tokenizer.encode_one("Query: what is up?")
+ assert out.multivector is not None
+ assert out.multivector[0].shape == (len(expected), HEAD_WIDTH)
+ assert out.extra["input_token_counts"] == [len(expected)]
+
+ def test_document_template_drops_skiplist_tokens(self, adapter: TopkEmbedAdapter) -> None:
+ out = adapter.encode([Item(text="Hello, world.")], ["multivector"])
+ assert adapter._tokenizer.calls[-1]["texts"] == ["Document: Hello, world."]
+ ids = adapter._tokenizer.encode_one("Document: Hello, world.")
+ kept = [i for i in ids if i not in PUNCT.values()]
+ assert out.multivector is not None
+ assert out.multivector[0].shape == (len(kept), HEAD_WIDTH)
+ # Billing counts every token the model ran, punctuation included.
+ assert out.extra["input_token_counts"] == [len(ids)]
+
+ def test_empty_document_keeps_the_prompt_word(self, adapter: TopkEmbedAdapter) -> None:
+ out = adapter.encode([Item(text=""), Item(text=" ")], ["multivector"])
+ assert adapter._tokenizer.calls[-1]["texts"] == ["Document:", "Document:"]
+ assert out.multivector is not None
+ assert [v.shape[0] for v in out.multivector] == [1, 1]
+
+ def test_caps_are_passed_to_the_tokenizer(self, adapter: TopkEmbedAdapter) -> None:
+ adapter.encode([Item(text="a b c")], ["multivector"], is_query=True)
+ assert adapter._tokenizer.calls[-1]["max_length"] == 16
+ adapter.encode([Item(text="a b c")], ["multivector"])
+ assert adapter._tokenizer.calls[-1]["max_length"] == 64
+
+ def test_long_query_is_truncated(self, adapter: TopkEmbedAdapter) -> None:
+ out = adapter.encode([Item(text=" ".join(["word"] * 40))], ["multivector"], is_query=True)
+ assert out.multivector is not None
+ assert out.multivector[0].shape[0] == 16
+
+ def test_rows_are_right_padded_without_leaking_pads(self, adapter: TopkEmbedAdapter) -> None:
+ short, long = "one", "one two three four five six"
+ batched = adapter.encode([Item(text=short), Item(text=long)], ["multivector"], is_query=True)
+ alone = adapter.encode([Item(text=short)], ["multivector"], is_query=True)
+ assert batched.multivector is not None
+ assert alone.multivector is not None
+ np.testing.assert_allclose(batched.multivector[0], alone.multivector[0], rtol=0, atol=1e-6)
+ mask = adapter._model.language_model.calls[-2]["attention_mask"]
+ assert mask.tolist()[0][:3] == [1, 1, 1]
+ assert mask[0].sum() < mask[1].sum()
+ assert mask[0, -1] == 0
+
+ def test_text_rows_get_default_positions(self, adapter: TopkEmbedAdapter) -> None:
+ adapter.encode([Item(text="abc")], ["multivector"], is_query=True)
+ assert adapter._model.language_model.calls[-1]["position_ids"] is None
+
+ def test_vectors_are_truncated_then_normalized(self, adapter: TopkEmbedAdapter) -> None:
+ adapter._multivector_dim = 4
+ out = adapter.encode([Item(text="alpha beta")], ["multivector"], is_query=True)
+ assert out.multivector is not None
+ vectors = out.multivector[0]
+ assert vectors.shape[1] == 4
+ np.testing.assert_allclose(np.linalg.norm(vectors, axis=1), 1.0, atol=1e-5)
+ ids = torch.tensor(adapter._tokenizer.encode_one("Query: alpha beta"))
+ with torch.no_grad():
+ raw = adapter._head(adapter._model.embed(ids))[:, :4]
+ np.testing.assert_allclose(vectors, torch.nn.functional.normalize(raw, dim=-1).numpy(), atol=1e-5)
+
+ def test_normalize_can_be_turned_off(self, adapter: TopkEmbedAdapter) -> None:
+ out = adapter.encode([Item(text="alpha")], ["multivector"], is_query=True, options={"normalize": False})
+ assert out.multivector is not None
+ assert not np.allclose(np.linalg.norm(out.multivector[0], axis=1), 1.0)
+
+ def test_batches_respect_the_padded_token_budget(self, adapter: TopkEmbedAdapter) -> None:
+ adapter._text_batch_tokens = 10
+ batches = adapter._plan_text_batches([2, 9, 3, 5, 1])
+ assert sorted(i for batch in batches for i in batch) == [0, 1, 2, 3, 4]
+ lengths = [2, 9, 3, 5, 1]
+ for batch in batches:
+ assert len(batch) == 1 or len(batch) * max(lengths[i] for i in batch) <= 10
+
+
+class TestInputs:
+ def test_rejects_unsupported_output_types(self, adapter: TopkEmbedAdapter) -> None:
+ with pytest.raises(ValueError, match="Unsupported output types"):
+ adapter.encode([Item(text="x")], ["dense"])
+
+ def test_rejects_image_queries(self, adapter: TopkEmbedAdapter) -> None:
+ with pytest.raises(InvalidInputError, match="queries must be text"):
+ adapter.encode([Item(images=[_png()])], ["multivector"], is_query=True)
+
+ def test_rejects_instructions(self, adapter: TopkEmbedAdapter) -> None:
+ with pytest.raises(InvalidInputError, match="instructions are not supported"):
+ adapter.encode([Item(text="x")], ["multivector"], instruction="Represent this")
+
+ def test_rejects_items_without_input(self, adapter: TopkEmbedAdapter) -> None:
+ with pytest.raises(InvalidInputError, match="requires text or image"):
+ adapter.encode([Item()], ["multivector"])
+
+
+class TestImages:
+ def test_mixed_batch_routes_by_modality_and_keeps_order(self, adapter: TopkEmbedAdapter) -> None:
+ items = [Item(text="first text"), Item(images=[_png()]), Item(text="second")]
+ with _fake_vision(adapter):
+ out = adapter.encode(items, ["multivector"])
+ assert out.multivector is not None
+ assert len(out.multivector) == 3
+ row = adapter._image_row(Image.new("RGB", (64, 64), "white"))
+ assert out.multivector[1].shape == (_image_tokens(row), HEAD_WIDTH)
+ ids = adapter._tokenizer.encode_one("Document: first text")
+ assert out.multivector[0].shape[0] == len([i for i in ids if i not in PUNCT.values()])
+ counts = out.extra["input_token_counts"]
+ assert counts[1] == 0
+ assert counts[0] == len(ids)
+ # One text forward and one image forward.
+ assert len(adapter._model.language_model.calls) == 2
+
+ def test_image_rows_get_3d_positions(self, adapter: TopkEmbedAdapter) -> None:
+ with _fake_vision(adapter):
+ adapter.encode([Item(images=[_png()])], ["multivector"])
+ positions = adapter._model.language_model.calls[-1]["position_ids"]
+ assert positions is not None
+ assert positions.shape[0] == 3
+
+ def test_multi_image_item_concatenates(self, adapter: TopkEmbedAdapter) -> None:
+ with _fake_vision(adapter):
+ one = adapter.encode([Item(images=[_png()])], ["multivector"])
+ two = adapter.encode([Item(images=[_png(), _png("black")])], ["multivector"])
+ assert one.multivector is not None
+ assert two.multivector is not None
+ assert two.multivector[0].shape[0] == 2 * one.multivector[0].shape[0]
+
+ def test_image_row_layout(self, adapter: TopkEmbedAdapter) -> None:
+ row = adapter._image_row(Image.new("RGB", (64, 48), "white"))
+ _, grid_h, grid_w = row.grid_thw
+ count = grid_h * grid_w // 4
+ assert row.input_ids.tolist() == PREFIX + [IMAGE_TOKEN_ID] * count + SUFFIX
+ assert row.pixel_values.shape == (grid_h * grid_w, 3 * 2 * 4 * 4)
+ # White pixels normalize to 255 / 127.5 - 1 == 1.
+ torch.testing.assert_close(row.pixel_values, torch.ones_like(row.pixel_values))
+
+ def test_image_token_budget_bounds_the_patch_count(self, adapter: TopkEmbedAdapter) -> None:
+ row = adapter._image_row(Image.new("RGB", (400, 300), "white"))
+ assert _image_tokens(row) <= 16
+
+ def test_position_ids_follow_the_merged_grid(self, adapter: TopkEmbedAdapter) -> None:
+ # grid (1, 4, 6) merges 2x2 -> a 2 x 3 image; prefix of 3 tokens, suffix of 2.
+ ids = torch.tensor(PREFIX + [IMAGE_TOKEN_ID] * 6 + SUFFIX)
+ row = _ImageRow(input_ids=ids, pixel_values=torch.zeros(24, 96), grid_thw=(1, 4, 6))
+ positions = adapter._image_position_ids([row], len(ids) + 1)[:, 0, :]
+ assert positions[:, :3].tolist() == [[0, 1, 2]] * 3
+ assert positions[0, 3:9].tolist() == [3] * 6
+ assert positions[1, 3:9].tolist() == [3, 3, 3, 4, 4, 4]
+ assert positions[2, 3:9].tolist() == [3, 4, 5, 3, 4, 5]
+ # Text after the image resumes at prefix + max(2, 3).
+ assert positions[:, 9:11].tolist() == [[6, 7]] * 3
+ assert positions[:, 11].tolist() == [0, 0, 0]
+
+ def test_grid_inputs_are_cached_and_consistent(self, adapter: TopkEmbedAdapter) -> None:
+ index, weight, rot = adapter._grid_inputs((1, 4, 6))
+ assert index.shape == (4, 24)
+ assert weight.shape == (4, 24)
+ assert rot.shape == (24, 2)
+ torch.testing.assert_close(weight.sum(0), torch.ones(24))
+ assert adapter._grid_inputs((1, 4, 6))[0] is index
+
+ def test_the_grid_cache_is_bounded_and_keeps_the_most_recently_used(self, adapter: TopkEmbedAdapter) -> None:
+ with patch("sie_server.adapters.topk_embed.adapter._GRID_CACHE_SIZE", 2):
+ first = adapter._grid_inputs((1, 4, 6))[0]
+ adapter._grid_inputs((1, 4, 8))
+ assert adapter._grid_inputs((1, 4, 6))[0] is first # a hit makes (1, 4, 6) the most recent
+ adapter._grid_inputs((1, 6, 6)) # evicts (1, 4, 8), the least recently used
+ assert list(adapter._grid_cache) == [(1, 4, 6), (1, 6, 6)]
+
+
+class TestSmartResize:
+ def test_page_fits_the_default_budget(self) -> None:
+ # A 1600x1200 page: 30 x 41 merged patches, the 1230 tokens the reference produces.
+ assert smart_resize(1200, 1600, factor=32, min_pixels=65536, max_pixels=1280 * 32 * 32) == (960, 1312)
+
+ def test_rounds_to_the_factor(self) -> None:
+ assert smart_resize(500, 700, factor=32, min_pixels=65536, max_pixels=1280 * 32 * 32) == (512, 704)
+
+ def test_scales_down_to_the_budget(self) -> None:
+ height, width = smart_resize(4000, 3000, factor=32, min_pixels=65536, max_pixels=1280 * 32 * 32)
+ assert height * width <= 1280 * 32 * 32
+ assert height % 32 == 0
+ assert width % 32 == 0
+
+ def test_scales_up_small_images(self) -> None:
+ height, width = smart_resize(100, 100, factor=32, min_pixels=65536, max_pixels=1280 * 32 * 32)
+ assert height * width >= 65536
+
+ def test_rejects_extreme_aspect_ratios(self) -> None:
+ with pytest.raises(InvalidInputError, match="aspect ratio"):
+ smart_resize(10, 3000, factor=32, min_pixels=1, max_pixels=10**7)
+
+
+class TestScoring:
+ def test_score_is_maxsim_over_encode(self, adapter: TopkEmbedAdapter) -> None:
+ query, docs = Item(text="alpha beta"), [Item(text="alpha"), Item(text="gamma delta")]
+ scores = adapter.score(query, docs)
+ q = adapter.encode([query], ["multivector"], is_query=True).multivector
+ d = adapter.encode(docs, ["multivector"]).multivector
+ assert q is not None
+ assert d is not None
+ expected = [float((q[0] @ doc.T).max(axis=1).sum()) for doc in d]
+ np.testing.assert_allclose(scores, expected, rtol=1e-5)
+
+ def test_score_pairs_forwards_options(self, adapter: TopkEmbedAdapter) -> None:
+ queries = [Item(text="alpha"), Item(text="alpha")]
+ docs = [Item(text="alpha"), Item(text="beta")]
+ normalized = adapter.score_pairs(queries, docs)
+ raw = adapter.score_pairs(queries, docs, options={"normalize": False})
+ assert normalized.scores.shape == (2,)
+ assert not np.allclose(normalized.scores, raw.scores)
+
+
+class TestMetering:
+ def test_count_input_tokens_scatters_over_mixed_items(self, adapter: TopkEmbedAdapter) -> None:
+ items = [Item(text="one two"), Item(images=[_png()], text="ignored caption"), Item(text="three")]
+ assert adapter.count_input_tokens(items) == [2, 0, 1]
+
+ def test_postprocessor_uses_the_token_dim(self, adapter: TopkEmbedAdapter) -> None:
+ postprocessors = adapter.get_postprocessors()
+ assert set(postprocessors) == {"muvera"}
+ assert postprocessors["muvera"].token_dim == HEAD_WIDTH
+
+
+# On the cluster path one item's serialized result is chunked only up to 16 MiB (the sidecar's
+# MAX_CHUNKED_RESULT_BYTES and the gateway's per-item limit); past it the item fails.
+_CLUSTER_ITEM_RESULT_BYTES = 16 * 1024 * 1024
+_MODELS_DIR = Path(__file__).resolve().parents[2] / "models"
+
+
[email protected]("model", ["topk-io__topk-embed-v1-xsmall", "topk-io__topk-embed-v1-small"])
+def test_a_longest_document_fits_one_cluster_result(model: str) -> None:
+ config = yaml.safe_load((_MODELS_DIR / f"{model}.yaml").read_text(encoding="utf-8"))
+ dim = config["tasks"]["encode"]["multivector"]["dim"]
+ vectors = config["max_sequence_length"] * dim * 2 # float16, the default response
+ assert vectors + 256 * 1024 <= _CLUSTER_ITEM_RESULT_BYTES # room for the result envelope
diff --git a/packages/sie_server/tests/adapters/test_topk_embed_graphs.py b/packages/sie_server/tests/adapters/test_topk_embed_graphs.py
new file mode 100644
index 000000000..f56843d7e
--- /dev/null
+++ b/packages/sie_server/tests/adapters/test_topk_embed_graphs.py
@@ -0,0 +1,378 @@
+"""TopK-Embed CUDA graphs: shapes, recording policy, numerics of the recorded forward, adapter wiring.
+
+These run without a GPU: recording and replay are replaced by a fake graph whose
+replay runs the recorded forward eagerly, so the runner's own code decides what to
+record and replay, and the padded forward it would record is checked against the
+packed one. Real graphs are checked on a GPU by the Modal harness.
+"""
+
+from __future__ import annotations
+
+from collections.abc import Callable
+from typing import Any, cast
+from unittest.mock import patch
+
+import numpy as np
+import pytest
+import torch
+from sie_server.adapters._cuda_graphs import RECORDING_LOCK
+from sie_server.adapters.topk_embed import graphs, packed
+from sie_server.adapters.topk_embed.adapter import TopkEmbedAdapter
+from sie_server.types.inputs import Item
+
+from .test_topk_embed import HIDDEN, PAD_ID, _fake_vision, _png, make_adapter
+from .test_topk_embed_packed import _IdentityText, tiny_qwen3_5_text_model
+
+
+class _FakeGraph:
+ """Stands in for ``torch.cuda.CUDAGraph``: a replay runs the recorded computation eagerly."""
+
+ def __init__(self, replay: Callable[[], Any]) -> None:
+ self._replay = replay
+ self.replays = 0
+
+ def replay(self) -> None:
+ self.replays += 1
+ self._replay()
+
+
+class _Clock:
+ def __init__(self) -> None:
+ self.now = 0.0
+
+ def __call__(self) -> float:
+ return self.now
+
+
+class _Runner(graphs.GraphRunner):
+ """Records into fake graphs on the CPU; everything else is the runner's own code."""
+
+ def __init__(
+ self,
+ text_model: Any,
+ embed: Any,
+ *,
+ free: int = 10**12,
+ total: int = 10**12,
+ device_bytes: int = 0,
+ **kwargs: Any,
+ ) -> None:
+ super().__init__(text_model, embed, **kwargs)
+ self.free, self.total, self.device_bytes = free, total, device_bytes
+ self.fail_with: BaseException | None = None
+ self.captured: list[graphs.Key] = []
+
+ def _free_memory(self) -> int:
+ return self.free
+
+ def _total_memory(self) -> int:
+ return self.total
+
+ def _capture(self, key: graphs.Key) -> Any:
+ self.captured.append(key)
+ if self.fail_with is not None:
+ raise self.fail_with
+ rows, length = key
+ input_ids = torch.full((rows, length), self._pad_token_id, dtype=torch.long)
+ mask = torch.ones((rows, length), dtype=torch.bool)
+ hidden = self._hidden_states(key)
+ graph = _FakeGraph(lambda: hidden.copy_(self._forward(input_ids, mask)))
+ return graphs._Graph(graph=graph, input_ids=input_ids, mask=mask, device_bytes=self.device_bytes)
+
+
+def _identity(embeds: torch.Tensor, positions: torch.Tensor, layout: Any) -> torch.Tensor:
+ return embeds
+
+
+def _runner(max_tokens: int = 256, clock: Callable[[], float] | None = None, **kwargs: Any) -> _Runner:
+ torch.manual_seed(0)
+ embed = torch.nn.Embedding(64, HIDDEN)
+ return _Runner(
+ _identity, embed, pad_token_id=PAD_ID, max_tokens=max_tokens, clock=clock or _Clock(), name="test", **kwargs
+ )
+
+
+def _rows(*lengths: int) -> list[torch.Tensor]:
+ # Token ids within the stand-in embedding's 64, never the pad id.
+ return [torch.arange(n) % 63 + 1 for n in lengths]
+
+
+class TestShapes:
+ @pytest.mark.parametrize(
+ ("length", "bucketed"),
+ [(1, 16), (16, 16), (17, 32), (128, 128), (129, 192), (500, 512), (513, 768), (1000, 1024)],
+ )
+ def test_lengths_round_up_to_their_bucket(self, length: int, bucketed: int) -> None:
+ assert graphs.bucket_length(length) == bucketed
+
+ def test_row_buckets_are_powers_of_two_and_the_most_that_fit(self) -> None:
+ assert graphs.row_buckets(16, 1536) == (1, 2, 4, 8, 16, 32, 64, 96)
+ assert graphs.row_buckets(512, 1536) == (1, 2, 3)
+ assert graphs.row_buckets(2048, 1536) == ()
+
+ def test_keys(self) -> None:
+ assert graphs.graph_key(3, 20, 1536) == (4, 32)
+ assert graphs.graph_key(1, 1, 1536) == (1, 16)
+ assert graphs.graph_key(96, 16, 1536) == (96, 16)
+ assert graphs.graph_key(97, 16, 1536) is None # too many rows at that length
+ assert graphs.graph_key(1, 1600, 1536) is None # too long for any graph
+
+ @pytest.mark.parametrize(("hidden", "tokens"), [(512, 2048), (768, 2048), (1024, 1536), (2048, 768)])
+ def test_wider_models_hold_fewer_tokens(self, hidden: int, tokens: int) -> None:
+ assert graphs.default_max_tokens(hidden) == tokens
+
+ @pytest.mark.parametrize("max_tokens", [768, 1536])
+ def test_the_shapes_are_a_small_fixed_set_within_the_bound(self, max_tokens: int) -> None:
+ shapes = graphs.bucketed_shapes(max_tokens)
+ assert len(shapes) < 100
+ assert all(rows * length <= max_tokens for rows, length in shapes)
+ for rows in range(1, 20):
+ for length in range(1, 200, 7):
+ key = graphs.graph_key(rows, length, max_tokens)
+ assert key is None or key in shapes
+
+
+class TestRecordingPolicy:
+ def test_a_shape_records_once_and_then_replays(self) -> None:
+ runner = _runner()
+ assert runner.run(_rows(20, 5, 7)) is not None # three rows pad to four
+ assert runner.run(_rows(25, 3, 9, 1)) is not None # also (4, 32): same graph
+ assert runner.captured == [(4, 32)]
+ assert (runner.stats.recorded, runner.stats.replayed) == (1, 1)
+
+ def test_each_row_gets_its_own_vectors_right_padded(self) -> None:
+ runner = _runner()
+ rows = _rows(3, 9)
+ hidden = runner.run(rows)
+ assert hidden is not None
+ assert hidden.shape == (2, 16, HIDDEN)
+ embed = cast("torch.nn.Embedding", runner._embed)
+ for i, row in enumerate(rows):
+ torch.testing.assert_close(hidden[i, : len(row)], embed(row))
+ torch.testing.assert_close(hidden[i, len(row) :], embed(torch.full((16 - len(row),), PAD_ID)))
+
+ def test_padding_rows_attend_to_their_first_position(self) -> None:
+ runner = _runner()
+ runner.run(_rows(3, 5, 2)) # three rows in a graph of four
+ entry = runner._graphs[(4, 16)]
+ assert entry.mask[:3].sum(dim=1).tolist() == [3, 5, 2]
+ assert entry.mask[3].tolist() == [True] + [False] * 15
+
+ def test_past_the_token_bound_runs_eagerly(self) -> None:
+ runner = _runner(max_tokens=64)
+ assert runner.run(_rows(65)) is None
+ assert runner.run(_rows(*[4] * 5)) is None # five rows of 16 tokens is 80
+ assert runner.stats.eager == {"too_large": 2}
+ assert runner.captured == []
+
+ def test_recording_is_rationed_in_time(self) -> None:
+ clock = _Clock()
+ runner = _runner(max_tokens=4096, clock=clock)
+ lengths = [16 * step for step in range(1, 9)] + [128 + 64 * step for step in range(1, 7)] + [768, 1024]
+ for length in lengths: # 16 shapes, the burst
+ assert runner.run(_rows(length)) is not None
+ assert runner.run(_rows(1280)) is None
+ assert runner.stats.eager == {"recording_paused": 1}
+ clock.now += 2.0
+ assert runner.run(_rows(1280)) is not None
+
+ def test_one_recording_at_a_time_in_the_process(self) -> None:
+ runner = _runner()
+ assert RECORDING_LOCK.acquire(blocking=False) # another model is recording
+ try:
+ assert runner.run(_rows(5)) is None
+ finally:
+ RECORDING_LOCK.release()
+ assert runner.stats.eager == {"busy": 1}
+ assert runner.run(_rows(5)) is not None
+ assert not RECORDING_LOCK.locked()
+
+ def test_no_recording_while_device_memory_is_short(self) -> None:
+ runner = _runner(free=9 * 10**10, total=10**12) # 9% free
+ assert runner.run(_rows(5)) is None
+ assert runner.stats.eager == {"no_headroom": 1}
+
+ def test_over_the_budget_it_stops_recording_and_keeps_its_graphs(self) -> None:
+ runner = _runner(total=10**9, free=10**9, device_bytes=5 * 10**7) # 5% of the device per graph
+ assert runner.run(_rows(5)) is not None
+ assert runner.run(_rows(40)) is None
+ assert runner.stats.eager == {"budget_full": 1}
+ assert runner.run(_rows(7)) is not None # the recorded shape still replays
+ assert runner.stats.replayed == 1
+
+ def test_a_shape_that_fails_to_record_runs_eagerly_from_then_on(self) -> None:
+ runner = _runner()
+ runner.fail_with = RuntimeError("capture failed")
+ assert runner.run(_rows(5)) is None
+ assert runner.run(_rows(6)) is None
+ assert runner.stats.eager == {"recording_failed": 1, "failed_shape": 1}
+ assert runner.stats.recording_failures == 1
+ runner.fail_with = None
+ assert runner.run(_rows(20)) is not None # other shapes still record
+
+ def test_three_shapes_that_fail_turn_graphs_off(self) -> None:
+ runner = _runner()
+ assert runner.run(_rows(5)) is not None
+ runner.fail_with = RuntimeError("capture failed")
+ for length in (20, 40, 60):
+ assert runner.run(_rows(length)) is None
+ assert runner.disabled
+ assert runner.graph_count == 0
+ assert runner.run(_rows(5)) is None
+ assert runner.stats.eager["disabled"] == 1
+
+ def test_running_out_of_memory_while_recording_drops_the_graphs_and_pauses(self) -> None:
+ clock = _Clock()
+ runner = _runner(clock=clock)
+ assert runner.run(_rows(5)) is not None
+ runner.fail_with = torch.cuda.OutOfMemoryError("CUDA out of memory. Tried to allocate 2 MiB")
+ assert runner.run(_rows(40)) is None
+ assert runner.graph_count == 0
+ assert runner.stats.drops == 1
+ assert runner.stats.recording_failures == 0 # memory is not the shape's fault
+ runner.fail_with = None
+ assert runner.run(_rows(5)) is None
+ assert runner.stats.eager["recording_paused"] == 1
+ clock.now += 60.0
+ assert runner.run(_rows(5)) is not None
+
+ def test_every_forward_counts_once(self) -> None:
+ runner = _runner(max_tokens=64)
+ for lengths in ((5,), (5,), (70,), (6, 7)):
+ runner.run(_rows(*lengths))
+ assert runner.stats.forwards == 4
+
+
+class TestWarmUp:
+ def test_runs_the_padded_forward_at_each_step_up_to_the_bound(self) -> None:
+ runner = _runner(max_tokens=2500)
+ shapes: list[tuple[int, ...]] = []
+
+ def forward(input_ids: torch.Tensor, mask: torch.Tensor) -> torch.Tensor:
+ assert bool(mask.all())
+ shapes.append(tuple(input_ids.shape))
+ return torch.zeros(*input_ids.shape, HIDDEN)
+
+ with patch.object(runner, "_forward", side_effect=forward):
+ runner.warm_up(1024)
+ assert shapes == [(1, 1024), (1, 2048), (1, 2500)]
+ assert runner.stats.forwards == 0 # nothing recorded, nothing counted
+
+
+class TestRecordedForward:
+ """The padded forward a graph records gives each input what the packed forward gives it."""
+
+ def test_matches_the_packed_forward(self) -> None:
+ model = tiny_qwen3_5_text_model()
+ text = packed.PackedTextModel(model, packed.reference_kernels())
+ runner = _Runner(text, model.embed_tokens, pad_token_id=0, max_tokens=256, clock=_Clock())
+ torch.manual_seed(9)
+ rows = [torch.randint(1, 32, (n,)) for n in (5, 70, 1)] # 70 spans two delta-rule chunks
+ with torch.inference_mode():
+ hidden = runner.run(rows)
+ assert hidden is not None
+ lengths = [len(row) for row in rows]
+ positions = torch.cat([torch.arange(n) for n in lengths]).view(1, 1, -1).expand(3, 1, -1)
+ ours = text(
+ model.embed_tokens(torch.cat(rows).unsqueeze(0)), positions, packed.Packing.from_lengths(lengths, "cpu")
+ )
+ start = 0
+ for i, n in enumerate(lengths):
+ torch.testing.assert_close(hidden[i, :n], ours[0, start : start + n], rtol=1e-4, atol=1e-4)
+ start += n
+
+
+class _Graphs:
+ """Stands in for the adapter's runner: serves right-padded embeddings, or declines."""
+
+ def __init__(self, embed: torch.nn.Embedding, *, serve: bool = True, error: BaseException | None = None) -> None:
+ self.embed, self.serve, self.error = embed, serve, error
+ self.calls: list[list[int]] = []
+ self.cleared = 0
+
+ def run(self, rows: list[torch.Tensor]) -> torch.Tensor | None:
+ self.calls.append([len(row) for row in rows])
+ if self.error is not None:
+ raise self.error
+ if not self.serve:
+ return None
+ length = graphs.bucket_length(max(len(row) for row in rows))
+ ids = torch.full((len(rows), length), PAD_ID)
+ for i, row in enumerate(rows):
+ ids[i, : len(row)] = row
+ return self.embed(ids)
+
+ def clear(self) -> None:
+ self.cleared += 1
+
+
+class TestAdapterWiring:
+ def test_the_mode_is_checked_at_construction(self) -> None:
+ assert make_adapter(cuda_graphs=False)._cuda_graphs == "off"
+ assert make_adapter(cuda_graphs="bucketed")._cuda_graphs == "bucketed"
+ with pytest.raises(ValueError, match="cuda_graphs"):
+ make_adapter(cuda_graphs="sometimes")
+
+ def test_graphs_stay_off_without_cuda_or_the_fast_kernels(self) -> None:
+ adapter = make_adapter(cuda_graphs="bucketed")
+ assert adapter._graph_runner("cpu") is None
+ adapter._packed_text = cast("Any", _IdentityText())
+ with patch.object(adapter._packed_text, "kernels", packed.reference_kernels(), create=True):
+ assert adapter._graph_runner("cuda:0") is None # reference kernels only
+
+ @pytest.fixture
+ def adapters(self) -> tuple[TopkEmbedAdapter, TopkEmbedAdapter]:
+ graphed = make_adapter(packed=True)
+ graphed._packed_text = cast("Any", _IdentityText())
+ graphed._graphs = cast("Any", _Graphs(graphed._model.get_input_embeddings()))
+ return make_adapter(), graphed
+
+ def test_text_uses_the_graphs(self, adapters: tuple[TopkEmbedAdapter, TopkEmbedAdapter]) -> None:
+ padded, graphed = adapters
+ items = [Item(text="a short one"), Item(text="another, slightly longer, document.")]
+ ours = graphed.encode(items, ["multivector"])
+ reference = padded.encode(items, ["multivector"])
+ assert ours.multivector is not None
+ assert reference.multivector is not None
+ for a, b in zip(ours.multivector, reference.multivector, strict=True):
+ np.testing.assert_allclose(a, b, rtol=0, atol=1e-6)
+ runner = cast("_Graphs", graphed._graphs)
+ assert len(runner.calls) == 1
+ assert cast("_IdentityText", graphed._packed_text).calls == [] # the eager packed path never ran
+
+ def test_a_runner_that_declines_leaves_the_packed_path(
+ self, adapters: tuple[TopkEmbedAdapter, TopkEmbedAdapter]
+ ) -> None:
+ _, graphed = adapters
+ cast("_Graphs", graphed._graphs).serve = False
+ graphed.encode([Item(text="a short one")], ["multivector"])
+ assert len(cast("_IdentityText", graphed._packed_text).calls) == 1
+
+ def test_images_skip_the_graphs(self, adapters: tuple[TopkEmbedAdapter, TopkEmbedAdapter]) -> None:
+ _, graphed = adapters
+ with _fake_vision(graphed):
+ graphed.encode([Item(images=[_png()])], ["multivector"])
+ assert cast("_Graphs", graphed._graphs).calls == []
+
+ def test_running_out_of_memory_drops_the_graphs(self, adapters: tuple[TopkEmbedAdapter, TopkEmbedAdapter]) -> None:
+ _, graphed = adapters
+ runner = cast("_Graphs", graphed._graphs)
+ runner.error = torch.cuda.OutOfMemoryError("CUDA out of memory. Tried to allocate 2 MiB")
+ with pytest.raises(torch.cuda.OutOfMemoryError):
+ graphed.encode([Item(text="a short one")], ["multivector"])
+ assert runner.cleared == 1
+
+ def test_other_errors_keep_the_graphs(self, adapters: tuple[TopkEmbedAdapter, TopkEmbedAdapter]) -> None:
+ _, graphed = adapters
+ runner = cast("_Graphs", graphed._graphs)
+ runner.error = RuntimeError("something else")
+ with pytest.raises(RuntimeError, match="something else"):
+ graphed.encode([Item(text="a short one")], ["multivector"])
+ assert runner.cleared == 0
+
+ def test_unload_drops_the_graphs(self, adapters: tuple[TopkEmbedAdapter, TopkEmbedAdapter]) -> None:
+ _, graphed = adapters
+ runner = cast("_Graphs", graphed._graphs)
+ graphed.unload()
+ assert graphed._graphs is None
+ assert runner.cleared == 1
diff --git a/packages/sie_server/tests/adapters/test_topk_embed_overlap.py b/packages/sie_server/tests/adapters/test_topk_embed_overlap.py
new file mode 100644
index 000000000..5dd6806a4
--- /dev/null
+++ b/packages/sie_server/tests/adapters/test_topk_embed_overlap.py
@@ -0,0 +1,107 @@
+"""TopK-Embed's host side: vectors copied as float16 when the response is float16, batches run back to back."""
+
+from __future__ import annotations
+
+from typing import Any, cast
+from unittest.mock import patch
+
+import numpy as np
+import pytest
+import torch
+from sie_server.adapters.topk_embed import adapter as adapter_module
+from sie_server.adapters.topk_embed.adapter import TopkEmbedAdapter, _Launched
+from sie_server.adapters.topk_embed.packed import to_device
+from sie_server.types.inputs import Item
+
+from .test_topk_embed import _fake_vision, _png, make_adapter
+from .test_topk_embed_packed import _IdentityText
+
+TEXTS = [Item(text="a short one"), Item(text="a somewhat longer document, with commas."), Item(text="x")]
+
+
[email protected](params=["padded", "packed"])
+def adapter(request: pytest.FixtureRequest) -> TopkEmbedAdapter:
+ if request.param == "padded":
+ return make_adapter()
+ packed_adapter = make_adapter(packed=True)
+ packed_adapter._packed_text = cast("Any", _IdentityText())
+ return packed_adapter
+
+
+class TestTransferDtype:
+ def test_float16_responses_come_back_as_float16(self, adapter: TopkEmbedAdapter) -> None:
+ full = adapter.encode(TEXTS, ["multivector"])
+ half = adapter.encode(TEXTS, ["multivector"], options={"output_dtype": "float16"})
+ assert full.multivector is not None
+ assert half.multivector is not None
+ for a, b in zip(full.multivector, half.multivector, strict=True):
+ assert a.dtype == np.float32
+ assert b.dtype == np.float16
+ np.testing.assert_allclose(b.astype(np.float32), a, rtol=0, atol=1e-3)
+
+ @pytest.mark.parametrize(
+ "options",
+ [{}, {"output_dtype": "float32"}, {"output_dtype": "int8"}, {"output_dtype": "float16", "muvera": {}}],
+ )
+ def test_everything_else_stays_float32(self, adapter: TopkEmbedAdapter, options: dict[str, Any]) -> None:
+ # MUVERA reads the multi-vectors after the adapter, so they stay at full precision.
+ output = adapter.encode(TEXTS, ["multivector"], options=options)
+ assert output.multivector is not None
+ assert all(vector.dtype == np.float32 for vector in output.multivector)
+
+ def test_page_vectors_follow_the_same_rule(self, adapter: TopkEmbedAdapter) -> None:
+ with _fake_vision(adapter):
+ half = adapter.encode([Item(images=[_png()])], ["multivector"], options={"output_dtype": "float16"})
+ assert half.multivector is not None
+ assert half.multivector[0].dtype == np.float16
+
+ def test_scores_use_float32_whatever_the_response(self, adapter: TopkEmbedAdapter) -> None:
+ options = {"output_dtype": "float16"}
+ scores = adapter.score(Item(text="a short one"), TEXTS, options=options)
+ reference = adapter.score(Item(text="a short one"), TEXTS)
+ assert scores == reference
+
+
+class TestBackToBack:
+ def test_each_batch_is_unpacked_after_the_next_one_launches(self) -> None:
+ adapter = make_adapter()
+ events: list[str] = []
+
+ def launch(rows: list[torch.Tensor], **kwargs: Any) -> _Launched:
+ index = len([e for e in events if e.startswith("launch")])
+ events.append(f"launch {index}")
+ return _Launched(torch.empty(0), None, lambda _: [torch.zeros(len(row), 6) for row in rows])
+
+ def deliver(batch: list[int], launched: _Launched) -> None:
+ events.append(f"deliver {batch[0]}")
+ launched.rows()
+
+ batches = [([i], [torch.tensor([1, 2, 3])], None) for i in range(3)]
+ with patch.object(adapter, "_launch", side_effect=launch):
+ adapter._run_batches(batches, normalize=True, dtype=torch.float32, deliver=deliver)
+ assert events == ["launch 0", "launch 1", "deliver 0", "launch 2", "deliver 1", "deliver 2"]
+
+ def test_many_batches_give_the_same_vectors(self, adapter: TopkEmbedAdapter) -> None:
+ one_batch = adapter.encode(TEXTS, ["multivector"])
+ adapter._text_batch_tokens = 1 # one row per batch
+ many = adapter.encode(TEXTS, ["multivector"])
+ assert one_batch.multivector is not None
+ assert many.multivector is not None
+ for a, b in zip(one_batch.multivector, many.multivector, strict=True):
+ np.testing.assert_allclose(a, b, rtol=0, atol=1e-6)
+
+ def test_a_ready_launch_hands_back_its_rows(self) -> None:
+ launched = _Launched(torch.arange(6.0).view(2, 3), None, list)
+ assert [row.tolist() for row in launched.rows()] == [[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]]
+
+
+def test_host_copies_stay_plain_off_cuda() -> None:
+ tensor = torch.arange(4)
+ moved = to_device(tensor, "cpu")
+ assert moved.device.type == "cpu"
+ assert torch.equal(moved, tensor)
+
+
+def test_the_adapter_module_keeps_its_forward_entry_points() -> None:
+ assert callable(adapter_module.TopkEmbedAdapter._launch)
+ assert callable(adapter_module.TopkEmbedAdapter._run_batches)
diff --git a/packages/sie_server/tests/adapters/test_topk_embed_packed.py b/packages/sie_server/tests/adapters/test_topk_embed_packed.py
new file mode 100644
index 000000000..46420ab16
--- /dev/null
+++ b/packages/sie_server/tests/adapters/test_topk_embed_packed.py
@@ -0,0 +1,327 @@
+"""Unit tests for TopK-Embed's packed (variable-length) path.
+
+The fast kernels need CUDA and flash-linear-attention; ``test_topk_embed_parity.py``
+covers them on real weights. These tests pin what runs anywhere: kernel selection,
+the PyTorch reference kernels against the stock modules' math, the packed forward
+against the stock text model on a small random Qwen3.5 (transformers >= 5.2), and
+the adapter's packing plumbing.
+"""
+
+from __future__ import annotations
+
+from typing import Any
+from unittest.mock import patch
+
+import numpy as np
+import pytest
+import torch
+from sie_server.adapters.topk_embed import packed
+from sie_server.adapters.topk_embed.adapter import TopkEmbedAdapter
+from sie_server.types.inputs import Item
+from torch.nn import functional as F
+
+from .test_topk_embed import _fake_vision, _png, make_adapter
+
+
+def _stub(*args: Any, **kwargs: Any) -> torch.Tensor:
+ return torch.empty(0)
+
+
+def _stub_kernels() -> packed.PackedKernels:
+ return packed.PackedKernels(
+ delta_rule=_stub, causal_conv=_stub, attention=_stub, rms_norm=_stub, gated_rms_norm=_stub, swiglu=_stub
+ )
+
+
+class TestResolveKernels:
+ def test_auto_does_not_pack_off_cuda(self) -> None:
+ assert packed.resolve_kernels("cpu", mode=None) is None
+
+ def test_off_never_packs(self) -> None:
+ with patch.object(packed, "_fast_kernels", return_value=_stub_kernels()):
+ assert packed.resolve_kernels("cuda:0", mode=False) is None
+
+ def test_forced_packing_off_cuda_uses_reference_kernels(self) -> None:
+ kernels = packed.resolve_kernels("cpu", mode=True)
+ assert kernels is not None
+ assert kernels.delta_rule is packed.reference_delta_rule
+ assert kernels.causal_conv is packed.reference_causal_conv
+ assert kernels.attention is packed.reference_attention
+ assert kernels.rms_norm is packed.reference_rms_norm
+ assert kernels.gated_rms_norm is packed.reference_gated_rms_norm
+ assert kernels.swiglu is packed.reference_swiglu
+
+ def test_auto_on_cuda_needs_the_fast_kernels(self) -> None:
+ with patch.object(packed, "_fast_kernels", return_value=None):
+ assert packed.resolve_kernels("cuda:0", mode=None) is None
+ forced = packed.resolve_kernels("cuda:0", mode=True)
+ assert forced is not None
+ assert forced.names["delta_rule"] == "reference"
+ fast = _stub_kernels()
+ with patch.object(packed, "_fast_kernels", return_value=fast):
+ assert packed.resolve_kernels("cuda:0", mode=None) is fast
+
+
+def _packing(lengths: list[int]) -> packed.Packing:
+ return packed.Packing.from_lengths(lengths, "cpu")
+
+
+class TestPacking:
+ def test_offsets_and_segments(self) -> None:
+ packing = _packing([3, 1, 4])
+ assert packing.cu_seqlens.tolist() == [0, 3, 4, 8]
+ assert packing.cu_seqlens.dtype == torch.long
+ assert packing.cu_seqlens_int32.dtype == torch.int32
+ assert packing.cu_seqlens_int32.tolist() == [0, 3, 4, 8]
+ assert packing.cu_seqlens_cpu.device.type == "cpu"
+ assert packing.max_len == 4
+ assert packing.segments() == [(0, 3), (3, 4), (4, 8)]
+
+
+class TestReferenceKernels:
+ def test_causal_conv_matches_each_sequence_alone(self) -> None:
+ torch.manual_seed(0)
+ lengths, dim, width = [5, 2, 7], 6, 4
+ x = torch.randn(1, sum(lengths), dim)
+ weight, bias = torch.randn(dim, width), torch.randn(dim)
+ out = packed.reference_causal_conv(x, weight, bias, "silu", _packing(lengths))
+ start = 0
+ for length in lengths:
+ seq = x[:, start : start + length].transpose(1, 2)
+ # transformers' fallback: symmetric padding, then keep the first ``length`` outputs.
+ expected = F.conv1d(seq, weight.unsqueeze(1), bias, padding=width - 1, groups=dim)
+ expected = F.silu(expected[..., :length]).transpose(1, 2)
+ torch.testing.assert_close(out[:, start : start + length], expected)
+ start += length
+
+ def test_causal_conv_keeps_sequences_apart(self) -> None:
+ torch.manual_seed(1)
+ x = torch.randn(1, 9, 4)
+ weight = torch.randn(4, 4)
+ changed = x.clone()
+ changed[:, 5:] += 10.0
+ a = packed.reference_causal_conv(x, weight, None, None, _packing([5, 4]))
+ b = packed.reference_causal_conv(changed, weight, None, None, _packing([5, 4]))
+ torch.testing.assert_close(a[:, :5], b[:, :5])
+
+ def test_attention_is_block_diagonal_and_bidirectional(self) -> None:
+ torch.manual_seed(2)
+ lengths, heads, kv_heads, dim = [4, 3, 5], 4, 2, 8
+ total = sum(lengths)
+ q = torch.randn(total, heads, dim)
+ k = torch.randn(total, kv_heads, dim)
+ v = torch.randn(total, kv_heads, dim)
+ out = packed.reference_attention(q, k, v, _packing(lengths), dim**-0.5)
+ segment = torch.repeat_interleave(torch.arange(len(lengths)), torch.tensor(lengths))
+ mask = segment[:, None] == segment[None, :]
+ expected = F.scaled_dot_product_attention(
+ q.transpose(0, 1).unsqueeze(0),
+ k.repeat_interleave(heads // kv_heads, dim=1).transpose(0, 1).unsqueeze(0),
+ v.repeat_interleave(heads // kv_heads, dim=1).transpose(0, 1).unsqueeze(0),
+ attn_mask=mask,
+ )[0].transpose(0, 1)
+ torch.testing.assert_close(out, expected, rtol=1e-5, atol=1e-5)
+
+ def test_rms_norm_without_residual_is_qwen3_5_rms_norm(self) -> None:
+ torch.manual_seed(3)
+ x = torch.randn(2, 5, 16, dtype=torch.bfloat16)
+ weight = torch.randn(16, dtype=torch.bfloat16) * 0.1
+ # Qwen3_5RMSNorm.forward (zero-centred weight, float32 math, cast back).
+ xf = x.float()
+ expected = (xf * torch.rsqrt(xf.pow(2).mean(-1, keepdim=True) + 1e-6) * (1.0 + weight.float())).type_as(x)
+ normed, residual = packed.reference_rms_norm(x, 1.0 + weight.float(), 1e-6)
+ assert torch.equal(normed, expected)
+ assert residual is x
+
+ def test_rms_norm_adds_the_residual_first(self) -> None:
+ torch.manual_seed(4)
+ x = torch.randn(1, 6, 16, dtype=torch.bfloat16)
+ residual = torch.randn(1, 6, 16, dtype=torch.bfloat16)
+ scale = torch.rand(16) + 0.5
+ normed, summed = packed.reference_rms_norm(x, scale, 1e-6, residual)
+ # The residual stream is the stock bf16 add, bit for bit ...
+ assert summed.dtype == torch.bfloat16
+ assert torch.equal(summed, residual + x)
+ # ... and the norm reads the unrounded float32 sum.
+ total = x.float() + residual.float()
+ expected = total * torch.rsqrt(total.pow(2).mean(-1, keepdim=True) + 1e-6) * scale
+ assert torch.equal(normed, expected.to(torch.bfloat16))
+ stock = packed.reference_rms_norm(residual + x, scale, 1e-6)[0]
+ torch.testing.assert_close(normed.float(), stock.float(), rtol=0.02, atol=0.02)
+
+ def test_gated_rms_norm_is_the_float32_formula(self) -> None:
+ torch.manual_seed(5)
+ x = torch.randn(8, 16, dtype=torch.bfloat16)
+ gate = torch.randn(8, 16, dtype=torch.bfloat16)
+ weight = (torch.rand(16) + 0.5).to(torch.bfloat16)
+ out = packed.reference_gated_rms_norm(x, gate, weight, 1e-6)
+ xf = x.float()
+ normed = xf * torch.rsqrt(xf.pow(2).mean(-1, keepdim=True) + 1e-6)
+ assert torch.equal(out, (normed * weight.float() * F.silu(gate.float())).to(torch.bfloat16))
+ # Close to transformers' Qwen3_5RMSNormGated, which rounds to bf16 between steps.
+ stock = (weight * normed.to(torch.bfloat16)) * F.silu(gate.float())
+ torch.testing.assert_close(out.float(), stock.to(torch.bfloat16).float(), rtol=0.02, atol=0.02)
+
+ def test_swiglu(self) -> None:
+ torch.manual_seed(6)
+ gate, up = torch.randn(3, 10, dtype=torch.bfloat16), torch.randn(3, 10, dtype=torch.bfloat16)
+ out = packed.reference_swiglu(gate, up)
+ assert out.dtype == torch.bfloat16
+ assert torch.equal(out, (F.silu(gate.float()) * up.float()).to(torch.bfloat16))
+
+
+def tiny_qwen3_5_text_model() -> Any:
+ """A random 4-layer Qwen3.5 text model: three Gated DeltaNet layers, then full attention.
+
+ Norm weights are randomized (zero-centred RMSNorms around 0, the Gated DeltaNet
+ norm around 1), and there are more value heads than key heads, so the
+ grouped-value repeat runs too. Skips without transformers >= 5.2.
+ """
+ pytest.importorskip("transformers.models.qwen3_5", reason="needs transformers >= 5.2 (the transformers5 bundle)")
+ from transformers.models.qwen3_5 import ( # ty: ignore[unresolved-import]
+ Qwen3_5TextConfig,
+ Qwen3_5TextModel,
+ )
+
+ torch.manual_seed(7)
+ config = Qwen3_5TextConfig(
+ vocab_size=32,
+ hidden_size=64,
+ intermediate_size=96,
+ num_hidden_layers=4,
+ num_attention_heads=4,
+ num_key_value_heads=2,
+ head_dim=32,
+ linear_num_key_heads=2,
+ linear_num_value_heads=4,
+ linear_key_head_dim=16,
+ linear_value_head_dim=16,
+ max_position_embeddings=256,
+ )
+ config.is_causal = False
+ config.use_cache = False
+ model = Qwen3_5TextModel(config).eval()
+ with torch.no_grad():
+ for name, parameter in model.named_parameters():
+ if name.endswith("linear_attn.norm.weight"):
+ parameter.normal_(1.0, 0.2)
+ elif "norm" in name:
+ parameter.normal_(0.0, 0.2)
+ for layer in model.layers:
+ if hasattr(layer, "self_attn"):
+ layer.self_attn.is_causal = False
+ return model
+
+
+class TestPackedTextModel:
+ """The packed forward (reference kernels) against the stock text model run one input at a time."""
+
+ @pytest.fixture(scope="class")
+ def model(self) -> Any:
+ return tiny_qwen3_5_text_model()
+
+ def test_matches_the_stock_model_per_input(self, model: Any) -> None:
+ assert [
+ type(layer.linear_attn if hasattr(layer, "linear_attn") else layer.self_attn).__name__
+ for layer in model.layers
+ ] == [
+ "Qwen3_5GatedDeltaNet",
+ "Qwen3_5GatedDeltaNet",
+ "Qwen3_5GatedDeltaNet",
+ "Qwen3_5Attention",
+ ]
+ torch.manual_seed(8)
+ lengths = [7, 1, 70, 12] # 70 spans two delta-rule chunks
+ embeds = [torch.randn(1, n, model.config.hidden_size) for n in lengths]
+ positions = [torch.arange(n).view(1, 1, -1).expand(3, 1, -1) for n in lengths]
+ text = packed.PackedTextModel(model, packed.reference_kernels())
+ with torch.inference_mode():
+ ours = text(torch.cat(embeds, dim=1), torch.cat(positions, dim=2), _packing(lengths))
+ start = 0
+ for n, embed, position in zip(lengths, embeds, positions, strict=True):
+ stock = model(
+ inputs_embeds=embed, attention_mask=torch.ones(1, n, dtype=torch.long), position_ids=position
+ ).last_hidden_state
+ torch.testing.assert_close(ours[:, start : start + n], stock, rtol=1e-4, atol=1e-4)
+ start += n
+
+ def test_rejects_a_non_silu_mlp(self, model: Any) -> None:
+ with patch.object(model.config, "hidden_act", "gelu"), pytest.raises(ValueError, match="SiLU"):
+ packed.PackedTextModel(model, packed.reference_kernels())
+
+
+class _IdentityText:
+ """Stands in for ``PackedTextModel``: records its inputs and returns the embeddings."""
+
+ def __init__(self) -> None:
+ self.calls: list[dict[str, Any]] = []
+
+ def __call__(self, embeds: torch.Tensor, position_ids: torch.Tensor, packing: packed.Packing) -> torch.Tensor:
+ self.calls.append({"embeds": embeds.shape, "positions": position_ids, "packing": packing})
+ return embeds
+
+
+class TestAdapterPacking:
+ """With an identity backbone, the packed and padded paths must give the same vectors."""
+
+ @pytest.fixture
+ def adapters(self) -> tuple[TopkEmbedAdapter, TopkEmbedAdapter, _IdentityText]:
+ text = _IdentityText()
+ packed_adapter = make_adapter(packed=True)
+ packed_adapter._packed_text = text # ty: ignore[invalid-assignment]
+ return make_adapter(), packed_adapter, text
+
+ def test_text_matches_the_padded_path(
+ self, adapters: tuple[TopkEmbedAdapter, TopkEmbedAdapter, _IdentityText]
+ ) -> None:
+ padded_adapter, packed_adapter, text = adapters
+ items = [Item(text="a short one"), Item(text="a somewhat longer document, with commas."), Item(text="x")]
+ ours = packed_adapter.encode(items, ["multivector"])
+ reference = padded_adapter.encode(items, ["multivector"])
+ assert ours.multivector is not None
+ assert reference.multivector is not None
+ for a, b in zip(ours.multivector, reference.multivector, strict=True):
+ np.testing.assert_allclose(a, b, rtol=0, atol=1e-6)
+ assert ours.extra["input_token_counts"] == reference.extra["input_token_counts"]
+ # One packed call: boundaries at the (length-sorted) row ends, positions restart per row.
+ assert len(text.calls) == 1
+ lengths = sorted(reference.extra["input_token_counts"])
+ packing = text.calls[0]["packing"]
+ assert packing.cu_seqlens.tolist() == [0, *np.cumsum(lengths).tolist()]
+ assert packing.max_len == max(lengths)
+ positions = text.calls[0]["positions"]
+ assert positions.shape == (3, 1, sum(lengths))
+ assert positions[0, 0, : lengths[0]].tolist() == list(range(lengths[0]))
+ assert positions[0, 0, lengths[0]] == 0
+
+ def test_images_match_the_padded_path(
+ self, adapters: tuple[TopkEmbedAdapter, TopkEmbedAdapter, _IdentityText]
+ ) -> None:
+ padded_adapter, packed_adapter, text = adapters
+ items = [Item(images=[_png()]), Item(images=[_png("black", (96, 64))])]
+ with _fake_vision(packed_adapter):
+ ours = packed_adapter.encode(items, ["multivector"])
+ with _fake_vision(padded_adapter):
+ reference = padded_adapter.encode(items, ["multivector"])
+ assert ours.multivector is not None
+ assert reference.multivector is not None
+ for a, b in zip(ours.multivector, reference.multivector, strict=True):
+ np.testing.assert_allclose(a, b, rtol=0, atol=1e-6)
+ assert text.calls[0]["positions"].shape[0] == 3
+
+ def test_packed_batches_budget_the_sum_of_lengths(
+ self, adapters: tuple[TopkEmbedAdapter, TopkEmbedAdapter, _IdentityText]
+ ) -> None:
+ padded_adapter, packed_adapter, _ = adapters
+ padded_adapter._text_batch_tokens = packed_adapter._text_batch_tokens = 10
+ lengths = [2, 2, 3, 3, 9]
+ # Padded: count x longest; packed: plain sum, so more rows fit per batch.
+ assert padded_adapter._plan_text_batches(lengths) == [[0, 1, 2], [3], [4]]
+ assert packed_adapter._plan_text_batches(lengths) == [[0, 1, 2, 3], [4]]
+
+ def test_unload_forgets_the_packed_model(
+ self, adapters: tuple[TopkEmbedAdapter, TopkEmbedAdapter, _IdentityText]
+ ) -> None:
+ _, packed_adapter, _ = adapters
+ packed_adapter.unload()
+ assert packed_adapter._packed_text is None
diff --git a/packages/sie_server/tests/adapters/test_topk_embed_parity.py b/packages/sie_server/tests/adapters/test_topk_embed_parity.py
new file mode 100644
index 000000000..12b38a714
--- /dev/null
+++ b/packages/sie_server/tests/adapters/test_topk_embed_parity.py
@@ -0,0 +1,148 @@
+r"""Parity between the TopK-Embed-V1 adapter and TopK's own pipeline.
+
+The goldens under ``goldens/topk_embed`` come from the checkpoint's
+sentence-transformers stack (``MultiVectorEncoder`` with its remote code), run by
+``packages/sie_server/scripts/generate_topk_embed_goldens.py`` without any SIE code.
+That stack packs a batch into one sequence and needs CUDA-only kernels
+(flash-linear-attention, compiled flex attention); the CPU goldens swap only those
+kernels for reference implementations with the same math (``generated_with``).
+
+The adapter runs on stock ``transformers.models.qwen3_5`` classes, either one
+right-padded row per input or one packed sequence per batch (both are tested). Token ids, token counts and scoring masks must match exactly. Vectors are
+compared through their projections onto fixed random unit directions, and MaxSim
+scores directly. The adapter's vision tower is TopK's, so page vectors differ only
+through the text tower's kernels (sdpa and the unpacked delta rule vs flex attention
+and the packed one). Measured on CPU (bf16) against the CPU goldens, over both
+models, the largest differences were 0.008 (text) and 0.009 (pages) per projection
+(0.0006 on average for pages) and 0.023 per score, with the same top document for
+every query. The tolerances below leave about 2.5x that.
+
+These tests need transformers >= 5.2 (the transformers5 bundle); run them with the
+bundle's requirements:
+
+ python -m sie_server.cli resolve-deps --bundle transformers5 > /tmp/t5.txt
+ uv run --no-sync --with-requirements /tmp/t5.txt pytest -c pyproject.toml -m model \\
+ packages/sie_server/tests/adapters/test_topk_embed_parity.py
+"""
+
+from __future__ import annotations
+
+import io
+import json
+from pathlib import Path
+from typing import Any
+
+import numpy as np
+import pytest
+from PIL import Image
+from sie_server.adapters.topk_embed.adapter import TopkEmbedAdapter
+from sie_server.core.loader import load_adapter, load_model_configs
+from sie_server.types.inputs import ImageInput, Item
+
+pytestmark = pytest.mark.model
+
+_GOLDENS = sorted((Path(__file__).parent / "goldens" / "topk_embed").glob("*.json"))
+_MODELS_DIR = Path(__file__).resolve().parents[2] / "models"
+_TEXT_PROJECTION_TOLERANCE = 0.02
+_PAGE_PROJECTION_TOLERANCE = 0.025
+_PAGE_PROJECTION_MEAN_TOLERANCE = 0.0015
+_SCORE_TOLERANCE = 0.05
+
+
+def _golden(path: Path) -> dict[str, Any]:
+ return json.loads(path.read_text(encoding="utf-8"))
+
+
+ scope="module",
+ params=[(path, packed) for path in _GOLDENS for packed in (False, True)],
+ ids=[f"{path.stem}-{'packed' if packed else 'padded'}" for path in _GOLDENS for packed in (False, True)],
+)
+def case(request: pytest.FixtureRequest) -> tuple[dict[str, Any], TopkEmbedAdapter]:
+ pytest.importorskip("transformers.models.qwen3_5", reason="needs transformers >= 5.2 (the transformers5 bundle)")
+ path, packed = request.param
+ golden = _golden(path)
+ config = load_model_configs(_MODELS_DIR)[golden["model"]]
+ assert config.hf_revision == golden["revision"], "golden was generated for a different checkpoint revision"
+ adapter = load_adapter(config, _MODELS_DIR, device="cpu")
+ assert isinstance(adapter, TopkEmbedAdapter)
+ # On CPU the packed path runs its PyTorch reference kernels; on CUDA the fast ones.
+ adapter._packed = packed
+ adapter.load("cpu")
+ assert (adapter._packed_text is not None) == packed
+ return golden, adapter
+
+
+def _page(spec: dict[str, Any]) -> ImageInput:
+ # Same synthetic page as the generator: dark bars on a light background.
+ rng = np.random.default_rng(spec["seed"])
+ height, width = spec["height"], spec["width"]
+ page = np.full((height, width, 3), 245, dtype=np.uint8)
+ line_height = max(6, height // 40)
+ for top in range(height // 12, height - height // 12, line_height * 2):
+ length = int(width * rng.uniform(0.3, 0.8))
+ shade = int(rng.integers(10, 60))
+ page[top : top + line_height, width // 10 : width // 10 + length] = shade
+ buf = io.BytesIO()
+ Image.fromarray(page).save(buf, "PNG")
+ return ImageInput(data=buf.getvalue(), format="png")
+
+
+def _directions(golden: dict[str, Any], dim: int) -> np.ndarray:
+ spec = golden["generated_with"]["directions"]
+ matrix = np.random.default_rng(spec["seed"]).standard_normal((spec["count"], dim))
+ return matrix / np.linalg.norm(matrix, axis=1, keepdims=True)
+
+
+def _maxsim(queries: list[np.ndarray], documents: list[np.ndarray]) -> np.ndarray:
+ return np.array([[float((q @ d.T).max(axis=1).sum()) for d in documents] for q in queries])
+
+
+def _encode(adapter: TopkEmbedAdapter, golden: dict[str, Any]) -> dict[str, list[np.ndarray]]:
+ queries = adapter.encode([Item(text=q["text"]) for q in golden["queries"]], ["multivector"], is_query=True)
+ documents = adapter.encode([Item(text=d["text"]) for d in golden["documents"]], ["multivector"])
+ # One page per call, as the goldens were generated.
+ pages = [adapter.encode([Item(images=[_page(p)])], ["multivector"]).multivector for p in golden["pages"]]
+ assert queries.multivector is not None
+ assert documents.multivector is not None
+ return {
+ "queries": queries.multivector,
+ "documents": documents.multivector,
+ "pages": [page[0] for page in pages if page is not None],
+ }
+
+
+def test_text_tokenization_matches(case: tuple[dict[str, Any], TopkEmbedAdapter]) -> None:
+ golden, adapter = case
+ tokenizer = adapter._tokenizer
+ queries = [adapter._query_template + q["text"].strip() for q in golden["queries"]]
+ documents = [(adapter._document_prompt + d["text"]).strip() for d in golden["documents"]]
+ assert tokenizer(queries)["input_ids"] == [q["input_ids"] for q in golden["queries"]]
+ assert tokenizer(documents)["input_ids"] == [d["input_ids"] for d in golden["documents"]]
+
+
+def test_vectors_and_scores_match(case: tuple[dict[str, Any], TopkEmbedAdapter]) -> None:
+ golden, adapter = case
+ encoded = _encode(adapter, golden)
+ basis = _directions(golden, encoded["queries"][0].shape[1])
+
+ for kind, tolerance in (("queries", _TEXT_PROJECTION_TOLERANCE), ("documents", _TEXT_PROJECTION_TOLERANCE)):
+ for vectors, expected in zip(encoded[kind], golden[kind], strict=True):
+ assert len(vectors) == expected["tokens"], f"{kind}: {expected['text']!r}"
+ np.testing.assert_allclose(basis @ vectors.T, expected["projections"], rtol=0, atol=tolerance)
+
+ for vectors, expected in zip(encoded["pages"], golden["pages"], strict=True):
+ assert len(vectors) == expected["tokens"], expected["name"]
+ diff = np.abs(basis @ vectors.T - np.array(expected["projections"]))
+ assert diff.max() <= _PAGE_PROJECTION_TOLERANCE, expected["name"]
+ assert diff.mean() <= _PAGE_PROJECTION_MEAN_TOLERANCE, expected["name"]
+
+ for key, documents in (("text_scores", encoded["documents"]), ("page_scores", encoded["pages"])):
+ scores = _maxsim(encoded["queries"], documents)
+ expected = np.array(golden[key])
+ np.testing.assert_allclose(scores, expected, rtol=0, atol=_SCORE_TOLERANCE)
+ # Retrieval order, for every query: by TopK's scores, the document SIE ranks first scores within
+ # twice the score tolerance of TopK's first. With a clear winner that is the same document; in a
+ # near tie (an empty query against pages of bars is within 0.001) rounding alone can swap them.
+ for row, expected_row in zip(scores, expected, strict=True):
+ assert expected_row[row.argmax()] >= expected_row.max() - 2 * _SCORE_TOLERANCE
diff --git a/packages/sie_server/tests/adapters/test_topk_embed_vision_rotary.py b/packages/sie_server/tests/adapters/test_topk_embed_vision_rotary.py
new file mode 100644
index 000000000..8575d4a5d
--- /dev/null
+++ b/packages/sie_server/tests/adapters/test_topk_embed_vision_rotary.py
@@ -0,0 +1,40 @@
+"""The vision tower's fused rotary kernel: used only on CUDA, bit-identical to the PyTorch chain it replaces."""
+
+from __future__ import annotations
+
+import pytest
+import torch
+from sie_server.adapters.topk_embed import adapter as adapter_module
+from sie_server.adapters.topk_embed import vision_rotary
+
+
+def _eager(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor) -> torch.Tensor:
+ """The PyTorch chain: float32 rotation, rounded back to the input dtype."""
+ xf = x.float()
+ c, s = cos.unsqueeze(-2).float(), sin.unsqueeze(-2).float()
+ return ((xf * c) + (adapter_module._rotate_half(xf) * s)).to(x.dtype)
+
+
+def _inputs(device: str, tokens: int = 37, heads: int = 12, dim: int = 64) -> tuple[torch.Tensor, ...]:
+ torch.manual_seed(0)
+ # A strided view, as the vision tower's unbind of its fused qkv projection gives.
+ qkv = torch.randn(tokens, 3, heads, dim, device=device, dtype=torch.bfloat16)
+ query = qkv.permute(1, 0, 2, 3).unbind(0)[0]
+ angles = torch.randn(tokens, dim, device=device).to(torch.bfloat16)
+ return query, angles.cos(), angles.sin()
+
+
+def test_cpu_tensors_keep_the_pytorch_chain() -> None:
+ query, cos, sin = _inputs("cpu")
+ assert not vision_rotary.available(query)
+ out_q, out_k = adapter_module._apply_rotary_pos_emb_vision(query, query, cos, sin)
+ assert torch.equal(out_q, _eager(query, cos, sin))
+ assert torch.equal(out_k, out_q)
+
+
[email protected](not torch.cuda.is_available() or vision_rotary._kernel is None, reason="needs CUDA and Triton")
[email protected](("tokens", "heads", "dim"), [(37, 12, 64), (4920, 16, 64), (5, 3, 80)])
+def test_the_kernel_is_bit_identical_on_cuda(tokens: int, heads: int, dim: int) -> None:
+ query, cos, sin = _inputs("cuda", tokens, heads, dim)
+ assert vision_rotary.available(query)
+ assert torch.equal(vision_rotary.rotate(query, cos, sin), _eager(query, cos, sin))
diff --git a/packages/sie_server/tests/adapters/test_topk_embed_warmup.py b/packages/sie_server/tests/adapters/test_topk_embed_warmup.py
new file mode 100644
index 000000000..12c9669a0
--- /dev/null
+++ b/packages/sie_server/tests/adapters/test_topk_embed_warmup.py
@@ -0,0 +1,131 @@
+"""TopK-Embed's warm-up: every tuning step of the packed path, then a query and a page, on CUDA only."""
+
+from __future__ import annotations
+
+from typing import Any, cast
+from unittest.mock import MagicMock, patch
+
+import pytest
+import torch
+from sie_server.adapters.topk_embed.adapter import TopkEmbedAdapter, _Launched
+from sie_server.types.inputs import decode_image
+
+from .test_topk_embed import make_adapter
+from .test_topk_embed_packed import _IdentityText
+
+
+def _packed(**kwargs: Any) -> TopkEmbedAdapter:
+ adapter = make_adapter(packed=True, **kwargs)
+ adapter._packed_text = cast("Any", _IdentityText())
+ return adapter
+
+
+def _warm(adapter: TopkEmbedAdapter, *, oom_from: int | None = None) -> tuple[list[list[int]], list[dict[str, Any]]]:
+ """Run the warm-up as on CUDA; returns each packed batch's row lengths and each ``encode`` call."""
+ batches: list[list[int]] = []
+ encodes: list[dict[str, Any]] = []
+
+ def forward(rows: list[torch.Tensor], **kwargs: Any) -> _Launched:
+ assert kwargs["graphs"] is False
+ batches.append([len(row) for row in rows])
+ if oom_from is not None and sum(batches[-1]) >= oom_from:
+ raise torch.OutOfMemoryError("CUDA out of memory. Tried to allocate 2.00 GiB")
+ return _Launched(torch.empty(0), None, lambda _: [])
+
+ def encode(items: list[Any], output_types: list[str], **kwargs: Any) -> None:
+ encodes.append({"items": items, **kwargs})
+
+ adapter._device = "cuda:0"
+ with (
+ patch.object(adapter, "_forward_packed", side_effect=forward),
+ patch.object(adapter, "encode", side_effect=encode),
+ ):
+ adapter.warmup()
+ return batches, encodes
+
+
+def test_one_packed_batch_per_step_up_to_the_largest_batch() -> None:
+ adapter = _packed(text_batch_tokens=4096)
+ batches, _ = _warm(adapter)
+ assert [sum(batch) for batch in batches] == [1024, 2048, 3072, 4096]
+ # Rows stay within the document cap, as real batches do.
+ assert all(length <= adapter._doc_max_length for batch in batches for length in batch)
+
+
+def test_the_steps_follow_the_per_head_norms() -> None:
+ # 8 query heads: the attention layers' norms see 8 rows per token, so they tune every 256 tokens.
+ adapter = _packed(text_batch_tokens=1024)
+ adapter._attention_heads = 8
+ batches, _ = _warm(adapter)
+ assert [sum(batch) for batch in batches] == [256, 512, 768, 1024]
+
+
+def test_the_graphs_padded_forward_warms_at_each_convolution_step() -> None:
+ adapter = _packed(text_batch_tokens=1024)
+ graphs = MagicMock()
+ adapter._graphs = graphs
+ _warm(adapter)
+ graphs.warm_up.assert_called_once_with(1024)
+
+
+def test_a_batch_of_pages_can_be_the_largest() -> None:
+ adapter = _packed(text_batch_tokens=1024, image_batch_size=64)
+ page = 16 + len(adapter._image_prefix) + len(adapter._image_suffix) # 16 merged patches at most
+ assert adapter._largest_batch_tokens() == 64 * page
+ batches, _ = _warm(adapter)
+ assert sum(batches[-2]) < 64 * page <= sum(batches[-1])
+
+
+def test_then_a_query_and_a_page() -> None:
+ _, encodes = _warm(_packed(text_batch_tokens=1024))
+ query, page = encodes
+ assert query["is_query"] is True
+ assert query["items"][0].text
+ assert not page.get("is_query", False)
+ (image,) = page["items"][0].images
+ assert decode_image(image).size == (256, 256)
+
+
+def test_out_of_memory_stops_the_steps_but_not_the_load() -> None:
+ batches, encodes = _warm(_packed(text_batch_tokens=4096), oom_from=3072)
+ assert [sum(batch) for batch in batches] == [1024, 2048, 3072]
+ assert len(encodes) == 2
+
+
+def test_other_errors_fail_the_load() -> None:
+ adapter = _packed(text_batch_tokens=2048)
+ adapter._device = "cuda:0"
+ with (
+ patch.object(adapter, "_forward_packed", side_effect=RuntimeError("an illegal memory access")),
+ pytest.raises(RuntimeError, match="illegal memory access"),
+ ):
+ adapter.warmup()
+
+
[email protected]("device", ["cpu", "mps"])
+def test_nothing_to_compile_off_cuda(device: str) -> None:
+ adapter = _packed()
+ adapter._device = device
+ with patch.object(adapter, "_forward_packed") as forward, patch.object(adapter, "encode") as encode:
+ adapter.warmup()
+ forward.assert_not_called()
+ encode.assert_not_called()
+
+
+def test_nothing_to_compile_on_the_row_per_input_path() -> None:
+ adapter = make_adapter()
+ adapter._device = "cuda:0"
+ with patch.object(adapter, "_forward_packed") as forward, patch.object(adapter, "encode") as encode:
+ adapter.warmup()
+ forward.assert_not_called()
+ encode.assert_not_called()
+
+
+def test_the_warm_up_forward_skips_the_graphs() -> None:
+ adapter = _packed()
+ graphs = MagicMock()
+ adapter._graphs = graphs
+ rows = [torch.tensor([1, 2, 3])]
+ launched = adapter._forward_packed(rows, images=None, normalize=True, dtype=torch.float32, graphs=False)
+ assert [len(row) for row in launched.rows()] == [3]
+ graphs.run.assert_not_called()
diff --git a/packages/sie_server/tests/config/test_visual_muvera_containment.py b/packages/sie_server/tests/config/test_visual_muvera_containment.py
index 44daa17a7..3c8855d47 100644
--- a/packages/sie_server/tests/config/test_visual_muvera_containment.py
+++ b/packages/sie_server/tests/config/test_visual_muvera_containment.py
@@ -12,6 +12,8 @@ VISUAL_MODELS = (
"TomoroAI/tomoro-colqwen3-embed-4b",
"nvidia/llama-nemoretriever-colembed-3b-v1",
"nvidia/nemotron-colembed-vl-4b-v2",
+ "topk-io/topk-embed-v1-xsmall",
+ "topk-io/topk-embed-v1-small",
)
diff --git a/packages/sie_server/tests/core/test_bundle_requirements.py b/packages/sie_server/tests/core/test_bundle_requirements.py
index 078896ef0..6a1d8b2f9 100644
--- a/packages/sie_server/tests/core/test_bundle_requirements.py
+++ b/packages/sie_server/tests/core/test_bundle_requirements.py
@@ -25,9 +25,9 @@ def test_resolve_bundle_requirements_preserves_cli_semantics() -> None:
def test_resolve_bundle_requirements_can_exclude_normalized_cuda_packages() -> None:
assert resolve_bundle_requirements(
- {"Flash_Attn": "==1", "xformers": "==2", "portable": "==3"},
+ {"Flash_Attn": "==1", "xformers": "==2", "FLA_core": {"version": "==3"}, "portable": "==4"},
exclude_cuda=True,
- ) == ["portable==3"]
+ ) == ["portable==4"]
def test_release_pin_normalization_is_sorted_and_marker_free() -> None:
diff --git a/packages/sie_server/tests/test_all_models.py b/packages/sie_server/tests/test_all_models.py
index 7e650df2c..f7e06c680 100644
--- a/packages/sie_server/tests/test_all_models.py
+++ b/packages/sie_server/tests/test_all_models.py
@@ -724,6 +724,37 @@ def test_vidore_colqwen2_5_v0_2_image_multivector() -> None:
_assert_multivector_image("vidore/colqwen2.5-v0.2", 128, None)
+# TopK-Embed-V1 needs transformers >= 5.2, which the transformers5 bundle carries:
+# run these with that bundle's requirements, e.g.
+# python -m sie_server.cli resolve-deps --bundle transformers5 > /tmp/t5.txt
+# uv run --no-sync --with-requirements /tmp/t5.txt pytest -c pyproject.toml -m model \
+# packages/sie_server/tests/test_all_models.py -k topk_embed
+def test_topk_io_topk_embed_v1_xsmall_multivector() -> None:
+ pytest.importorskip("transformers.models.qwen3_5", reason="needs transformers >= 5.2 (the transformers5 bundle)")
+ _assert_multivector(
+ "topk-io/topk-embed-v1-xsmall", 1024, [-0.033416748046875, 0.038848876953125, 0.0215911865234375]
+ )
+
+
+def test_topk_io_topk_embed_v1_xsmall_image_multivector() -> None:
+ pytest.importorskip("transformers.models.qwen3_5", reason="needs transformers >= 5.2 (the transformers5 bundle)")
+ _assert_multivector_image(
+ "topk-io/topk-embed-v1-xsmall", 1024, [-0.069580078125, 0.037445068359375, -0.021209716796875]
+ )
+
+
+def test_topk_io_topk_embed_v1_small_multivector() -> None:
+ pytest.importorskip("transformers.models.qwen3_5", reason="needs transformers >= 5.2 (the transformers5 bundle)")
+ _assert_multivector("topk-io/topk-embed-v1-small", 2048, [0.02752685546875, -0.04046630859375, 0.00592041015625])
+
+
+def test_topk_io_topk_embed_v1_small_image_multivector() -> None:
+ pytest.importorskip("transformers.models.qwen3_5", reason="needs transformers >= 5.2 (the transformers5 bundle)")
+ _assert_multivector_image(
+ "topk-io/topk-embed-v1-small", 2048, [0.036773681640625, -0.04022216796875, -0.0186614990234375]
+ )
+
+
# =============================================================================
# Multivector models with muvera profiles (dense via postprocessor)
# =============================================================================