{
  "id": 118084,
  "title": "Produce Consistent results, PyTorch",
  "url": "/competitions/Kannada-MNIST/discussion/118084",
  "author_name": "",
  "post_date": "2019-11-19T13:45:12.683280800Z",
  "votes": 7,
  "comment_count": 1,
  "views": 0,
  "content": "<p>To get the same results each time I run my kernel, I need to add the following codeblock. Then I will get exactly the same weights every time I run the kernel:</p>\n\n<pre><code>def random_seed(seed_value, use_cuda):\n    np.random.seed(seed_value) # cpu vars\n    torch.manual_seed(seed_value) # cpu  vars\n    random.seed(seed_value) # Python\n    if use_cuda: \n        torch.cuda.manual_seed(seed_value)\n        torch.cuda.manual_seed_all(seed_value) # gpu vars\n        torch.backends.cudnn.deterministic = True  #needed\n        torch.backends.cudnn.benchmark = False\n\nrandom_seed(13,True)  #Seed-Value that happens to give an accurate model\n</code></pre>",
  "messages": [
    {
      "id": "676772",
      "postDate": "11/19/2019 13:45:12",
      "content": "<p>To get the same results each time I run my kernel, I need to add the following codeblock. Then I will get exactly the same weights every time I run the kernel:</p>\n\n<pre><code>def random_seed(seed_value, use_cuda):\n    np.random.seed(seed_value) # cpu vars\n    torch.manual_seed(seed_value) # cpu  vars\n    random.seed(seed_value) # Python\n    if use_cuda: \n        torch.cuda.manual_seed(seed_value)\n        torch.cuda.manual_seed_all(seed_value) # gpu vars\n        torch.backends.cudnn.deterministic = True  #needed\n        torch.backends.cudnn.benchmark = False\n\nrandom_seed(13,True)  #Seed-Value that happens to give an accurate model\n</code></pre>",
      "rawMarkdown": "To get the same results each time I run my kernel, I need to add the following codeblock. Then I will get exactly the same weights every time I run the kernel:\n\n    def random_seed(seed_value, use_cuda):\n        np.random.seed(seed_value) # cpu vars\n        torch.manual_seed(seed_value) # cpu  vars\n        random.seed(seed_value) # Python\n        if use_cuda: \n            torch.cuda.manual_seed(seed_value)\n            torch.cuda.manual_seed_all(seed_value) # gpu vars\n            torch.backends.cudnn.deterministic = True  #needed\n            torch.backends.cudnn.benchmark = False\n        \n    random_seed(13,True)  #Seed-Value that happens to give an accurate model",
      "votes": null
    },
    {
      "id": "689625",
      "postDate": "12/07/2019 07:26:22",
      "content": "<p>The torch.backends.cudnn.benchmark line seems not needed, or maybe I have some misunderstanding for it.</p>",
      "rawMarkdown": "The torch.backends.cudnn.benchmark line seems not needed, or maybe I have some misunderstanding for it.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 689625,
      "author_name": "lhy1997",
      "author_url": "",
      "post_date": "12/07/2019 07:26:22",
      "content": "<p>The torch.backends.cudnn.benchmark line seems not needed, or maybe I have some misunderstanding for it.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "676772": "To get the same results each time I run my kernel, I need to add the following codeblock. Then I will get exactly the same weights every time I run the kernel:\n\n    def random_seed(seed_value, use_cuda):\n        np.random.seed(seed_value) # cpu vars\n        torch.manual_seed(seed_value) # cpu  vars\n        random.seed(seed_value) # Python\n        if use_cuda: \n            torch.cuda.manual_seed(seed_value)\n            torch.cuda.manual_seed_all(seed_value) # gpu vars\n            torch.backends.cudnn.deterministic = True  #needed\n            torch.backends.cudnn.benchmark = False\n        \n    random_seed(13,True)  #Seed-Value that happens to give an accurate model",
    "689625": "The torch.backends.cudnn.benchmark line seems not needed, or maybe I have some misunderstanding for it."
  },
  "source": "meta"
}