Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include timestamp and span-compatible attributes in done files #23

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/build/
requirements-test
__pycache__
/src/monobase/_version.py
10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
[project]
name = "monobase"
version = "0.1.0"
description = "Replicate monolithic base dependency build friend"
readme = "README.md"
requires-python = ">=3.13"
dependencies = []
license = {file = "LICENSE"}
dynamic = ["version"]

[build-system]
requires = ["hatchling"]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[tool.hatch.version]
source = "vcs"

[tool.hatch.build.hooks.vcs]
version-file = "src/monobase/_version.py"
28 changes: 22 additions & 6 deletions script/test
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,49 @@ test() {
-d) [ -d "$f" ] || r=1 ;;
-f) [ -f "$f" ] || r=1 ;;
-h) [ -h "$f" ] || r=1 ;;
-s) [ -s "$f" ] || r=1 ;;
-x) [ -x "$f" ] || r=1 ;;
esac

if [ "$r" -eq 0 ]; then
echo "PASS: [ $op /srv/r8/monobase/$2 ]"
else
echo "FAIL: [ $op /srv/r8/monobase/$2 ]"
fail=$((fail+1))
fail=$((fail + 1))
fi
}

is-json() {
f="$PWD/build/monobase/$1"
if jq < "$f" >/dev/null; then
echo "PASS: is-json /srv/r8/monobase/$1"
else
echo "FAIL: is-json /srv/r8/monobase/$1"
fail=$((fail + 1))
fi
}

# Test /srv/r8/monobase structure
test -x 'bin/uv'
test -x 'bin/pget'
test -h 'cog/latest'
test -f 'cog/latest/.done'
test -s 'cog/latest/.done'
is-json 'cog/latest/.done'
test -h 'cog/latest/default-python3.12'
test -h 'monobase/latest'
test -d 'monobase/g00000'
test -f 'monobase/g00000/.done'
test -s 'monobase/g00000/.done'
is-json 'monobase/g00000/.done'
test -h 'monobase/g00000/cuda12.4'
test -f 'monobase/g00000/cuda12.4/.done'
test -s 'monobase/g00000/cuda12.4/.done'
is-json 'monobase/g00000/cuda12.4/.done'
test -h 'monobase/g00000/cudnn9-cuda12'
test -f 'monobase/g00000/cudnn9-cuda12/.done'
test -s 'monobase/g00000/cudnn9-cuda12/.done'
is-json 'monobase/g00000/cudnn9-cuda12/.done'
test -d 'monobase/g00000/ld.so.cache.d'
test -d 'monobase/g00000/python3.12-torch2.4.1-cu124'
test -f 'monobase/g00000/python3.12-torch2.4.1-cu124/.done'
test -s 'monobase/g00000/python3.12-torch2.4.1-cu124/.done'
is-json 'monobase/g00000/python3.12-torch2.4.1-cu124/.done'

if [ "$fail" -gt 0 ]; then
exit 1
Expand Down
31 changes: 24 additions & 7 deletions script/test-mini
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,52 @@ test() {
-d) [ -d "$f" ] || r=1 ;;
-f) [ -f "$f" ] || r=1 ;;
-h) [ -h "$f" ] || r=1 ;;
-s) [ -s "$f" ] || r=1 ;;
-x) [ -x "$f" ] || r=1 ;;
esac

if [ "$r" -eq 0 ]; then
echo "PASS: [ $op /srv/r8/monobase/$2 ]"
else
echo "FAIL: [ $op /srv/r8/monobase/$2 ]"
fail=$((fail+1))
fail=$((fail + 1))
fi
}

is-json() {
f="$PWD/build/monobase/$1"
if jq < "$f" >/dev/null; then
echo "PASS: is-json /srv/r8/monobase/$1"
else
echo "FAIL: is-json /srv/r8/monobase/$1"
fail=$((fail + 1))
fi
}

# Test /srv/r8/monobase structure
test -x 'bin/uv'
test -x 'bin/pget'
test -h 'cog/latest'
test -f 'cog/latest/.done'
test -s 'cog/latest/.done'
is-json 'cog/latest/.done'
test -h 'cog/latest/default-python3.12'
test -h 'monobase/latest'
test -d 'monobase/g00000'
test -f 'monobase/g00000/.done'
test -s 'monobase/g00000/.done'
is-json 'monobase/g00000/.done'
test -h 'monobase/g00000/cuda12.4'
test -f 'monobase/g00000/cuda12.4/.done'
test -s 'monobase/g00000/cuda12.4/.done'
is-json 'monobase/g00000/cuda12.4/.done'
test -h 'monobase/g00000/cudnn9-cuda12'
test -f 'monobase/g00000/cudnn9-cuda12/.done'
test -s 'monobase/g00000/cudnn9-cuda12/.done'
is-json 'monobase/g00000/cudnn9-cuda12/.done'
test -d 'monobase/g00000/ld.so.cache.d'
test -d 'monobase/g00000/python3.12-torch2.4.1-cu124'
test -f 'monobase/g00000/python3.12-torch2.4.1-cu124/.done'
test -s 'monobase/g00000/python3.12-torch2.4.1-cu124/.done'
is-json 'monobase/g00000/python3.12-torch2.4.1-cu124/.done'
test -d 'user'
test -f 'user/.done'
test -s 'user/.done'
is-json 'user/.done'
test -f 'requirements-cog.txt'
test -f 'requirements-mono.txt'
test -f 'requirements-user.txt'
Expand Down
24 changes: 18 additions & 6 deletions src/monobase/build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import datetime
import logging
import os
import os.path
Expand All @@ -16,8 +17,8 @@
add_arguments,
desc_version,
desc_version_key,
is_done,
mark_done,
require_done_or_rm,
setup_logging,
)
from monobase.uv import install_venv
Expand Down Expand Up @@ -87,7 +88,7 @@

def build_generation(args: argparse.Namespace, mg: MonoGen) -> None:
gdir = os.path.join(args.prefix, 'monobase', f'g{mg.id:05d}')
if is_done(gdir):
if require_done_or_rm(gdir):
return

logging.info(f'Building monobase generation {mg.id}...')
Expand All @@ -96,7 +97,10 @@ def build_generation(args: argparse.Namespace, mg: MonoGen) -> None:
for k, v in desc_version_key(mg.cuda):
src = install_cuda(args, v)
dst = f'{gdir}/cuda{k}'
os.symlink(os.path.relpath(src, gdir), dst)
reldst = os.path.relpath(src, gdir)
if os.path.exists(dst):
os.remove(dst)
os.symlink(reldst, dst)
logging.info(f'CUDA symlinked in {dst}')

cuda_major_p = re.compile(r'\.\d+$')
Expand All @@ -105,7 +109,10 @@ def build_generation(args: argparse.Namespace, mg: MonoGen) -> None:
for m in desc_version(cuda_majors):
src = install_cudnn(args, v, m)
dst = f'{gdir}/cudnn{k}-cuda{m}'
os.symlink(os.path.relpath(src, gdir), dst)
reldst = os.path.relpath(src, gdir)
if os.path.exists(dst):
os.remove(dst)
os.symlink(reldst, dst)
logging.info(f'CuDNN symlinked in {dst}')

suffix = '' if args.environment == 'prod' else f'-{args.environment}'
Expand All @@ -118,11 +125,13 @@ def build_generation(args: argparse.Namespace, mg: MonoGen) -> None:
optimize_ld_cache(args, gdir, mg)
optimize_rdfind(args, gdir, mg)

mark_done(gdir)
mark_done(gdir, kind='monogen', **mg.__dict__)
logging.info(f'Generation {mg.id} installed in {gdir}')


def build(args: argparse.Namespace) -> None:
start_time = datetime.datetime.now(datetime.UTC)

monogens = sorted(MONOGENS[args.environment], reverse=True)
if args.mini:
mg = monogens[0]
Expand Down Expand Up @@ -207,7 +216,10 @@ def pick(d: dict[str, str], env: str) -> dict[str, str]:
cmd = ['du', '-ch', '-d', '1', args.prefix]
subprocess.run(cmd, check=True)

logging.info(f'Monobase build completed: {sorted(gens)}')
duration = datetime.datetime.now(datetime.UTC) - start_time
logging.info(
f'Monobase build completed: generations={sorted(gens)} duration={duration}'
)


if __name__ == '__main__':
Expand Down
13 changes: 10 additions & 3 deletions src/monobase/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import shutil
import subprocess

from monobase.util import is_done, mark_done
from monobase.util import mark_done, require_done_or_rm

LINK_REGEX = re.compile(r'<(?P<url>https://[^>]+)>; rel="next"')

Expand Down Expand Up @@ -66,7 +66,7 @@ def install_cogs(args: argparse.Namespace, python_versions: list[str]) -> None:
sha256 = cog_gen_hash(cog_versions, args.default_cog_version, python_versions)[:8]
gid = f'g{sha256}'
gdir = os.path.join(cdir, gid)
if is_done(gdir):
if require_done_or_rm(gdir):
return

logging.info(f'Installing cog generation {gid} in {gdir}...')
Expand All @@ -85,7 +85,14 @@ def install_cogs(args: argparse.Namespace, python_versions: list[str]) -> None:
os.remove(latest)
os.symlink(gid, latest)

mark_done(gdir)
mark_done(
gdir,
kind='cog',
id=gid,
versions=cog_versions,
default_version=args.default_cog_version,
python_versions=python_versions,
)

for g in os.listdir(cdir):
if g in {'latest', gid}:
Expand Down
14 changes: 7 additions & 7 deletions src/monobase/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dataclasses import dataclass

from monobase.urls import cuda_urls, cudnn_urls
from monobase.util import Version, is_done, mark_done
from monobase.util import Version, mark_done, require_done_or_rm


@dataclass(frozen=True, order=True)
Expand Down Expand Up @@ -65,11 +65,11 @@ def build_cudnns() -> dict[str, CuDNN]:

def install_cuda(args: argparse.Namespace, version: str) -> str:
cdir = os.path.join(args.prefix, 'cuda', f'cuda-{version}')
if is_done(cdir):
if require_done_or_rm(cdir):
return cdir
if args.skip_cuda:
os.makedirs(cdir, exist_ok=True)
mark_done(cdir)
mark_done(cdir, kind='cuda', version=version, skipped=True)
logging.info(f'CUDA {version} skipped in {cdir}')
return cdir

Expand Down Expand Up @@ -111,19 +111,19 @@ def install_cuda(args: argparse.Namespace, version: str) -> str:
cmd = ['find', cdir, '-name', 'lib*.a', '-delete']
subprocess.run(cmd, check=True)

mark_done(cdir)
mark_done(cdir, kind='cuda', version=version, url=cuda.url)
logging.info(f'CUDA {version} installed in {cdir}')
return cdir


def install_cudnn(args: argparse.Namespace, version: str, cuda_major: str) -> str:
key = f'{version}-cuda{cuda_major}'
cdir = os.path.join(args.prefix, 'cuda', f'cudnn-{key}')
if is_done(cdir):
if require_done_or_rm(cdir):
return cdir
if args.skip_cuda:
os.makedirs(cdir, exist_ok=True)
mark_done(cdir)
mark_done(cdir, kind='cudnn', version=version, skipped=True)
logging.info(f'CuDNN {key} skipped in {cdir}')
return cdir

Expand All @@ -145,6 +145,6 @@ def install_cudnn(args: argparse.Namespace, version: str, cuda_major: str) -> st
cmd = ['tar', '-xf', file, '--strip-components=1', '--exclude=lib*.a', '-C', cdir]
subprocess.run(cmd, check=True)

mark_done(cdir)
mark_done(cdir, kind='cudnn', version=version, url=cudnn.url)
logging.info(f'CuDNN {key} installed in {cdir}')
return cdir
12 changes: 9 additions & 3 deletions src/monobase/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import subprocess
from typing import Optional

from monobase.util import Version, is_done, mark_done, parse_requirements
from monobase.util import Version, mark_done, parse_requirements, require_done_or_rm
from monobase.uv import cuda_suffix


Expand All @@ -18,7 +18,7 @@ def freeze(uv: str, vdir: str) -> str:

def build_user_venv(args: argparse.Namespace) -> None:
udir = os.path.join(args.prefix, 'user')
if is_done(udir):
if require_done_or_rm(udir):
return

logging.info(f'Building user venv {udir}...')
Expand Down Expand Up @@ -110,5 +110,11 @@ def build_user_venv(args: argparse.Namespace) -> None:
cmd = [uv, 'pip', 'install', '--no-deps', '--requirement', user_req_path]
subprocess.run(cmd, check=True, env=env)

mark_done(udir)
mark_done(
udir,
kind='user',
python_version=python_version,
torch_version=torch_version,
cuda_version=cuda_version,
)
logging.info(f'User venv installed in {udir}')
Loading
Loading