Drop separate reqs file for tests

Update docker containers
Create cli helpers for interacting with skynet
Add test
Begin adding hyperion api to telegram frontend
add-txt2txt-models
Guillermo Rodriguez 2023-05-27 17:50:47 -03:00
parent dcd020f0da
commit 3607c568de
No known key found for this signature in database
GPG Key ID: EC3AB66D5D83B392
8 changed files with 214 additions and 53 deletions

View File

@ -4,7 +4,6 @@ env DEBIAN_FRONTEND=noninteractive
workdir /skynet workdir /skynet
copy requirements.test.txt requirements.test.txt
copy requirements.txt requirements.txt copy requirements.txt requirements.txt
copy pytest.ini ./ copy pytest.ini ./
copy setup.py ./ copy setup.py ./
@ -12,8 +11,6 @@ copy skynet ./skynet
run pip install \ run pip install \
-e . \ -e . \
-r requirements.txt \ -r requirements.txt
-r requirements.test.txt
copy scripts ./
copy tests ./ copy tests ./

View File

@ -1,5 +1,5 @@
from nvidia/cuda:11.7.0-devel-ubuntu20.04 from nvidia/cuda:11.7.0-devel-ubuntu20.04
from python:3.10.0 from python:3.11
env DEBIAN_FRONTEND=noninteractive env DEBIAN_FRONTEND=noninteractive
@ -15,21 +15,15 @@ run pip install -v -r requirements.cuda.0.txt
run pip install -v -r requirements.cuda.1.txt run pip install -v -r requirements.cuda.1.txt
run pip install -v -r requirements.cuda.2.txt run pip install -v -r requirements.cuda.2.txt
copy requirements.test.txt requirements.test.txt
copy requirements.txt requirements.txt copy requirements.txt requirements.txt
copy pytest.ini pytest.ini copy pytest.ini pytest.ini
copy setup.py setup.py copy setup.py setup.py
copy skynet skynet copy skynet skynet
run pip install -e . \ run pip install -e . -r requirements.txt
-r requirements.txt \
-r requirements.test.txt
env PYTORCH_CUDA_ALLOC_CONF max_split_size_mb:128 env PYTORCH_CUDA_ALLOC_CONF max_split_size_mb:128
env NVIDIA_VISIBLE_DEVICES=all env NVIDIA_VISIBLE_DEVICES=all
env HF_HOME /hf_home env HF_HOME /hf_home
copy scripts scripts
copy tests tests copy tests tests
expose 40000-45000

View File

@ -1,6 +0,0 @@
pdbpp
pytest
docker
psycopg2-binary
git+https://github.com/guilledk/py-leap.git@async_net_requests#egg=py-eosio

View File

@ -1,9 +1,13 @@
trio trio
asks asks
numpy numpy
pdbpp
Pillow Pillow
triopg triopg
pytest
docker
aiohttp aiohttp
psycopg2-binary
pyTelegramBotAPI pyTelegramBotAPI
git+https://github.com/goodboy/tractor.git@master#egg=tractor py-leap@git+https://github.com/guilledk/py-leap.git@v0.1a11

View File

@ -1,6 +1,4 @@
#!/usr/bin/python #!/usr/bin/python
import importlib.util
torch_enabled = importlib.util.find_spec('torch') != None
import os import os
import json import json
@ -13,17 +11,14 @@ import trio
import click import click
import docker import docker
import asyncio import asyncio
import requests
from leap.cleos import CLEOS, default_nodeos_image from leap.cleos import CLEOS, default_nodeos_image
from leap.sugar import get_container from leap.sugar import get_container, collect_stdout
if torch_enabled:
from . import utils
from .dgpu import open_dgpu_node
from .db import open_new_database from .db import open_new_database
from .config import * from .config import *
from .nodeos import open_nodeos from .nodeos import open_cleos, open_nodeos
from .constants import ALGOS from .constants import ALGOS
from .frontend.telegram import run_skynet_telegram from .frontend.telegram import run_skynet_telegram
@ -44,6 +39,7 @@ def skynet(*args, **kwargs):
@click.option('--steps', '-s', default=26) @click.option('--steps', '-s', default=26)
@click.option('--seed', '-S', default=None) @click.option('--seed', '-S', default=None)
def txt2img(*args, **kwargs): def txt2img(*args, **kwargs):
from . import utils
_, hf_token, _, cfg = init_env_from_config() _, hf_token, _, cfg = init_env_from_config()
utils.txt2img(hf_token, **kwargs) utils.txt2img(hf_token, **kwargs)
@ -58,6 +54,7 @@ def txt2img(*args, **kwargs):
@click.option('--steps', '-s', default=26) @click.option('--steps', '-s', default=26)
@click.option('--seed', '-S', default=None) @click.option('--seed', '-S', default=None)
def img2img(model, prompt, input, output, strength, guidance, steps, seed): def img2img(model, prompt, input, output, strength, guidance, steps, seed):
from . import utils
_, hf_token, _, cfg = init_env_from_config() _, hf_token, _, cfg = init_env_from_config()
utils.img2img( utils.img2img(
hf_token, hf_token,
@ -76,6 +73,7 @@ def img2img(model, prompt, input, output, strength, guidance, steps, seed):
@click.option('--output', '-o', default='output.png') @click.option('--output', '-o', default='output.png')
@click.option('--model', '-m', default='weights/RealESRGAN_x4plus.pth') @click.option('--model', '-m', default='weights/RealESRGAN_x4plus.pth')
def upscale(input, output, model): def upscale(input, output, model):
from . import utils
utils.upscale( utils.upscale(
img_path=input, img_path=input,
output=output, output=output,
@ -84,9 +82,104 @@ def upscale(input, output, model):
@skynet.command() @skynet.command()
def download(): def download():
from . import utils
_, hf_token, _, cfg = init_env_from_config() _, hf_token, _, cfg = init_env_from_config()
utils.download_all_models(hf_token) utils.download_all_models(hf_token)
@skynet.command()
@click.option(
'--account', '-a', default='telegram1')
@click.option(
'--permission', '-p', default='active')
@click.option(
'--key', '-k', default=None)
@click.option(
'--node-url', '-n', default='http://skynet.ancap.tech')
@click.option('--algo', '-a', default='midj')
@click.option(
'--prompt', '-p', default='a red old tractor in a sunny wheat field')
@click.option('--output', '-o', default='output.png')
@click.option('--width', '-w', default=512)
@click.option('--height', '-h', default=512)
@click.option('--guidance', '-g', default=10)
@click.option('--step', '-s', default=26)
@click.option('--seed', '-S', default=420)
@click.option('--upscaler', '-U', default='x4')
def enqueue(
account: str,
permission: str,
key: str | None,
node_url: str,
**kwargs
):
with open_cleos(node_url, key=key) as cleos:
req = json.dumps({
'method': 'diffuse',
'params': kwargs
})
binary = ''
ec, out = cleos.push_action(
'telos.gpu', 'enqueue', [account, req, binary], f'{account}@{permission}'
)
assert ec == 0
print(collect_stdout(out))
@skynet.command()
@click.option(
'--node-url', '-n', default='http://skynet.ancap.tech')
def queue(node_url: str):
resp = requests.post(
f'{node_url}/v1/chain/get_table_rows',
json={
'code': 'telos.gpu',
'table': 'queue',
'scope': 'telos.gpu',
'json': True
}
)
print(json.dumps(resp.json(), indent=4))
@skynet.command()
@click.option(
'--node-url', '-n', default='http://skynet.ancap.tech')
@click.argument('request-id')
def status(node_url: str, request_id: int):
resp = requests.post(
f'{node_url}/v1/chain/get_table_rows',
json={
'code': 'telos.gpu',
'table': 'status',
'scope': request_id,
'json': True
}
)
print(json.dumps(resp.json(), indent=4))
@skynet.command()
@click.option(
'--account', '-a', default='telegram1')
@click.option(
'--permission', '-p', default='active')
@click.option(
'--key', '-k', default=None)
@click.option(
'--node-url', '-n', default='http://skynet.ancap.tech')
@click.argument('request-id')
def dequeue(
account: str,
permission: str,
key: str | None,
node_url: str,
request_id: int
):
with open_cleos(node_url, key=key) as cleos:
ec, out = cleos.push_action(
'telos.gpu', 'dequeue', [account, request_id], f'{account}@{permission}'
)
assert ec == 0
@skynet.group() @skynet.group()
def run(*args, **kwargs): def run(*args, **kwargs):
@ -114,7 +207,7 @@ def nodeos():
@click.option( @click.option(
'--key', '-k', default=None) '--key', '-k', default=None)
@click.option( @click.option(
'--node-url', '-n', default='http://test1.us.telos.net:42000') '--node-url', '-n', default='http://skynet.ancap.tech')
@click.option( @click.option(
'--algos', '-A', default=json.dumps(['midj'])) '--algos', '-A', default=json.dumps(['midj']))
def dgpu( def dgpu(
@ -125,25 +218,30 @@ def dgpu(
node_url: str, node_url: str,
algos: list[str] algos: list[str]
): ):
dclient = docker.from_env() from .dgpu import open_dgpu_node
vtestnet = get_container( vtestnet = None
dclient, try:
default_nodeos_image(), dclient = docker.from_env()
force_unique=True, vtestnet = get_container(
detach=True, dclient,
network='host', default_nodeos_image(),
remove=True) force_unique=True,
detach=True,
network='host',
remove=True)
cleos = CLEOS(dclient, vtestnet, url=node_url, remote=node_url) cleos = CLEOS(dclient, vtestnet, url=node_url, remote=node_url)
trio.run( trio.run(
partial( partial(
open_dgpu_node, open_dgpu_node,
account, permission, account, permission,
cleos, key=key, initial_algos=json.loads(algos) cleos, key=key, initial_algos=json.loads(algos)
)) ))
vtestnet.stop() finally:
if vtestnet:
vtestnet.stop()
@run.command() @run.command()
@ -155,7 +253,7 @@ def dgpu(
@click.option( @click.option(
'--key', '-k', default=None) '--key', '-k', default=None)
@click.option( @click.option(
'--node-url', '-n', default='http://test1.us.telos.net:42000') '--node-url', '-n', default='http://skynet.ancap.tech')
@click.option( @click.option(
'--db-host', '-h', default='localhost:5432') '--db-host', '-h', default='localhost:5432')
@click.option( @click.option(

View File

@ -12,6 +12,7 @@ import docker
from PIL import Image from PIL import Image
from leap.cleos import CLEOS, default_nodeos_image from leap.cleos import CLEOS, default_nodeos_image
from leap.sugar import get_container, collect_stdout from leap.sugar import get_container, collect_stdout
from leap.hyperion import HyperionAPI
from trio_asyncio import aio_as_trio from trio_asyncio import aio_as_trio
from telebot.types import ( from telebot.types import (
InputFile, InputMediaPhoto, InlineKeyboardButton, InlineKeyboardMarkup InputFile, InputMediaPhoto, InlineKeyboardButton, InlineKeyboardMarkup
@ -53,7 +54,6 @@ def prepare_metainfo_caption(tguser, meta: dict) -> str:
meta_str += f'algo: \"{meta["algo"]}\"\n' meta_str += f'algo: \"{meta["algo"]}\"\n'
if meta['upscaler']: if meta['upscaler']:
meta_str += f'upscaler: \"{meta["upscaler"]}\"\n' meta_str += f'upscaler: \"{meta["upscaler"]}\"\n'
meta_str += f'sampler: k_euler_ancestral\n'
meta_str += f'skynet v{VERSION}' meta_str += f'skynet v{VERSION}'
return meta_str return meta_str
@ -78,6 +78,7 @@ async def run_skynet_telegram(
remove=True) remove=True)
cleos = CLEOS(dclient, vtestnet, url=node_url, remote=node_url) cleos = CLEOS(dclient, vtestnet, url=node_url, remote=node_url)
hyperion = HyperionAPI(node_url)
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)

View File

@ -7,8 +7,38 @@ from contextlib import contextmanager as cm
import docker import docker
from leap.cleos import CLEOS from leap.cleos import CLEOS, default_nodeos_image
from leap.sugar import get_container, Symbol from leap.sugar import get_container, Symbol, random_string
@cm
def open_cleos(
node_url: str,
key: str | None
):
vtestnet = None
try:
dclient = docker.from_env()
vtestnet = get_container(
dclient,
default_nodeos_image(),
name=f'skynet-wallet-{random_string(size=8)}',
force_unique=True,
detach=True,
network='host',
remove=True)
cleos = CLEOS(dclient, vtestnet, url=node_url, remote=node_url)
if key:
cleos.setup_wallet(key)
yield cleos
finally:
if vtestnet:
vtestnet.stop()
@cm @cm
@ -17,6 +47,7 @@ def open_nodeos(cleanup: bool = True):
vtestnet = get_container( vtestnet = get_container(
dclient, dclient,
'guilledk/py-eosio:leap-skynet-4.0.0', 'guilledk/py-eosio:leap-skynet-4.0.0',
name='skynet-nodeos',
force_unique=True, force_unique=True,
detach=True, detach=True,
network='host') network='host')
@ -38,20 +69,19 @@ def open_nodeos(cleanup: bool = True):
time.sleep(0.5) time.sleep(0.5)
public_dev_key = 'EOS5fLreY5Zq5owBhmNJTgQaLqQ4ufzXSTpStQakEyfxNFuUEgNs1'
cleos.setup_wallet('5JnvSc6pewpHHuUHwvbJopsew6AKwiGnexwDRc2Pj2tbdw6iML9') cleos.setup_wallet('5JnvSc6pewpHHuUHwvbJopsew6AKwiGnexwDRc2Pj2tbdw6iML9')
cleos.wait_blocks(1) cleos.wait_blocks(1)
cleos.boot_sequence(token_sym=Symbol('GPU', 4)) cleos.boot_sequence(token_sym=Symbol('GPU', 4))
cleos.new_account('telos.gpu', ram=300000) cleos.new_account('telos.gpu', ram=300000, key=public_dev_key)
for i in range(1, 4): for i in range(1, 4):
cleos.create_account_staked( cleos.create_account_staked(
'eosio', f'testworker{i}', 'eosio', f'testworker{i}', key=public_dev_key)
key='EOS5fLreY5Zq5owBhmNJTgQaLqQ4ufzXSTpStQakEyfxNFuUEgNs1')
cleos.create_account_staked( cleos.create_account_staked(
'eosio', 'telegram1', ram=500000, 'eosio', 'telegram1', ram=500000, key=public_dev_key)
key='EOS5fLreY5Zq5owBhmNJTgQaLqQ4ufzXSTpStQakEyfxNFuUEgNs1')
cleos.deploy_contract_from_host( cleos.deploy_contract_from_host(
'telos.gpu', 'telos.gpu',

View File

@ -11,6 +11,8 @@ import requests
from skynet.dgpu import open_dgpu_node from skynet.dgpu import open_dgpu_node
from leap.sugar import collect_stdout
def test_enqueue_work(cleos): def test_enqueue_work(cleos):
@ -79,3 +81,44 @@ def test_enqueue_work(cleos):
assert resp.status_code == 200 assert resp.status_code == 200
assert sha_hash == sha256(resp.content).hexdigest() assert sha_hash == sha256(resp.content).hexdigest()
def test_enqueue_dequeue(cleos):
user = cleos.new_account()
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(
'telos.gpu', 'enqueue', [user, req, binary], f'{user}@active'
)
assert ec == 0
request_id = int(collect_stdout(out))
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