Skip to content

Drop two no-op cpu() calls in the k-means cuda path - #2835

Open
darkdi wants to merge 1 commit into
apple:mainfrom
darkdi:kmeans-drop-noop-cpu-calls
Open

darkdi wants to merge 1 commit into
apple:mainfrom
darkdi:kmeans-drop-noop-cpu-calls

Conversation

@darkdi

@darkdi darkdi commented Aug 25, 2026

Copy link
Copy Markdown

Noticed this in the cuda branch of _cluster_weights_2d. Tensor.cpu() is not in place, so both calls build a copy and drop it while the originals stay on the device, and the assignment ten lines up shows the form that was meant. If freeing device memory before the return was the point, layerwise_compressor does it with del plus empty_cache, so you may want that here instead.

@darkdi

darkdi commented Sep 28, 2026

Copy link
Copy Markdown
Author

Ping on this one, it has been open a month with no CI run. The two lines drop a .cpu() result that is thrown away, ten lines above in the same method the assignment form is there. Anything you need from me to get it looked at?

max_iter=300,
).fit(weight_2d, sample_weight=importance_2d)

weight_2d.cpu()

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.

Looks like weight_2d could potentially be running on CUDA, see line 666.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, it can be on CUDA. Tensor.cpu() returns a CPU copy without changing the source tensor, so these two calls discard that copy and leave weight_2d and importance_2d on CUDA. The .cpu() calls on the returned centers and labels are still there. PyTorch docs.

This branch has not been deployed

No deployments
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.

2 participants