Skip to main content

Add your description here

Project description

This is a python package, called gen_worker, which provides the worker runtime SDK:

  • Orchestrator gRPC client + job loop
  • Function discovery via @worker_function
  • ActionContext + errors + progress events
  • Model downloading from the Cozy hub (async + retries + progress)
  • Output uploads (presigned PUT or S3 creds)

Torch-based model memory management is optional and installed via extras.


Files in src/gen_worker/pb must be auto-generated in the gen-orchestrator repo, using the proto files. Go in there and run task proto

Install modes:

  • Core only: gen-worker
  • Torch runtime add-on: gen-worker[torch] (torch + torchvision + torchaudio + safetensors + flashpack + numpy)

Example tenant projects live in ../worker-example-functions. They use:

  • pyproject.toml + uv.lock for dependencies (no requirements.txt)
  • cozy.toml TOML manifest for deployment config (functions.modules, runtime.base_image, etc.)

Dependency policy:

  • Require pyproject.toml and/or uv.lock
  • Do not use requirements.txt
  • Put Cozy deployment config in cozy.toml

Example:

[functions]
modules = ["functions"]

[runtime]
base_image = "ghcr.io/cozy/python-worker:cuda12.1-torch2.6"

Function signature:

from gen_worker import worker_function, ResourceRequirements, ActionContext

@worker_function(ResourceRequirements(model_family="sdxl", requires_gpu=True))
def generate(ctx: ActionContext, payload: dict) -> dict:
    return {"ok": True}

Dynamic checkpoints:

  • Use ResourceRequirements(model_family=...) to declare a family (e.g., "sdxl")
  • Pass the exact checkpoint at runtime via request payload (e.g., model_ref)

Build contract (gen-builder):

  • Tenant code + pyproject.toml/uv.lock + cozy.toml are packaged together
  • gen-builder layers tenant code + deps on top of a python-worker base image
  • gen-orchestrator deploys the resulting worker image

Env hints:

  • SCHEDULER_ADDR sets the primary scheduler address.
  • SCHEDULER_ADDRS (comma-separated) provides seed addresses for leader discovery.
  • WORKER_JWT is accepted as the auth token if AUTH_TOKEN is not set.
  • SCHEDULER_JWKS_URL enables verification of WORKER_JWT before connecting.
  • JWT verification uses RSA and requires PyJWT crypto support (installed by default via PyJWT[crypto]).
  • WORKER_MAX_INPUT_BYTES, WORKER_MAX_OUTPUT_BYTES, WORKER_MAX_UPLOAD_BYTES cap payload sizes.
  • WORKER_MAX_CONCURRENCY limits concurrent runs; ResourceRequirements(max_concurrency=...) limits per-function.
  • COZY_HUB_URL base URL for Cozy hub downloads (used by core downloader).
  • COZY_HUB_TOKEN optional bearer token for Cozy hub downloads.
  • MODEL_MANAGER_CLASS optional ModelManager plugin (module:Class) loaded at startup.

Error hints:

  • Use gen_worker.errors.RetryableError in worker functions to flag retryable failures.

Output upload hints:

  • To upload raw bytes, include an output_upload object in the job input:
    • Presigned PUT:
      • {"output_upload":{"put_url":"...","headers":{"Content-Type":"image/png"},"public_url":"https://..."}}
    • S3 creds:
      • {"output_upload":{"s3":{"bucket":"...","key":"...","region":"...","access_key_id":"...","secret_access_key":"..."}}}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gen_worker-0.1.4.tar.gz (198.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gen_worker-0.1.4-py3-none-any.whl (81.3 kB view details)

Uploaded Python 3

File details

Details for the file gen_worker-0.1.4.tar.gz.

File metadata

  • Download URL: gen_worker-0.1.4.tar.gz
  • Upload date:
  • Size: 198.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gen_worker-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ffb560809211d7fc065bbfd3f6ad0ceaa433249dae0024dc2102a97e82ed9f72
MD5 8f2d35b81171bf260c761184c263427e
BLAKE2b-256 dd2e516a5545b2d14da237694aa16486e8eece776320571fb0658a1d482c7c6b

See more details on using hashes here.

File details

Details for the file gen_worker-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: gen_worker-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 81.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gen_worker-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a07655aa3ae7b40251f63a8b972b59e1aa4195e22ce5dc4decb7847119883e02
MD5 dac1f9e4d8bd77439bf9ea71a4548628
BLAKE2b-256 79b639c777c44a6d12bf5bc7729f95d8a2e794187a87996ca2aceb9caba82bfb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page