Repository navigation
perf(tier2): store clustering similarities in packed doubles - #714
Conversation
Signed-off-by: Afloat <ShuffleMonkey@163.com>
chrisknvidia
left a comment
There was a problem hiding this comment.
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.
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>
rng1995
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
Merge current main while retaining this change and the published release notes. Signed-off-by: Afloat <ShuffleMonkey@163.com>
|
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. |
Signed-off-by: Afloat <ShuffleMonkey@163.com>
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>
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>
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
tracemallocrun over 1,024 chunks produced:random.Random(42).uniform(-1, 1), threshold 1.0, no clustersThese 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.
make lintequivalent:python -m ruff check src testsmake testdid not complete successfully in this environment (see below)make buildequivalent:python -m build(wheel and sdist)The unchanged base
8fe9723, tested withpython -m pytest -x -q, stops after 456 passed and 19 deselected attests/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 invokesmktemp -d /tmp/skillevaluator-enriched-tier1.XXXXXX. The same test fails for the same reason on the retry branch.Release Impact
CHANGELOG.mdMerge follow-up — 2026-11-19
Current head:
bb0117ee3f19eeea2e1987fd4468ebeb10d757de.Integrated upstream main
ac9fc0ef4999ee5eb86eae27ec3a83c880891c92and resolved the sole conflict inCHANGELOG.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, andtests/deduplication/utils/test_chunk_bounds.py: 143 passed on Python 3.13.11 with the repository-locked dependency environment.python -m ruff check src testsand the OSS source-boundary scan passed.git diff --checkpassed; 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.