Skip to content

Commit 9d0593b

Browse files
fix: only cast float64 tensors in dict_to_device
Avoid converting boolean masks to float, which breaks ~ and torch.where. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c6d5521 commit 9d0593b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

direct/utils/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,13 @@ def dict_to_device(
172172
"""
173173
if keys is None:
174174
keys = data.keys()
175-
return {k: v.float().to(device) if isinstance(v, torch.Tensor) else v for k, v in data.items() if k in keys}
175+
return {
176+
k: (v.float() if v.dtype == torch.float64 else v).to(device)
177+
if isinstance(v, torch.Tensor)
178+
else v
179+
for k, v in data.items()
180+
if k in keys
181+
}
176182

177183

178184
def detach_dict(data: Dict[str, torch.Tensor], keys: Optional[Union[List, Tuple, KeysView]] = None) -> Dict:

0 commit comments

Comments
 (0)