-
Notifications
You must be signed in to change notification settings - Fork 54
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
"Cuda" counterpart for Apple M1 computers #149
Comments
If this source is to be believed then it looks like the M1 gpu might work in pytorch 1.12+ It looks like if we want cellbender to use the M1 gpu, then we have to use the device "mps" rather than "cuda". That's probably the only change that would need to be made. I can try to make these changes if you're interested! But I would need you to test it out, as I don't have an Apple M1 myself :) |
Hello @sjfleming ! I'd love to try this out. So are you saying that the code should look something like this?
Just use |
Update: I tried this and it seems like it's not working. I've seen this link before https://towardsdatascience.com/gpu-acceleration-comes-to-pytorch-on-m1-macs-195c399efcc1 . I did install PyTorch but I'm not super familiar with it. Also not very well-versed with Python. If you could walk me through what I should do, that would be nice. Would love to help figuring this out. Thank you! |
Hi @areyoukidneyme , okay great to hear. Well, I will have to make some code changes in cellbender actually, before you can try that out. (I will make it so that you can use I will let you know once I get something ready for you to test out. |
Gotcha! Just let me know and I will try it out. Honestly, I kinda stop using CellBender for my dataset because it took me 20+ hours to finish 1 sample without the Anyway, thank you and let me know! |
Yes, on a GPU, the code should run in about 1.5 hours. Still kind of longer than I'd like, but much more manageable. In the meantime, have you ever tried using a GPU on google colab? Some users told me they have been able to successfully run cellbender there for free. (You can get kicked off the machine randomly though...) You can run command-line commands from a Jupyter notebook cell in google colab by starting the line with !cellbender remove-background --cuda --input input_file.h5 --output output_file.h5 Or, if by chance you are part of a research lab that uses Terra for cloud compute (app.terra.bio), you can run the cellbender workflow there on google cloud GPUs. It's all set up for you. But you do have to pay for compute. |
Okay, when you get a chance, could you install cellbender from the cellbender remove-background \
--mps \
--input 'raw_feature_bc_matrix.h5' \
--output 'X_cellbender_output.h5' \
--expected-cells 10000 \
--total-droplets-included 30000 \
--epochs 150 \
--z-dim 200 \
--z-layers 1000 |
(I have not been able to test this, so we might need to go back-and-forth a bit until any errors I've made are corrected...) |
Sorry, what do you mean by install cellbender from the sf_pytorch_mps_backend branch on this GitHub repository? ? I don't know if this info's gonna help but these are my current conda environments:
|
We might also be a little too early for this to work… it looks like PyTorch is not yet fully functional for the MPS backend |
Ooooh. I see. Anyway, thanks for trying tho! I really appreciate it! |
Well it’s possible it might work! But now I’m slightly more pessimistic |
If you installed the cellbender package with “pip install -e CellBender”, then it’s installed in editable mode, so all you need to do is navigate to that CellBender folder and then do
That will change your local copy of the code to the new branch, and since you pip installed with “-e”, then you’ll be ready to try it out without needing to reinstall CellBender. |
Hey @sjfleming ! So sorry for getting back at this super late. I tried doing this
but it's giving me this |
Hi @areyoukidneyme , I think I can help. That So on my laptop for example, I did something like
then the root directory of my clone would be at Then if i want to checkout the
I would then probably also do this (if you are using a conda environment for your cellbender installation, as in the README...
Then you should be ready to try it out |
So I tried this out, this is what happened:
Already up to date.
Switched to a new branch 'sf_pytorch_mps_backend And then I tried running this:
I got this error:
|
Okay it looks like the branch switching worked so that's good. But it seems like you will have to re-run this command:
That should re-install cellbender and allow you to use that new branch (hopefully). |
I installed from the
in But it seems you will have to wait for some more updates to pytorch. When running with
I have pytorch=1.13.0 installed via conda. So I will just have to run the slow cpu version for now I guess. |
Oh very interesting, thank you @asabjorklund ! (I guess you can also try setting that environment variable and see if other things are still faster on MPS.) I will be trying a small change to see if it speeds up CPU compute soon #160 |
@sjfleming I already tested setting the
So I gave up and reverted to the cpu version, great to hear that it will be faster soon! |
Hmm, okay thank you for posting this... I am not sure what's going on there unfortunately. Bummer that it doesn't work. Seems to be this pytorch/pytorch#78429 so I'll try to check what the solution is there. |
Hey! This is an awesome tool, thankyou for developing. I am also getting this running on my M3 mac, and also have the issue with regards to --cuda. Wondering if there is some update on this? I will try the branch indicate in the meantime, and if it doesn't work feeling motivated enough I will see if I can update cellbender's code and put in a pull request :) Thanks! |
OK so I got this going on my M3 mac now: https://github.com/BradBalderson/CellBender Works with: Note that I added this to the top of the run script: This ensures that for components of pytorch that are not implemented for MPS device, will fall back to CPU. Also had to make sure had the latest version of pyro and pytorch installed. These are my exact versions of major CellBender dependencies:
I determined the correct pytorch for my machine here: https://pytorch.org/get-started/locally/ At first did not have the latest pytorch version and so ran into more mps issues (particular torch.where would not work). Thanks for a nice tool! I will put in a pull request. Have not tested to make sure I didn't break cuda though (though write in a way that should be more backend agnostic), perhaps @sjfleming could test?? Thankyou! |
I don't know why, but it runs for a few epochs, then I get a stranger error with regards to two tensors not being the same shape with the above implementation. Will debug next time I need to run, but just thought I'd flag this to other users if they try my M3 apple silicon implementation. If I run the equivalent on CPU, no such error occurs. Think there is something M3 specific happening in the backend of Pytorch that will be tricky to debug. |
@BradBalderson , can you please file a github issue for |
I'm running CellBender in my M1 Macbook but I guess the "cuda" argument to call for GPU use does not work in M1 computers. Was wondering if we could call for GPU usage in M1 devices when running CellBender.
Thanks in advance!
The text was updated successfully, but these errors were encountered: