Skip to content

fix: release SuperKMeans sample buffer after rotation - #5648

Closed
marcelo-cjl wants to merge 2 commits into
facebookresearch:mainfrom
marcelo-cjl:codex/release-superkmeans-sample-buffer
Closed

marcelo-cjl wants to merge 2 commits into
facebookresearch:mainfrom
marcelo-cjl:codex/release-superkmeans-sample-buffer

Conversation

@marcelo-cjl

@marcelo-cjl marcelo-cjl commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • release the temporary subsampled training buffer as soon as rotation has populated X_tilde
  • avoid retaining that buffer during Forgy initialization and the SuperKMeans iteration loop
  • preserve the existing algorithm and rotation-time peak-memory behavior

Memory result

One build run on Cohere 1M x 768 FP32 with SCANN (nlist=1024, sub_dim=2, with_raw_data=false, 16 threads):

  • SuperKMeans before this change: 6749.1 MiB average RSS
  • SuperKMeans with this change: 6425.4 MiB average RSS
  • reduction: 323.7 MiB (4.8% of total average RSS; 8.5% of build RSS above baseline)

The released sample buffer is 768 MiB. The measured reduction is smaller because average RSS is time-weighted over the full build; the buffer is still required during sampling and rotation.

Test plan

  • built the AVX2 CPU faiss_test target in Release mode
  • faiss_test --gtest_filter='AdSampling.*:PdxLayout.*:BlockL2.*:SuperKMeansAssignIteration.*' (13 tests passed)
  • Knowhere vendored integration test for SuperKMeans (3 cases, 44 assertions passed)

Closes #5650

@meta-codesync

meta-codesync Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

@alibeklfc has imported this pull request. If you are a Meta employee, you can view this in D121294074.

@meta-codesync meta-codesync Bot closed this in 3f08095 Sep 25, 2026
@meta-codesync meta-codesync Bot added the Merged label Sep 25, 2026
@meta-codesync

meta-codesync Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@alibeklfc merged this pull request in 3f08095.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SuperKMeans retains the sampled training buffer after rotation

2 participants