@@ -450,10 +450,7 @@ def __init__(self, trajectory, volume_shape, detector_shape, *, beam="cone", |
450 | 450 | self.native_volume_layout = bool(native_volume_layout) |
451 | 451 | self.precision = precision |
452 | 452 | self.dtype = torch.float64 if precision == "float64" else torch.float32 |
453 | | - if self.dtype == torch.float64 and any( |
454 | | - getattr(component, "device", torch.device("cpu")).type == "mps" |
455 | | - for component in trajectory): |
456 | | - raise ValueError("precision must be 'fast' or 'float32' on MPS; MPS provides no float64") |
| 453 | + self._validate_precision(trajectory) |
457 | 454 | self._reference = None |
458 | 455 | self.partition = partition |
459 | 456 | if not isinstance(partition, str) or partition not in ("views", "space", "hybrid"): |
@@ -583,6 +580,12 @@ def __init__(self, trajectory, volume_shape, detector_shape, *, beam="cone", |
583 | 580 | UserWarning, stacklevel=2, |
584 | 581 | ) |
585 | 582 |
|
| 583 | + def _validate_precision(self, values): |
| 584 | + if self.dtype == torch.float64 and any( |
| 585 | + torch.device(getattr(value, "device", "cpu")).type == "mps" |
| 586 | + for value in values): |
| 587 | + raise ValueError("precision must be 'fast' or 'float32' on MPS; MPS provides no float64") |
| 588 | + |
586 | 589 | def _validate_geometry_range(self): |
587 | 590 | if self.dtype == torch.float32 and self.beam in ("fan", "cone") and self.detector_surface is None: |
588 | 591 | # Both FP32 backends set up each segment from the endpoint nearer |
@@ -2542,8 +2545,6 @@ def project(self, volume, *, trajectory=None): |
2542 | 2545 | return self._call_with_geometry(trajectory, "_project", volume) |
2543 | 2546 |
|
2544 | 2547 | def _project(self, volume): |
2545 | | - if self.dtype == torch.float64 and isinstance(volume, torch.Tensor) and volume.device.type == "mps": |
2546 | | - raise ValueError("precision must be 'fast' or 'float32' on MPS; MPS provides no float64") |
2547 | 2548 | if self._reference is not None: |
2548 | 2549 | return self._reference.project(volume) |
2549 | 2550 | if torch._C._are_functorch_transforms_active(): |
@@ -2567,8 +2568,6 @@ def backproject(self, sinogram, *, trajectory=None): |
2567 | 2568 | return self._call_with_geometry(trajectory, "_backproject", sinogram) |
2568 | 2569 |
|
2569 | 2570 | def _backproject(self, sinogram): |
2570 | | - if self.dtype == torch.float64 and isinstance(sinogram, torch.Tensor) and sinogram.device.type == "mps": |
2571 | | - raise ValueError("precision must be 'fast' or 'float32' on MPS; MPS provides no float64") |
2572 | 2571 | if self._reference is not None: |
2573 | 2572 | return self._reference.backproject(sinogram) |
2574 | 2573 | if torch._C._are_functorch_transforms_active(): |
@@ -2619,8 +2618,10 @@ def _call_with_geometry(self, trajectory, operation, *args): |
2619 | 2618 | override = trajectory is not None |
2620 | 2619 | if trajectory is None and self._learnable: |
2621 | 2620 | trajectory = self._learnable |
2622 | | - if trajectory is not None: |
2623 | | - try: |
| 2621 | + try: |
| 2622 | + self._validate_precision(args) |
| 2623 | + if trajectory is not None: |
| 2624 | + self._validate_precision(trajectory) |
2624 | 2625 | _reject_trajectory_tangents(trajectory) |
2625 | 2626 | frames, views = _validate_trajectory( |
2626 | 2627 | trajectory, self.beam, detector_surface=self.detector_surface is not None, |
@@ -2703,8 +2704,8 @@ def _call_with_geometry(self, trajectory, operation, *args): |
2703 | 2704 | (coincident, "source and detector surface pixels must differ"), |
2704 | 2705 | ]) |
2705 | 2706 | del staged |
2706 | | - except (TypeError, ValueError, RuntimeError) as failure: |
2707 | | - error = failure |
| 2707 | + except (TypeError, ValueError, RuntimeError) as failure: |
| 2708 | + error = failure |
2708 | 2709 | # None must participate too: mixed override/default calls or gradient |
2709 | 2710 | # layouts cannot skip a collective on only one rank. |
2710 | 2711 | # Metadata transport needs ordinary storage-backed tensors, even when |
@@ -2732,10 +2733,6 @@ def _call_with_geometry(self, trajectory, operation, *args): |
2732 | 2733 | return result |
2733 | 2734 |
|
2734 | 2735 | def _execute_into(self, value, output, is_project): |
2735 | | - if self.dtype == torch.float64 and any( |
2736 | | - getattr(tensor, "device", torch.device("cpu")).type == "mps" |
2737 | | - for tensor in (value, output)): |
2738 | | - raise ValueError("precision must be 'fast' or 'float32' on MPS; MPS provides no float64") |
2739 | 2736 | self.last_execution_stats = None |
2740 | 2737 | self._snapshot_d2h_bytes = 0 |
2741 | 2738 | if self._reference is not None and self.world_size > 1: |
|