1
0
Fork 0
mirror of https://github.com/p-e-w/heretic.git synced 2026-12-03 18:42:57 +07:00

[GH-ISSUE #177] print_residual_geometry(): silhouette_score scaling bottleneck and optional efficient mode proposal #100

Closed
opened 2026-11-01 04:17:32 +07:00 by bsakaguchi · 5 comments
Owner

Originally created by @Ziechoes on GitHub (Feb 18, 2026).
Original GitHub issue: https://github.com/p-e-w/heretic/issues/177

While reviewing src/heretic/analyzer.py (Analyzer.print_residual_geometry, line 31), I noticed silhouette_score is computed per-layer on full residual tensors.

For larger models, this appears to scale poorly both in runtime and memory, especially since residuals are already projected to 2D using PaCMAP for visualization.

Would you be open to an optional mode that computes silhouette score on a stratified subsample or directly on the existing 2D embedding as an approximation?

This would preserve default behavior while keeping residual analysis tractable at larger scales.

Happy to implement this as a PR if useful.

Originally created by @Ziechoes on GitHub (Feb 18, 2026). Original GitHub issue: https://github.com/p-e-w/heretic/issues/177 While reviewing src/heretic/analyzer.py (Analyzer.print_residual_geometry, line 31), I noticed silhouette_score is computed per-layer on full residual tensors. For larger models, this appears to scale poorly both in runtime and memory, especially since residuals are already projected to 2D using PaCMAP for visualization. Would you be open to an optional mode that computes silhouette score on a stratified subsample or directly on the existing 2D embedding as an approximation? This would preserve default behavior while keeping residual analysis tractable at larger scales. Happy to implement this as a PR if useful.
Author
Owner

@p-e-w commented on GitHub (Feb 18, 2026):

How long does it take for you? I'm seeing sub-minute runtimes for models in the 70B range, which I think is quite alright for an optional research feature that is only invoked occasionally.

I don't think using PaCMAP as a basis is a good idea. The embedding space is high-dimensional, and lots of information is lost in projection. The silhouette score would be far less meaningful if computed from the 2D vectors.

<!-- gh-comment-id:3919090631 --> @p-e-w commented on GitHub (Feb 18, 2026): How long does it take for you? I'm seeing sub-minute runtimes for models in the 70B range, which I think is quite alright for an optional research feature that is only invoked occasionally. I don't think using PaCMAP as a basis is a good idea. The embedding space is high-dimensional, and lots of information is lost in projection. The silhouette score would be far less meaningful if computed from the 2D vectors.
Author
Owner

@Muitamax commented on GitHub (Feb 18, 2026):

Instead of projecting to 2D, propose:

  • Optional Stratified Subsampling (Statistically Sound)
    Silhouette score is a sample-based estimator anyway.
    Add an optional parameter:
    max_samples: Optional[int] = None

Behavior:
If residual count > max_samples:
Sample uniformly or stratified by cluster label.
Compute silhouette on subset.
Otherwise use full data.

This preserves:
Metric integrity
High-dimensional geometry
Backwards compatibility
This is a strong engineering compromise.

<!-- gh-comment-id:3919302448 --> @Muitamax commented on GitHub (Feb 18, 2026): Instead of projecting to 2D, propose: - Optional Stratified Subsampling (Statistically Sound) Silhouette score is a sample-based estimator anyway. Add an optional parameter: max_samples: Optional[int] = None Behavior: If residual count > max_samples: Sample uniformly or stratified by cluster label. Compute silhouette on subset. Otherwise use full data. This preserves: Metric integrity High-dimensional geometry Backwards compatibility This is a strong engineering compromise.
Author
Owner

@p-e-w commented on GitHub (Feb 18, 2026):

So far I haven't seen even a bit of evidence that there is a problem here to begin with.

Please provide benchmarks before discussing supposed solutions.

<!-- gh-comment-id:3919844072 --> @p-e-w commented on GitHub (Feb 18, 2026): So far I haven't seen even a bit of evidence that there is a problem here to begin with. Please provide benchmarks before discussing supposed solutions.
Author
Owner

@Ziechoes commented on GitHub (Feb 18, 2026):

So far I haven't seen even a bit of evidence that there is a problem here to begin with.

Please provide benchmarks before

You’re right that current runtimes are fine — sub-minute at your current N is consistent with the expected scaling.

The reason I raised it is silhouette computation scales quadratically in the number of residual vectors N per layer (pairwise distance structure). That means runtime should increase ~4× if N doubles.

Would you be willing to run a quick sweep varying prompt count (for example N≈200, 500, 1000, 2000) and observe how runtime scales?

If it follows the expected quadratic curve, then everything is behaving exactly as designed. If not, that would be interesting in itself.

<!-- gh-comment-id:3920193796 --> @Ziechoes commented on GitHub (Feb 18, 2026): > So far I haven't seen even a bit of evidence that there is a problem here to begin with. > > Please provide benchmarks before You’re right that current runtimes are fine — sub-minute at your current N is consistent with the expected scaling. The reason I raised it is silhouette computation scales quadratically in the number of residual vectors N per layer (pairwise distance structure). That means runtime should increase ~4× if N doubles. Would you be willing to run a quick sweep varying prompt count (for example N≈200, 500, 1000, 2000) and observe how runtime scales? If it follows the expected quadratic curve, then everything is behaving exactly as designed. If not, that would be interesting in itself.
Author
Owner

@p-e-w commented on GitHub (Feb 18, 2026):

Closing this issue until someone convinces me that this is an actual problem.

<!-- gh-comment-id:3920897460 --> @p-e-w commented on GitHub (Feb 18, 2026): Closing this issue until someone convinces me that this is an actual problem.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
p-e-w/heretic#100
No description provided.