From 2d7550a69bb0e8fc40326b94630fec57d9a6c7e5 Mon Sep 17 00:00:00 2001 From: Dhruv Kapur <37783178+dkapur17@users.noreply.github.com> Date: Thu, 19 Feb 2026 11:28:19 -0500 Subject: [PATCH] Change reduce_value type from double to float Fixes data type mismatch between the Python binding and CUDA code (which expects a float), potentially leading to nan gradients. --- minitorch/cuda_kernel_ops.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/minitorch/cuda_kernel_ops.py b/minitorch/cuda_kernel_ops.py index a3acfad..a8a0281 100644 --- a/minitorch/cuda_kernel_ops.py +++ b/minitorch/cuda_kernel_ops.py @@ -173,7 +173,7 @@ def ret(a: Tensor, dim: int) -> Tensor: np.ctypeslib.ndpointer(dtype=np.int32, ndim=1, flags='C_CONTIGUOUS'), # in_shape np.ctypeslib.ndpointer(dtype=np.int32, ndim=1, flags='C_CONTIGUOUS'), # in_strides ctypes.c_int, # reduce_dim - ctypes.c_double, # reduce_value + ctypes.c_float, # reduce_value ctypes.c_int, # shape_len ctypes.c_int, # fn_id ] @@ -375,4 +375,4 @@ def matrix_multiply(a: Tensor, b: Tensor) -> Tensor: if more_3d: out = out.view(*ls) # print(f"Debug in matmul: output shape {out.shape}") - return out \ No newline at end of file + return out