The best ChatGPT that $100 can buy.
Python
fix: cast bf16 to fp32 on MPS (like CPU) to avoid dtype issues
Dipesh Babu7a40ee77b469
diff --git a/nanochat/checkpoint_manager.py b/nanochat/checkpoint_manager.pyindex a9327c4..2fcb01b 100644--- a/nanochat/checkpoint_manager.py+++ b/nanochat/checkpoint_manager.py@@ -65,7 +65,7 @@ def build_model(checkpoint_dir, step, device, phase):"""assert phase in ["train", "eval"], f"Invalid phase: {phase}"model_data, optimizer_data, meta_data = load_checkpoint(checkpoint_dir, step, device, load_optimizer=False)- if device.type == "cpu":+ if device.type in {"cpu", "mps"}:# Convert bfloat16 tensors to float for CPU inferencemodel_data = {k: v.float() if v.dtype == torch.bfloat16 else v