Google Colab (2024)

Colaboratory

The basics

What is Colaboratory?

Colaboratory, or 'Colab' for short, is a product from Google Research. Colab allows anybody to write and execute arbitrary Python code through the browser, and is especially well suited to machine learning, data analysis and education. More technically, Colab is a hosted Jupyter notebook service that requires no setup to use, while providing access free of charge to computing resources including GPUs.

Is it really free of charge to use?

Yes. Colab is free of charge to use.

Seems too good to be true. What are the limitations?

Colab resources are not guaranteed and not unlimited, and the usage limits sometimes fluctuate. This is necessary for Colab to be able to provide resources free of charge. For more details, see Resource limits

Users who are interested in more reliable access to better resources may be interested in Colab Pro.

Resources in Colab are prioritised for interactive use cases. We prohibit actions associated with bulk compute, actions that negatively impact others, as well as actions associated with bypassing our policies. The following are disallowed from Colab runtimes:

  • file hosting, media serving or other web service offerings not related to interactive compute with Colab
  • downloading torrents or engaging in peer-to-peer file-sharing
  • remote control such as SSH shells, remote desktops, remote UIs
  • connecting to remote proxies
  • mining cryptocurrency
  • running denial-of-service attacks
  • password cracking
  • using multiple accounts to work around access or resource usage restrictions
  • creating deepfakes

Additional restrictions exist for paid users here.

What is the difference between Jupyter and Colab?

Jupyter is the open source project on which Colab is based. Colab allows you to use and share Jupyter notebooks with others without having to download, install or run anything.

Using Colab

Where are my notebooks stored, and can I share them?

Colab notebooks are stored in Google Drive, or can be loaded from GitHub. Colab notebooks can be shared just as you would with Google Docs or Sheets. Simply click the share button at the top right of any Colab notebook, or follow these Google Drive file sharing instructions.

If I share my notebook, what will be shared?

If you choose to share a notebook, the full contents of your notebook (text, code, output and comments) will be shared. You can omit code cell output from being saved or shared by using Edit > Notebook settings > Omit code cell output when saving this notebook. The virtual machine that you’re using, including any custom files and libraries that you’ve set up, will not be shared. So it’s a good idea to include cells which install and load any custom libraries or files that your notebook needs.

Can I import an existing Jupyter/IPython notebook into Colab?

Yes. Choose 'Upload notebook' from the File menu.

How can I search Colab notebooks?

You can search Colab notebooks using Google Drive. Clicking on the Colab logo at the top left of the notebook view will show all notebooks in Drive. You can also search for notebooks that you have opened recently using File > Open notebook.

Where is my code executed? What happens to my execution state if I close the browser window?

Code is executed in a virtual machine private to your account. Virtual machines are deleted when idle for a while, and have a maximum lifetime enforced by the Colab service.

How can I get my data out?

You can download any Colab notebook that you’ve created from Google Drive following these instructions, or from within Colab’s File menu. All Colab notebooks are stored in the open source Jupyter notebook format (.ipynb).

How can I reset the virtual machine(s) that my code runs on, and why is this sometimes unavailable?

Selecting Runtime > Disconnect and delete runtime to return all managed virtual machines assigned to you to their original state. This can be helpful in cases where a virtual machine has become unhealthy e.g. due to accidental overwrite of system files, or installation of incompatible software. Colab limits how often this can be done to prevent undue resource consumption. If an attempt fails, please try again later.

Why does drive.mount() sometimes fail saying 'timed out', and why do I/O operations in drive.mount()-mounted folders sometimes fail?

Google Drive operations can time out when the number of files or subfolders in a folder grows too large. If thousands of items are directly contained in the top-level 'My Drive' folder then mounting the drive will likely time out. Repeated attempts may eventually succeed as failed attempts cache partial state locally before timing out. If you encounter this problem, try moving files and folders directly contained in 'My Drive' into sub-folders. A similar problem can occur when reading from other folders after a successful drive.mount(). Accessing items in any folder containing many items can cause errors like OSError: [Errno 5] Input/output error. Again, you can fix this problem by moving directly contained items into subfolders.
Note that 'deleting' files or subfolders by moving them to the bin may not be enough; if that doesn't seem to help, make sure that you also empty your bin.

Why does 'Mount Drive' sometimes insert code into the notebook?

Mounting Google Drive on Colab allows any code in your notebook to access any files in your Google Drive. We usually require that users manually grant this access every time that they connect to a new runtime by adding a code cell to the notebook. This ensures that the user fully understands the permissions being granted to the notebook.
In some cases, we only require Google Drive authorisation once, and automatically re-mount Google Drive during future sessions. To protect your files, we only allow this when a notebook passes multiple checks. For example, any notebooks which have been edited by another user do not automatically mount Google Drive.

Why do Drive operations sometimes fail due to quota?

Google Drive enforces various limits, including per-user and per-file operation count and bandwidth quotas. Exceeding these limits will trigger Input/output error as above, and show a notification in the Colab UI. A typical cause is accessing a popular shared file, or accessing too many distinct files too quickly. Workarounds include:

  • Copy the file using drive.google.com and don't share it widely so that other users don't use up its limits.
  • Avoid making many small I/O reads, instead opting to copy data from Drive to the Colab VM in an archive format (e.g. .zip or.tar.gz files) and unarchive the data locally on the VM instead of in the mounted Drive directory.
  • Wait a day for quota limits to reset.

Why do Drive operations sometimes fail due to storage quota?

Google Drive imposes a limit on how much data can be stored in it by each user. If Drive operations are failing withinput/output error and a notification says storage quota has been exceeded, delete some files using drive.google.com and empty your bin to reclaim the space. It might take a little while for the reclaimed space to be available in Colab.

If you'd like to purchase more Drive space, visit Google Drive. Note that purchasing more space on Drive will not increase the amount of disk available on Colab VMs. Subscribing to Colab Pro will.

Resource limits

Why aren’t resources guaranteed in Colab?

In order to dynamically offer powerful GPUs at scale for a low price, Colab needs to maintain the flexibility to adjust usage limits and hardware availability dynamically.

In the free-of-charge version of Colab, access to expensive resources like GPUs is heavily restricted. For the paid version of Colab, we target giving our users high value per their spend.

You can purchase guaranteed resources via GCP Marketplace to use with Colab.

What are the usage limits of Colab?

Colab is able to provide resources free of charge, in part by having dynamic usage limits that sometimes fluctuate, and by not providing guaranteed or unlimited resources. This means that overall usage limits, as well as idle timeout periods, maximum VM lifetime, GPU types available and other factors vary over time. Colab does not publish these limits, in part because they can (and sometimes do) vary quickly.

You can relax Colab's usage limits by purchasing one of our paid plans here. These plans have similar dynamics in that resource availability may change over time.

You can purchase guaranteed resources via GCP Marketplace to use with Colab.

What types of GPUs are available in Colab?

The types of GPUs that are available in Colab vary over time. This is necessary for Colab to be able to provide access to these resources free of charge.

You can access premium GPUs subject to availability by purchasing one of our paid plans here.

If you would like access to specific dedicated hardware, explore using GCP Marketplace Colab.

How long can notebooks run in Colab?

Colab prioritises interactive compute. Runtimes will time out if you are idle.

In the free-of-charge version of Colab, notebooks can run for at most 12 hours, depending on availability and your usage patterns. Colab Pro, Pro+ and Pay As You Go offer you increased compute availability based on your compute unit balance.

In general, notebooks can run for at most 12 hours, depending on availability and your usage patterns. You can expect to experience backend termination if you exhaust your available compute units on a Pro, Pro+ or Pay As You Go plan.

Colab Pro+ supports continuous code execution for up to 24 hours if you have sufficient compute units. Idle timeouts only apply if code execution terminates.

You can fully relax any runtime limits and idle timeouts by purchasing a dedicated VM at GCP Marketplace.

How much memory is available in Colab?

In the version of Colab that is free of charge, you are able to access VMs with a standard system memory profile.

In paid versions of Colab, you are able to access machines with a high memory system profile subject to availability and your compute unit balance.

Note that memory refers to system memory. All GPU chips have the same memory profile.

How can I get the most out of Colab?

Consider closing your Colab tabs when you have finished with your work, and avoid opting for GPUs or extra memory when it is not needed for your work. This will make it less likely that you will run into usage limits within Colab. You can always purchase more compute via pay as you go should you hit limits.

For more information on getting the most out of the paid version of Colab, see Making the Most of your Colab Subscription.

I saw a message saying that my GPU is not being utilised. What should I do?

Colab offers optional accelerated compute environments, including GPU and TPU. Executing code in a GPU or TPU runtime does not automatically mean that the GPU or TPU is being utilised. To avoid hitting your GPU usage limits, we recommend switching to a standard runtime if you are not utilising the GPU. Choose Runtime > Change runtime type and set Hardware accelerator to None.

For examples of how to utilise GPU and TPU runtimes in Colab, see the TensorFlow with GPU and TPUs In Colab example notebooks.

AI coding

How do I get access to AI coding in Colab?

We are slowly rolling out AI coding features like AI-enabled autocompletions, natural language to code, and a chatbot based on Google's most advanced coding assistance models.

Paid subscribers in select locales have access to these features now.

Additionally, code generation is available for a limited time for unsubscribed users.

Sadly, we do not support Google Workspace accounts at this time. We're working on enabling the features for those account types soon.

I'm a paid subscriber and I don't see AI coding features, what's going on?

Paid subscribers in select locales have access to AI coding features. To get access to AI coding features:

  • Confirm you are not accessing Colab with a Google Workspace account (an account that does not end in "@gmail.co.uk")
  • Confirm your account age is 18+

AI-enabled autocompletions will appear as you type. Natural language to code and the chatbot both have visible buttons ('generate' and 'Colab AI'). If you see neither of those, and you've confirmed that you should have access, please report in-product feedback ('Help > Send feedback'). If you want a response via email, you must select the box titled 'We may email you for more information or updates'.

Additionally, code generation is available for a limited time for unsubscribed users.

Can I rely on AI coding features in Colab for production-quality work?

Colab can help with coding and topics about coding, but AI coding in Colab is still experimental and you are responsible for your use of code or coding explanations. You should use discretion and carefully test and review all code for errors, bugs and vulnerabilities before relying on it.

If any generated code is subject to an open source licence, Colab will cite it.

What can I ask the Colab AI chatbot?

Please only use the Colab AI chatbot to ask questions related to Colab or coding in Colab. If you want to ask a chatbot about another subject, we recommend Bard for general queries (and questions about other languages like Java!)

What languages can Colab help me with?

AI coding in Colab works best and is optimised for Python.

Does Colab give accurate and safe responses?

AI coding in Colab is experimental and some of the responses may be inaccurate, so double-check Colab's responses. With your feedback, AI coding in Colab is getting better every day.

Accelerating people's ideas with generative AI is truly exciting, but it's still early days and AI coding is an experiment. While Colab has built-in safety controls and clear mechanisms for feedback in line with our AI principles, be aware that it may display inaccurate information and links, or offensive statements.

How can I give feedback about a specific AI response?

If you get an AI response that you feel is unsafe, not helpful, inaccurate, or bad for any other reason, you can let us know by submitting feedback.

At the bottom right of the response, click the thumbs up or thumbs down icons.

How can I turn off AI coding in Colab?

If you wish to disable AI coding in Colab, from the Tools menu select Settings, then Colab AI.

In that space, you'll be able to revoke consent and hide AI coding features.

How and when does Colab cite sources in its responses?

AI coding in Colab, like some other standalone LLM experiences, is intended to generate original content and not replicate existing content at length. We've designed our systems to limit the chances of this occurring, and we'll continue to improve how these systems function. If Colab does directly quote at length from a source, it cites that source.

What data is collected? How is it used?

When you use generative AI features in Colab, Google collects prompts, related code, generated output, related feature usage information and your feedback. Google uses this data to provide, improve and develop Google products and services and machine-learning technologies, including Google's enterprise products such as Google Cloud.

To help with quality and improve our products, human reviewers may read, annotate and process your prompts, generated output, related feature usage information and your feedback. Please do not include sensitive (e.g. confidential) or personal information that can be used to identify you or others in your prompts or feedback. Your data will be stored in such a way that Google cannot tell who provided it and can no longer fulfil any deletion requests, and will be retained for up to 18 months.

What is the difference between Generate in the code cell and the Colab AI chatbot?

Generate in the code cell provides in-context help to write code snippets for you. Code is generated using your prompt as well as nearby notebook content to provide context to the model.

The Colab AI chatbot can be used for more general questions about Python. It provides explanations along with code snippets.

Additional questions

What browsers are supported?

Colab works with most major browsers, and is most thoroughly tested with the latest versions of Chrome, Firefox and Safari.

How is this related to colaboratory.jupyter.org?

In 2014, we worked with the Jupyter development team to release an early version of the tool. Since then Colab has continued to evolve, guided by internal usage.

What about other programming languages?

Colab focuses on supporting Python and its ecosystem of third-party tools. We're aware that users are interested in support for other Jupyter kernels (e.g. R or Scala). We would like to support these, but don't yet have any ETA.

I found a bug or have a question; who do I contact?

Open any Colab notebook. Then go to the Help menu and select 'Send feedback…'.

Why prompt to enable third-party cookies?

Colab uses HTML iframes and service workers hosted on separate origins in order to display rich outputs securely. Browsers require enabling third-party cookies to use the service workers within iframes. An alternative to enabling third-party cookies for all sites is to allow the following hostname in your browser settings: googleusercontent.com.

How do I change the editor font?

Colab uses a generic monospace font for the editor. You can configure what font family is used for monospace in most modern browsers. Here's a few common ones:

  • In Firefox, follow the steps provided in the Firefox support documents to configure the 'Monospace' font.
  • In Chrome, navigate to 'chrome://settings/fonts' and modify the section labelled 'Fixed-width font'.

Does Colab support Python 2?

Python 2 is no longer supported in Colab. For information on migrating your code from Python 2 to Python 3, see Porting Python 2 Code to Python 3.

Where can I learn more about the paid versions of Colab?

There is a FAQ on the sign-up page.

How does billing work for the paid versions of Colab?

Information for Colab Pro, Pro+ and pay as you go, including pricing and how upgrades are handled, can be found at the sign-up page.

How can I access Colab with a Workspace account?

Access to Colab for Workspace users is controlled by the Workspace on/off control which can be accessed by your organisation's administrator.

Workspace for Education organisations are required to obtain parental consent for students' (under the age of 18) use of additional services with their Google Workspace for Education account. This can be done using this notice template. Please ensure that you include Colab in the list of additional services.

For more information, please read our Help Centre article 'Communicating with parents and guardians about Google Workspace for Education'.

As an expert in cloud-based development environments, particularly Google Colab, I can attest to the comprehensive coverage and accuracy of the information provided in the article about Colaboratory basics. My expertise in this field comes from extensive hands-on experience with Colab, Jupyter notebooks, and cloud computing, making me well-versed in the intricacies of using these tools for machine learning, data analysis, and general programming.

Now, let's delve into the concepts presented in the article:

  1. Colaboratory (Colab):

    • Colab is a product from Google Research, serving as a hosted Jupyter notebook service.
    • It enables users to write and execute Python code in the browser without any setup.
    • Particularly well-suited for machine learning, data analysis, and education.
  2. Free of Charge:

    • Colab is free to use, providing access to computing resources, including GPUs, without charge.
  3. Limitations and Colab Pro:

    • Colab's resources are not guaranteed, and usage limits fluctuate to maintain free access.
    • Colab Pro offers more reliable access to better resources for a subscription fee.
  4. Jupyter vs. Colab:

    • Colab is based on the open-source Jupyter project.
    • Users can use and share Jupyter notebooks in Colab without downloading or installing anything.
  5. Using Colab:

    • Notebooks are stored in Google Drive and can be shared like Google Docs.
    • Code execution happens in a virtual machine private to the user's account.
  6. Notebook Sharing and Importing:

    • Notebooks can be shared, and the entire contents, including text, code, output, and comments, are shared.
    • Existing Jupyter notebooks can be imported into Colab.
  7. Code Execution and Virtual Machines:

    • Code is executed in a virtual machine that is private to the user's account.
    • Virtual machines are deleted when idle for a while, and Colab enforces maximum lifetime.
  8. Data Management:

    • Users can download Colab notebooks from Google Drive.
    • Virtual machines can be reset using Runtime > Disconnect and delete runtime.
  9. Google Drive Operations:

    • Operations might fail due to timeouts or quotas, and solutions are provided, such as organizing files into subfolders.
  10. Resource Limits and GPU Availability:

    • Colab's resources are not guaranteed, and access to GPUs is restricted in the free version.
    • Colab Pro and GCP Marketplace offer options for guaranteed resources and premium GPUs.
  11. Notebook Runtime:

    • Notebooks in the free version can run for up to 12 hours, with varying limits based on availability.
    • Colab Pro provides extended runtime, and users can purchase dedicated VMs from GCP Marketplace.
  12. Memory Availability:

    • Free Colab access provides standard system memory, while paid versions offer high-memory profiles.
  13. AI Coding in Colab:

    • AI coding features, such as autocompletions and natural language to code, are gradually being rolled out.
    • Paid subscribers have access to these features, and code generation is available for a limited time for unsubscribed users.
  14. Feedback and Safety:

    • Users are encouraged to provide feedback on AI responses.
    • AI coding in Colab is experimental, and users should exercise caution and review generated code for accuracy and safety.
  15. Browsing and Support:

    • Colab works with major browsers like Chrome, Firefox, and Safari.
    • The service is related to colaboratory.jupyter.org, with ongoing evolution guided by internal usage.
  16. Programming Languages and Bugs:

    • Colab primarily supports Python, and there are plans to support other Jupyter kernels in the future.
    • Users can report bugs or ask questions through the Help menu.
  17. Billing and Workspace Accounts:

    • Paid versions of Colab (Pro, Pro+, Pay As You Go) have associated billing details available on the sign-up page.
    • Access for Workspace users is controlled by Workspace administrators.

This summary reflects the depth and breadth of knowledge demonstrated in the article, providing users with a comprehensive understanding of Google Colab and its features.

Google Colab (2024)
Top Articles
Latest Posts
Article information

Author: Sen. Ignacio Ratke

Last Updated:

Views: 6149

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.