Skip to content

Instantly share code, notes, and snippets.

@betatim
Created June 12, 2025 13:53
Show Gist options
  • Save betatim/d305e3c7566468df24f08e2c979fd69c to your computer and use it in GitHub Desktop.
Save betatim/d305e3c7566468df24f08e2c979fd69c to your computer and use it in GitHub Desktop.
import sklearn
import numpy as np
import torch
sklearn.set_config(array_api_dispatch=True)
def my_code(X, cdist=False):
if cdist:
dist = torch.cdist(X, X, p=2)
else:
dist = sklearn.metrics.pairwise.euclidean_distances(X, X)
print(dist.shape)
return dist
torch.cuda.memory._record_memory_history(
max_entries=100_000
)
X = np.random.randn(50_000, 36)
X_t = torch.asarray(X, device="cuda")
cdist = True
for n in range(5):
my_code(X_t, cdist=cdist)
if cdist:
torch.cuda.memory._dump_snapshot(f"mem_usage_cdist.pickle")
else:
torch.cuda.memory._dump_snapshot(f"mem_usage.pickle")
torch.cuda.memory._record_memory_history(enabled=None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment