Skip to content

Instantly share code, notes, and snippets.

View mlaves's full-sized avatar

Max-Heinrich Laves mlaves

View GitHub Profile
@mlaves
mlaves / benchmark_grid_sampler_3d.py
Created July 29, 2025 21:14
Benchmark grid_sampler_3d on MPS vs. CPU
import torch
from time import perf_counter
def benchmark_grid_sampler_3d(device, input_shape, grid_shape, interp=0, padding=0, align_corners=False, num_warmup=5, num_runs=20):
input = torch.randn(input_shape, dtype=torch.float32).to(device)
grid = torch.randn(grid_shape, dtype=torch.float32).to(device)
for _ in range(num_warmup):
_ = torch.grid_sampler_3d(input, grid, interp, padding, align_corners)
@mlaves
mlaves / test_grid_sampler_3d_output_accuracy.py
Created July 29, 2025 20:27
Test grid_sampler_3d output accuracy between CPU and MPS implementations
import sys
import torch
torch.manual_seed(42)
def test_grid_sampler3d_output(input_shape, grid_shape, interp, padding, align_corners) -> tuple:
"""Test grid_sampler_3d output accuracy between CPU and MPS."""
# CPU computation
device = "cpu"
t = torch.randn(input_shape).to(device)
@mlaves
mlaves / test_grid_sampler3d_grad.py
Created July 29, 2025 20:25
Test gradient of grid_sampler_3d for MPS
import torch
torch.manual_seed(42)
def test_grid_sampler3d_grad_input(input_shape, grid_shape, interp, padding, align_corners) -> bool:
device = "cpu"
t = torch.randn(input_shape).to(device).requires_grad_(True)
g = torch.randn(grid_shape).to(device).tanh().requires_grad_(False)
l = torch.grid_sampler_3d(t, g, interp, padding, align_corners).mean()
l.backward()
@mlaves
mlaves / coremltools_unet3d_crash.ipynb
Last active October 1, 2023 08:14
Example of coremltools segfault on larger input sizes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mlaves
mlaves / rug_plot_matplotlib.ipynb
Created January 26, 2023 10:29
rug_plot_matplotlib.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mlaves
mlaves / kernel-svm.ipynb
Created September 8, 2021 08:25
Kernel SVM.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mlaves
mlaves / pytorch_radon.ipynb
Created July 16, 2021 12:28
pytorch_radon.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mlaves
mlaves / incremental_ik-panda.ipynb
Last active November 25, 2024 13:20
Incremental Inverse Kinematics for Franka Emika Panda 7DoF Robot
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mlaves
mlaves / client.py
Last active April 15, 2024 13:20
Send a numpy array via socket to a C/C++ program.
import socket
import numpy as np
HOST = '127.0.0.1' # The server's hostname or IP address
PORT = 65432 # The port used by the server
data = np.random.rand(1000000)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
print(f"Sent {np.prod(data.shape)} elements.")
@mlaves
mlaves / bayesian_optimization_gpytorch.ipynb
Created February 6, 2021 09:51
bayesian_optimization_gpytorch.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.