Skip to content

Commit e780dab

Browse files
committed
#36 - Fix to_device() incorrectly casting integer tensors
Only apply dtype conversion to floating-point tensors, preserving integer and boolean tensors for HuggingFace model compatibility. Signed-off-by: Dpakkk <pokharelbikash981@gmail.com>
1 parent e0e2ac3 commit e780dab

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/alpamayo_r1/helper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ def to_device(
8686
) -> Any:
8787
"""Recursively cast data into the specified device, dtype."""
8888
if isinstance(data, torch.Tensor):
89-
data = data.to(
90-
device=device,
91-
dtype=dtype,
92-
)
89+
if dtype is not None and data.is_floating_point():
90+
data = data.to(device=device, dtype=dtype)
91+
else:
92+
data = data.to(device=device)
9393
return data
9494
elif isinstance(data, collections.abc.Mapping):
9595
return {key: to_device(data[key], device=device, dtype=dtype) for key in data}

0 commit comments

Comments
 (0)