Skip to content

Handle automatic chunks duration for SC2 #3721

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

Open
wants to merge 61 commits into
base: main
Choose a base branch
from

Conversation

yger
Copy link
Collaborator

@yger yger commented Feb 25, 2025

When using large number of cores, we might want to automatically set the chunk_size as function of the available RAM and/or number of cores. While I know that currently, in SI, the preprocessing nodes can consumes more RAM than chunk_size, at least this will avoid swapping and automatically adjust the sizes

@yger yger added sortingcomponents Related to sortingcomponents module sorters Related to sorters module labels Feb 25, 2025
@yger yger changed the title Handle automatic RAM allocation for chunks Handle automatic chunks duration for SC2 Feb 25, 2025
Copy link
Collaborator

@zm711 zm711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple more cosmetic questions.

n_jobs = int(min(n_jobs, memory_usage // ram_requested))
job_kwargs.update(dict(n_jobs=n_jobs))
else:
print("psutil is required to use only a fraction of available memory")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these prints or warnings? in general.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll use the warning package instead

if recording.get_total_memory_size() < memory_usage:
recording = recording.save_to_memory(format="memory", shared=True, **job_kwargs)
else:
print("Recording too large to be preloaded in RAM...")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for these prints.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@@ -73,6 +75,8 @@ class Spykingcircus2Sorter(ComponentsBasedSorter):
"matched_filtering": "Boolean to specify whether circus 2 should detect peaks via matched filtering (slightly slower)",
"cache_preprocessing": "How to cache the preprocessed recording. Mode can be memory, file, zarr, with extra arguments. In case of memory (default), \
memory_limit will control how much RAM can be used. In case of folder or zarr, delete_cache controls if cache is cleaned after sorting",
"chunk_preprocessing": "How much RAM (approximately) should be devoted to load data chunks. memory_limit will control how much RAM can be used\
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to say what units of RAM this will work with. I'm confused by this with the way it is currently written. I think users will need a bit more info to really understand how to use this.

@b-grimaud
Copy link
Contributor

With a few modifications, it can process a minute long recording in 8h45.

  • In the main sorting function, it would often crash at estimate_templates. I added a call to get_optimal_n_jobs with the same ram_requested as in clustering/circus.py.
  • In cases where the requested RAM is high and/or the memory limit is low, int will round n_jobs down to 0, which will return an error. I think get_optimal_n_jobs should ensure that n_jobs is at least 1, or at least return a specific warning.
  • In clustering/circus.py, I also had crashes at remove_duplicates_via_matching. Passing the same job_kwargs as those used in estimate_templates does the trick, but another call to get_optimal_n_jobs with a proper estimate of the requested amount of RAM could be more appropriate.
  • In clustering_tools.py, detect_mixtures sets n_jobs to 1 in its main loop. I'm guessing this part can't be parallelized ?

@yger
Copy link
Collaborator Author

yger commented Apr 7, 2025

Ok, good to know, I'll update the PR. Meanwhile, I'll also make

  • a PR to bypass the estimate_templates() call needed at the end of the clustering. In fact, templates could be inferred (at the cost of slight smoothing) from the SVD components that have been precomputed and are saved in RAM.
  • a PR to use the new graph-based clustering that we developed with sam. Such a clustering, taking the whole probe into account as a whole, would not need to deal with duplicates and thus detect_mixtures() should not be needed anymore. That's being said, I think that this function could also be skipped in your case (and in recent version of circus2). Because the final merging has been improved, keeping some duplicates should not hurt too much, and you are welcome to give it a try. How many are removed by such a function in your case?

Thanks again for the feedback

@b-grimaud
Copy link
Contributor

Thanks for the update !

detect_mixtures removes 6 units out of 3705, so about 0,2%. This seems entirely acceptable.

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

Successfully merging this pull request may close these issues.

3 participants