minimind/trainer
Lingxu 655d4705eb feat: support Apple Silicon (MPS) for training and web demo
`device_type` currently only distinguishes "cuda" from "cpu", so running
with `--device mps` on Apple Silicon falls into the "cpu" branch, disables
autocast entirely and forces fp32 training.

Changes (9 files, mechanical):
- `device_type` now resolves to cuda / mps / cpu
- `torch.cuda.amp.autocast(...)` -> `torch.amp.autocast(device_type, ...)`
- `torch.cuda.amp.GradScaler(...)` -> `torch.amp.GradScaler(device_type, ...)`,
  enabled only for CUDA + fp16 (MPS has no gradient scaler)
- `web_demo.py` device selection now prefers mps when available

This also silences the `torch.cuda.amp.*` deprecation warnings on torch 2.x.
CUDA behaviour is unchanged.

Measured on Apple M5 Pro (24GB), hidden_size=512 / 8 layers, bs=16, seq=512:
- before (fp32, no autocast): 11,784 tok/s
- after  (bf16 autocast):     15,492 tok/s   (+31%)

Verified end-to-end on MPS: pretrain, full_sft, lora, dpo, ppo, grpo,
distillation and agent RL all run to completion, and the resulting weights
export correctly to transformers / GGUF.

Note for macOS users: `--num_workers 0` is currently required, as DataLoader
worker processes deadlock on macOS + Python 3.12 due to fork safety.
2026-09-09 21:42:03 +08:00
..
rollout_engine.py [fix] inference bug 2026-05-03 20:48:48 +08:00
train_agent.py feat: support Apple Silicon (MPS) for training and web demo 2026-09-09 21:42:03 +08:00
train_distillation.py feat: support Apple Silicon (MPS) for training and web demo 2026-09-09 21:42:03 +08:00
train_dpo.py feat: support Apple Silicon (MPS) for training and web demo 2026-09-09 21:42:03 +08:00
train_full_sft.py feat: support Apple Silicon (MPS) for training and web demo 2026-09-09 21:42:03 +08:00
train_grpo.py feat: support Apple Silicon (MPS) for training and web demo 2026-09-09 21:42:03 +08:00
train_lora.py feat: support Apple Silicon (MPS) for training and web demo 2026-09-09 21:42:03 +08:00
train_ppo.py feat: support Apple Silicon (MPS) for training and web demo 2026-09-09 21:42:03 +08:00
train_pretrain.py feat: support Apple Silicon (MPS) for training and web demo 2026-09-09 21:42:03 +08:00
train_tokenizer.py [update] minimind-3 2026-03-25 23:57:45 +08:00
trainer_utils.py [update] minimind-3 2026-03-25 23:57:45 +08:00