{
  "id": 481682,
  "title": "training transformers  with TPU ",
  "url": "/competitions/tpu-getting-started/discussion/481682",
  "author_name": "Ziad Ayman",
  "post_date": "2024-03-04T16:25:25.818000",
  "votes": 9,
  "comment_count": 5,
  "views": null,
  "content": "<p>I couldn't find a better place to ask this than here where almost everyone already tried working with TPUs .<br>\nI just started trying out Kaggle's TPU since my training phase is taking more then kaggle's runtime limit which is 12 hours ( working on training a T5 transformer for generative question answering ) so i decided to try kaggle's TPU.<br>\nbut right away i faced a problem with the imports , they don't produce any errors but they take about 3 minutes to finish running  and at the end they just don't get imported . </p>\n<p>snippet : <br>\n!pip install --upgrade pip<br>\n!pip install --upgrade Pyarrow  <br>\n!pip install --upgrade ipywidgets <br>\n!pip install --upgrade wordcloud<br>\n!pip install --upgrade seaborn</p>\n<p>import torch<br>\nimport numpy as np <br>\nimport pandas as pd <br>\nimport matplotlib.pyplot as plt<br>\nimport seaborn as sns<br>\nfrom wordcloud import WordCloud<br>\nimport tensorflow as tf<br>\nfrom sklearn.model_selection import train_test_split<br>\nfrom torch.utils.data import Dataset, DataLoader<br>\nfrom transformers import AdamW , T5Tokenizer ,  T5ForConditionalGeneration<br>\nfrom kaggle_datasets import KaggleDatasets </p>\n<p>GCS_DS_PATH = KaggleDatasets().get_gcs_path()</p>\n<p>Note : Below is a couple of attached images Post running . <br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F12970798%2F679ea956f3775407527fd3f28968f745%2Fimage_2024-03-04_182049506.png?generation=1709569248214230&amp;alt=media\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F12970798%2F7ec3879b7a2ddb9458024bbe24a7dc22%2Fimage_2024-03-04_182628515.png?generation=1709569587285763&amp;alt=media\"></p>\n<p>even the other cells they look like they finished running but nothing happens , no outputs , and sometimes no errors  just nothing .</p>\n<p>i tried restarting and factory reset .<br>\neverything works fine when i use any other accelerator , even with no accelerators .</p>",
  "messages": [
    {
      "id": 2681418,
      "postDate": "2024-03-04T16:25:25.817Z",
      "content": "<p>I couldn't find a better place to ask this than here where almost everyone already tried working with TPUs .<br>\nI just started trying out Kaggle's TPU since my training phase is taking more then kaggle's runtime limit which is 12 hours ( working on training a T5 transformer for generative question answering ) so i decided to try kaggle's TPU.<br>\nbut right away i faced a problem with the imports , they don't produce any errors but they take about 3 minutes to finish running  and at the end they just don't get imported . </p>\n<p>snippet : <br>\n!pip install --upgrade pip<br>\n!pip install --upgrade Pyarrow  <br>\n!pip install --upgrade ipywidgets <br>\n!pip install --upgrade wordcloud<br>\n!pip install --upgrade seaborn</p>\n<p>import torch<br>\nimport numpy as np <br>\nimport pandas as pd <br>\nimport matplotlib.pyplot as plt<br>\nimport seaborn as sns<br>\nfrom wordcloud import WordCloud<br>\nimport tensorflow as tf<br>\nfrom sklearn.model_selection import train_test_split<br>\nfrom torch.utils.data import Dataset, DataLoader<br>\nfrom transformers import AdamW , T5Tokenizer ,  T5ForConditionalGeneration<br>\nfrom kaggle_datasets import KaggleDatasets </p>\n<p>GCS_DS_PATH = KaggleDatasets().get_gcs_path()</p>\n<p>Note : Below is a couple of attached images Post running . <br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F12970798%2F679ea956f3775407527fd3f28968f745%2Fimage_2024-03-04_182049506.png?generation=1709569248214230&amp;alt=media\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F12970798%2F7ec3879b7a2ddb9458024bbe24a7dc22%2Fimage_2024-03-04_182628515.png?generation=1709569587285763&amp;alt=media\"></p>\n<p>even the other cells they look like they finished running but nothing happens , no outputs , and sometimes no errors  just nothing .</p>\n<p>i tried restarting and factory reset .<br>\neverything works fine when i use any other accelerator , even with no accelerators .</p>",
      "rawMarkdown": "I couldn't find a better place to ask this than here where almost everyone already tried working with TPUs .\nI just started trying out Kaggle's TPU since my training phase is taking more then kaggle's runtime limit which is 12 hours ( working on training a T5 transformer for generative question answering ) so i decided to try kaggle's TPU.\nbut right away i faced a problem with the imports , they don't produce any errors but they take about 3 minutes to finish running  and at the end they just don't get imported . \n\nsnippet : \n!pip install --upgrade pip\n!pip install --upgrade Pyarrow  \n!pip install --upgrade ipywidgets \n!pip install --upgrade wordcloud\n!pip install --upgrade seaborn\n\nimport torch\nimport numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom wordcloud import WordCloud\nimport tensorflow as tf\nfrom sklearn.model_selection import train_test_split\nfrom torch.utils.data import Dataset, DataLoader\nfrom transformers import AdamW , T5Tokenizer ,  T5ForConditionalGeneration\nfrom kaggle_datasets import KaggleDatasets \n\nGCS_DS_PATH = KaggleDatasets().get_gcs_path()\n\n\nNote : Below is a couple of attached images Post running . \n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F12970798%2F679ea956f3775407527fd3f28968f745%2Fimage_2024-03-04_182049506.png?generation=1709569248214230&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F12970798%2F7ec3879b7a2ddb9458024bbe24a7dc22%2Fimage_2024-03-04_182628515.png?generation=1709569587285763&alt=media)\n\neven the other cells they look like they finished running but nothing happens , no outputs , and sometimes no errors  just nothing .\n\ni tried restarting and factory reset .\neverything works fine when i use any other accelerator , even with no accelerators .",
      "votes": 9
    },
    {
      "id": 2681448,
      "postDate": "2024-03-04T16:45:04.813Z",
      "content": "<p>I think i solved it , upgrading all packages seems to do the trick . specifically tensorflow</p>",
      "rawMarkdown": "I think i solved it , upgrading all packages seems to do the trick . specifically tensorflow",
      "votes": 1,
      "replies": [
        {
          "id": 2681703,
          "postDate": "2024-03-04T20:00:09.280Z",
          "content": "<p><a href=\"https://www.kaggle.com/ziadaymantesla\" target=\"_blank\">@ziadaymantesla</a> ,I have similar problems with TPU. Constant errors even at the tensorflow import stage.</p>",
          "rawMarkdown": "@ziadaymantesla ,I have similar problems with TPU. Constant errors even at the tensorflow import stage.",
          "votes": 1,
          "replies": [
            {
              "id": 2681884,
              "postDate": "2024-03-05T00:24:05.503Z",
              "content": "<p><a href=\"https://www.kaggle.com/bratkovskyevgeny\" target=\"_blank\">@bratkovskyevgeny</a> i guess it's merely because of the TPU's environment they require special setup and modifications , even with the data it's better to load it using ( GCS_DS_PATH = KaggleDatasets().get_gcs_path() ) so that it's closer to where the TPUs are  if that makes sense .<br>\nI found both of those tutorial and post helpful maybe you would too : <br>\n<a href=\"https://youtu.be/1pdwRQ1DQfY\" target=\"_blank\">https://youtu.be/1pdwRQ1DQfY</a><br>\n<a href=\"https://www.kaggle.com/docs/tpu\" target=\"_blank\">https://www.kaggle.com/docs/tpu</a> </p>",
              "rawMarkdown": "@bratkovskyevgeny i guess it's merely because of the TPU's environment they require special setup and modifications , even with the data it's better to load it using ( GCS_DS_PATH = KaggleDatasets().get_gcs_path() ) so that it's closer to where the TPUs are  if that makes sense .\nI found both of those tutorial and post helpful maybe you would too : \nhttps://youtu.be/1pdwRQ1DQfY\nhttps://www.kaggle.com/docs/tpu ",
              "votes": 4
            },
            {
              "id": 2682229,
              "postDate": "2024-03-05T07:11:05.683Z",
              "content": "<p>Thanks a lot for links! </p>",
              "rawMarkdown": "Thanks a lot for links! ",
              "votes": 1
            }
          ]
        }
      ]
    },
    {
      "id": 2681428,
      "postDate": "2024-03-04T16:29:40.993Z",
      "content": "<p>I think maybe  it might have something to do with the virtual environment not being correctly set , but i am still finding out if that's the case and how to resolve it </p>",
      "rawMarkdown": "I think maybe  it might have something to do with the virtual environment not being correctly set , but i am still finding out if that's the case and how to resolve it ",
      "votes": 1
    }
  ],
  "comments": [
    {
      "id": 2681448,
      "author_name": "Ziad Ayman",
      "author_url": "",
      "post_date": "2024-03-04T16:45:04.813000",
      "content": "<p>I think i solved it , upgrading all packages seems to do the trick . specifically tensorflow</p>",
      "votes": 1,
      "replies": [
        {
          "id": 2681703,
          "author_name": "Evgeny Bratkovsky",
          "author_url": "",
          "post_date": "2024-03-04T20:00:09.280000",
          "content": "<p><a href=\"https://www.kaggle.com/ziadaymantesla\" target=\"_blank\">@ziadaymantesla</a> ,I have similar problems with TPU. Constant errors even at the tensorflow import stage.</p>",
          "votes": 1,
          "replies": [
            {
              "id": 2681884,
              "author_name": "Ziad Ayman",
              "author_url": "",
              "post_date": "2024-03-05T00:24:05.503000",
              "content": "<p><a href=\"https://www.kaggle.com/bratkovskyevgeny\" target=\"_blank\">@bratkovskyevgeny</a> i guess it's merely because of the TPU's environment they require special setup and modifications , even with the data it's better to load it using ( GCS_DS_PATH = KaggleDatasets().get_gcs_path() ) so that it's closer to where the TPUs are  if that makes sense .<br>\nI found both of those tutorial and post helpful maybe you would too : <br>\n<a href=\"https://youtu.be/1pdwRQ1DQfY\" target=\"_blank\">https://youtu.be/1pdwRQ1DQfY</a><br>\n<a href=\"https://www.kaggle.com/docs/tpu\" target=\"_blank\">https://www.kaggle.com/docs/tpu</a> </p>",
              "votes": 4,
              "replies": []
            },
            {
              "id": 2682229,
              "author_name": "Evgeny Bratkovsky",
              "author_url": "",
              "post_date": "2024-03-05T07:11:05.683000",
              "content": "<p>Thanks a lot for links! </p>",
              "votes": 1,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2681428,
      "author_name": "Ziad Ayman",
      "author_url": "",
      "post_date": "2024-03-04T16:29:40.993000",
      "content": "<p>I think maybe  it might have something to do with the virtual environment not being correctly set , but i am still finding out if that's the case and how to resolve it </p>",
      "votes": 1,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2681418": "I couldn't find a better place to ask this than here where almost everyone already tried working with TPUs .\nI just started trying out Kaggle's TPU since my training phase is taking more then kaggle's runtime limit which is 12 hours ( working on training a T5 transformer for generative question answering ) so i decided to try kaggle's TPU.\nbut right away i faced a problem with the imports , they don't produce any errors but they take about 3 minutes to finish running  and at the end they just don't get imported . \n\nsnippet : \n!pip install --upgrade pip\n!pip install --upgrade Pyarrow  \n!pip install --upgrade ipywidgets \n!pip install --upgrade wordcloud\n!pip install --upgrade seaborn\n\nimport torch\nimport numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom wordcloud import WordCloud\nimport tensorflow as tf\nfrom sklearn.model_selection import train_test_split\nfrom torch.utils.data import Dataset, DataLoader\nfrom transformers import AdamW , T5Tokenizer ,  T5ForConditionalGeneration\nfrom kaggle_datasets import KaggleDatasets \n\nGCS_DS_PATH = KaggleDatasets().get_gcs_path()\n\n\nNote : Below is a couple of attached images Post running . \n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F12970798%2F679ea956f3775407527fd3f28968f745%2Fimage_2024-03-04_182049506.png?generation=1709569248214230&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F12970798%2F7ec3879b7a2ddb9458024bbe24a7dc22%2Fimage_2024-03-04_182628515.png?generation=1709569587285763&alt=media)\n\neven the other cells they look like they finished running but nothing happens , no outputs , and sometimes no errors  just nothing .\n\ni tried restarting and factory reset .\neverything works fine when i use any other accelerator , even with no accelerators .",
    "2681448": "I think i solved it , upgrading all packages seems to do the trick . specifically tensorflow",
    "2681428": "I think maybe  it might have something to do with the virtual environment not being correctly set , but i am still finding out if that's the case and how to resolve it "
  }
}