Skip to content

Commit c427e54

Browse files
committed
run task on bacalhau
1 parent 7ff248d commit c427e54

File tree

4 files changed

+84
-8
lines changed

4 files changed

+84
-8
lines changed

deploy.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ def main():
1313
from mlweb3.fetch.deployment import deploy
1414
case 'golem':
1515
from mlweb3.golem.deployment import deploy
16+
case 'bacalhau':
17+
from mlweb3.bacalhau.deployment import deploy
1618
case _:
1719
raise ValueError('unsupported infra')
1820
deploy()
1921

2022

2123
def parse_arguments():
2224
parser = argparse.ArgumentParser()
23-
parser.add_argument('-i', '--infra', choices=['ocean', 'fetch', 'golem'])
25+
parser.add_argument('-i', '--infra', choices=['ocean', 'fetch', 'golem', 'bacalhau'])
2426
return vars(parser.parse_args())
2527

2628

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
name: mlweb3-bacalhau
22
channels:
3-
- pytorch
43
- conda-forge
54
- defaults
65
dependencies:
76
- bzip2
87
- ca-certificates
98
- pip
109
- python=3.10
11-
- pytorch=1.12.1
12-
- pytorch-mutex
1310
- readline
1411
- requests
1512
- six
1613
- sqlite
1714
- tk
18-
- torchvision=0.13.1
1915
- typing_extensions
2016
- tzdata
2117
- urllib3
@@ -26,5 +22,5 @@ dependencies:
2622
- pip:
2723
- python-dotenv
2824
# ---- bacalhau ----
29-
- bacalhau-sdk
25+
- bacalhau-sdk~=1.4.2
3026
prefix: /home/devin/miniconda3/envs/mlweb3-bacalhau

mlweb3/bacalhau/inference.py

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,82 @@
22
inference logic for bacalhau
33
"""
44

5+
# lib
6+
import time
7+
import pprint
8+
from bacalhau_apiclient.models.job import Job
9+
from bacalhau_apiclient.models.task import Task
10+
from bacalhau_apiclient.models.resources import Resources
11+
from bacalhau_apiclient.models.timeout_config import TimeoutConfig
12+
from bacalhau_apiclient.models.all_of_execution_published_result import SpecConfig
13+
from bacalhau_apiclient.models.api_put_job_request import ApiPutJobRequest
14+
from bacalhau_sdk.jobs import Jobs
15+
16+
IMAGE = 'devinaconley/mnist-pytorch-gpu:dev'
17+
518

619
def predict():
7-
raise NotImplemented('bacalhau predict not implemented.')
20+
# setup job
21+
task = Task(
22+
name='My Main task',
23+
engine=SpecConfig(
24+
type='docker',
25+
params=dict(
26+
Image='ubuntu:latest', # TODO
27+
Entrypoint=['/bin/bash'],
28+
Parameters=['-c', 'echo hello world'],
29+
),
30+
),
31+
resources=Resources(
32+
cpu='0.1',
33+
memory='256mb',
34+
gpu='0'
35+
),
36+
timeouts=TimeoutConfig(
37+
execution_timeout=300,
38+
queue_timeout=600,
39+
total_timeout=1500
40+
),
41+
publisher=SpecConfig(type='IPFS', params=dict()),
42+
43+
)
44+
job = Job(
45+
name='a simple docker job',
46+
type='batch',
47+
count=1,
48+
tasks=[task]
49+
)
50+
job_req = ApiPutJobRequest(job=job)
51+
52+
# submit
53+
jobs = Jobs()
54+
res = jobs.put(job_req)
55+
job_id = res.job_id
56+
print(res)
57+
58+
# wait for completion
59+
while True:
60+
res = jobs.get(job_id)
61+
state = res.job.state.state_type
62+
if state in ['Pending', 'Queued']:
63+
print(state)
64+
time.sleep(5)
65+
continue
66+
elif state == 'Failed':
67+
print(res.job.state.message)
68+
break
69+
70+
print(res.job)
71+
72+
# TODO
73+
res0 = jobs.results(job_id)
74+
pprint.pprint(res0)
75+
76+
res1 = jobs.history(job_id)
77+
pprint.pprint(res1)
78+
79+
res2 = jobs.get(job_id)
80+
pprint.pprint(res2)
81+
82+
res3 = jobs.executions(job_id)
83+
pprint.pprint(res3)

predict.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ def main():
1313
from mlweb3.fetch.inference import predict
1414
case 'golem':
1515
from mlweb3.golem.inference import predict
16+
case 'bacalhau':
17+
from mlweb3.bacalhau.inference import predict
1618
case _:
1719
raise ValueError('unsupported infra')
1820
predict()
1921

2022

2123
def parse_arguments():
2224
parser = argparse.ArgumentParser()
23-
parser.add_argument('-i', '--infra', choices=['ocean', 'fetch', 'golem'])
25+
parser.add_argument('-i', '--infra', choices=['ocean', 'fetch', 'golem', 'bacalhau'])
2426
return vars(parser.parse_args())
2527

2628

0 commit comments

Comments
 (0)