{
  "id": 285507,
  "title": "Detectron2 and reproducability ",
  "url": "/competitions/sartorius-cell-instance-segmentation/discussion/285507",
  "author_name": "Konrad Banachewicz",
  "post_date": "2021-11-05T00:35:37.767000",
  "votes": 9,
  "comment_count": 6,
  "views": 0,
  "content": "<p>Just curious: has anyone managed to make the model reproducible across runs? The usual PyTorch manner</p>\n<pre><code>def seed_everything(seed):\n    random.seed(seed)\n    os.environ['PYTHONHASHSEED'] = str(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    torch.cuda.manual_seed(seed)\n    torch.backends.cudnn.deterministic = True\n\nseed_everything(CFG.seed)\n</code></pre>\n<p>does not seem to suffice.</p>",
  "messages": [
    {
      "id": 1571547,
      "postDate": "2021-11-05T00:35:37.767Z",
      "content": "<p>Just curious: has anyone managed to make the model reproducible across runs? The usual PyTorch manner</p>\n<pre><code>def seed_everything(seed):\n    random.seed(seed)\n    os.environ['PYTHONHASHSEED'] = str(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    torch.cuda.manual_seed(seed)\n    torch.backends.cudnn.deterministic = True\n\nseed_everything(CFG.seed)\n</code></pre>\n<p>does not seem to suffice.</p>",
      "rawMarkdown": "Just curious: has anyone managed to make the model reproducible across runs? The usual PyTorch manner\n\n```\ndef seed_everything(seed):\n    random.seed(seed)\n    os.environ['PYTHONHASHSEED'] = str(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    torch.cuda.manual_seed(seed)\n    torch.backends.cudnn.deterministic = True\n\nseed_everything(CFG.seed)\n```\n\ndoes not seem to suffice.",
      "votes": 9
    },
    {
      "id": 1571899,
      "postDate": "2021-11-05T09:01:33.157Z",
      "content": "<p>Would you try this function ?</p>\n<pre><code>def seed_everything(seed):\n    os.environ['PYTHONHASHSEED'] = str(seed)\n    random.seed(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    torch.cuda.manual_seed(seed)\n    torch.cuda.manual_seed_all(seed)\n    torch.backends.cudnn.deterministic = True\n    torch.backends.cudnn.benchmark = False\n</code></pre>",
      "rawMarkdown": "Would you try this function ?\n\n\n    def seed_everything(seed):\n        os.environ['PYTHONHASHSEED'] = str(seed)\n        random.seed(seed)\n        np.random.seed(seed)\n        torch.manual_seed(seed)\n        torch.cuda.manual_seed(seed)\n        torch.cuda.manual_seed_all(seed)\n        torch.backends.cudnn.deterministic = True\n        torch.backends.cudnn.benchmark = False\n",
      "votes": 3,
      "replies": [
        {
          "id": 1572004,
          "postDate": "2021-11-05T10:53:10.303Z",
          "content": "<p>That might help, thanks.</p>",
          "rawMarkdown": "That might help, thanks."
        }
      ]
    },
    {
      "id": 1571929,
      "postDate": "2021-11-05T09:32:54.657Z",
      "content": "<p>Hi,<br>\nEnvironment variable <code>PYTHONHASHSEED</code> has to be set before running python interpreter. Setting it up while already running a script will not take any effect, afaic. This <a href=\"https://stackoverflow.com/questions/32538764/unable-to-see-or-modify-value-of-pythonhashseed-through-a-module\" target=\"_blank\">answer</a> on the SO may clarify this further for you. <br>\nThis <a href=\"https://pytorch.org/docs/stable/notes/randomness.html\" target=\"_blank\">pytorch tutorial</a> also describes shortly potential sources of non-deterministic behavior and could help to clarify where to look for reproducibility for your setup.<br>\nHope this helps.</p>",
      "rawMarkdown": "Hi,\nEnvironment variable `PYTHONHASHSEED` has to be set before running python interpreter. Setting it up while already running a script will not take any effect, afaic. This [answer](https://stackoverflow.com/questions/32538764/unable-to-see-or-modify-value-of-pythonhashseed-through-a-module) on the SO may clarify this further for you. \nThis [pytorch tutorial](https://pytorch.org/docs/stable/notes/randomness.html) also describes shortly potential sources of non-deterministic behavior and could help to clarify where to look for reproducibility for your setup.\nHope this helps.",
      "votes": 2,
      "replies": [
        {
          "id": 1572005,
          "postDate": "2021-11-05T10:53:21.767Z",
          "content": "<p>Brilliant, thanks.</p>",
          "rawMarkdown": "Brilliant, thanks."
        }
      ]
    },
    {
      "id": 1571693,
      "postDate": "2021-11-05T05:01:59.933Z",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/konradb\" target=\"_blank\">@konradb</a>,<br>\nI am also struggling to make the runs reproducible. Although the situation improved after seeding everything, still there's a slight difference between the runs</p>\n<p><img src=\"https://github.com/Gladiator07/Kaggle-images/blob/main/Screenshot%202021-11-05%20102412.png?raw=true\" alt=\"\"></p>",
      "rawMarkdown": "Hi @konradb,\nI am also struggling to make the runs reproducible. Although the situation improved after seeding everything, still there's a slight difference between the runs\n\n![](https://github.com/Gladiator07/Kaggle-images/blob/main/Screenshot%202021-11-05%20102412.png?raw=true)"
    },
    {
      "id": 1574417,
      "postDate": "2021-11-07T14:26:16.657Z",
      "rawMarkdown": "",
      "isDeleted": true
    }
  ],
  "comments": [
    {
      "id": 1571899,
      "author_name": "Park",
      "author_url": "",
      "post_date": "2021-11-05T09:01:33.157000",
      "content": "<p>Would you try this function ?</p>\n<pre><code>def seed_everything(seed):\n    os.environ['PYTHONHASHSEED'] = str(seed)\n    random.seed(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    torch.cuda.manual_seed(seed)\n    torch.cuda.manual_seed_all(seed)\n    torch.backends.cudnn.deterministic = True\n    torch.backends.cudnn.benchmark = False\n</code></pre>",
      "votes": 3,
      "replies": [
        {
          "id": 1572004,
          "author_name": "Konrad Banachewicz",
          "author_url": "",
          "post_date": "2021-11-05T10:53:10.303000",
          "content": "<p>That might help, thanks.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1571929,
      "author_name": "A.Demyanchuk",
      "author_url": "",
      "post_date": "2021-11-05T09:32:54.657000",
      "content": "<p>Hi,<br>\nEnvironment variable <code>PYTHONHASHSEED</code> has to be set before running python interpreter. Setting it up while already running a script will not take any effect, afaic. This <a href=\"https://stackoverflow.com/questions/32538764/unable-to-see-or-modify-value-of-pythonhashseed-through-a-module\" target=\"_blank\">answer</a> on the SO may clarify this further for you. <br>\nThis <a href=\"https://pytorch.org/docs/stable/notes/randomness.html\" target=\"_blank\">pytorch tutorial</a> also describes shortly potential sources of non-deterministic behavior and could help to clarify where to look for reproducibility for your setup.<br>\nHope this helps.</p>",
      "votes": 2,
      "replies": [
        {
          "id": 1572005,
          "author_name": "Konrad Banachewicz",
          "author_url": "",
          "post_date": "2021-11-05T10:53:21.767000",
          "content": "<p>Brilliant, thanks.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1571693,
      "author_name": "Atharva Ingle",
      "author_url": "",
      "post_date": "2021-11-05T05:01:59.933000",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/konradb\" target=\"_blank\">@konradb</a>,<br>\nI am also struggling to make the runs reproducible. Although the situation improved after seeding everything, still there's a slight difference between the runs</p>\n<p><img src=\"https://github.com/Gladiator07/Kaggle-images/blob/main/Screenshot%202021-11-05%20102412.png?raw=true\" alt=\"\"></p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1574417,
      "author_name": "",
      "author_url": "",
      "post_date": "2021-11-07T14:26:16.657000",
      "content": "",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1571547": "Just curious: has anyone managed to make the model reproducible across runs? The usual PyTorch manner\n\n```\ndef seed_everything(seed):\n    random.seed(seed)\n    os.environ['PYTHONHASHSEED'] = str(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    torch.cuda.manual_seed(seed)\n    torch.backends.cudnn.deterministic = True\n\nseed_everything(CFG.seed)\n```\n\ndoes not seem to suffice.",
    "1571899": "Would you try this function ?\n\n\n    def seed_everything(seed):\n        os.environ['PYTHONHASHSEED'] = str(seed)\n        random.seed(seed)\n        np.random.seed(seed)\n        torch.manual_seed(seed)\n        torch.cuda.manual_seed(seed)\n        torch.cuda.manual_seed_all(seed)\n        torch.backends.cudnn.deterministic = True\n        torch.backends.cudnn.benchmark = False\n",
    "1571929": "Hi,\nEnvironment variable `PYTHONHASHSEED` has to be set before running python interpreter. Setting it up while already running a script will not take any effect, afaic. This [answer](https://stackoverflow.com/questions/32538764/unable-to-see-or-modify-value-of-pythonhashseed-through-a-module) on the SO may clarify this further for you. \nThis [pytorch tutorial](https://pytorch.org/docs/stable/notes/randomness.html) also describes shortly potential sources of non-deterministic behavior and could help to clarify where to look for reproducibility for your setup.\nHope this helps.",
    "1571693": "Hi @konradb,\nI am also struggling to make the runs reproducible. Although the situation improved after seeding everything, still there's a slight difference between the runs\n\n![](https://github.com/Gladiator07/Kaggle-images/blob/main/Screenshot%202021-11-05%20102412.png?raw=true)",
    "1574417": ""
  }
}