Skip to content

Distributed collections

Distributed collections are available inside functions running on a compute. They are replicated across the compute's nodes and accessed synchronously from the task's worker.

Values are serialized by Skyward. Map keys must be hashable because they are used to route operations. Collections replicate to min(3, nodes) members.

Consistency

strong is the default. Writes require a majority acknowledgement. eventual acknowledges on one replica and reads the nearest copy; use it for state where lower coordination cost is acceptable.

counts = sky.counter("processed", consistency="eventual")

Collections

Factory Operations
sky.dict(name) Mapping operations, get, pop, items, clear
sky.set(name) add, remove, membership, items, clear
sky.counter(name) add, get, reset
sky.queue(name) Non-blocking offer, poll, len, clear
sky.registry(name) register, lookup, unregister, list
sky.barrier(name, parties) Wait for the configured number of participants
sky.lock(name, ttl=30, timeout=None) Context-manager lease across the compute
@sky.function
def save_checkpoint(step, model):
    checkpoints = sky.registry("checkpoints")
    checkpoints.register(step, model)
    return checkpoints.list()

@sky.function
def worker_step(batch):
    processed = sky.counter("processed")
    processed.add(len(batch))
    with sky.lock("checkpoint"):
        write_checkpoint()

queue.poll() does not block: an empty queue returns None. A lock is released when its context exits; its lease also expires if the holder dies.

skyward.Consistency = Literal['strong', 'eventual']

How hard a write is acknowledged before the call returns.

  • "strong" — the default: a majority of replicas must ack, so a value read back after a write is the value written, and it survives losing a minority.
  • "eventual" — one replica acks and reads take the nearest copy. Cheaper, and enough when a collection is a scratchpad rather than a source of truth.

skyward.DistributedRegistry

A named place to leave objects for the other nodes to find.

models = sky.registry("checkpoints")
models.register(step, model)          # on the node that trained it
model = models.lookup(latest_step)    # on any node that wants it

A map with a directory's vocabulary — register a value under a name, lookup it from anywhere, list the names on offer. It replicates and survives a dead node the same way the other collections do.

__init__(name)

register(key, value)

lookup(key)

unregister(key)

list()

skyward.dict(name, consistency='strong')

skyward.set(name, consistency='strong')

skyward.counter(name, consistency='strong')

skyward.registry(name)

skyward.queue(name)

skyward.barrier(name, parties)

skyward.lock(name, ttl=30.0, timeout=None)