Skip to content
Mayukh Deb edited this page Sep 12, 2021 · 3 revisions

Quick start

Hosting

The steps to host a pipeline with eden are:

  1. Configuring a block and defining the input arguments
from eden.block import BaseBlock
from eden.datatypes import Image

eden_block = BaseBlock()

my_args = {
        'prompt': 'hello world', ## text input
        'input_image': Image(),  ## for image input
    }
  1. Define run
@eden_block.run(args = my_args, progress = True)
def do_something(config): 

    prompt = config['prompt']
    pil_image = config['input_image']

    ## Do your stuff here

    return {
        'some_text': 'hello world',  ## returning text (str)
        'image': Image(pil_image)   ## Image() works on PIL.Image, numpy.array and on jpg an png files
    }

Now in order to host the block, run the following:

from eden.hosting import host_block

host_block(
    block = eden_block, 
    port= 5656,
    max_num_workers= 4 
)

Client side

Now in order to send requests to this hosted block, open another file and:

  1. Set up a Client
from eden.client import Client
from eden.datatypes import Image

c = Client(url = 'http://127.0.0.1:5656', username= 'abraham')
  1. In order to start a job:
config = {
    'prompt': 'let there be light',
    'number': 2233,
    'input_image': Image('test_images/krusty_krab.png')  ## Image() supports jpg, png filenames, np.array or PIL.Image
}

run_response = c.run(config)

After you start a task with run() as shown above, it returns a token as run_response['token']. This token should be used later on to check the status of the task or to obtain your results.

Configuring GPUs

  • If you have a machine with multiple GPUs and you want to automatically allocate a GPU to each working thread, you should set requires_gpu = True in host_block().

  • if requires_gpu is True and max_num_workers is greater than the number of gpus available, then it throws a warning and max_num_workers automatically decreases to be equal to the number of GPUs available.

  • If you want to exclude some GPUs from eden (say gpus 2 and 3), set exclude_gpu_ids = [2,3]

host_block(
    block = some_block, 
    port= 5656,
    max_num_workers = 4, ## will use 4 GPUs if available
    requires_gpu = True  ## default: True,
    exclude_gpu_ids = [2,3] ## ignore gpus 2 and 3 
)

Updating progress

When setting up a block, make sure you set progress = True as:

from eden.block import BaseBlock

eden_block = BaseBlock(progress = True)

and then you can update progress with config.progress.update(1/10)

@eden_block.run(args = my_args, progress = True)
def do_something(config): 
    num_iterations = 10

    for i in range(num_iterations):
        config.progress.update(1/num_iterations)  ## updating progress
  
    return {
       'message': 'hello there!'
    }
Clone this wiki locally