The Random Walk Blog

2024-06-26

Tiny Pi, Mighty AI: How to Run LLM on a Raspberry Pi 4

Tiny Pi, Mighty AI: How to Run LLM on a Raspberry Pi 4

Using Large Language Models (LLMs) in businesses presents challenges, including high computational resource requirements, concerns about data privacy and security, and the potential for bias in outputs. These issues can hinder effective implementation and raise ethical considerations in decision-making processes.

Introducing local LLMs on small computers is one solution to these challenges. This approach enables businesses to operate offline, enhance data privacy, achieve cost efficiency, and customize LLM functionalities to meet specific operational requirements.

Our goal was to create an LLM on a small, affordable computer demonstrating the potential of powerful models to run on modest hardware. We used Raspberry Pi OS with Ollama as our source file to achieve our goal.

The Raspberry Pi is a compact, low-cost single-board computer that enables people to explore computing and learn how to program. It has its own processor, memory, and graphics driver, running the Raspberry Pi OS, a Linux variant. Beyond core functionalities like internet browsing, high-definition video streaming, and office productivity applications, this device empowers users to delve into creative digital maker projects. Despite its small size, it makes an excellent platform for AI and machine learning experiments.

Choosing and Setting Up the Raspberry Pi

We used the Raspberry Pi 4 Model B, with 8GB of RAM, to balance performance and cost. This model provides enough memory to handle the demands of AI tasks while remaining cost-effective.

First, we set up Raspberry Pi OS by downloading the Raspberry Pi Imager and installed a lite 64-bit OS onto a microSD card. This step is crucial for ensuring the system runs smoothly and efficiently. To prepare the system for further deployment, we completed the OS installation, network configuration, and system updates to ensure optimal functionality and security.

sudo apt update

sudo apt upgrade

sudo apt install python3-pip

Downloading and Setting Up Ollama

Ollama is an open-source language model designed for efficient training and inference. Its lightweight architecture makes it suitable for running on resource-constrained devices like the Raspberry Pi.

  • Downloading Ollama: We downloaded the Linux version of Ollama and verified its compatibility with the Raspberry Pi by running the provided code. This step ensures that the software can run effectively on the Raspberry Pi’s architecture.

curl -fsSL https://ollama.com/install.sh | sh

  • Configuring Ollama: Following Ollama’s installation and configuration, we selected and integrated an appropriate model. This involves setting the correct parameters and ensuring the system can handle the computational load.

Choosing the Model

The Ollama website offers various models, making it challenging to choose the best one for the Raspberry Pi, given its 8GB RAM limitation. Large or medium-sized LLMs could overload the system. Therefore, we decided on the phi3 mini model, which is regularly updated and has a small storage size. This model is ideal for the Raspberry Pi, providing a balance between performance and resource usage.

Setting Up the PHI3 Mini Model

Setting up the phi3 mini model was straightforward but time-consuming. Since the Raspberry Pi lacks a graphics card, the model runs in CPU mode. This version of the phi3 mini model, which we named Jarvis, can change its responses and act as a versatile virtual AI assistant. Jarvis is designed to handle a variety of tasks and queries, making it a powerful tool for natural language processing (NLP) and semantic understanding.

./ollama --model phi3_mini

About Jarvis as an AI Assistant

Jarvis, our version of the phi3 mini model, is an advanced AI assistant capable of responding in a human-like manner, infused with humor, sarcasm, and wit. This customization adds a unique personality to the AI assistant. NLP enables Jarvis to analyze user queries by breaking down the input into comprehensible components, identifying key phrases and context. This allows Jarvis to generate relevant and accurate responses, providing a seamless and intuitive user experience.

Testing and Validation

After thorough testing, it is observed that both versions of phi3 work as expected and provide satisfactory outcomes. Jarvis is capable of handling various queries and tasks efficiently, showcasing the power of LLMs on a modest platform. The testing phase involved running multiple scenarios and queries to ensure Jarvis could handle different types of input and provide accurate, relevant responses.

large language model.svg

natural language processing.svg

Enhancing Jarvis as an AI Assistant

To enhance Jarvis further, we plan to install additional Python packages, create a more interactive environment, and add more code to develop a user-friendly interface and integrate more functionalities. This includes expanding Jarvis’s capabilities to understand more complex queries and provide more detailed responses. Future enhancements could also involve integrating Jarvis with other systems and platforms to broaden its utility.

Challenges Encountered

Throughout the development, we encountered several challenges:

  • Network Configuration: Initially, we faced issues with network configuration due to a booting problem. This was resolved by using a dedicated Raspberry Pi power adapter.

  • Coding Issues: Several coding challenges emerged but were resolved through debugging and community support. The Raspberry Pi community proved invaluable for troubleshooting and finding solutions.

  • Overheating: The Raspberry Pi overheated due to the lack of a graphics card. This was managed by adding heat sinks and a cooling fan, ensuring the system could run smoothly without overheating.

Building an LLM on a Raspberry Pi with Ollama has been both challenging and rewarding. This initiative showcases the potential of low-cost, low-power hardware for wider adoption of LLMs and innovation for business use cases.  As these advancements continue, the future promises even greater integration of AI into everyday operations.

Related Blogs

I Built an AI Agent From Scratch—Here’s What I Learned

I’ve worked with LangChain. I’ve played with LlamaIndex. They’re great—until they aren’t.

I Built an AI Agent From Scratch—Here’s What I Learned

How Can Enterprises Benefit from Generative AI in Data Visualization

It’s New Year’s Eve, and John, a data analyst, is finishing up a fun party with his friends. Feeling tired and eager to relax, he looks forward to unwinding. But as he checks his phone, a message from his manager pops up: “Is the dashboard ready for tomorrow’s sales meeting?” John’s heart sinks. The meeting is in less than 12 hours, and he’s barely started on the dashboard. Without thinking, he quickly types back, “Yes,” hoping he can pull it together somehow. The problem? He’s exhausted, and the thought of combing through a massive 1000-row CSV file to create graphs in Excel or Tableau feels overwhelming. Just when he starts to panic, he remembers his secret weapon: Fortune Cookie, the AI-assistant that can turn data into insightful data visualizations in no time. Relieved, John knows he doesn’t have to break a sweat. Fortune Cookie has him covered, and the dashboard will be ready in no time.

How Can Enterprises Benefit from Generative AI in Data Visualization

Streamlining File Management with MindFolder’s Intelligent Edge

Brain rot, the 2024 Word of the Year, perfectly encapsulates the overwhelming state of mental fatigue caused by endless information overload—a challenge faced by individuals and businesses alike in today’s fast-paced digital world. At its core, this term highlights the need for streamlined systems that simplify the way we interact with data and files.

Streamlining File Management with MindFolder’s Intelligent Edge

Refining and Creating Data Visualizations with LIDA and AI Fortune Cookie

Data visualization and storytelling are critical for making sense of today’s data-rich world. Whether you’re an analyst, a researcher, or a business leader, translating raw data into actionable insights often hinges on effective tools. Two innovative platforms that elevate this process are Microsoft’s LIDA and our RAG-enhanced data visualization platform using gen AI, AI Fortune Cookie. While LIDA specializes in refining and enhancing infographics, Fortune Cookie transforms disparate datasets into cohesive dashboards with the power of natural language prompts. Together, they form a powerful combination for visual storytelling and data-driven decision-making.

Refining and Creating Data Visualizations with LIDA and AI Fortune Cookie

1-bit LLMs: The Future of Efficient and Accessible Enterprise AI

As data grows, enterprises face challenges in managing their knowledge systems. While Large Language Models (LLMs) like GPT-4 excel in understanding and generating text, they require substantial computational resources, often needing hundreds of gigabytes of memory and costly GPU hardware. This poses a significant barrier for many organizations, alongside concerns about data privacy and operational costs. As a result, many enterprises find it difficult to utilize the AI capabilities essential for staying competitive, as current LLMs are often technically and financially out of reach.

1-bit LLMs: The Future of Efficient and Accessible Enterprise AI
I Built an AI Agent From Scratch—Here’s What I Learned

I Built an AI Agent From Scratch—Here’s What I Learned

I’ve worked with LangChain. I’ve played with LlamaIndex. They’re great—until they aren’t.

How Can Enterprises Benefit from Generative AI in Data Visualization

How Can Enterprises Benefit from Generative AI in Data Visualization

It’s New Year’s Eve, and John, a data analyst, is finishing up a fun party with his friends. Feeling tired and eager to relax, he looks forward to unwinding. But as he checks his phone, a message from his manager pops up: “Is the dashboard ready for tomorrow’s sales meeting?” John’s heart sinks. The meeting is in less than 12 hours, and he’s barely started on the dashboard. Without thinking, he quickly types back, “Yes,” hoping he can pull it together somehow. The problem? He’s exhausted, and the thought of combing through a massive 1000-row CSV file to create graphs in Excel or Tableau feels overwhelming. Just when he starts to panic, he remembers his secret weapon: Fortune Cookie, the AI-assistant that can turn data into insightful data visualizations in no time. Relieved, John knows he doesn’t have to break a sweat. Fortune Cookie has him covered, and the dashboard will be ready in no time.

Streamlining File Management with MindFolder’s Intelligent Edge

Streamlining File Management with MindFolder’s Intelligent Edge

Brain rot, the 2024 Word of the Year, perfectly encapsulates the overwhelming state of mental fatigue caused by endless information overload—a challenge faced by individuals and businesses alike in today’s fast-paced digital world. At its core, this term highlights the need for streamlined systems that simplify the way we interact with data and files.

Refining and Creating Data Visualizations with LIDA and AI Fortune Cookie

Refining and Creating Data Visualizations with LIDA and AI Fortune Cookie

Data visualization and storytelling are critical for making sense of today’s data-rich world. Whether you’re an analyst, a researcher, or a business leader, translating raw data into actionable insights often hinges on effective tools. Two innovative platforms that elevate this process are Microsoft’s LIDA and our RAG-enhanced data visualization platform using gen AI, AI Fortune Cookie. While LIDA specializes in refining and enhancing infographics, Fortune Cookie transforms disparate datasets into cohesive dashboards with the power of natural language prompts. Together, they form a powerful combination for visual storytelling and data-driven decision-making.

1-bit LLMs: The Future of Efficient and Accessible Enterprise AI

1-bit LLMs: The Future of Efficient and Accessible Enterprise AI

As data grows, enterprises face challenges in managing their knowledge systems. While Large Language Models (LLMs) like GPT-4 excel in understanding and generating text, they require substantial computational resources, often needing hundreds of gigabytes of memory and costly GPU hardware. This poses a significant barrier for many organizations, alongside concerns about data privacy and operational costs. As a result, many enterprises find it difficult to utilize the AI capabilities essential for staying competitive, as current LLMs are often technically and financially out of reach.

Additional

Your Random Walk Towards AI Begins Now