textcat training is not deterministic with gpu enabled
See original GitHub issueHow to reproduce the behaviour
This is related to #6177. I can verify that when using CPU, the training losses/weights for textcat can be deterministic with fix_random_seed
. However, if I enable GPU via spacy.require_gpu()
, the training losses/weights become different every time.
import spacy
spacy.require_gpu()
for _ in range(2):
spacy.util.fix_random_seed(0)
model = spacy.load('en_core_web_sm')
model.add_pipe(model.create_pipe('textcat'))
model.remove_pipe('parser')
model.remove_pipe('tagger')
cat = model.get_pipe('textcat')
cat.add_label("dog")
cat.add_label("donut")
model.begin_training()
print(model("What even is?").cats)
Output:
{'dog': 0.2501096725463867, 'donut': 0.3427947163581848}
{'dog': 0.9567031860351562, 'donut': 0.9506585001945496}
Your Environment
- Operating System: Linux
- Python Version Used: 3.6.9
- spaCy Version Used: latest on master (git sha: 320a8b14814c7e0c6dce705ad7bf0f13bf64b61c)
- Environment Information: Google Colab
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Models are not deterministic / reproducible on GPU #6490
I cannot reproduce the same results when training a NER model using GPU in Google Colab. When running the same code with CPU...
Read more >How to handle non-determinism when training on a GPU?
TL;DR. Non-determinism for a priori deterministic operations come from concurrent (multi-threaded) implementations.
Read more >A Workaround for Non-Determinism in TensorFlow - Two Sigma
Two Sigma researcher Ben Rossi demonstrates this problem for a neural network trained to recognize MNIST digits, and a workaround to enable training...
Read more >Projects · spaCy Usage Documentation
spaCy projects let you manage and share end-to-end spaCy workflows for different use cases and domains, and orchestrate training, packaging and serving your ......
Read more >Text Classification · Prodigy · An annotation tool for AI ...
At the end of the process, you export “gold-standard” data that you can train your model with. In Prodigy, you can use this...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s my test script (just adapted a bit from the one in the colab example):
Output:
I tested in a new venv with everything from wheels except spacy (from
master
as of now).example 10
is the model cats output for the text"example 10"
.example 10
for a few more GPU runs:pip freeze
: freeze.txtI redid the test with v3 and the results are a bit more variable than I thought between CPU and GPU, but they’re not that different across GPU runs.
Hmm, I do think there may be a bug of some sort here in spacy v2. Locally and with the colab example above I get consistent results within multiple CPU and GPU runs (also with our quick internal test cases related to this), but the CPU and GPU results are not similar to each other, and if I extend the training a bit I do get different results for multiple GPU runs. We will look into it!
In better news, with spacy v3 I get the same results on both (minus some float rounding differences, of course).