MUVERA: compute the encoding on the GPU, not on the inference thread's CPU
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Lĩnh vực
- backend, machine-learning, performance
Hướng nghiên cứu
Read packages/sie_server/src/sie_server/core/postprocessor.py: MuveraPostprocessor.transform and _build_random_cache, then trace EncodeHandler.run_inference through PostprocessorRegistry.transform_sync and an adapter such as colqwen2. First reproduce the numpy output on CPU for each MUVERA variant and compare it with the proposed batched torch formulation. Done means the device path matches numpy within float32 rounding for documents and queries, including empty and one-token items, while the numpy fallback remains.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem
The 16 model configs with a muvera profile (the ColBERT, ColPali, ColQwen, ColSmol and NVIDIA colembed models, and TopK-Embed-V1 from #417) compute MUVERA on the CPU, after the forward pass, on the model's inference thread:
- The adapter copies each item's token vectors from the GPU to the host as float32 numpy arrays, for example in colqwen2.
ModelWorkerruns inference on a single thread, andEncodeHandler.run_inferenceapplies postprocessors on that same thread throughPostprocessorRegistry.transform_sync.MuveraPostprocessor.transformworks in numpy, one item at a time and, per item, one repetition at a time: a SimHash projection, a scatter-add of every token into its partition (np.add.at), then a scatter-add into the Count Sketch.
This suited the 128-number models it was written for (the module docstring says "for ColBERT/ColPali"). The work grows with tokens × token width × repetitions, and the models added since are wide: NVIDIA's colembed models use 2,560 and 3,072 numbers per token, TopK-Embed-V1 uses 1,024 and 2,048. On TopK-Embed-V1's 2B model the CPU step takes longer per page than the forward pass itself. Because it runs on the inference thread:
- the GPU idles while MUVERA runs;
- every other request to the model, default-profile requests included, waits behind it;
- the adapter copies the full float32 token matrix to the host only to reduce it to one fixed-size vector.
Nothing in the algorithm needs the CPU. Every step is a matrix multiply or a sum into fixed slots, and the token vectors are already on the GPU when the forward pass ends.
Proposal
-
Batched formulation. Compute every item and every repetition of a batch at once, in torch, from the packed token matrix
X [N, d]and per-item offsets (item[t]is tokent's item):# Once per model, on its device: the structures _build_random_cache() makes today, # from the same seeds and numpy RNG calls, so encodings stay compatible with existing indexes. H = cat(simhash_matrices, dim=1) # [d, R*k], R = 40 repetitions, k = 6 bits, P = 2**k partitions A = cat(ams_projection_matrices, dim=1) # [d, R*p], only when projection_dim is set (text ColBERT: p = 8) cs_idx, cs_sign # [R*P*d'], only when final_projection_dim is set (page models: 10240) # Per batch. if center_tokens: X = X - per_item_mean(X)[item] bits = (X @ H > 0).view(N, R, k) part = gray_code(bits) # [N, R], same recurrence as _sketches_to_gray_partitions seg = (item[:, None] * R + arange(R)) * P + part # one segment per (item, repetition, partition) V = X if identity else (X @ A).view(N, R, p) # d' = d or p sums = zeros(B * R * P, d_prime) for r in range(R): # avoids an [N, R, d] copy of the tokens sums.index_add_(0, seg[:, r], V if identity else V[:, r]) if not is_query: # documents average, queries sum sums /= bincount(seg.flatten(), minlength=B * R * P).clamp_min(1)[:, None] fde = sums.view(B, -1) if final_dim: fde = zeros(B, final_dim).index_add_(1, cs_idx, fde * cs_sign) if normalize: fde = fde / fde.norm(dim=1, keepdim=True)A CPU check of this formulation against
MuveraPostprocessor(identity projection with the 10,240 Count Sketch, 128 to 3,072 numbers per token, documents and queries) gave bit-identical outputs. Theprojection_dim: 8andcenter_tokensvariants are not checked yet. On the GPU, float32 sums in a different order should differ only by rounding. -
Run it before the host copy. Give
MuveraPostprocessora device method, for exampleencode_device(tokens, offsets, *, is_query) -> Tensor [B, D]. The multi-vector adapters call it on their device output when the request's options carrymuvera, returndensedirectly, and skip the float32 multivector host copy. The registry skips the numpy transform when the adapter has already filleddense. Adapters:colbert,colbert_modernbert_flash,colbert_rotary_flash,colpali,colqwen2,colqwen3,colsmol,nemo_colembedandtopk_embed, the wide ones (nemo_colembed,topk_embed) first. -
Keep the numpy path as the fallback for CPU-only deployments and adapters that have not opted in. Separately, that path could leave the inference thread: the registry's async
transform()already runs postprocessors on a CPU pool, but the server callstransform_syncon the inference thread. -
Bound the memory. The per-partition sums are
[B·R·P, d']float32, about 170 MB for a batch of eight 2,048-number pages. Process the repetitions in chunks if that competes with the model's activations.
Acceptance
- For each MUVERA variant SIE ships (identity projection with the 10,240 Count Sketch;
projection_dim: 8without a sketch; with and withoutcenter_tokens), for documents and queries, including empty and one-token items: the device path matches the numpy path within float32 rounding, and an item's encoding does not depend on the rest of its batch. - With the
muveraprofile on a wide model, the GPU no longer waits on the CPU between batches, andmuverarequests no longer hold up default-profile requests to the same model. - CPU-only deployments keep working through the numpy path.
- Performance is re-evaluated after the change: the
muveraprofile's throughput and latency on a GPU, before and after.
Out of scope: whether 10,240 numbers are enough for tokens of 1,024 to 3,072 numbers (search quality), and the paper's step that fills empty partitions for documents. Each needs its own measurement.
- Ngôn ngữ chính
- Python
- Star
- 3.5k
- Fork
- 328
- Merge trung bình
- 16 giờ 25 phút
- Pull request đã merge (30 ngày)
- 121
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của superlinked/sie
-
MODEL_NOT_FOUND gives no suggestion for a model listed only as model:profileCó thể đã có người làm @ShaiShmuel đã nhận hôm nay. Đang mởenhancement rust
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
superlinked/sie#985 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
superlinked/sie#969 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
superlinked/sie#903 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
superlinked/sie#892 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
superlinked/sie#851 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của superlinked/sie
Issue tương tự
-
Feature Request
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 68/100
spotDL/spotify-downloader#2839 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Missing license fileĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
ops/setup.py writes ops/hub.json non-atomically (the torn-write class of #219, in the installer)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
mattabate/life-distributable#230 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement triage:not-checked
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
inventree/InvenTree#13318 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
google/secops-wrapper#229 ·