A step-by-step tutorial

Created by using Pixlr

In the field of Artificial Intelligence, large language models (LLMs) are transforming the landscape of what machines can achieve. These sophisticated models excel at tasks like summarising text, generating human-like content, translating languages, and answering complex questions. However, the computational resources required to run such models can be prohibitive for many individuals and small teams. Let’s enter the world of Google Colab. Colab is a Python platform by Google. It provides a game-changing solution by offering a free cloud-based environment that supports Python code execution. This allows you to leverage powerful hardware, including GPUs, without the financial burden of expensive infrastructure. We can run the LLM models on the free version of Google Colab using their free T4 GPU. Here’s how you can utilise Google Colab to run LLMs effectively.

1. Introduction to Google Colab

Google Colab simplifies the execution of Python code in your browser with no setup required. It democratises access to advanced computational resources, making it feasible to run LLMs without hefty costs. Key features include:

2. Setting Up Your Environment

2.1 Creating a New Notebook

Start by opening Google Colab:

  1. Visit Google Colab.
  2. Click “New Notebook” to create a new Python 3 environment.

2.2 Selecting GPU Runtime and Enabling GPU Acceleration

Ensure that you are using a GPU for enhanced performance:

Navigate to Runtime > Change runtime type. Select GPU under Hardware accelerator.

Created from Google Colab Jupyter Notebook by Tohfa Siddika Barbhuiya
Created from Google Colab Jupyter Notebook by Tohfa Siddika Barbhuiya

Then click on Connect

2.3 Installing Required Libraries

For LLMs, you’ll need libraries like transformers. Install it using the following code:

3. Mounting Google Drive (if the user wants to)

Google Drive integration allows easy data management. Here’s how to mount your drive:

Follow the instructions:

Click on the link that appears. Choose your Google account. Copy the authorisation code provided. Paste the authorisation code back into Colab:

After pasting the code, your Google Drive will be mounted. You can now access your Google Drive files directly from your Colab notebook.

4. Running Large Language Models

Now, let’s run a large language model using Hugging Face’s transformers library. For this demonstration, the Open Source LLM Modle Falcon-7b-Instruct Model (TII) is used. Here is a basic example for sentiment analysis:

You will get a surprising output. Check your notebook after running it.

Uncomment the next prompt and run. Again you will get a surprising output from the response. Also, you can connect to Ollama remotely through Google Colab as well.

6. Conclusion

Google Colab provides a versatile and accessible platform for running large language models, removing the barriers of expensive hardware and complex setups. By offering free GPU access, seamless Google Drive integration, and a user-friendly interface, Colab empowers individuals and small teams to explore and utilise the capabilities of advanced AI models like Falcon-7B-Instruct, running Ollama remotely and running LLM Models. This democratisation of technology enables more people to engage in cutting-edge AI research and applications, making powerful computational tools available to a wider audience. Start using Google Colab today to unlock the potential of LLMs in your projects.

References

About the Author

Tohfa Siddika Barbhuiya
Intern at Research Graph Foundation |  + posts