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

CU-8694hukwm: Document the materialising of generator when multiproce… #433

Merged
merged 3 commits into from
May 22, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions medcat/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,11 @@ def multiprocessing_batch_docs_size(self,

This method batches the data based on the number of documents as specified by the user.

NOTE: When providing a generator for `data`, the generator is evaluated (`list(in_data)`)
and thus all the data is kept in memory and (potentially) duplicated for use in
multiple threads. So if you're using a lot of data, it may be better to use
`CAT.multiprocessing_batch_char_size` instead.

PS:
This method supports Windows.

Expand All @@ -1550,6 +1555,8 @@ def multiprocessing_batch_docs_size(self,
if nproc == 0:
raise ValueError("nproc cannot be set to zero")

# TODO: Surely there's a way to not materialise all of the incoming data in memory?
# This is counter productive for allowing the passing of generators.
in_data = list(in_data) if isinstance(in_data, Iterable) else in_data
n_process = nproc if nproc is not None else min(max(cpu_count() - 1, 1), math.ceil(len(in_data) / batch_factor))
batch_size = batch_size if batch_size is not None else math.ceil(len(in_data) / (batch_factor * abs(n_process)))
Expand Down
Loading