reflop

module
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: Apache-2.0

README

reFLOP

CI Release

PyTorch C Go

Linux macOS

Lend your GPU as a calculator.

Guests send tensor math. Never code execution, never shell access.

Install · Quick Start · How it works · Security · Docs Website


Run existing PyTorch code with a prefix:

reflop run python train.py    # code that uses device="cuda"

Or use the reflop library and run the script as usual:

import torch, reflop

dev = reflop.device()         # the connected GPU
model = MyModel().to(dev)     # weights live on the server

for x, y in loader:
    loss = loss_fn(model(x.to(dev)), y.to(dev))
    loss.backward()
    opt.step(); opt.zero_grad()
    print(loss.item())        # only this number comes back
python3 train.py

[!IMPORTANT] The server never runs Guest code. Requests can only use a closed set of 592 operators (571 PyTorch overloads, 21 reFLOP-native). Each request is validated, then run in a sandboxed worker. There is no request for "delete a file", "open a socket" or "start a process".

Guest requests reach a wall of 592 operators. Operator calls such as aten.mm, aten.convolution and aten.relu pass through, are validated, and run in a sandboxed worker on the Owner's machine. Things like rm -rf /, exec or socket() are not operators, so no request can express them.

Install

Guest: reflop Owner: reflopd
Platform macOS or Linux Linux x86_64 or aarch64, glibc ≥ 2.28
Requires Python ≥ 3.10, PyTorch ≥ 2.6 NVIDIA driver ≥ 525

Guest

# Recommended
uv add reflop

# Or
pip install reflop
# Or Install script
curl -fsSL https://reflop.ai/install.sh | sh
  • You get the Python library (import reflop) and the reflop command.
  • The install script uses the active virtual environment, or creates its own.

Owner

# Installs reflopd to ~/.local/bin
curl -fsSL https://reflop.ai/install.sh | sh -s -- --server
Update
reflop update      # Guest
reflopd update     # Owner

Each command updates only its own program to the newest release, after checking the release signature.

  • uv project: upgrades reflop in uv.lock and syncs, so uv run keeps the new version.
  • pip environment: installs the release's wheel.
  • pip install -U reflop and uv lock --upgrade-package reflop && uv sync also work. The files on PyPI are the files of the signed GitHub release.

[!WARNING] On 0.2.0 or earlier, plain update can fail because the repository moved. Run reflop update --version v0.2.1 or reflopd update --version v0.2.1 once, then use plain update.

From the Releases tab

Download reflopd_0.6.2_linux_<arch>.tar.gz or reflop-0.6.2-py3-none-any.whl from Releases with checksums.txt and checksums.txt.sig. Check the signature, then the file:

echo 'reflop-release ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKqs9C0dx4nGfqCL1Vw0hgwleOGNaDOPYyMBCwYU3lsW' > allowed_signers
ssh-keygen -Y verify -f allowed_signers -I reflop-release -n reflop-release -s checksums.txt.sig < checksums.txt
sha256sum --check --ignore-missing checksums.txt

Then put reflopd on your PATH or pip install the wheel.

Build from source

Requires Go (see go.mod) and, for the client, Python 3.10+:

git clone https://github.com/reflopai/reflop.git && cd reflop
make build                                  # bin/reflopd, with the worker embedded
pip install ./client/python                 # the reFLOP client

Quick Start

Owner

sudo ufw allow 7460/tcp                  # only if ufw is enabled
reflopd up --listen <IP-addr>:7460       # Tailscale address recommended
reflopd invite --name alice              # prints a pairing code

Guest

reflop pair reflop1-baaraai2b4…          # paste the pairing code
reflop status

reflop test --unet                       # measure throughput (Owner needs reflopd ≥ 0.4.2)
reflop test --resnet
reflop test --all

python reflop_train.py                   # code that imports reflop
reflop run python train.py               # or any script, with the prefix

Multiple GPUs

Each GPU gets its own pairing code. To the Guest, every GPU is a separate server, whether or not they share a machine.

Owner

reflopd gpu list                                          # list GPUs

reflopd up --gpu 0 --listen <LAN-or-Tailscale-addr>:7460  # expose GPUs one by one
reflopd up --gpu 2 --listen <LAN-or-Tailscale-addr>:7460
reflopd up --gpu 0 --gpu 2 --listen <LAN-or-Tailscale-addr>:7460   # or together

reflopd invite --name alice --gpu 0                       # one code per GPU
reflopd invite --name alice --gpu 2
reflopd unpair alice --gpu 0

Guest

reflop pair <gpu-0-code>                       # default name: the GPU model
reflop pair <gpu-2-code> --name lab-5090       # or choose a name

reflop rename <current-name> <new-name>
reflop use lab-5090                            # switch the default GPU
reflop unpair nvidia-h100
  • Default names use the GPU model: nvidia-h100, then nvidia-h100-2.
  • reflop status shows whether each pairing is online.

How it works

Your Python stays on your machine. Only tensor operations go to the GPU.

Each time you ask for a value, such as loss.item():

  • Shapes are computed locally, so shape checks never wait on the network.
  • Weights and optimizer state stay on the server.
  • A repeated graph is sent once; later steps send only new inputs.

What the Owner is protected from

[!TIP] reflopd doctor shows which protections are active on your machine, and reflopd selftest --security checks them on a live worker. Details: threat model.

Datasets

Decode and preprocess on your laptop and upload once. After that, each step sends only batch indices.

reflop data build --from my_data:load --out ./cifar_pack   # runs your code locally
reflop data push ./cifar_pack --name cifar10               # resumable, verified per 4 MiB chunk
ds = reflop.dataset("cifar10")
for batch in ds.loader(batch_size=128, shuffle=True, seed=0):
    x = batch["images"].float() / 255     # gathered on the server
    y = batch["labels"]

Fast steady-state training

Eager mode records every operation on every step, at tens of microseconds per operation on the client. If a step's graph does not change, reflop.capture replays it on the server without running your Python:

step = reflop.capture(train_step)     # train_step(x, y) -> loss
for x, y in data:
    loss = step(x, y)                 # one request per step after two warm-up calls

  • CUDA graphs (0.6.0). The worker records a captured step's kernels once and launches them together when timing shows that is faster. Steps with many small operations no longer wait on each launch (ADR-076).
  • LSTM and GRU (0.6.1). The 0.6.0 run used one fused cell per timestep; native PyTorch runs cuDNN over the whole sequence. Since 0.6.1 each layer is one operation, and a stack of layers is one operation whose layers overlap on the GPU (ADR-077, ADR-078). A captured two-layer LSTM step at batch 128 went from 5.1 ms to 2.5 ms (native cuDNN: 1.7 ms). See recurrent layers.
  • Very short steps are bound by the request. An MLP step runs on the server in 0.15–0.19 ms but takes 0.5–0.6 ms on the Guest.
  • Uploading inputs every step is bound by the network. At about 10 MiB/s and a 4.0 ms round trip, these cases keep 0.2–76% of native speed, depending on how much a step uploads. A dataset keeps the data on the server at 8 bytes per sample, and took the CNN from 142 ms to 2.3 ms per step.
  • Long runs are stable. A 20-minute soak ran 83,400 steps at a constant 14.1 ms/step, with flat memory use.

reflop test --<architecture> (for example reflop test --transformer) measures your own setup in about 10 seconds. To reproduce the full run, see benchmark/; this run's data is in the report.

[!NOTE] Steps whose Python numbers change every step, such as a non-capturable Adam's bias correction or a Python learning-rate schedule, are detected and refused. Use capturable=True or tensor learning rates.

Limitations

See all limitations and automatic checkpoints.

Documentation

runtime.reflop.ai has these guides as a searchable site, with the Python API, the operator set and the changelog.

Guide Covers
Owner guide setup, exposure, Level 1, SSH mode, rails, quotas, troubleshooting
Guest guide API, capture, datasets, placement, what works and what doesn't
C and C++ API libreflop for non-Python programs

Design: Threat model · Design decisions · Spike report · Operator set

Development

make build              # bin/reflopd
make test               # Go tests (race) and Python tests
make lint               # gofmt, go vet, ruff, and the I1/I2 static check
make build-probes       # test build with isolation probes (never ship it)
make test-isolation     # run the probes inside real sandboxed workers
make clib               # libreflop and the C/C++ examples

See CONTRIBUTING.md, SECURITY.md and the Code of Conduct.

License

Apache-2.0

Directories

Path Synopsis
clib
go command
Command libreflop builds the reFLOP C API as a shared library:
Command libreflop builds the reFLOP C API as a shared library:
pkg
opset
Package opset exposes opset v1 (generated from opset/v1/opset.yaml, the single source of truth, invariant I10) to Go code: reflopd and libreflop.
Package opset exposes opset v1 (generated from opset/v1/opset.yaml, the single source of truth, invariant I10) to Go code: reflopd and libreflop.
sshhost
Package sshhost handles the sshd host keys that SSH invites carry, so the Guest's ssh trusts exactly the host the Owner paired them with (SEC_SWEEP L6).
Package sshhost handles the sshd host keys that SSH invites carry, so the Guest's ssh trusts exactly the host the Owner paired them with (SEC_SWEEP L6).
wire
Package wire implements reflop framing: a uint32 big-endian length prefix followed by a protobuf message.
Package wire implements reflop framing: a uint32 big-endian length prefix followed by a protobuf message.
Package server embeds the Python worker into reflopd so that a single binary carries everything the Owner needs (PLAN.md §4.2).
Package server embeds the Python worker into reflopd so that a single binary carries everything the Owner needs (PLAN.md §4.2).
reflopd/cmd/reflopd command
Command reflopd is the reFLOP server daemon.
Command reflopd is the reFLOP server daemon.
reflopd/internal/audit
Package audit keeps an append-only, per-identity log of what Guests did (PLAN.md §9.9): registrations, executes, transfers, validation failures, rail hits and kills.
Package audit keeps an append-only, per-identity log of what Guests did (PLAN.md §9.9): registrations, executes, transfers, validation failures, rail hits and kills.
reflopd/internal/auth
Package auth manages the server key, Guest identities, invites, and the challenge-response authentication of PLAN.md §15 (ADR-006).
Package auth manages the server key, Guest identities, invites, and the challenge-response authentication of PLAN.md §15 (ADR-006).
reflopd/internal/buildinfo
Package buildinfo carries version metadata injected at build time with -ldflags "-X github.com/reflopai/reflop/server/reflopd/internal/buildinfo.Version=...".
Package buildinfo carries version metadata injected at build time with -ldflags "-X github.com/reflopai/reflop/server/reflopd/internal/buildinfo.Version=...".
reflopd/internal/cgroup
Package cgroup manages worker cgroups inside a delegated cgroup v2 subtree (systemd user service or scope with Delegate=yes, or the Level 1 system unit).
Package cgroup manages worker cgroups inside a delegated cgroup v2 subtree (systemd user service or scope with Delegate=yes, or the Level 1 system unit).
reflopd/internal/cli
Package cli implements the reflopd command line (PLAN.md §16.1).
Package cli implements the reflopd command line (PLAN.md §16.1).
reflopd/internal/config
Package config holds reflopd settings.
Package config holds reflopd settings.
reflopd/internal/gpu
Package gpu detects NVIDIA GPUs and the driver without loading CUDA in reflopd (reflopd never touches the GPU, PLAN.md §9.1).
Package gpu detects NVIDIA GPUs and the driver without loading CUDA in reflopd (reflopd never touches the GPU, PLAN.md §9.1).
reflopd/internal/paths
Package paths decides every server-side location.
Package paths decides every server-side location.
reflopd/internal/rails
Package rails implements the always-on safety rails of PLAN.md §9.6: a disk free floor on the store filesystem and a host RAM floor.
Package rails implements the always-on safety rails of PLAN.md §9.6: a disk free floor on the store filesystem and a host RAM floor.
reflopd/internal/runtime
Package runtime installs the pinned compute runtime: a standalone CPython plus PyTorch wheels whose SHA-256 hashes are embedded in this reflopd build (lock.json, generated by codegen/lock_runtime.py).
Package runtime installs the pinned compute runtime: a standalone CPython plus PyTorch wheels whose SHA-256 hashes are embedded in this reflopd build (lock.json, generated by codegen/lock_runtime.py).
reflopd/internal/selfupdate
Package selfupdate replaces the running reflopd binary with a published GitHub release.
Package selfupdate replaces the running reflopd binary with a published GitHub release.
reflopd/internal/server
Package server is reflopd's daemon: listeners, authentication, sessions, workers, rails, Owner controls and audit (PLAN.md §9).
Package server is reflopd's daemon: listeners, authentication, sessions, workers, rails, Owner controls and audit (PLAN.md §9).
reflopd/internal/sshpipe
Package sshpipe manages SSH pipe mode (PLAN.md §4.4, §15.4): the Guest's key goes into authorized_keys with restrict and a forced command, so SSH is a pipe that can only run `reflopd serve --stdio`, never a shell.
Package sshpipe manages SSH pipe mode (PLAN.md §4.4, §15.4): the Guest's key goes into authorized_keys with restrict and a forced command, so SSH is a pipe that can only run `reflopd serve --stdio`, never a shell.
reflopd/internal/store
Package store keeps each identity's TensorPacks content-addressed under a server-chosen path: <root>/<identity>/blobs/<sha256> (invariant I7).
Package store keeps each identity's TensorPacks content-addressed under a server-chosen path: <root>/<identity>/blobs/<sha256> (invariant I7).
reflopd/internal/supervisor
Package supervisor spawns, watches and kills sandboxed workers: one process per (identity, session), invariant I5.
Package supervisor spawns, watches and kills sandboxed workers: one process per (identity, session), invariant I5.
reflopd/internal/suspend
Package suspend moves a worker's GPU memory to host RAM and back with the CUDA driver's process checkpoint API (ADR-030).
Package suspend moves a worker's GPU memory to host RAM and back with the CUDA driver's process checkpoint API (ADR-030).
reflopd/internal/usage
Package usage accounts how much compute each Guest identity has used.
Package usage accounts how much compute each Guest identity has used.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL