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

it will Raise RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! #37

Open
xiaozhen28 opened this issue Apr 11, 2024 · 1 comment

Comments

@xiaozhen28
Copy link

it will Raise RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! if gmm.fix(x) be used in the second time. I dont konw hao to fix it. The code as gmm = GaussianMixture(n_components, x.size(1), covariance_type="diag").cuda() gmm.fit(x) gmm.fit(x) #this will raise error

@LifelongYuan
Copy link

The error occurs if you call fit() multiple times. The improper initialization of self.var causes this problem. You could have a quick fix by adding converting it to cuda:

self.var = torch.nn.Parameter(torch.ones(1, self.n_components, self.n_features), requires_grad=False)

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

No branches or pull requests

2 participants