Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix(core): make _extract_device_dtype torch.compile fullgraph-safe (#3797)

Edgar Ribacf184de5ecb9
diff --git a/kornia/core/utils.py b/kornia/core/utils.py
index b75923e57..3d2ca2878 100644
--- a/kornia/core/utils.py
+++ b/kornia/core/utils.py
@@ -113,7 +113,10 @@ def _extract_device_dtype(tensor_list: List[Optional[Any]]) -> Tuple[torch.devic
expected_device=device,
)
if device is None:
- device = torch.get_default_device()
+ # `torch.empty(0).device` reads the current default device and, unlike
+ # `torch.get_default_device()`, is traceable by dynamo β€” so this helper stays
+ # fullgraph-compilable even when a caller can't prove a tensor is in the list.
+ device = torch.empty(0).device
if dtype is None:
dtype = torch.get_default_dtype()
return (device, dtype)