Skip to content

Commit e887517

Browse files
committed
chore: Enable debug prints and fix diagnostic script
1 parent 06f4912 commit e887517

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

benchmarks/verify_gpu_fallback.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def verify_gpu_fallback():
6060
# DIAGNOSTIC: Test TorchWrapper directly
6161
print("\n--- TorchWrapper Diagnostic ---")
6262
try:
63+
import torch
64+
import numpy as np
6365
try:
6466
from ppxf.torch_wrapper import TorchWrapper
6567
except ImportError:
@@ -74,6 +76,9 @@ def verify_gpu_fallback():
7476
z_float = tw.zeros((10, 10), dtype=float)
7577
print(f"tw.zeros((10,10), dtype=float) dtype: {z_float.dtype}")
7678

79+
z_np = tw.zeros((10, 10), dtype=np.float64)
80+
print(f"tw.zeros((10,10), dtype=np.float64) dtype: {z_np.dtype}")
81+
7782
if z.dtype == torch.float32 and tw.device.type != 'mps':
7883
print("CRITICAL IF: TorchWrapper defaulting to float32 on non-MPS device!")
7984

torch_wrapper.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def asnumpy(self, a):
6464
def zeros(self, shape, dtype=float):
6565
# Default to float (float64) to match dict(numpy)
6666
t_dtype = self._get_dtype(dtype)
67+
# DEBUG
68+
print(f"DEBUG: TorchWrapper.zeros requested dtype={dtype} mapped to {t_dtype} on device {self.device}")
6769
return torch.zeros(shape, device=self.device, dtype=t_dtype)
6870

6971
def ones(self, shape, dtype=float):
@@ -79,11 +81,20 @@ def _map_dtype(self, dtype):
7981
if dtype == int: return torch.long
8082
if dtype == float: return torch.float64
8183
if dtype == complex: return torch.complex128
84+
# Handle pure numpy types if passed
85+
if dtype == np.float64: return torch.float64
86+
if dtype == np.float32: return torch.float32
87+
if dtype == np.int64: return torch.long
88+
if dtype == np.int32: return torch.int32
89+
if dtype == np.complex128: return torch.complex128
90+
if dtype == np.complex64: return torch.complex64
8291
return dtype
8392

8493
def _get_dtype(self, dtype):
8594
t_dtype = self._map_dtype(dtype)
86-
return self._apply_device_constraints(t_dtype)
95+
res = self._apply_device_constraints(t_dtype)
96+
# print(f"DEBUG: _get_dtype({dtype}) -> mapped {t_dtype} -> constrained {res}")
97+
return res
8798

8899
def _apply_device_constraints(self, dtype):
89100
if self.device.type == 'mps':

0 commit comments

Comments
 (0)