Skip to content

MPS (Apple Silicon): .float() on device tensors crashes with float64 error — use .to(torch.float32) #14

Description

@musicalplatypus

Environment

  • Platform: Apple Silicon (MPS)
  • PyTorch MPS backend
  • tinyml-tinyverse r1.4

Bug

tinyml_tinyverse/common/utils/utils.py calls .float() on tensors after .to(device) in multiple training functions. On Apple Silicon (MPS), .float() resolves to float64, which MPS does not support:

Affected lines

All occurrences of the pattern .to(device[, non_blocking=True]).float() in utils.py, e.g.:

# Line ~1452 (and 15 other sites)
data = data_feat_ext.to(device).float()  # crashes on MPS


Fix
Replace .float() with .to(torch.float32) — explicit dtype is the PyTorch-recommended pattern for cross-device code:

data = data_feat_ext.to(device).to(torch.float32)  # works on MPS, CUDA, CPU
Workaround
Applied locally to the installed package (16 sites in utils.py).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions