Giter VIP home page Giter VIP logo

bacalhau-project / lilypad-modicum Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 11.0 56.44 MB

This is the deprecated Lilypad v1. See https://github.com/bacalhau-project/lilypad for v2. Previous FEVM-Bacalhau bridge (v0): https://github.com/bacalhau-project/lilypad-v0

License: GNU General Public License v3.0

Shell 9.17% JavaScript 0.18% C++ 17.55% Python 3.52% Perl 0.05% C 22.32% Assembly 1.44% CSS 0.21% TeX 1.00% ANTLR 0.06% Makefile 4.47% HTML 21.73% M4 0.09% Dockerfile 0.02% Roff 17.90% SWIG 0.05% Solidity 0.20% HCL 0.02% Go 0.03%

lilypad-modicum's Introduction

Lilypad ๐Ÿƒ

This cloud is just someone else's computer.

image

Read the docs!

This guide shows you (amongst other things) how to:

  • trigger jobs on other peoples' computers with just a metamask wallet and our CLI
  • trigger the same jobs from a smart contract deployed to our testnet
  • make crypto with your GPU by running Stable Diffusion fine-tuning & inference jobs for someone else.

Caveat: today it is just worthless test crypto, but one day soon it will be real crypto!

Get private key

Set up metamask with our Lalechuza testnet.

Click the down arrow on networks and click add network.

The variables you need are:

  • Network name: Lilypad Lalechuza testnet
  • New RPC URL: http://testnet.lilypadnetwork.org:8545
  • Chain ID: 1337
  • Currency symbol: ETH
  • Block explorer URL: (leave blank)

Click save and click "switch to Lilypad Lalechuza testnet".

  • Click the down arrow next to Account 1 on the top bar, then click the ... next to Account 1 in the list
  • Account details - then click Show private key

  • Show private key
  • Enter your metamask password
  • Copy private key for account - DO NOT COPY THE WALLET ADDRESS BY MISTAKE

Open a terminal on macOS, Linux or WSL2, and type:

export PRIVATE_KEY=<the private key you copied>

Go get some funds from the faucet: http://testnet.lilypadnetwork.org/

Now let's run a job!

Hello (cow) world example

Requires:

Works on Linux, macOS and WSL2 (x86_64 and arm64)

Install lilypad CLI:

curl -sSL -O https://raw.githubusercontent.com/bacalhau-project/lilypad-modicum/main/lilypad && sudo install lilypad /usr/local/bin/lilypad

run a job (x86_64 or arm64)

Run cowsay via the BLOCKCHAIN

export PRIVATE_KEY=<as above>
lilypad run --template cowsay:v0.0.1 --params "hello lilypad"

(ensure your user is in the docker group if necessary on your platform)

run a node (x86_64 only)

To contribute your resources to the network and get paid

export PRIVATE_KEY=<as above>
sudo -E lilypad serve

usage

stable diffusion (requires GPU)

lilypad run --template stable_diffusion:v0.0.1 --params "blue frog"

TODO:

filecoin data prep

lilypad run --template filecoin_data_prep:v0.0.1 \
	--params '{"s3_bucket": "noaa-goes16", \
	           "s3_key": "ABI-L1b-RadC/2000/001/12/OR_ABI-L1b-RadC-M3C01*"}'
  • TODO: read results from http rather than ipfs for high performance

arbitrary wasm (run in a deterministic env)

  • TODO: the following seems to be a csv2parquet program that requires a CSV as input - need to also provide a CSV as input! (but it runs, giving the error message rn)
lilypad run --template deterministic_wasm:v0.0.1 \
	--params '{"wasm_cid": "Qmajb9T3jBdMSp7xh2JruNrqg3hniCnM6EUVsBocARPJRQ", \
	           "wasm_entrypoint": "_start"}'

lilypad-modicum's People

Contributors

31z4 avatar binocarlos avatar developerally avatar eiselesr avatar lukemarsden avatar xqua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

lilypad-modicum's Issues

add idempotency to transactions

For the following list of actions - we should make them idempotent otherwise we end up with ever appending lists:

  • resourceProviderAddTrustedMediator - if the mediator is already trusted don't call this
  • jobCreatorAddTrustedMediator - ^ same
  • postResOffer - if there is aready a resource offer that has not been matched - don't add another

verification

check verification mechanism and ensure it's working

hash based verification based on outputs should be how it works - we'll have to wire up the bacalhau result hasher to modicum

Persist solver state outside of memory

Currently - the solver works by keeping an in memory map of resource offers and job offers - as well as trusted mediators for both parties.

The probem is if the solver restarts then everything breaks because it relys on it's in-memory map to match jobs.

Let's add some persistance to the solver service so it can survive restarts otherwise guaranteed this will break the testnet at the worst possible time :-)

retry on nonce too low

as seen below, when there's contention on the smart contract because of the short block times we are more likely to see this, we just need to retry in the client

2023-07-17 12:19:02,606;ResourceProvider;๐ŸŸ  post resource offer
Exception in thread Thread-1 (platformListener):
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/app/modicum/ResourceProvider.py", line 303, in platformListener
    self.postDefaultOffer()
  File "/app/modicum/ResourceProvider.py", line 90, in postDefaultOffer
    self.postOffer({"request": "post",
  File "/app/modicum/ResourceProvider.py", line 78, in postOffer
    ).transact({
  File "/usr/local/lib/python3.10/dist-packages/web3/contract/contract.py", line 479, in transact
    return transact_with_contract_function(
  File "/usr/local/lib/python3.10/dist-packages/web3/contract/utils.py", line 172, in transact_with_contract_function
    txn_hash = w3.eth.send_transaction(transact_transaction)
  File "/usr/local/lib/python3.10/dist-packages/web3/eth/eth.py", line 362, in send_transaction
    return self._send_transaction(transaction)
  File "/usr/local/lib/python3.10/dist-packages/web3/module.py", line 68, in caller
    result = w3.manager.request_blocking(
  File "/usr/local/lib/python3.10/dist-packages/web3/manager.py", line 232, in request_blocking
    return self.formatted_response(
  File "/usr/local/lib/python3.10/dist-packages/web3/manager.py", line 205, in formatted_response
    raise ValueError(response["error"])
ValueError: {'code': -32000, 'message': 'nonce too low: next nonce 120, tx nonce 119'}

ipc testnet

as well as our geth testnet, we should add an ipc one so users can spend tFIL

workaround for `No package metadata was found for Modicum`

When running in dev mode (no DATA_DIRECTORY) on a new checkout, if you get

Traceback (most recent call last):
  File "/usr/local/bin/modicum", line 33, in <module>
    sys.exit(load_entry_point('Modicum', 'console_scripts', 'modicum')())
  File "/usr/local/bin/modicum", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 957, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 548, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for Modicum

then running pip install -e . inside /app inside one of the containers will fix it (permanently, even though the container restarts -- the change that this causes which fixes it, whatever it is, must persist inside the bind-mounted directory)

only schedule gpu jobs to gpu nodes

as soon as we have random users connecting nodes, the solver will have to get a bit smarter about only routing jobs to nodes that can run them

gpu is just one parameter of course - architecture and mem/cpu requests are also a factor

catch and recreate filter

2023-07-19 05:36:10,449;ResourceProvider;๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต RUN JOB NOW
2023-07-19 05:47:40,621;ResourceProvider;๐ŸŸข๐ŸŸข๐ŸŸข Posting result: 
{"matchID": 0, "joid": 1, "contractStatus": 0, "resultHash": "QmTocYmkghKwXf4UPEpt4HRS1G8saACfCqWdEZNgJ1GKaA"}
Exception in thread Thread-1 (platformListener):
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/app/modicum/ResourceProvider.py", line 197, in platformListener
    events = self.ethclient.poll_events()
  File "/app/modicum/EthereumClient.py", line 272, in poll_events
    log = self.filter.get_new_entries()
  File "/usr/local/lib/python3.10/dist-packages/web3/_utils/filters.py", line 181, in get_new_entries
    self.eth_module.get_filter_changes(self.filter_id)
  File "/usr/local/lib/python3.10/dist-packages/web3/module.py", line 68, in caller
    result = w3.manager.request_blocking(
  File "/usr/local/lib/python3.10/dist-packages/web3/manager.py", line 232, in request_blocking
    return self.formatted_response(
  File "/usr/local/lib/python3.10/dist-packages/web3/manager.py", line 205, in formatted_response
    raise ValueError(response["error"])
ValueError: {'code': -32000, 'message': 'filter not found'}

we might miss some events.. but probably better than doing this

mediator uses 100% cpu

which makes my laptop warm, and i don't like it

(this is when running

./stack lilypad-modicum-process runAsMediator

)

docs for creating a module

one day it would also be nice to have docs for how to add new modules, a bit like

Mediator and job creator accounts are the same

We made this change in order to fix a bug with the solver but it now means that the mediator address will always be the same as the job creator address - which will change when the user supplies their own private key.

We need to deloy the mediator against a fixed account and then both the resource provider and job creator should reference that static mediator address

Proper attribution

Reference modicum in the readme and give them proper credit and mention gplv3

enforce pricing in contract

since we're going with simple fixed pricing for now, we should enforce the prices in the contract (currently, a user can send too little and they will still get the work done if other nodes have jobs in progress ๐Ÿ™€)

Add verification to onchain client

The purely onchain job creator currently accepts every job without verification, unlike the CLI which will verify 10% of jobs

Add verification to the onchain job creator contract. This will require a source of entropy/randomness

money stuff

check payment mechanism and ensure it's working

if we don't have cpu usage checking in bacalhau now, fix job price per module (e.g. stable diffusion inference = 10p, fine tuning = ยฃ1, cowsay = 1p)

only runs container the first time

for some reason, if you start the ResourceProvider, and then run

./stack lilypad-modicum-process runLilypadCLI --template cowsay --params "HAHAHACOWS"

twice, it only works the first time - the second time everything hangs

fix gpu nodes

failing to find nvidia-smi means we don't find gpu nodes, need to install nvidia-smi in our container and set --gpu=all in the outer container

add ResultsPosted to list of emojis in cli.py

E_MISSING_EMOJI

luke@floating:~/pb/lilypad$ lilypad run --template cowsay:v0.0.1 --params "hello lilypad"

๐ŸŒŸ Lilypad submitting job cowsay:v0.0.1('hello lilypad') ๐ŸŒŸ

๐Ÿ”— Connecting to smart contract
๐Ÿ”‘ Loaded private key for 0x2cebeea7E84E3746b991E2B7bf32D9587aCB64E8
๐Ÿ”Œ Registering job creator
๐Ÿง˜ Adding mediator 0xcD9379EEDcBb9a077025Fbdf5AE81F1399e43F2C
๐Ÿ’Œ Posting offer for cowsay:v0.0.1
๐Ÿฅฐ Running job... Sending deposit of 1 ETH to contract
ResultsPosted Fetching results... https://ipfs.io/ipfs/QmNjJUyFZpSg7HC9akujZ6KHWvJbCEytre3NRSMHzCA6NR
๐Ÿƒ EtherTransferred Released deposit of 1 ETH to compute provider

๐Ÿ‚ Lilypad job completed ๐Ÿ‘‰ Released deposit of 1 ETH to compute provider

quotes don't get passed thru stack

luke@floating:~/pb/MODICUM$ ./stack lilypad-modicum-process runLilypadCLI --template cowsay --params "HAHAHA COWS"
I am about to invoke runLilypadCLI
Usage: modicum runLilypadCLI [OPTIONS]
Try 'modicum runLilypadCLI --help' for help.

Error: Got unexpected extra argument (COWS)

somehow the quotes get stripped off, is it something missing in how we're doing "$@" in stack?

Once the solver does a match - the resource offer is wiped

Once the solver matches a job to a resource provider - it wipes the resource offer from the in memory state of the solver...

This means the resource provider will only do one job until we either:

  • change this behaviour (e.g. keep hold of the resource offer but then how do we rate limit)
  • re-register the resource offer once a job has completed

Block Explorer for Lalechuza Testnet

Ability to see transactions and blocks on the Lalechuza testnet would be great to have (perhaps ethernals? - it appears you can "turn your explorer public" here)

See thread https://bacalhauproject.slack.com/archives/C05FWMSJ3B6/p1689343663397499?thread_ts=1689343162.181219&cid=C05FWMSJ3B6

Also: Expedition - https://github.com/xops/expedition Blog: https://www.quicknode.com/guides/infrastructure/blockchain-data-tools/how-to-run-the-expedition-block-explorer-for-ethereum

feature: include public IP of node in blockchain

then expose bacalhau get, logs, describe, dashboard etc via a lilypad wrapper that simply looks up the node address

also set --wait=false and then publish the job id immediately so that long running jobs can have a better UX

error when private key not set

when private key is unset, and we're in production-client trim, error rather than using unlocked account zero

we should also move all the funds out of the unlocked account

what happens if a resource provider goes away

I am a compute node - I start lilypad, it registers a resource offer.

The solver is now looping waiting for job offers to match.

I then stop my lilypad node so it's no longer waiting for match events to arrive to trigger jobs.

However - the solver still thinks I am there and ready to run jobs.

Do we need a removeResourceOffer workflow?

add http publisher

give the resource provider a way to write an output to a location which is (by CID) served over native HTTP, for efficient publishing for the filecoin data prep use case

we can't write back to S3 because we can't consume secrets in the public network

Use a different account for different roles

Presently - we use a single admin account for:

  • deploying the contract
  • running the mediator and solver

The user will supply their own keys (ergo addresses) for:

  • resource provider
  • job creator

This means the mediator will always have a different address than the resource provider and job creator.

This issue exists to replicate that same setup in local development - i.e. the mediator must use a different address than the RP and JC to replicate production.

tail logs in cli

given direct access to the bacalhau API, it should be possible to tail logs (with the bacalhau CLI) from a node

this is an optional service that compute nodes can offer for better DX and is not incentivized or guaranteed to be correct...

tweak prices for things

e.g. lilETH = hypothetical $1

cowsay = $0.01
SD FT = $1
SD inference = $0.10
filecoin data prep up to 1GB = $0.50
arbitrary wasm for up to 10 minutes = $0.20

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.