更新.gitignore以忽略Result.xlsx文件,修改run.py以优先使用macOS的MPS设备,优化设备设置逻辑

This commit is contained in:
harry.zhang 2025-08-18 14:32:20 +08:00
parent bef30b9c2f
commit 8025a46baa
3 changed files with 6 additions and 2 deletions

1
.gitignore vendored
View File

@ -170,3 +170,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/ .idea/
.DS_Store .DS_Store
Result.xlsx

Binary file not shown.

7
run.py
View File

@ -20,8 +20,11 @@ import yaml
def main(): def main():
args = parse_args() args = parse_args()
# Set device # Set device (prefer MPS on macOS, then CUDA, else CPU)
if torch.cuda.is_available() and args['device'] != 'cpu': if hasattr(torch.backends, 'mps') and torch.backends.mps.is_available() and args['device'] != 'cpu':
args['device'] = 'mps'
args['model']['device'] = args['device']
elif torch.cuda.is_available() and args['device'] != 'cpu':
torch.cuda.set_device(int(args['device'].split(':')[1])) torch.cuda.set_device(int(args['device'].split(':')[1]))
args['model']['device'] = args['device'] args['model']['device'] = args['device']
else: else: