GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix MPS precision validation for stores and trajectory overrides · cslht11/diffct@8cc6797

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • diffct
    • operators.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎diffct/operators.py‎

Copy file name to clipboardExpand all lines: diffct/operators.py
+13-16Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,7 @@ def __init__(self, trajectory, volume_shape, detector_shape, *, beam="cone",
450450
self.native_volume_layout = bool(native_volume_layout)
451451
self.precision = precision
452452
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)
457454
self._reference = None
458455
self.partition = partition
459456
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",
583580
UserWarning, stacklevel=2,
584581
)
585582

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+
586589
def _validate_geometry_range(self):
587590
if self.dtype == torch.float32 and self.beam in ("fan", "cone") and self.detector_surface is None:
588591
# Both FP32 backends set up each segment from the endpoint nearer
@@ -2542,8 +2545,6 @@ def project(self, volume, *, trajectory=None):
25422545
return self._call_with_geometry(trajectory, "_project", volume)
25432546

25442547
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")
25472548
if self._reference is not None:
25482549
return self._reference.project(volume)
25492550
if torch._C._are_functorch_transforms_active():
@@ -2567,8 +2568,6 @@ def backproject(self, sinogram, *, trajectory=None):
25672568
return self._call_with_geometry(trajectory, "_backproject", sinogram)
25682569

25692570
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")
25722571
if self._reference is not None:
25732572
return self._reference.backproject(sinogram)
25742573
if torch._C._are_functorch_transforms_active():
@@ -2619,8 +2618,10 @@ def _call_with_geometry(self, trajectory, operation, *args):
26192618
override = trajectory is not None
26202619
if trajectory is None and self._learnable:
26212620
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)
26242625
_reject_trajectory_tangents(trajectory)
26252626
frames, views = _validate_trajectory(
26262627
trajectory, self.beam, detector_surface=self.detector_surface is not None,
@@ -2703,8 +2704,8 @@ def _call_with_geometry(self, trajectory, operation, *args):
27032704
(coincident, "source and detector surface pixels must differ"),
27042705
])
27052706
del staged
2706-
except (TypeError, ValueError, RuntimeError) as failure:
2707-
error = failure
2707+
except (TypeError, ValueError, RuntimeError) as failure:
2708+
error = failure
27082709
# None must participate too: mixed override/default calls or gradient
27092710
# layouts cannot skip a collective on only one rank.
27102711
# Metadata transport needs ordinary storage-backed tensors, even when
@@ -2732,10 +2733,6 @@ def _call_with_geometry(self, trajectory, operation, *args):
27322733
return result
27332734

27342735
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")
27392736
self.last_execution_stats = None
27402737
self._snapshot_d2h_bytes = 0
27412738
if self._reference is not None and self.world_size > 1:

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.