Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix:环境为GPU时,无法使用CPU #29

Closed
xiangking opened this issue Jan 24, 2022 · 1 comment · Fixed by #34
Closed

Fix:环境为GPU时,无法使用CPU #29

xiangking opened this issue Jan 24, 2022 · 1 comment · Fixed by #34

Comments

@xiangking
Copy link
Owner

xiangking commented Jan 24, 2022

Environment info

Python 3.8.10
ark-nlp 0.0.6

### Information

设置cpu无法生效

model = Task(dl_module, optimizer, 'lsce', device='cpu')

@xiangking
Copy link
Owner Author

将'ark_nlp.factory.task.base._task.Task'中的初始化方法

if device is None:
    if torch.cuda.is_available():
        if cuda_device == -1:
            self.device = torch.device("cuda")
        else:
            self.device = torch.device(f"cuda:{cuda_device}")
    else:
        self.device = "cpu"

改为

self.device = device 

if self.device is None:
    if torch.cuda.is_available():
        if cuda_device == -1:
            self.device = torch.device("cuda")
        else:
            self.device = torch.device(f"cuda:{cuda_device}")
    else:
        self.device = "cpu"

This was referenced Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant