Repository navigation
Proposal: QGEMeans, mini-batch e-means with SymphonyQG assignment - #261
TamimEhsan wants to merge 10 commits into
Conversation
|
Thanks for the proposal! 0.9 is in its final release steps, so we're holding new features until it lands on After the rebase we'll review it in full. In case you want to prepare, we'll check:
|
|
0.9.0 is now on |
4b52078 to
9ed76e5
Compare
…batch-law shift overflow
|
Thanks for the rebase. I checked Share the centroid-graph assigner instead of copying it.
Two small doc fixes:
|
|
Thanks for the review. Done:
Also: QGEMeans now only allocates the query-sum cache when a row is searched more than once, and a new test covers the row index together with the cache at d=512. |
QGEMeans, mini-batch e-means with SymphonyQG assignment
Adds
rabitqlib::qgemeans::QGEMeans(C++) andrabitqlib.QGEMeans(Python). It is the e-means recipe (arXiv:2611.09501, Algorithm 1, with the constants and the cost-based revival of Faisscontrib/e_meansat b14b3d693), with each mini-batch assigned through a SymphonyQG graph over the current centroids. This is a new class; QGKMeans and RaBitQKMeans keep their current behaviour.closing_handover=False. Split, updated and closing coordinates stay within the boundtrainandassignaccept, so a trained model always assigns.train,train_centroids,assign,centroids,assignments,distances,iteration_stats(one entry per iteration) andfinal_obj.final_assignmentis'approximate'by default, or'exact'. A failedtrainkeeps the previous results, and results are identical for any thread count.assignsearches the same kind of graph as training, so it reproduces the training labels.niter=8,batch_size=0(use the batch-size law),max_degree=32,ef_construction=240,ef_search=16(at least 2, since each search returns the two nearest centroids),graph_build_iterations=1,seed,num_threads,verbose. Names follow QGKMeans (niter,max_degree,ef_construction, ...), in C++ and Python alike, so there are no deprecated aliases;batch_sizeis the only new one.detail/emeans.hppholdsEMeans<Parameters, Assignment>, the counterpart ofLloydKMeans: the training loop, API, validation and final assignment over a pluggable assignment.qgemeans.hppholds the parameters and the SymphonyQG plug-in,QGEAssignment, andQGEMeansis a two-constructor class on top, likeQGKMeans. The plug-in contract followsLloydKMeans(kName,ModelState,assign_with_state, ...) and addsprepare, a top-2assign_batchover the batch's row indices, andend_pass, so a later RaBitQ e-means only needs its own plug-in.qgkmeans.hpp,detail/kmeans.hppand their tests are identical to main. QGEMeans carries its own copy of the centroid-graph assigner and graph cache (inqgemeans.hpp) and of the Lloyd parameter checks (indetail/emeans.hpp). This duplicates some code once, in exchange for a diff that leaves QGKMeans untouched; the copies can be merged in a follow-up.bin/qgemeans), C++ and Python tests, the type stub, and docs inclustering.md.Benchmark
Seed 42, Xeon Gold 6418H, GCC 14
-march=native, one thread pinned to an idle physical core, one run of each. The machine is shared: the GIST1M runs started while other users' jobs were running, so their times may be somewhat inflated.GIST1M, k = 4096:
SIFT1M, k = 2048:
Next: quantized graph build
I'm working on a quantized (8-bit, AVX-512 VNNI) SymphonyQG graph build. On a full GIST1M index it cuts build time from 31.8 s to 19.4 s at 48 threads, and from 662 s to 407 s on one thread, with recall within noise. QGEMeans rebuilds its centroid graph before every mini-batch, so a faster build should lower its total time further. That will come as a follow-up PR once this one is merged.
Checks
.github/scripts, for the workflow test-name update.mkdocs build --strict.