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

Remove on_batch_begin and on_batch_end callbacks #3078

Merged
merged 6 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 5 additions & 22 deletions gensim/models/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,11 @@ class CallbackAny2Vec:

See examples at the module level docstring for how to define your own callbacks by inheriting from this class.

As of gensim 4.0.0, the following callbacks are no longer supported, and overriding them will have no effect:

- on_batch_begin
- on_batch_end

"""
def on_epoch_begin(self, model):
"""Method called at the start of each epoch.
Expand All @@ -601,28 +606,6 @@ def on_epoch_end(self, model):
"""
pass

def on_batch_begin(self, model):
"""Method called at the start of each batch.

Parameters
----------
model : :class:`~gensim.models.word2vec.Word2Vec` or subclass
Current model.

"""
pass

def on_batch_end(self, model):
"""Method called at the end of each batch.

Parameters
----------
model : :class:`~gensim.models.word2vec.Word2Vec` or subclass
Current model.

"""
pass

def on_train_begin(self, model):
"""Method called at the start of the training process.

Expand Down
8 changes: 0 additions & 8 deletions gensim/models/word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,22 +1145,15 @@ def _worker_loop(self, job_queue, progress_queue):
"""
thread_private_mem = self._get_thread_working_mem()
jobs_processed = 0
callbacks = progress_queue.callbacks
while True:
job = job_queue.get()
if job is None:
progress_queue.put(None)
break # no more jobs => quit this worker
data_iterable, alpha = job

for callback in callbacks:
callback.on_batch_begin(self)

tally, raw_tally = self._do_train_job(data_iterable, alpha, thread_private_mem)

for callback in callbacks:
callback.on_batch_end(self)

progress_queue.put((len(data_iterable), tally, raw_tally)) # report back progress
jobs_processed += 1
logger.debug("worker exiting, processed %i jobs", jobs_processed)
Expand Down Expand Up @@ -1410,7 +1403,6 @@ def _train_epoch(
"""
job_queue = Queue(maxsize=queue_factor * self.workers)
progress_queue = Queue(maxsize=(queue_factor + 1) * self.workers)
progress_queue.callbacks = callbacks # messy way to pass along for just this session

workers = [
threading.Thread(
Expand Down