spaCy/spacy
Daniël de Kok b734e5314d
Avoid TrainablePipe.finish_update getting called twice during training (#12450)
* Avoid `TrainablePipe.finish_update` getting called twice during training

PR #12136 fixed an issue where the tok2vec pipe was updated before
gradient were accumulated. However, it introduced a new bug that cause
`finish_update` to be called twice when using the training loop. This
causes a fairly large slowdown.

The `Language.update` method accepts the `sgd` argument for passing an
optimizer. This argument has three possible values:

- `Optimizer`: use the given optimizer to finish pipe updates.
- `None`: use a default optimizer to finish pipe updates.
- `False`: do not finish pipe updates.

However, the latter option was not documented and not valid with the
existing type of `sgd`. I assumed that this was a remnant of earlier
spaCy versions and removed handling of `False`.

However, with that change, we are passing `None` to `Language.update`.
As a result, we were calling `finish_update` in both `Language.update`
and in the training loop after all subbatches are processed.

This change restores proper handling/use of `False`. Moreover, the role
of `False` is now documented and added to the type to avoid future
accidents.

* Fix typo

* Document defaults for `Language.update`
2023-03-30 09:30:42 +02:00
..
cli Merge branch 'master' into sync/master-into-v4 2023-03-06 16:27:56 +01:00
displacy Auto-format code with black (#12100) 2023-01-13 10:12:10 +01:00
kb Entity linking: use SpanGroup instead of Iterable[Span] for mentions (#12344) 2023-03-20 12:25:18 +01:00
lang Merge branch 'master' into sync/master-into-v4 2023-03-02 16:24:15 +01:00
matcher Merge branch 'master' into sync/master-into-v4 2023-03-02 16:24:15 +01:00
ml Entity linking: use SpanGroup instead of Iterable[Span] for mentions (#12344) 2023-03-20 12:25:18 +01:00
pipeline Entity linking: use SpanGroup instead of Iterable[Span] for mentions (#12344) 2023-03-20 12:25:18 +01:00
tests Avoid TrainablePipe.finish_update getting called twice during training (#12450) 2023-03-30 09:30:42 +02:00
tokens Return Tuple[Span] for all Doc/Span attrs that provide spans (#12288) 2023-03-01 16:00:02 +01:00
training Avoid TrainablePipe.finish_update getting called twice during training (#12450) 2023-03-30 09:30:42 +02:00
__init__.pxd
__init__.py
__main__.py
about.py Set version to v4.0.0.dev0 (#12126) 2023-01-19 09:25:34 +01:00
attrs.pxd
attrs.pyx
compat.py Drop python 3.6/3.7, remove unneeded compat (#12187) 2023-01-27 15:48:20 +01:00
default_config_distillation.cfg Add the configuration schema for distillation (#12201) 2023-01-31 13:06:02 +01:00
default_config_pretraining.cfg
default_config.cfg Add training.before_update callback (#11739) 2022-11-23 17:54:58 +01:00
errors.py Introduce hierarchy for EL Candidate objects (#12341) 2023-03-20 00:34:35 +01:00
glossary.py
language.py Avoid TrainablePipe.finish_update getting called twice during training (#12450) 2023-03-30 09:30:42 +02:00
lexeme.pxd Delete unused imports for StringStore (#12040) 2023-01-03 17:43:09 +01:00
lexeme.pyi
lexeme.pyx Refactor lexeme mem passing (#12125) 2023-01-25 12:50:21 +09:00
lookups.py
morphology.pxd
morphology.pyx
parts_of_speech.pxd
parts_of_speech.pyx
pipe_analysis.py
py.typed
schemas.py Add the configuration schema for distillation (#12201) 2023-01-31 13:06:02 +01:00
scorer.py Rename language codes (Icelandic, multi-language) (#12149) 2023-01-31 17:30:43 +01:00
strings.pxd
strings.pyi Clean up Vocab constructor (#12290) 2023-03-19 23:41:20 +01:00
strings.pyx
structs.pxd
symbols.pxd
symbols.pyx
tokenizer.pxd Refactor lexeme mem passing (#12125) 2023-01-25 12:50:21 +09:00
tokenizer.pyx Refactor lexeme mem passing (#12125) 2023-01-25 12:50:21 +09:00
ty.py Add Language.distill (#12116) 2023-01-30 12:44:11 +01:00
typedefs.pxd
typedefs.pyx
util.py Merge branch 'master' into sync/master-into-v4 2023-03-02 16:24:15 +01:00
vectors.pyx Remove names for vectors (#12243) 2023-02-08 14:37:42 +01:00
vocab.pxd Refactor lexeme mem passing (#12125) 2023-01-25 12:50:21 +09:00
vocab.pyi Clean up Vocab constructor (#12290) 2023-03-19 23:41:20 +01:00
vocab.pyx Clean up Vocab constructor (#12290) 2023-03-19 23:41:20 +01:00