{
  "id": 130050,
  "title": "39th place solution, submission errors and memory leakage",
  "content": "<p>First of all I would like to say thank you to the <strong><em>organizers</em></strong> and <strong><em>all teams</em></strong>!\n It was very interesting and fruitful competition.</p>\n\n<h3>Agenda:</h3>\n\n<ul>\n<li>Models and Training </li>\n<li>Post-Processing</li>\n<li><strong>Pain 1 - submission errors</strong></li>\n<li><strong>Pain 2 - memory leakage using \"load_weights\" in keras</strong></li>\n</ul>\n\n<h3>Models and training</h3>\n\n<ul>\n<li>Dedicated BERT models for questions, answers and both questions and answers</li>\n<li>GroupKFold with question_title groups</li>\n<li>Weighted BCE loss function was the best. The higher weights were assigned to columns with small amount of non-zero elements like the \"question type spelling\"</li>\n<li>Blending strategy</li>\n<li>I tried weighted MSE loss function and mix of MSE + BCE but results were worse than using BCE standalone</li>\n</ul>\n\n<h3>Post-Processing</h3>\n\n<ul>\n<li>\"0,1 mapping\" - mapping of high values to 1.0 and low values to 0.0 worked the best. The percentige of values to be mapped is chosen for each column individually (optimization problem was solved for each predicted column of training set)</li>\n<li>\"Optimizer rounder\" helped me a lot to achive silver medal in previous competition \"2019 Data Science Bowl\". I was happy to find discreate classes in our targets (caused by limited number of assessors). I tried different quantization strategies:</li>\n</ul>\n\n<p><em><strong>standard:</strong></em> global optimization when the set of classes was set up using all unique values in target columns over the whole training set (single codebook case)</p>\n\n<p><em><strong>advanced:</strong></em> column-wise optimization when the number of classes were equal to the number of unique values in each target column in training set (multiple codebooks case)</p>\n\n<p>Using of \"Optimizer rounder\" standalone (standard and advanced) gave significant LB (+0.02) improvement but using it jointly with \"0,1 mapping\" led to LB decreasing (see scores below). Also it is well-known that \"Optimizer rounder\" is a very risky approach from overfitting point of view. Therefore I decided finally to chose two submissions: with and w/o \"Optimizer rounder\". When private results were published I saw that I was right and \"Optimizer rounder\" made final score lower.</p>\n\n<pre><code>public 0.43318 -&amp;gt; private 0.40901 (\"0,1 mapping\")\npublic 0.43050 -&amp;gt; private 0.40635 (\"0,1 mapping\" + \"Optimizer rounder\")\n</code></pre>\n\n<p>Solution w/o \"Optimizer rounder\" allowed to push me 30 positions up on private test set</p>\n\n<h3>Pain 1 - submission errors</h3>\n\n<p>A lot of time was spent to overcome submission errors:\n- <strong>Submission CSV Not Found</strong>\n- <strong>Submission Scoring Error</strong></p>\n\n<p>I have met such errors more than 30 times. It was really annoyed. The worst thing is that there is no additional information from the system to understand that was wrong. I experimentally found that <strong>\"Submission CSV Not Found\"</strong> is usually caused by RAM memory restriction. It occures because private test set is 7 times bigger that public one. <strong>\"Submission Scoring Error\"</strong> is caused by columns with small amound of non-zero elements. The reason is features of correlation metric calculation.</p>\n\n<h3>Pain 2 - memory leakage in keras</h3>\n\n<p>I have met the problem with \"load weights\" method in keras when perform blending. It loads model weights to RAM but does not free memory after clear_session(). It is well-known issue that was discussed many times in different resources but nothing changed.\n(for example here <a href=\"https://github.com/keras-team/keras/issues/7271\">https://github.com/keras-team/keras/issues/7271</a> and here <a href=\"https://github.com/tensorflow/tensorflow/issues/27511\">https://github.com/tensorflow/tensorflow/issues/27511</a>). \nUnfortunately the latest version of keras 2.3.1 still has this issue.</p>\n\n<p>Possible reason according to @robieta is the following:\n<strong>\"The issue is with K.clear_session(), which clears the default graph. In 1.x, Keras uses the default tf graph, but in 2.0 Keras manages its own graph. So the clear session call isn't \nactually clearing the keras graph and models are accumulating there and preventing memory from being freed. It should be a simple fix to make clear_session clears the right graph in 2.0\"</strong></p>\n\n<p>I tried multiple things to overcome it including but not limited to:\n- garbage collector calling (\"del\" for all variables + \"gc.collect()\").\n- multiprocessing strategy where tensorflow and keras were imported in a separate thread as well as models with weights.</p>\n\n<p>But nothing helped. It has limited the number of models that I could use in blending. I hope that it will be fixed somewhen. Please let me know if you aware how to fix this bug.</p>\n\n<h3>Thanks for reading and good luck in future competitions!</h3>",
  "comments": [
    {
      "id": 744258,
      "author_name": "Aditya Soni",
      "author_url": "",
      "post_date": "2020-02-12T17:27:39.127000",
      "content": "<p>Great Solution and Congratulations! \n- Here you go to solve the GPU Mem issue in somewhat a smart way 😅 <a href=\"https://www.kaggle.com/c/google-quest-challenge/discussion/129963\">Discussion</a></p>\n\n<p>Edit Updated link😅</p>",
      "votes": 3,
      "replies": [
        {
          "id": 744274,
          "author_name": "DN",
          "author_url": "",
          "post_date": "2020-02-12T17:35:37.910000",
          "content": "<p>Thank you! I got it 😄 </p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 744345,
          "author_name": "Mycroft Holmes",
          "author_url": "",
          "post_date": "2020-02-12T18:54:33.693000",
          "content": "<p>the thread I get is: \"What happened to Connecticut this year?\" </p>\n\n<p>this is the correct <a href=\"https://www.kaggle.com/c/google-quest-challenge/discussion/129963\">link</a></p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 744400,
          "author_name": "DN",
          "author_url": "",
          "post_date": "2020-02-12T19:51:56.800000",
          "content": "<p>I also already had found correct link via his profile. Anyway thanks for sharing!</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 744251,
      "author_name": "Mycroft Holmes",
      "author_url": "",
      "post_date": "2020-02-12T17:23:09.263000",
      "content": "<p>If somebody has managed to solve keras 2.xx memory leak please link to it here or make a new topic. I believe this affected many in this competition.</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 743383,
      "author_name": "Ailurophile",
      "author_url": "",
      "post_date": "2020-02-12T02:42:57.880000",
      "content": "<p>Congratulations!\nThanks for Sharing your Approach &amp; Insights!! <a href=\"/dmitrynovikov\">@dmitrynovikov</a> </p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 743197,
      "author_name": "Mycroft Holmes",
      "author_url": "",
      "post_date": "2020-02-11T21:55:46.293000",
      "content": "<p>I feel your Pain 2</p>",
      "votes": 1,
      "replies": [
        {
          "id": 743202,
          "author_name": "DN",
          "author_url": "",
          "post_date": "2020-02-11T22:00:13.183000",
          "content": "<p>Ordinary for tensorflow + keras I use mutiprocessing to fix such issues or to train different CV folds simultaneously on different GPUs. But in jupyter notebook it does not help. Pytorch looks much better here...</p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "comment_count": 8,
  "messages": [
    {
      "id": 743196,
      "postDate": "2020-02-11T21:53:10.230Z",
      "content": "<p>First of all I would like to say thank you to the <strong><em>organizers</em></strong> and <strong><em>all teams</em></strong>!\n It was very interesting and fruitful competition.</p>\n\n<h3>Agenda:</h3>\n\n<ul>\n<li>Models and Training </li>\n<li>Post-Processing</li>\n<li><strong>Pain 1 - submission errors</strong></li>\n<li><strong>Pain 2 - memory leakage using \"load_weights\" in keras</strong></li>\n</ul>\n\n<h3>Models and training</h3>\n\n<ul>\n<li>Dedicated BERT models for questions, answers and both questions and answers</li>\n<li>GroupKFold with question_title groups</li>\n<li>Weighted BCE loss function was the best. The higher weights were assigned to columns with small amount of non-zero elements like the \"question type spelling\"</li>\n<li>Blending strategy</li>\n<li>I tried weighted MSE loss function and mix of MSE + BCE but results were worse than using BCE standalone</li>\n</ul>\n\n<h3>Post-Processing</h3>\n\n<ul>\n<li>\"0,1 mapping\" - mapping of high values to 1.0 and low values to 0.0 worked the best. The percentige of values to be mapped is chosen for each column individually (optimization problem was solved for each predicted column of training set)</li>\n<li>\"Optimizer rounder\" helped me a lot to achive silver medal in previous competition \"2019 Data Science Bowl\". I was happy to find discreate classes in our targets (caused by limited number of assessors). I tried different quantization strategies:</li>\n</ul>\n\n<p><em><strong>standard:</strong></em> global optimization when the set of classes was set up using all unique values in target columns over the whole training set (single codebook case)</p>\n\n<p><em><strong>advanced:</strong></em> column-wise optimization when the number of classes were equal to the number of unique values in each target column in training set (multiple codebooks case)</p>\n\n<p>Using of \"Optimizer rounder\" standalone (standard and advanced) gave significant LB (+0.02) improvement but using it jointly with \"0,1 mapping\" led to LB decreasing (see scores below). Also it is well-known that \"Optimizer rounder\" is a very risky approach from overfitting point of view. Therefore I decided finally to chose two submissions: with and w/o \"Optimizer rounder\". When private results were published I saw that I was right and \"Optimizer rounder\" made final score lower.</p>\n\n<pre><code>public 0.43318 -&amp;gt; private 0.40901 (\"0,1 mapping\")\npublic 0.43050 -&amp;gt; private 0.40635 (\"0,1 mapping\" + \"Optimizer rounder\")\n</code></pre>\n\n<p>Solution w/o \"Optimizer rounder\" allowed to push me 30 positions up on private test set</p>\n\n<h3>Pain 1 - submission errors</h3>\n\n<p>A lot of time was spent to overcome submission errors:\n- <strong>Submission CSV Not Found</strong>\n- <strong>Submission Scoring Error</strong></p>\n\n<p>I have met such errors more than 30 times. It was really annoyed. The worst thing is that there is no additional information from the system to understand that was wrong. I experimentally found that <strong>\"Submission CSV Not Found\"</strong> is usually caused by RAM memory restriction. It occures because private test set is 7 times bigger that public one. <strong>\"Submission Scoring Error\"</strong> is caused by columns with small amound of non-zero elements. The reason is features of correlation metric calculation.</p>\n\n<h3>Pain 2 - memory leakage in keras</h3>\n\n<p>I have met the problem with \"load weights\" method in keras when perform blending. It loads model weights to RAM but does not free memory after clear_session(). It is well-known issue that was discussed many times in different resources but nothing changed.\n(for example here <a href=\"https://github.com/keras-team/keras/issues/7271\">https://github.com/keras-team/keras/issues/7271</a> and here <a href=\"https://github.com/tensorflow/tensorflow/issues/27511\">https://github.com/tensorflow/tensorflow/issues/27511</a>). \nUnfortunately the latest version of keras 2.3.1 still has this issue.</p>\n\n<p>Possible reason according to @robieta is the following:\n<strong>\"The issue is with K.clear_session(), which clears the default graph. In 1.x, Keras uses the default tf graph, but in 2.0 Keras manages its own graph. So the clear session call isn't \nactually clearing the keras graph and models are accumulating there and preventing memory from being freed. It should be a simple fix to make clear_session clears the right graph in 2.0\"</strong></p>\n\n<p>I tried multiple things to overcome it including but not limited to:\n- garbage collector calling (\"del\" for all variables + \"gc.collect()\").\n- multiprocessing strategy where tensorflow and keras were imported in a separate thread as well as models with weights.</p>\n\n<p>But nothing helped. It has limited the number of models that I could use in blending. I hope that it will be fixed somewhen. Please let me know if you aware how to fix this bug.</p>\n\n<h3>Thanks for reading and good luck in future competitions!</h3>",
      "rawMarkdown": "First of all I would like to say thank you to the ***organizers*** and ***all teams***!\n It was very interesting and fruitful competition.\n\n### Agenda:\n- Models and Training \n- Post-Processing\n- **Pain 1 - submission errors**\n- **Pain 2 - memory leakage using \"load_weights\" in keras**\n\n### Models and training\n- Dedicated BERT models for questions, answers and both questions and answers\n- GroupKFold with question_title groups\n- Weighted BCE loss function was the best. The higher weights were assigned to columns with small amount of non-zero elements like the \"question type spelling\"\n- Blending strategy\n-  I tried weighted MSE loss function and mix of MSE + BCE but results were worse than using BCE standalone\n\n### Post-Processing\n- \"0,1 mapping\" - mapping of high values to 1.0 and low values to 0.0 worked the best. The percentige of values to be mapped is chosen for each column individually (optimization problem was solved for each predicted column of training set)\n- \"Optimizer rounder\" helped me a lot to achive silver medal in previous competition \"2019 Data Science Bowl\". I was happy to find discreate classes in our targets (caused by limited number of assessors). I tried different quantization strategies:\n\n***standard:*** global optimization when the set of classes was set up using all unique values in target columns over the whole training set (single codebook case)\n\n***advanced:*** column-wise optimization when the number of classes were equal to the number of unique values in each target column in training set (multiple codebooks case)\n\t\t\nUsing of \"Optimizer rounder\" standalone (standard and advanced) gave significant LB (+0.02) improvement but using it jointly with \"0,1 mapping\" led to LB decreasing (see scores below). Also it is well-known that \"Optimizer rounder\" is a very risky approach from overfitting point of view. Therefore I decided finally to chose two submissions: with and w/o \"Optimizer rounder\". When private results were published I saw that I was right and \"Optimizer rounder\" made final score lower.\n\n\tpublic 0.43318 -&gt; private 0.40901 (\"0,1 mapping\")\n\tpublic 0.43050 -&gt; private 0.40635 (\"0,1 mapping\" + \"Optimizer rounder\")\n\nSolution w/o \"Optimizer rounder\" allowed to push me 30 positions up on private test set\n\n\t\n### Pain 1 - submission errors\nA lot of time was spent to overcome submission errors:\n- **Submission CSV Not Found**\n- **Submission Scoring Error**\n\nI have met such errors more than 30 times. It was really annoyed. The worst thing is that there is no additional information from the system to understand that was wrong. I experimentally found that **\"Submission CSV Not Found\"** is usually caused by RAM memory restriction. It occures because private test set is 7 times bigger that public one. **\"Submission Scoring Error\"** is caused by columns with small amound of non-zero elements. The reason is features of correlation metric calculation.\n\n### Pain 2 - memory leakage in keras\nI have met the problem with \"load weights\" method in keras when perform blending. It loads model weights to RAM but does not free memory after clear_session(). It is well-known issue that was discussed many times in different resources but nothing changed.\n(for example here [https://github.com/keras-team/keras/issues/7271](https://github.com/keras-team/keras/issues/7271) and here [https://github.com/tensorflow/tensorflow/issues/27511](https://github.com/tensorflow/tensorflow/issues/27511)). \nUnfortunately the latest version of keras 2.3.1 still has this issue.\n\nPossible reason according to @robieta is the following:\n**\"The issue is with K.clear_session(), which clears the default graph. In 1.x, Keras uses the default tf graph, but in 2.0 Keras manages its own graph. So the clear session call isn't \nactually clearing the keras graph and models are accumulating there and preventing memory from being freed. It should be a simple fix to make clear_session clears the right graph in 2.0\"**\n\nI tried multiple things to overcome it including but not limited to:\n- garbage collector calling (\"del\" for all variables + \"gc.collect()\").\n- multiprocessing strategy where tensorflow and keras were imported in a separate thread as well as models with weights.\n\nBut nothing helped. It has limited the number of models that I could use in blending. I hope that it will be fixed somewhen. Please let me know if you aware how to fix this bug.\n\n### Thanks for reading and good luck in future competitions!",
      "votes": 7
    },
    {
      "id": 744258,
      "postDate": "2020-02-12T17:27:39.127Z",
      "content": "<p>Great Solution and Congratulations! \n- Here you go to solve the GPU Mem issue in somewhat a smart way 😅 <a href=\"https://www.kaggle.com/c/google-quest-challenge/discussion/129963\">Discussion</a></p>\n\n<p>Edit Updated link😅</p>",
      "rawMarkdown": "Great Solution and Congratulations! \n- Here you go to solve the GPU Mem issue in somewhat a smart way 😅 [Discussion]( https://www.kaggle.com/c/google-quest-challenge/discussion/129963)\n\nEdit Updated link😅",
      "votes": 3,
      "replies": [
        {
          "id": 744274,
          "postDate": "2020-02-12T17:35:37.910Z",
          "content": "<p>Thank you! I got it 😄 </p>",
          "rawMarkdown": "Thank you! I got it 😄 "
        },
        {
          "id": 744345,
          "postDate": "2020-02-12T18:54:33.693Z",
          "content": "<p>the thread I get is: \"What happened to Connecticut this year?\" </p>\n\n<p>this is the correct <a href=\"https://www.kaggle.com/c/google-quest-challenge/discussion/129963\">link</a></p>",
          "rawMarkdown": "the thread I get is: \"What happened to Connecticut this year?\" \n\nthis is the correct [link](https://www.kaggle.com/c/google-quest-challenge/discussion/129963)"
        },
        {
          "id": 744400,
          "postDate": "2020-02-12T19:51:56.800Z",
          "content": "<p>I also already had found correct link via his profile. Anyway thanks for sharing!</p>",
          "rawMarkdown": "I also already had found correct link via his profile. Anyway thanks for sharing!"
        }
      ]
    },
    {
      "id": 744251,
      "postDate": "2020-02-12T17:23:09.263Z",
      "content": "<p>If somebody has managed to solve keras 2.xx memory leak please link to it here or make a new topic. I believe this affected many in this competition.</p>",
      "rawMarkdown": "If somebody has managed to solve keras 2.xx memory leak please link to it here or make a new topic. I believe this affected many in this competition.",
      "votes": 1
    },
    {
      "id": 743383,
      "postDate": "2020-02-12T02:42:57.880Z",
      "content": "<p>Congratulations!\nThanks for Sharing your Approach &amp; Insights!! <a href=\"/dmitrynovikov\">@dmitrynovikov</a> </p>",
      "rawMarkdown": "Congratulations!\nThanks for Sharing your Approach &amp; Insights!! @dmitrynovikov ",
      "votes": 1
    },
    {
      "id": 743197,
      "postDate": "2020-02-11T21:55:46.293Z",
      "content": "<p>I feel your Pain 2</p>",
      "rawMarkdown": "I feel your Pain 2",
      "votes": 1,
      "replies": [
        {
          "id": 743202,
          "postDate": "2020-02-11T22:00:13.183Z",
          "content": "<p>Ordinary for tensorflow + keras I use mutiprocessing to fix such issues or to train different CV folds simultaneously on different GPUs. But in jupyter notebook it does not help. Pytorch looks much better here...</p>",
          "rawMarkdown": "Ordinary for tensorflow + keras I use mutiprocessing to fix such issues or to train different CV folds simultaneously on different GPUs. But in jupyter notebook it does not help. Pytorch looks much better here..."
        }
      ]
    }
  ],
  "complete": true,
  "source": "live",
  "fetched_at": "2026-10-19T19:08:21Z",
  "competition_id": 7968,
  "competition_slug": "google-quest-challenge",
  "team_id": 4297131,
  "solution_url": "/competitions/google-quest-challenge/writeups/dn-39th-place-solution-submission-errors-and-memor"
}