{
  "id": 134025,
  "title": "Can I use TPU on google colab to execute this code?",
  "url": "/competitions/flower-classification-with-tpus/discussion/134025",
  "author_name": "",
  "post_date": "2020-03-05T13:32:16.307447400Z",
  "votes": 9,
  "comment_count": 5,
  "views": 0,
  "content": "<p>There is also a TPU on Google Colab. Can I use the TPU on Google Colab to execute the entry code?</p>",
  "messages": [
    {
      "id": "764453",
      "postDate": "03/05/2020 13:32:16",
      "content": "<p>There is also a TPU on Google Colab. Can I use the TPU on Google Colab to execute the entry code?</p>",
      "rawMarkdown": "There is also a TPU on Google Colab. Can I use the TPU on Google Colab to execute the entry code?",
      "votes": null
    },
    {
      "id": "764482",
      "postDate": "03/05/2020 14:03:06",
      "content": "<p>Yes, but colab can't use <code>KaggleDatasets</code> library(maybe..), so you need to save the GCS path by yourself. <br>\nAs following:\n<br>\n<code>GCS_PATH = os.path.join('gs://kds-b2e6cdbc4af76dcf0363776c09c12fe46872cab211d1de9f60ec7aec', 'tfrecords-jpeg-512x512')</code>\n<code>Train_filenames = tf.io.gfile.glob(os.path.join(GCS_PATH, 'train/*.tfrec'))</code>\n<code>Valid_filenames = tf.io.gfile.glob(os.path.join(GCS_PATH, 'val/*.tfrec'))</code>\n<code>Test_filenames = tf.io.gfile.glob(os.path.join(GCS_PATH, 'test/*.tfrec'))</code>\n<br>\nAnd rest of the parts are pretty much the same.\nBut I noticed that TPU in colab seems has smaller memory size, since I need to reduce the batch_size in colab with exactly the same setting in kaggle.</p>",
      "rawMarkdown": "Yes, but colab can't use `KaggleDatasets` library(maybe..), so you need to save the GCS path by yourself.  \nAs following:\n<br>\n`GCS_PATH = os.path.join('gs://kds-b2e6cdbc4af76dcf0363776c09c12fe46872cab211d1de9f60ec7aec', 'tfrecords-jpeg-512x512')`\n`Train_filenames = tf.io.gfile.glob(os.path.join(GCS_PATH, 'train/*.tfrec'))`\n`Valid_filenames = tf.io.gfile.glob(os.path.join(GCS_PATH, 'val/*.tfrec'))`\n`Test_filenames = tf.io.gfile.glob(os.path.join(GCS_PATH, 'test/*.tfrec'))`\n<br>\nAnd rest of the parts are pretty much the same.\nBut I noticed that TPU in colab seems has smaller memory size, since I need to reduce the batch_size in colab with exactly the same setting in kaggle.",
      "votes": null
    },
    {
      "id": "764667",
      "postDate": "03/05/2020 17:55:57",
      "content": "<p>Yes, it should work fine with a couple of minor changes.</p>\n\n<p>1) As <a href=\"/xiejialun\">@xiejialun</a> said, you need to point to a GCS bucket with the data directly. The <code>KaggleDatasets</code> call is Kaggle specific.</p>\n\n<p>2) Colab also defaults to Tensorflow 1.x (for now) and you need to add the following \"magic\" call to switch it to Tensorflow 2.1:\n<code>\n%tensorflow_version 2.x\n</code></p>\n\n<p>3) The TPU offered on Colab is indeed a TPU v2 (again <a href=\"/xiejialun\">@xiejialun</a> got it right). Less powerful than the TPU v3 you get on Kaggle so yes please lower your batch size.</p>",
      "rawMarkdown": "Yes, it should work fine with a couple of minor changes.\n\n1) As @xiejialun said, you need to point to a GCS bucket with the data directly. The `KaggleDatasets` call is Kaggle specific.\n\n2) Colab also defaults to Tensorflow 1.x (for now) and you need to add the following \"magic\" call to switch it to Tensorflow 2.1:\n```\n%tensorflow_version 2.x\n```\n\n3) The TPU offered on Colab is indeed a TPU v2 (again @xiejialun got it right). Less powerful than the TPU v3 you get on Kaggle so yes please lower your batch size.",
      "votes": null
    },
    {
      "id": "766698",
      "postDate": "03/08/2020 15:21:58",
      "content": "<p>Is that GCS_PATH a valid google cloud storage link?</p>\n\n<p>Thanks for sharing your observations</p>",
      "rawMarkdown": "Is that GCS_PATH a valid google cloud storage link?\n\nThanks for sharing your observations",
      "votes": null
    },
    {
      "id": "766912",
      "postDate": "03/08/2020 23:47:25",
      "content": "<p>Seems to be, you can print the GCS_PATH from your kaggle kernel to check that, then use the print out GCS_PATH in your colab notebook.</p>",
      "rawMarkdown": "Seems to be, you can print the GCS_PATH from your kaggle kernel to check that, then use the print out GCS_PATH in your colab notebook.",
      "votes": null
    },
    {
      "id": "1093672",
      "postDate": "11/27/2020 22:47:58",
      "content": "<p>Is someone tried to use JAX with TPU on Kaggle? </p>",
      "rawMarkdown": "Is someone tried to use JAX with TPU on Kaggle?",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1093672,
      "author_name": "yurilla",
      "author_url": "",
      "post_date": "11/27/2020 22:47:58",
      "content": "<p>Is someone tried to use JAX with TPU on Kaggle? </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 764482,
      "author_name": "xiejialun",
      "author_url": "",
      "post_date": "03/05/2020 14:03:06",
      "content": "<p>Yes, but colab can't use <code>KaggleDatasets</code> library(maybe..), so you need to save the GCS path by yourself. <br>\nAs following:\n<br>\n<code>GCS_PATH = os.path.join('gs://kds-b2e6cdbc4af76dcf0363776c09c12fe46872cab211d1de9f60ec7aec', 'tfrecords-jpeg-512x512')</code>\n<code>Train_filenames = tf.io.gfile.glob(os.path.join(GCS_PATH, 'train/*.tfrec'))</code>\n<code>Valid_filenames = tf.io.gfile.glob(os.path.join(GCS_PATH, 'val/*.tfrec'))</code>\n<code>Test_filenames = tf.io.gfile.glob(os.path.join(GCS_PATH, 'test/*.tfrec'))</code>\n<br>\nAnd rest of the parts are pretty much the same.\nBut I noticed that TPU in colab seems has smaller memory size, since I need to reduce the batch_size in colab with exactly the same setting in kaggle.</p>",
      "votes": null,
      "replies": [
        {
          "id": 766698,
          "author_name": "kurianbenoy",
          "author_url": "",
          "post_date": "03/08/2020 15:21:58",
          "content": "<p>Is that GCS_PATH a valid google cloud storage link?</p>\n\n<p>Thanks for sharing your observations</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 766912,
          "author_name": "xiejialun",
          "author_url": "",
          "post_date": "03/08/2020 23:47:25",
          "content": "<p>Seems to be, you can print the GCS_PATH from your kaggle kernel to check that, then use the print out GCS_PATH in your colab notebook.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 764667,
      "author_name": "mgorner",
      "author_url": "",
      "post_date": "03/05/2020 17:55:57",
      "content": "<p>Yes, it should work fine with a couple of minor changes.</p>\n\n<p>1) As <a href=\"/xiejialun\">@xiejialun</a> said, you need to point to a GCS bucket with the data directly. The <code>KaggleDatasets</code> call is Kaggle specific.</p>\n\n<p>2) Colab also defaults to Tensorflow 1.x (for now) and you need to add the following \"magic\" call to switch it to Tensorflow 2.1:\n<code>\n%tensorflow_version 2.x\n</code></p>\n\n<p>3) The TPU offered on Colab is indeed a TPU v2 (again <a href=\"/xiejialun\">@xiejialun</a> got it right). Less powerful than the TPU v3 you get on Kaggle so yes please lower your batch size.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "764453": "There is also a TPU on Google Colab. Can I use the TPU on Google Colab to execute the entry code?",
    "764482": "Yes, but colab can't use `KaggleDatasets` library(maybe..), so you need to save the GCS path by yourself.  \nAs following:\n<br>\n`GCS_PATH = os.path.join('gs://kds-b2e6cdbc4af76dcf0363776c09c12fe46872cab211d1de9f60ec7aec', 'tfrecords-jpeg-512x512')`\n`Train_filenames = tf.io.gfile.glob(os.path.join(GCS_PATH, 'train/*.tfrec'))`\n`Valid_filenames = tf.io.gfile.glob(os.path.join(GCS_PATH, 'val/*.tfrec'))`\n`Test_filenames = tf.io.gfile.glob(os.path.join(GCS_PATH, 'test/*.tfrec'))`\n<br>\nAnd rest of the parts are pretty much the same.\nBut I noticed that TPU in colab seems has smaller memory size, since I need to reduce the batch_size in colab with exactly the same setting in kaggle.",
    "764667": "Yes, it should work fine with a couple of minor changes.\n\n1) As @xiejialun said, you need to point to a GCS bucket with the data directly. The `KaggleDatasets` call is Kaggle specific.\n\n2) Colab also defaults to Tensorflow 1.x (for now) and you need to add the following \"magic\" call to switch it to Tensorflow 2.1:\n```\n%tensorflow_version 2.x\n```\n\n3) The TPU offered on Colab is indeed a TPU v2 (again @xiejialun got it right). Less powerful than the TPU v3 you get on Kaggle so yes please lower your batch size.",
    "766698": "Is that GCS_PATH a valid google cloud storage link?\n\nThanks for sharing your observations",
    "766912": "Seems to be, you can print the GCS_PATH from your kaggle kernel to check that, then use the print out GCS_PATH in your colab notebook.",
    "1093672": "Is someone tried to use JAX with TPU on Kaggle?"
  },
  "source": "meta"
}