Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions coremltools/optimize/torch/_utils/k_means.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,6 @@ def _cluster_weights_2d(
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.

if importance_2d is not None:
importance_2d.cpu()

return kmeans_results.cluster_centers_.cpu(), kmeans_results.labels_.cpu()

@classmethod
Expand Down