{
  "id": 117102,
  "title": "XGBRegressor - out of memory",
  "url": "/competitions/ashrae-energy-prediction/discussion/117102",
  "author_name": "",
  "post_date": "2019-11-13T11:34:43.426857200Z",
  "votes": 1,
  "comment_count": 10,
  "views": 0,
  "content": "<p>Hi,</p>\n\n<p>I use XGBRegressor but when I run \"fit\" method with the whole train data, it fails on  out of memory. When I take only 1M of train records, it works fine. How can overcome this memory limit?</p>",
  "messages": [
    {
      "id": "671966",
      "postDate": "11/13/2019 11:34:43",
      "content": "<p>Hi,</p>\n\n<p>I use XGBRegressor but when I run \"fit\" method with the whole train data, it fails on  out of memory. When I take only 1M of train records, it works fine. How can overcome this memory limit?</p>",
      "rawMarkdown": "Hi,\n\nI use XGBRegressor but when I run \"fit\" method with the whole train data, it fails on  out of memory. When I take only 1M of train records, it works fine. How can overcome this memory limit?",
      "votes": null
    },
    {
      "id": "672067",
      "postDate": "11/13/2019 13:39:23",
      "content": "<p>Are you using GPU? I found using non GPU will have higher RAM available compared with GPU enabled. </p>",
      "rawMarkdown": "Are you using GPU? I found using non GPU will have higher RAM available compared with GPU enabled.",
      "votes": null
    },
    {
      "id": "672178",
      "postDate": "11/13/2019 15:32:13",
      "content": "<p>If your running kernel on local PC you can change virtual memory size (Windows) or change swap file size (Linux).</p>",
      "rawMarkdown": "If your running kernel on local PC you can change virtual memory size (Windows) or change swap file size (Linux).",
      "votes": null
    },
    {
      "id": "672182",
      "postDate": "11/13/2019 15:38:23",
      "content": "<p>I just tried CPU. Still fails. </p>",
      "rawMarkdown": "I just tried CPU. Still fails.",
      "votes": null
    },
    {
      "id": "672192",
      "postDate": "11/13/2019 15:46:32",
      "content": "<p>No, I run Kaggle kernel.</p>",
      "rawMarkdown": "No, I run Kaggle kernel.",
      "votes": null
    },
    {
      "id": "672211",
      "postDate": "11/13/2019 16:24:19",
      "content": "<p>Ok - I can't be of much help since I seldom use Kaggle kernels - but several shared kernels have described methods to reduce memory size so if you have not used any of those methods to reduce the bytes size for each of your variables they would be worth incorporating into your kernel.  Probably any of the best scoring or high voted kernels will have a def for memory usage reduction.</p>",
      "rawMarkdown": "Ok - I can't be of much help since I seldom use Kaggle kernels - but several shared kernels have described methods to reduce memory size so if you have not used any of those methods to reduce the bytes size for each of your variables they would be worth incorporating into your kernel.  Probably any of the best scoring or high voted kernels will have a def for memory usage reduction.",
      "votes": null
    },
    {
      "id": "672219",
      "postDate": "11/13/2019 16:41:49",
      "content": "<p>Please try to reduce the number of features and reduce the RAM usage of data types before calling XGB fit/train method.</p>",
      "rawMarkdown": "Please try to reduce the number of features and reduce the RAM usage of data types before calling XGB fit/train method.",
      "votes": null
    },
    {
      "id": "672941",
      "postDate": "11/14/2019 10:10:23",
      "content": "<p>Thanks for the answers.</p>\n\n<p>I solved it by the following steps:\n1. I opened only needed dataframes and deleted them immediately after completing to use them. For example test.csv is a huge one and I don't need it until the end of training.\n2. I used <a href=\"https://www.kaggle.com/arjanso/reducing-dataframe-memory-size-by-65\">reducing-dataframe-memory-size-by-65</a> techniques. But be careful: it's filling Null values. So make sure to fill them according to** your** logic.\n3. Even after improvements, I wasn't able to run it on Kaggle, since it fails on out of memory without proper logs. I had to run it on my laptop.</p>",
      "rawMarkdown": "Thanks for the answers.\n\nI solved it by the following steps:\n1. I opened only needed dataframes and deleted them immediately after completing to use them. For example test.csv is a huge one and I don't need it until the end of training.\n2. I used [reducing-dataframe-memory-size-by-65](https://www.kaggle.com/arjanso/reducing-dataframe-memory-size-by-65) techniques. But be careful: it's filling Null values. So make sure to fill them according to** your** logic.\n3. Even after improvements, I wasn't able to run it on Kaggle, since it fails on out of memory without proper logs. I had to run it on my laptop.",
      "votes": null
    },
    {
      "id": "686404",
      "postDate": "12/03/2019 05:39:37",
      "content": "<p>I was also facing the same issue. \nYou can delete the variables which are not in use so that it can be deleted from RAM.\n - Like after you split your training data into train and validation you can delete you full training dataset to save your RAM memory. \n<code>del training</code></p>",
      "rawMarkdown": "I was also facing the same issue. \nYou can delete the variables which are not in use so that it can be deleted from RAM.\n - Like after you split your training data into train and validation you can delete you full training dataset to save your RAM memory. \n`del training`",
      "votes": null
    },
    {
      "id": "686456",
      "postDate": "12/03/2019 07:09:36",
      "content": "<p>First, i suggest to make etl pipeline and save train, test in pkl or hdf in another kernel.\nAfter that , load and fit and if you run out of memory again , you need to drop one or more column (ram used by xgboost depends highly on the number of column and row). Max number of columns to keep is 26/29 (i find it by some trial).\nTake in mind that xgboost leaks some memory during the fit so if you make cv or more model you need to optimize more.</p>",
      "rawMarkdown": "First, i suggest to make etl pipeline and save train, test in pkl or hdf in another kernel.\nAfter that , load and fit and if you run out of memory again , you need to drop one or more column (ram used by xgboost depends highly on the number of column and row). Max number of columns to keep is 26/29 (i find it by some trial).\nTake in mind that xgboost leaks some memory during the fit so if you make cv or more model you need to optimize more.",
      "votes": null
    },
    {
      "id": "688873",
      "postDate": "12/06/2019 07:37:24",
      "content": "<p>Hello! I've faced the same problem, but I could only choose to run on my laptop because I lack an GPU on my computer. Do you use CPU to run the program?\nBy the way, do you solve the problem now?</p>",
      "rawMarkdown": "Hello! I've faced the same problem, but I could only choose to run on my laptop because I lack an GPU on my computer. Do you use CPU to run the program?\nBy the way, do you solve the problem now?",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 672067,
      "author_name": "klloke",
      "author_url": "",
      "post_date": "11/13/2019 13:39:23",
      "content": "<p>Are you using GPU? I found using non GPU will have higher RAM available compared with GPU enabled. </p>",
      "votes": null,
      "replies": [
        {
          "id": 672182,
          "author_name": "benzion18",
          "author_url": "",
          "post_date": "11/13/2019 15:38:23",
          "content": "<p>I just tried CPU. Still fails. </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 672219,
          "author_name": "klloke",
          "author_url": "",
          "post_date": "11/13/2019 16:41:49",
          "content": "<p>Please try to reduce the number of features and reduce the RAM usage of data types before calling XGB fit/train method.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 672178,
      "author_name": "pcjimmmy",
      "author_url": "",
      "post_date": "11/13/2019 15:32:13",
      "content": "<p>If your running kernel on local PC you can change virtual memory size (Windows) or change swap file size (Linux).</p>",
      "votes": null,
      "replies": [
        {
          "id": 672192,
          "author_name": "benzion18",
          "author_url": "",
          "post_date": "11/13/2019 15:46:32",
          "content": "<p>No, I run Kaggle kernel.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 672211,
          "author_name": "pcjimmmy",
          "author_url": "",
          "post_date": "11/13/2019 16:24:19",
          "content": "<p>Ok - I can't be of much help since I seldom use Kaggle kernels - but several shared kernels have described methods to reduce memory size so if you have not used any of those methods to reduce the bytes size for each of your variables they would be worth incorporating into your kernel.  Probably any of the best scoring or high voted kernels will have a def for memory usage reduction.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 672941,
      "author_name": "benzion18",
      "author_url": "",
      "post_date": "11/14/2019 10:10:23",
      "content": "<p>Thanks for the answers.</p>\n\n<p>I solved it by the following steps:\n1. I opened only needed dataframes and deleted them immediately after completing to use them. For example test.csv is a huge one and I don't need it until the end of training.\n2. I used <a href=\"https://www.kaggle.com/arjanso/reducing-dataframe-memory-size-by-65\">reducing-dataframe-memory-size-by-65</a> techniques. But be careful: it's filling Null values. So make sure to fill them according to** your** logic.\n3. Even after improvements, I wasn't able to run it on Kaggle, since it fails on out of memory without proper logs. I had to run it on my laptop.</p>",
      "votes": null,
      "replies": [
        {
          "id": 686456,
          "author_name": "stenford23",
          "author_url": "",
          "post_date": "12/03/2019 07:09:36",
          "content": "<p>First, i suggest to make etl pipeline and save train, test in pkl or hdf in another kernel.\nAfter that , load and fit and if you run out of memory again , you need to drop one or more column (ram used by xgboost depends highly on the number of column and row). Max number of columns to keep is 26/29 (i find it by some trial).\nTake in mind that xgboost leaks some memory during the fit so if you make cv or more model you need to optimize more.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 688873,
          "author_name": "laurencelin",
          "author_url": "",
          "post_date": "12/06/2019 07:37:24",
          "content": "<p>Hello! I've faced the same problem, but I could only choose to run on my laptop because I lack an GPU on my computer. Do you use CPU to run the program?\nBy the way, do you solve the problem now?</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 686404,
      "author_name": "prateek0x",
      "author_url": "",
      "post_date": "12/03/2019 05:39:37",
      "content": "<p>I was also facing the same issue. \nYou can delete the variables which are not in use so that it can be deleted from RAM.\n - Like after you split your training data into train and validation you can delete you full training dataset to save your RAM memory. \n<code>del training</code></p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "671966": "Hi,\n\nI use XGBRegressor but when I run \"fit\" method with the whole train data, it fails on  out of memory. When I take only 1M of train records, it works fine. How can overcome this memory limit?",
    "672067": "Are you using GPU? I found using non GPU will have higher RAM available compared with GPU enabled.",
    "672178": "If your running kernel on local PC you can change virtual memory size (Windows) or change swap file size (Linux).",
    "672182": "I just tried CPU. Still fails.",
    "672192": "No, I run Kaggle kernel.",
    "672211": "Ok - I can't be of much help since I seldom use Kaggle kernels - but several shared kernels have described methods to reduce memory size so if you have not used any of those methods to reduce the bytes size for each of your variables they would be worth incorporating into your kernel.  Probably any of the best scoring or high voted kernels will have a def for memory usage reduction.",
    "672219": "Please try to reduce the number of features and reduce the RAM usage of data types before calling XGB fit/train method.",
    "672941": "Thanks for the answers.\n\nI solved it by the following steps:\n1. I opened only needed dataframes and deleted them immediately after completing to use them. For example test.csv is a huge one and I don't need it until the end of training.\n2. I used [reducing-dataframe-memory-size-by-65](https://www.kaggle.com/arjanso/reducing-dataframe-memory-size-by-65) techniques. But be careful: it's filling Null values. So make sure to fill them according to** your** logic.\n3. Even after improvements, I wasn't able to run it on Kaggle, since it fails on out of memory without proper logs. I had to run it on my laptop.",
    "686404": "I was also facing the same issue. \nYou can delete the variables which are not in use so that it can be deleted from RAM.\n - Like after you split your training data into train and validation you can delete you full training dataset to save your RAM memory. \n`del training`",
    "686456": "First, i suggest to make etl pipeline and save train, test in pkl or hdf in another kernel.\nAfter that , load and fit and if you run out of memory again , you need to drop one or more column (ram used by xgboost depends highly on the number of column and row). Max number of columns to keep is 26/29 (i find it by some trial).\nTake in mind that xgboost leaks some memory during the fit so if you make cv or more model you need to optimize more.",
    "688873": "Hello! I've faced the same problem, but I could only choose to run on my laptop because I lack an GPU on my computer. Do you use CPU to run the program?\nBy the way, do you solve the problem now?"
  },
  "source": "meta"
}