2023-05-22 09:10:51 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import time
|
|
|
|
import json
|
|
|
|
|
|
|
|
from hashlib import sha256
|
|
|
|
from functools import partial
|
|
|
|
|
|
|
|
import trio
|
|
|
|
import requests
|
2023-06-04 20:51:43 +00:00
|
|
|
from skynet.constants import DEFAULT_IPFS_REMOTE
|
2023-05-22 09:10:51 +00:00
|
|
|
|
|
|
|
from skynet.dgpu import open_dgpu_node
|
|
|
|
|
2023-05-27 20:50:47 +00:00
|
|
|
from leap.sugar import collect_stdout
|
|
|
|
|
2023-05-22 09:10:51 +00:00
|
|
|
|
2023-05-24 16:24:46 +00:00
|
|
|
def test_enqueue_work(cleos):
|
2023-05-28 00:38:04 +00:00
|
|
|
user = 'telegram'
|
2023-05-22 09:10:51 +00:00
|
|
|
req = json.dumps({
|
|
|
|
'method': 'diffuse',
|
|
|
|
'params': {
|
|
|
|
'algo': 'midj',
|
|
|
|
'prompt': 'skynet terminator dystopic',
|
|
|
|
'width': 512,
|
|
|
|
'height': 512,
|
|
|
|
'guidance': 10,
|
|
|
|
'step': 28,
|
|
|
|
'seed': 420,
|
|
|
|
'upscaler': 'x4'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
binary = ''
|
|
|
|
|
|
|
|
ec, out = cleos.push_action(
|
2023-06-04 20:51:43 +00:00
|
|
|
'telos.gpu', 'enqueue', [user, req, binary, '20.0000 GPU', 1], f'{user}@active'
|
2023-05-22 09:10:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert ec == 0
|
|
|
|
|
|
|
|
queue = cleos.get_table('telos.gpu', 'telos.gpu', 'queue')
|
|
|
|
|
|
|
|
assert len(queue) == 1
|
|
|
|
|
|
|
|
req_on_chain = queue[0]
|
|
|
|
|
|
|
|
assert req_on_chain['user'] == user
|
|
|
|
assert req_on_chain['body'] == req
|
|
|
|
assert req_on_chain['binary_data'] == binary
|
|
|
|
|
2023-05-28 00:38:04 +00:00
|
|
|
trio.run(
|
|
|
|
partial(
|
|
|
|
open_dgpu_node,
|
|
|
|
f'testworker1',
|
|
|
|
'active',
|
|
|
|
cleos,
|
2023-06-04 20:51:43 +00:00
|
|
|
DEFAULT_IPFS_REMOTE,
|
|
|
|
cleos.private_keys['testworker1'],
|
2023-05-28 00:38:04 +00:00
|
|
|
initial_algos=['midj']
|
2023-05-22 09:10:51 +00:00
|
|
|
)
|
2023-05-28 00:38:04 +00:00
|
|
|
)
|
2023-05-22 09:10:51 +00:00
|
|
|
|
|
|
|
queue = cleos.get_table('telos.gpu', 'telos.gpu', 'queue')
|
|
|
|
|
|
|
|
assert len(queue) == 0
|
|
|
|
|
2023-05-27 20:50:47 +00:00
|
|
|
|
|
|
|
def test_enqueue_dequeue(cleos):
|
2023-05-28 00:38:04 +00:00
|
|
|
user = 'telegram'
|
2023-05-27 20:50:47 +00:00
|
|
|
req = json.dumps({
|
|
|
|
'method': 'diffuse',
|
|
|
|
'params': {
|
|
|
|
'algo': 'midj',
|
|
|
|
'prompt': 'skynet terminator dystopic',
|
|
|
|
'width': 512,
|
|
|
|
'height': 512,
|
|
|
|
'guidance': 10,
|
|
|
|
'step': 28,
|
|
|
|
'seed': 420,
|
|
|
|
'upscaler': 'x4'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
binary = ''
|
|
|
|
|
|
|
|
ec, out = cleos.push_action(
|
2023-06-04 20:51:43 +00:00
|
|
|
'telos.gpu', 'enqueue', [user, req, binary, '20.0000 GPU', 1], f'{user}@active'
|
2023-05-27 20:50:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert ec == 0
|
|
|
|
|
2023-06-04 20:51:43 +00:00
|
|
|
request_id, _ = collect_stdout(out).split(':')
|
|
|
|
request_id = int(request_id)
|
2023-05-27 20:50:47 +00:00
|
|
|
|
|
|
|
queue = cleos.get_table('telos.gpu', 'telos.gpu', 'queue')
|
|
|
|
|
|
|
|
assert len(queue) == 1
|
|
|
|
|
|
|
|
ec, out = cleos.push_action(
|
|
|
|
'telos.gpu', 'dequeue', [user, request_id], f'{user}@active'
|
|
|
|
)
|
|
|
|
|
|
|
|
assert ec == 0
|
|
|
|
|
|
|
|
queue = cleos.get_table('telos.gpu', 'telos.gpu', 'queue')
|
|
|
|
|
|
|
|
assert len(queue) == 0
|