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

'cnmf_refit.estimates.detrend_df_f' in demo_pipeline.ipynb requires tons of memory? #1274

Closed
brian-arnold opened this issue Feb 13, 2024 · 15 comments

Comments

@brian-arnold
Copy link

Please fill in the following for any issues

Your setup:
Repeatable on both my university's computing cluster and my Mac laptop

  1. Operating System (Linux, MacOS, Windows):
  • Linux and MacOS (14.2)
  1. Hardware type (x86, ARM..) and RAM:
  • Hardware: x86 and ARM
  • RAM: 150GB+ on computing cluster, 96GB on Mac
  1. Python Version (e.g. 3.9):
  • 3.11.7
  1. Caiman version (e.g. 1.9.12):
  • 1.10.2
  1. Which demo exhibits the problem (if applicable):
  • demo_pipeline.ipynb, ran cell by cell without making any changes, using the data provided by the tutorial: download_demo('Sue_2x_3000_40_-46.tif')
  1. How you installed Caiman (pure conda, conda + compile, colab, ..):
  • conda, but for my MAC I had to additionally 'pip install tensorflow-macos' to get the following command to run:
    cnmf_refit.estimates.evaluate_components
  1. Details:

Thank you for such a fabulous set of well-documented tools!

I'm running demo_pipeline.ipynb, using data provided by the demo, and all but one cell in the notebook works like a charm, both when I run the jupyter notebook (via VS Code) interactively on our computing cluster with lots of memory and my Mac, which also has a decent amount of memory.

However, every time I reach the cell containing the function that computes delta_f/f (using cnmf_refit.estimates.detrend_df_f), the kernel crashes. I suspect it's a memory issue because when I monitor memory consumption on our computing cluster using 'top', over the course of ~15 min memory usage gradually increases to ~200GB before it hits 0 and the kernel crashes. Likewise, on my Mac with 96GB of memory, after 15 min it says the application ran out of memory.

Are there any options or parameters I can change to help this? Or is the only solution to just get more memory? We have some large datasets we want to analyze, so I worry that if I'm hitting memory issues with the demo data that I will certainly encounter this issue on the data we're interested in.

Thanks for any help or advice!
Brian

@EricThomson
Copy link
Contributor

Yikes that's not good. This is a relatively simple calculation that shouldn't require that much memory. Let me try to reproduce soon: we've started to adjust things around that method recently (see #1260 ). I should be able to get to it tomorrow.

@kushalkolar
Copy link
Collaborator

kushalkolar commented Feb 14, 2024

What if you give use_residuals=False ? The residuals are huge.

@brian-arnold
Copy link
Author

I had use_residuals=False since it's specified that way in the demo_pipeline.ipynb notebook (although I see the default behavior is True).

@restrepd
Copy link

I was the person that filed nel-lab/mesmerize-core#276 in mesmerize. I gave use_residuals=False, and ran get_detrend_dfof and I still get the same problem. I agree that this is a simple calculation and should not require much memory leading to a crash. Here is a screenshot with nvtop. I suppose I could work around this by running the old matlab code exxtract_DF_F.m.
Screenshot 2024-02-14 at 2 24 02 AM
Thanks!

@kushalkolar
Copy link
Collaborator

@restrepd That's your GPU VRAM not your system RAM. Caiman doesn't use the GPU.

@restrepd
Copy link

@kushalkolar yes, the graph in nvtop is GPU and it is not used by caiman. But at the bottom it does list "CPU HOST MEM" (memsmerize is restrepd...). At any rate it crashed.

@EricThomson
Copy link
Contributor

EricThomson commented Feb 14, 2024

Yep this is #1262 . Ummm....avoid use_residuals=False right now this is the infinite while loop bug 😬 . I will start the fix on this today or asap this is pretty urgent. It has to do with some deprecations from scipy that we need to accommodate. Sorry about this. We are exposing things that have been hidden for a while in the dff calculation, so bugs are getting revealed and I need to fix them. Yikes I thought I had switched that in the demo notebook let me fix that I'm basically forcing the bug to run in the demo notebook 😨

Thanks for pushing on this! I'll fix the demo notebook asap. The underlying bug will be fixed as soon as I can.

@restrepd
Copy link

Thanks a bunch!

@EricThomson
Copy link
Contributor

Ok I wasn't crazy I thought I had fixed it (with a hack): the workaround in the notebook to avoid the infinite while loop bug is to set flag_auto=False. If you have flag_auto=True and use_residuals=True then you will hit the bug.

I'll work on an actual longer-term solution, but I should mention that this flag is pretty important because it's holding things together with spit and paper currently basically. 😬

@restrepd
Copy link

Thanks! It works!

@EricThomson
Copy link
Contributor

EricThomson commented Feb 14, 2024

Just to clarify: it isn't taking tons of CPU load because it is a computationally demanding computation, but because you are sucked into an infinite while loop. I will work on fixing this my guess is within a week, so people can once again use flag_auto. Please see programmer time translation guide. 😄

@brian-arnold
Copy link
Author

Also confirming that setting use_residuals=True and flag_auto=False makes everything work!

@EricThomson
Copy link
Contributor

EricThomson commented Feb 14, 2024

Just to clarify, as I was a bit murky above: it should work with either value of use_residuals as long as flag_auto is set to False.

@EricThomson
Copy link
Contributor

This is fixed as of #1288 the different permutations of dff calculation should now work (I think it is merged into main so should be part of conda install now).

@restrepd
Copy link

restrepd commented Mar 22, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants