-
Notifications
You must be signed in to change notification settings - Fork 5
Usage
The steps to host a pipeline with eden are:
- 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
}
- 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
)
Now in order to send requests to this hosted block, open another file and:
- 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')
- 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.
-
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
inhost_block()
. -
if
requires_gpu
isTrue
andmax_num_workers
is greater than the number of gpus available, then it throws a warning andmax_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
and3
), setexclude_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
)
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!'
}