Skip to content

feat(pq): train codebooks with e-means by default - #496

Open
ahuber21 wants to merge 1 commit into
dev/ahuber/emeansfrom
dev/ahuber/pq-emeans
Open

ahuber21 wants to merge 1 commit into
dev/ahuber/emeansfrom
dev/ahuber/pq-emeans

Conversation

@ahuber21

@ahuber21 ahuber21 commented Dec 1, 2026

Copy link
Copy Markdown
Member

PQ codebooks are now trained per subspace with e-means instead of Lloyd. Lloyd stays selectable via PQTrainer::Lloyd.

Gotchas:

  • Stacked on the e-means PR: the base is that branch, not main.
  • The default codebooks change for every train_codebooks and PQDataset::compress caller.
  • The e-means scaling law was fitted on DEEP at larger k and dimensions, so validity at low subspace width rests on this measurement.
  • PQ training is about 12-14x faster. Encode time is unchanged.

Flat-scan recall@10 (f32 tables, 256 centroids, 112 threads, single run per cell, default seed):

dataset width train_s Lloyd train_s e-means recall@10 Lloyd recall@10 e-means
DPR 1M x 768 8 4.86 0.42 0.4483 0.4499
DPR 1M x 768 4 9.56 0.75 0.6615 0.6583
MS MARCO FDE 4096-d 8 25.77 1.98 0.6882 0.6886
MS MARCO FDE 4096-d 4 51.65 3.59 0.8351 0.8409

DPR width 4 over three training seeds: mean recall@10 0.6607 (Lloyd) against 0.6611 (e-means). The -0.0032 above is seed noise.

@ahuber21
ahuber21 changed the base branch from dev/ahuber/pq-upstream to dev/ahuber/emeans December 1, 2026 08:28
@ahuber21
ahuber21 added this pull request to stack #497 December 1, 2026 08:28
@ahuber21
ahuber21 force-pushed the dev/ahuber/pq-emeans branch from a8e9980 to 67affb9 Compare December 1, 2026 10:09
@ahuber21
ahuber21 force-pushed the dev/ahuber/pq-emeans branch from 67affb9 to c88d341 Compare December 2, 2026 10:25
Add PQTrainer { EMeans, Lloyd } and an EMeansParameters member to
PQTrainingParameters. E-means is the default; Lloyd stays selectable and
num_iterations/minibatch_size apply to it only. train_subspace now
dispatches to train_subspace_lloyd (unchanged algorithm) or
train_subspace_emeans, sharing slicing, init_centroids and the per-subspace
rng stream. No existing test asserted exact centroid values, so none changed.
New tests: default trainer, e-means vs Lloyd reconstruction error, explicit
Lloyd selection, per-seed determinism for both trainers.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ahuber21
ahuber21 force-pushed the dev/ahuber/pq-emeans branch from c88d341 to 2482d0e Compare December 2, 2026 10:26

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant