Conversation
- Detect CUDA availability before falling back to MPS/CPU - Use bfloat16 when CUDA supports it (safer than float16 for training) - Explicitly move model to target device after loading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
当前代码在 CUDA GPU 上运行时存在两个问题:
train.py只检查 MPS (Mac) 和 CPU,完全遗漏了 CUDA 检测,导致模型始终加载到 CPU 上device='cuda',AutoModelForCausalLM.from_pretrained()返回的模型仍留在 CPU,需要显式.to(device)float16会导致训练时出现inf/nan崩溃(device-side assert),改用bfloat16更稳定修复
torch.cuda.is_available())bfloat16(如果硬件支持),否则回退到float32.to(device)测试