What is Lilypad Network? A Simple Introduction

What is Lilypad Network? A Simple Introduction

Welcome! In this blog entry we are going to introduce a cutting edge technology bringing web3 and arbitrary compute under one umbrella. This article will introduce Lilypad Network at a high level and demonstrate how it works with an example.

What is Lilypad?

Lilypad Network is a serverless, distributed compute network enabling users to preform internet scale data processing. Lilypad combines blockchain technology with off-chain decentralized compute to create a two sided open marketplace between users who want to compute data and those who are willing to rent out their hardware to fulfill those requests.

Lilypad can be used to run AI, ML and other arbitrary computational tasks; however, the most prominent use-case as of today is to run AI/ML jobs such as stable-diffusion and inference against various models. In today's landscape of AI/ML, you either have to spend a lot of money to set up the infrastructure to support your desired workload or have to turn to centralized solutions. With Lilypad you can "rent out" compute power from a network of providers who can run your workload for you (for a fee). Under the hood Lilypad is powered by the Bacalhau Network, a open peer to peer computing network, which preforms the computational tasks requested by users. The construct that enables computations to run through Lilypad are called Job Modules, which are basically open containerized apps (via Docker) or WASM workloads that can be executed through custom smart contracts to run AI inference, training, or any other arbitrary compute tasks. Thus, the Lilypad Network represents a globally accessible compute network combining the verifiable, trustless nature of blockchains with off-chain computing power capable of running high performance workloads.

Lilypad Stack

The Lilypad stack is made up of four core components according to their architecture docs:

  1. A SaaS layer abstracting away the nuances of web3 and allowing people to run and pay for transactions (i.e running jobs) in a web2-centric way

  2. The Lilypad Network which represents the "front door" for clients to request computation (e.g. calling job modules) and to retrieve the corresponding output

  3. A series of smart contracts deployed to run Lilypad handling responsibilities such as deal agreements, escrow payments, dispute resolutions and job payments

  4. Code libraries written in Go and Solidity bringing everything together

While all these pieces have a role to play, let's hone in on the Lilypad Network to complete this section before we walkthrough an example to see how it works. The network itself was inspired by a recent paper called "Mechanisms for Outsourcing Computation via a Decentralized Market" (MODiCuM) that introduced a framework for a decentralized system to outsource computation. Drawing inspiration from MODiCuM, the Lilypad Network introduced 5 main components that make up its ecosystem:

  1. Job Creators: The clients who have jobs that need running

  2. Resource Providers: The node operators that rent out their GPUs to Job Creators

  3. Solvers: The market makers that match Job Creators to Resource Providers

  4. Mediators: Trusted parties that handle resolution when there is a dispute

  5. File Directories: An underlying storage solution (like Filecoin) available for use by Job Creators and Resource Providers

Now let's see how all these components work together in our walkthrough example in the next section.

How Does it Work?

Let's walkthrough a simple example of how to run a job module through the Lilypad Network and go through what actually happens under the hood! So first thing you'll need to do is install the official Lilypad CLI which you can do by following the installation guide and making sure you import the Lilypad network into your Metamask. Furthermore, ensure that your wallet is properly funded with Arbitrum Sepolia Testnet ETH and Testnet LP tokens by following this guide.

Once you have the CLI installed and have confirmed it's working, we can now utilize the power of decentralized compute! Currently, Lilypad supports running jobs that can run stable diffusion (image and video), Llama LLM inference and their version of "Hello World" called Lilysay. For this walkthrough, let's do a run of using the Llama LLM to find some of the top spots to visit in Vancouver, BC, Canada.

Note: While we are using the CLI to run our example, we can also run a Job Module directly through a smart contract as well

Here's what we'll need to do to run our job through the Lilypad CLI:

  1. Open up a fresh new terminal window

  2. Run the following command (Note: since this is bleeding edge tech, the command may not work the first time and you may have to run this a couple times to get it to work):

lilypad run ollama-pipeline:llama3-8b-lilypad1 -i Prompt='What are some top spots to visit when in Vancouver, BC, Canada'

Let's breakdown the command bit by bit so that you have a better understanding of what's going on

Command SegmentExplanation
Lilypad runYou are telling the Lilypad CLI you want to execute the run command
ollama-pipeline:llama3-8b-lilypad1This is the name of the job module you want to run (ollama-pipeline) which is represented by a GitHub repo along with the version (llama3-8b-lilypad1) which represents a release version (i.e. GitHub tag)
-iA flag to indicate you are passing a parameter as input. If you have multiple inputs you are passing through you must include the -i flag for each
PROMPT='What are some top spots to visit when in Vancouver, BC, Canada'The actual input parameter we are passing into this module where we are asking it about the top spots to visit in Vancouver

Note: for the job module name you can also use a link to the GitHub repo in place of the name. So in this case you could replace ollama-pipeline with github.com/Lilypad-Tech/lilypad-module-ollama-pipeline

After running the above command, you should see output similar to this

The results of the computation will be available to you locally as well as on the IPFS network using the CID that was output in the console. To view the results locally (this job produces a json file), copy and run the open command the CLI produced. A finder window will appear with the results of the job run. Click into the outputs folder and open up the response.json file

The contents of the response.json file should look something like this:

{
  "model": "llama3",
  "created_at": "2024-06-24T19:20:06.374579437Z",
  "response": "Vancouver is a beautiful city with plenty of amazing attractions and activities. Here are some top spots to visit when in Vancouver, BC, Canada:\n\n1. **Stanley Park**: A must-visit attraction in Vancouver. This 400-hectare park features stunning beaches, walking trails, gardens, and the famous Stanley Park Brewing Company.\n2. **Granville Island**: A popular destination for shopping, dining, and entertainment. Explore the public market, artisan shops, and street performers on this lively island.\n3. **Capilano Suspension Bridge Park**: Walk across the suspension bridge, explore the treetop canopy walk, and learn about the park's indigenous culture.\n4. **Museum of Anthropology** (MOA): Located at UBC, MOA is home to a vast collection of Indigenous art and artifacts from around the world.\n5. **Grouse Mountain**: Take the Skyride tramway to the top for panoramic views, wildlife viewing, and outdoor activities like hiking and skiing.\n6. **English Bay Beach**: Enjoy the sun, sand, and stunning city skyline views at this popular beach.\n7. **Vancouver Aquarium**: Home to over 50,000 animals, including beluga whales, dolphins, and sea otters.\n8. **False Creek**: Take a ferry ride or stroll along the seawall to enjoy the city's scenic waterfront.\n9. **Gastown**: Explore Vancouver's oldest neighborhood, known for its cobblestone streets, historic buildings, and trendy shops.\n10. **Mount Pleasant**: Visit this hip neighborhood for a mix of vintage shops, restaurants, and bars.\n11. **Queen Elizabeth Park**: A beautiful park featuring rose gardens, walking trails, and stunning views of the city.\n12. **VanDusen Botanical Garden**: Explore over 7 acres of beautiful gardens, including a Japanese garden and a collection of rare plants.\n13. **Science World**: A family-friendly attraction with interactive science exhibits and a giant OMNIMAX theater.\n14. **Robson Street**: Known for its upscale shopping and dining, this street is perfect for a day of browsing and pampering.\n15. **Lighthouse Park**: A scenic beachside park with stunning views of the Burrard Inlet and surrounding mountains.\n\nThese are just a few of the many amazing spots to visit in Vancouver. Depending on your interests and time constraints, you may also want to explore:\n\n* The Vancouver Art Gallery\n* The H.R. MacMillan Space Centre\n* The Museum of Vancouver\n* The Vancouver Lookout (formerly known as the Capilano Tower)\n* The scenic drives along the Sea-to-Sky Highway or the Sunshine Coast\n\nRemember to check opening hours, ticket prices, and any specific regulations before visiting each attraction. Have a fantastic time exploring Vancouver!",
  "done": true,
  "done_reason": "stop",
  "context": [...],
  "total_duration": 23024512097,
  "load_duration": 8690982688,
  "prompt_eval_count": 24,
  "prompt_eval_duration": 93830000,
  "eval_count": 569,
  "eval_duration": 14198982000
}

Congratulations you just ran a decentralized compute job on the Lilypad Network and discovered a bunch of happening spots to check out while in Vancouver! But wait, what actually happened when you ran that command? While it may look like magic, beneath the covers the flow of execution basically consisted us running an approve function on a ERC-20 smart contract to allow us pay for the job and then actually submitting the job to the network.

The job submission is worth diving a bit deeper into to understand what's actually going on, here is a step by step overview of the flow:

  1. Submitting the job consists of us calling a function called runJob on the LilypadOnChainJobCreator smart contract that represents the job creation manager

  2. The runJob function checks if the required deposit has been approved to pay for the computation

  3. The funds get transferred to the on-chain solvers wallet

  4. The job is delegated to a solver who matches the job with a Resource Provider

  5. The Resource Provider receives the information about the job and offloads its execution to a node in the Bacalhau Network

  6. The Bacalhau node runs the job (off-chain) and returns the result to the Resource Provider. At this point the result also gets saved to a File Directory, which in this case is Filecoin and is made available via IPFS

  7. The Resource Provider relays the result to the on-chain solver which then calls the submitResults function at the origin to deliver the results with the unique identifier representing the output. Currently this id is returned as the IPFS Hash pointing to the location the output was saved

Summary

A we mentioned earlier, the Lilypad Network represents a globally accessible compute network combining the verifiable, trustless nature of blockchains with off-chain computing power capable of running high performance workloads. In this blog entry you learned about the Lilypad Network and saw it run a Llama LLM inference job by harnessing the power of decentralized compute. In a world of rising infrastructure demand and costs, Lilypad offers an open, decentralized compute network that lowers entry barriers and provides developers worldwide with access to high-performance AI. In the next blog entry, we'll walk through how to build your own Job Module from scratch to run a AI workload powered by a Hugging Face model and executed through the Lilypad Network!