Skip to content

Add GeneratorRecording for testing and diagnosing memory issues - #1391

Merged
alejoe91 merged 39 commits into
masterfrom
add_lazy_random_recorder
Mar 21, 2023
Merged

alejoe91 merged 39 commits into
masterfrom
add_lazy_random_recorder

Conversation

@h-mayorquin

@h-mayorquin h-mayorquin commented Mar 3, 2023 •

Copy link
Copy Markdown
Contributor

Recently we had some memory issues: #1234

As @samuelgarcia pointed out, this is more likely the result of known problems with memmap in numpy and we are discussing long-term solutions to this.

That said, memory problems come both from reading and writing. We write recorder objects for many reasons including long-term storage, serialization, marshalling and reading from docker. The aim of this PR is to introduce a testing tool for memory related problems while writing LazyRandomRecording.

The LazyRandomRecording generates traces samples of any desired size and structure on the fly. That is, it does not read and should not keep a reference to the data. In general, it can be used to stress-test the processing and writing parts of any pipeline in high memory load scenarios. This can be accomplished because it decouples reading (which is required in any other recorder that produces a lot of data) from processing or writing. As an example, a specific use case is to test how the ChunkRecordingExecutor handle traces chunks of different sizes in high memory load scenarios.

I added some tests and a convenience wrapper as that seems to be a standard practice that both @alejoe91 and @samuelgarcia. I am not completly satisfied with the name so any suggestions are welcome.

What do you guys think?

@h-mayorquin h-mayorquin added bug Something isn't working testing Related to test routines continuous integration Related to CI labels Mar 3, 2023
@h-mayorquin h-mayorquin self-assigned this Mar 3, 2023
@h-mayorquin h-mayorquin removed the bug Something isn't working label Mar 3, 2023
@samuelgarcia

Copy link
Copy Markdown
Member

Hi Ramon. This is super cool and very usefull.
I will make some feedback for the naming soon.

This random recording will be also usefull for generating fake recording efficiently.
I saw you put a seed but I think this will not generate two times the same random depending how many worker we have and also the chunk_size.
This is because we have one seed at the begining but the number of call to random will change depending the number of chunk and wowrker.
It would be super cool to have a strategy that make the seeding and the results independant of the n_jobs.

@h-mayorquin

h-mayorquin commented Mar 3, 2023 •

Copy link
Copy Markdown
Contributor Author

Hi Ramon. This is super cool and very usefull. I will make some feedback for the naming soon.

This random recording will be also usefull for generating fake recording efficiently. I saw you put a seed but I think this will not generate two times the same random depending how many worker we have and also the chunk_size. This is because we have one seed at the begining but the number of call to random will change depending the number of chunk and wowrker. It would be super cool to have a strategy that make the seeding and the results independant of the n_jobs.

Yes I wrote in the documentation that this is not consistent so it can only be used to test form and not values:

Note that get_traces is no consistent across calls. That is, get_traces(0, 10, :) may not be the same
as get_traces(0, 10, :). This is because the random numbers are generated on the fly.
For generate a consistent recording, use the `generate_recording` function.

My original intention was to revamp the generate_recording_function to make it lazy (see the branch name of the other PR that I made lol) however I soon stumbled upon this problem. I had the idea to map the start_frame:end_frame and channel_indeces (the signature of the get_traces function together with segment_index) to a specific seed so the results would be consistent. I tested this and it works BUT...

Then there is the rabbit hole:
get_traces(star_frame:end_frame) would generate some results that would be consistent (that is, if you call get_traces(star_frame:end_frame) and then get_traces(star_frame:end_frame) again, you will get the same results).

But if you call get_traces(star_frame:end_frame + 1) the results would be totally unrelated to get_traces(star_frame:end_frame) while in principle they should only different in the last frame.

I was that I was doing early optimization and I decided to leave that problem for later.

@h-mayorquin
h-mayorquin marked this pull request as ready for review March 3, 2023 14:38
@samuelgarcia

Copy link
Copy Markdown
Member

I think we could have some thinkg like this.

seed = an external number
rng = np.rnadom.default_rng([segment_index, start_frame])
traces = rng.random((num_sample, num_channel))

I have tested but I guess that for a given chunk_size we should have the same results independing the number of n_jobs which is not so bad.
No ?
Would you have time to test ?

@h-mayorquin

h-mayorquin commented Mar 7, 2023 •

Copy link
Copy Markdown
Contributor Author

@samuelgarcia
Yes, that is what I was trying to say above:

unique_seed_hash = (start_frame, end_frame, segment_index, fix_class_seed)
rng = np.random.default_rng(seed=unique_seed_hash)
traces = self.rng.random(...)

Should work to generate consistent traces, but you still have the problem that I described above:

But if you call get_traces(star_frame:end_frame + 1) the results would be totally unrelated to get_traces(star_frame:end_frame) while in principle they should only different in the last frame

Check the latest changes, I implemented a deterministic function. It now returns a deterministic generator very similar to the one in the generator_function (except that it has a different phase per channel). I think this is better for testing as the get_traces per chunk are independent how do you slice it or its size.

What do you think?

@h-mayorquin h-mayorquin changed the title Add LazyRandomRecording for testing and diagnosing memory issues Add GeneratorRecording for testing and diagnosing memory issues Mar 10, 2023
@h-mayorquin h-mayorquin mentioned this pull request Mar 10, 2023
3 tasks
@h-mayorquin

h-mayorquin commented Mar 10, 2023 •

Copy link
Copy Markdown
Contributor Author

@alejoe91 @samuelgarcia
As discussed, this is ready to go and we will wait to implement the rest of the features in #1413.

However, the sorting view tests seems to be failing here, any idea on why this could be?

This test is also failing on master:
https://github.com/SpikeInterface/spikeinterface/actions/runs/4386839164/jobs/7681399228

@alejoe91
alejoe91 merged commit f22e524 into master Mar 21, 2023
@h-mayorquin
h-mayorquin deleted the add_lazy_random_recorder branch March 21, 2023 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

continuous integration Related to CI testing Related to test routines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants