Skip to content

perf(tier2): store clustering similarities in packed doubles - #714

Merged
rng1995 merged 12 commits into
NVIDIA:mainfrom
Afloat16:perf/compact-cluster-pair-scores
Nov 19, 2026
Merged

rng1995 merged 12 commits into
NVIDIA:mainfrom
Afloat16:perf/compact-cluster-pair-scores

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

At the supported 1,024-chunk limit, content clustering caches 523,776 pair similarities in a dictionary keyed by two-element tuples. The object overhead consumes tens of megabytes even when no duplicate cluster is found.

Store the upper-triangle scores in rows of packed doubles and read each pair using its row offset. Keep double precision, union-find connections, sibling exclusions, cluster statistics, and ordering. Cluster-statistics scratch storage also uses packed doubles.

Measurement

A local Python 3.12 tracemalloc run over 1,024 chunks produced:

Fixture Before peak After peak
Eight-dimensional vectors from random.Random(42).uniform(-1, 1), threshold 1.0, no clusters 63,402,020 bytes 4,957,340 bytes
Identical one-dimensional vectors, threshold 1.0, one 1,024-member cluster 55,121,516 bytes 8,853,628 bytes

These are Python allocation peaks for these fixtures, with chunk construction excluded; they are not a process RSS or production workload guarantee.

Verification

python -m pytest tests/deduplication/intra_skill/test_semantic_clustering.py tests/deduplication/intra_skill/test_intra_skill_validator.py tests/deduplication/utils/test_chunk_bounds.py -q — 143 passed.

The added regression checks multiple clusters whose member indices are separated by singleton and other-cluster chunks, including their maximum and average similarities. Existing coverage includes the 1,024-chunk ceiling and split-source pieces.

  • I am familiar with the Contributing Guidelines
  • Added or updated focused tests
  • Updated documentation for user-visible changes (Unreleased changelog)
  • Ran make lint equivalent: python -m ruff check src tests
  • Full make test did not complete successfully in this environment (see below)
  • Ran make build equivalent: python -m build (wheel and sdist)
  • Did not add credentials, private datasets, or proprietary benchmark content

The unchanged base 8fe9723, tested with python -m pytest -x -q, stops after 456 passed and 19 deselected at tests/ci/test_gateway_benchmark_workflows.py::test_gitlab_enriched_tier1_applies_the_keyless_job_baselines[extra0-expected0]. The sandbox has no /tmp, while that workflow fixture explicitly invokes mktemp -d /tmp/skillevaluator-enriched-tier1.XXXXXX. The same test fails for the same reason on the retry branch.

Release Impact

  • No user-visible release note needed
  • Updated CHANGELOG.md

Merge follow-up — 2026-11-19

Current head: bb0117ee3f19eeea2e1987fd4468ebeb10d757de.

Integrated upstream main ac9fc0ef4999ee5eb86eae27ec3a83c880891c92 and resolved the sole conflict in CHANGELOG.md, retaining both release notes. The original implementation and regression-test files are byte-for-byte unchanged; other upstream files match that main commit.

  • tests/deduplication/intra_skill/test_semantic_clustering.py, test_intra_skill_validator.py, and tests/deduplication/utils/test_chunk_bounds.py: 143 passed on Python 3.13.11 with the repository-locked dependency environment.
  • Full python -m ruff check src tests and the OSS source-boundary scan passed.
  • Wheel and sdist builds passed on Python 3.12.14 with the required setuptools backend available.
  • git diff --check passed; the published tree and ordered merge parents match the validated candidate.

The earlier full-suite environment limitation remains documented above. This follow-up records focused checks on the merged tree; it does not claim a new full-suite pass.

Signed-off-by: Afloat <ShuffleMonkey@163.com>

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a clean swap and it checks out. I ran the old and new build_clusters side by side on 1,200 random chunk sets (duplicate vectors, zero vectors, split-group siblings, thresholds 0.5/0.8/1.0) plus the two-chunk, all-sibling, 1,024-chunk and 1,025-chunk cases: members, max and average similarity, ordering and the raised errors are identical bit for bit, which follows from array('d') holding the same IEEE doubles as a Python float and the sums running in the same order. On 1,024 random 8-dimensional chunks peak allocation went from 63 MB to 5 MB and the call got about 30% faster; the identical-vector case went from 55 MB to 9 MB. Nothing outside this function reads the score store and ContentCluster is unchanged, so there is no caller expecting a list.

Not blocking: the new test passes on the old code too, which is fine for a refactor; it does catch an off-by-one in the row index, which is the one new thing that could go wrong. One wording nit on the changelog line inline.

Comment thread CHANGELOG.md Resolved
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, @Afloat16.

Reviewed 177177f8fbcb. No additional actionable issues found. Packed upper-triangle storage preserves each pair score and the existing clustering decisions; component indices remain in ascending order, so the array lookup maps back to the correct pair. The prior changelog wording feedback is addressed.

Validation: 22 semantic-clustering tests passed, including separated cluster-member score checks.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Afloat16 for this contribution! I reviewed 177177f8fb. I reproduced the problem on main, confirmed this change fixes it, and ran the new and related tests on this head (all pass). I left 1 inline comment (1 P3); please take a look.

Comment thread CHANGELOG.md Resolved
Merge current main while retaining this change and the published release notes.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
@Afloat16

Copy link
Copy Markdown
Contributor Author

Moved the clustering memory improvement into Unreleased.

Commit 532aef2 resolves the changelog conflict and keeps the user-facing wording: much lower memory use for skills with many chunks, with unchanged similarity scores and clusters. Published release notes and the existing production/test blobs are unchanged. Hosted workflows await maintainer approval.

@Afloat16
Afloat16 requested a review from rng1995 November 18, 2026 04:30
Signed-off-by: Afloat <ShuffleMonkey@163.com>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Afloat16 for this contribution and for addressing the earlier review! I re-checked 025b756e23: all 1 earlier comment is resolved in the code, the tests pass, and I found nothing new. Approving.

Resolve the changelog overlap while retaining both release notes. Keep the
clustering implementation and regression files unchanged.

Validation: 143 focused tests passed; Ruff, OSS source-boundary scan, and
wheel/sdist builds passed. Full-suite environment limitations remain documented.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
Afloat16 and others added 3 commits November 19, 2026 17:14
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
@rng1995
rng1995 merged commit 2f6126c into NVIDIA:main Nov 19, 2026
20 checks passed
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.

3 participants