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

Problem with get_minirocket_features while using CUDA in training #153

Closed
Scienceseb opened this issue Jul 9, 2021 · 2 comments
Closed
Labels
bug Something isn't working documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@Scienceseb
Copy link

Scienceseb commented Jul 9, 2021

Hi!

So this code is working:

mrf = MiniRocketFeatures(np.asarray(X_train).shape[1], np.asarray(X_train).shape[2]).to(default_device())
X_train = torch.from_numpy((np.asarray(X_train))).to(default_device())
mrf.fit(X_train) 

but I cannot do:
X_feat = get_minirocket_features(np.asarray(X_train), mrf, chunksize=1024)

I get the following error:
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

While when I put everything on the CPU :

mrf = MiniRocketFeatures(np.asarray(X_train).shape[1], np.asarray(X_train).shape[2])
X_train = torch.from_numpy((np.asarray(X_train)))
mrf.fit(X_train)

X_feat = get_minirocket_features(np.asarray(X_train), mrf, chunksize=1024)

It works perfectly.

So the issue is that when the model is train using the GPU (CUDA) it work, but I cannot use the get_minirocket_features function.
While when the model is train using the CPU, I can use the get_minirocket_features but the GPU acceleration is lost.

Thanks for your help.

Kind regards,
Sébastien de Blois

@oguiza oguiza added question Further information is requested bug Something isn't working documentation Improvements or additions to documentation good first issue Good for newcomers and removed question Further information is requested labels Jul 15, 2021
oguiza pushed a commit that referenced this issue Jul 16, 2021
@oguiza
Copy link
Contributor

oguiza commented Jul 16, 2021

Hi @Scienceseb,

I've reviewed this and it was indeed a but. I've already fixed it now.

I've also modified the code so that the fit method in MiniRocketFeatures can either take a np.ndarray or torch.Tensor. I think it's easier to remember than X or X_train is always a np.ndarray. In this way you can now do the following:

dsid = 'LSST'
X_train, y_train, X_valid, y_valid = get_UCR_data(dsid, split_data=True)
mrf = MiniRocketFeatures(X_train.shape[1], X_train.shape[2]).to(default_device())
mrf.fit(X_train) # here X_train is a np.ndarray
X_feat = get_minirocket_features(X_train, mrf, chunksize=1024) # X_feat is also a np.ndarray

Even if you pass an np.ndarray, the entire process is run on a gpu if available.

It'd be good if you would test if it works well.

Thanks!

@Scienceseb
Copy link
Author

Scienceseb commented Jul 18, 2021

Thanks everything works well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants