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

Variable results for textcat on GPU (nightly) #6416

Closed
svlandeg opened this issue Nov 20, 2020 · 3 comments
Closed

Variable results for textcat on GPU (nightly) #6416

svlandeg opened this issue Nov 20, 2020 · 3 comments
Labels
bug Bugs and behaviour differing from documentation feat / textcat Feature: Text Classifier gpu Using spaCy on GPU 🌙 nightly Discussion and contributions related to nightly builds reproducibility Consistency, reproducibility, determinism, and randomness

Comments

@svlandeg
Copy link
Member

svlandeg commented Nov 20, 2020

Issue #6373 pointed out a reproducibility issue on v2 with the ensemble textcat architecture. This was due to the ParametricAttention layer of the CNN model.

It looks like v3 has a similar reproducibility issue, but for a different reason. When I disable the ParametricAttention layer, I still get the reproducibility problem. This happens with the default ensemble and the CNN configs, but not with the BOW.

Script to reproduce:

from thinc.api import require_gpu, Config
import spacy
from spacy.training import Example
from spacy.lang.en import English
from spacy.pipeline.textcat import default_model_config


if __name__ == "__main__":
    require_gpu()

    for i in range(5):
        spacy.util.fix_random_seed(0)

        # Toy data
        text = "Once hot, form ping-pong-ball-sized balls of the mixture, each weighing roughly 25 g."
        annots = {"cats": {"Labe1": 1.0, "Label2": 0.0, "Label3": 0.0}}

        # Set up component pipe
        nlp = English()
        pipe_cfg = Config().from_str(default_model_config)  # bow_model_config, cnn_model_config
        textcat = nlp.add_pipe("textcat", config=pipe_cfg)
        for label in annots["cats"]:
            textcat.add_label(label)

        # Training
        optimizer = nlp.begin_training()
        doc = nlp.make_doc(text)
        for _ in range(30):
            nlp.update([Example.from_dict(doc, annots)])

        # Run one document through textcat NN for scoring
        print(f"{i} result: {textcat.model.predict([doc])}")

Example output:

0 result: [[9.9999356e-01 4.1301223e-07 3.6208020e-04]]
1 result: [[9.9999356e-01 4.1301223e-07 3.6208055e-04]]
2 result: [[9.9999356e-01 4.1301223e-07 3.6208020e-04]]
3 result: [[9.9999356e-01 4.1301223e-07 3.6208075e-04]]
4 result: [[9.9999356e-01 4.1301223e-07 3.6208055e-04]]

Your Environment

  • spaCy version: 3.0.0rc2
  • Platform: Windows 10
  • Python version: 3.6.8
@svlandeg svlandeg added bug Bugs and behaviour differing from documentation feat / textcat Feature: Text Classifier gpu Using spaCy on GPU 🌙 nightly Discussion and contributions related to nightly builds labels Nov 20, 2020
@svlandeg svlandeg changed the title Variable results for textcat on GPU Variable results for textcat on GPU (nightly) Nov 20, 2020
@svlandeg
Copy link
Member Author

svlandeg commented Dec 28, 2020

Pretty puzzeled by this one. I've established that the reproducibility issue doesn't happen when we set exclusive_classes = True, which seems to point to a problem with the Logistic layer. But I can't for the life of me understand how the Logistic layer could be causing this. Perhaps some rounding errors from earlier layers get amplified? But even then, rounding errors should be deterministic, no? Unless there is some parallellization somewhere that is mixing up arithmetic order?

@polm
Copy link
Contributor

polm commented Nov 17, 2021

This looks like it's the same as #6490, so I'll close it in favor of that issue.

@polm polm closed this as completed Nov 17, 2021
@github-actions
Copy link
Contributor

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 18, 2021
@polm polm added the reproducibility Consistency, reproducibility, determinism, and randomness label Nov 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bugs and behaviour differing from documentation feat / textcat Feature: Text Classifier gpu Using spaCy on GPU 🌙 nightly Discussion and contributions related to nightly builds reproducibility Consistency, reproducibility, determinism, and randomness
Projects
None yet
Development

No branches or pull requests

2 participants