pytensor-federated
This package implements federated computing with PyTensor.
Using pytensor-federated, differentiable cost functions can be computed on federated nodes.
Inputs and outputs are transmitted in binary via a bidirectional gRPC stream.
A client side LogpGradOp is provided to conveniently embed federated compute operations in PyTensor graphs such as a PyMC model.
The example code implements a simple Bayesian linear regression to data that is "private" to the federated compute process.
Run each command in its own terminal:
python demo_node.py
python demo_model.py
Architecture
pytensor-federated is designed to be a very generalizable framework for federated computing with gRPC, but it comes with implementations for PyTensor, and specifically for use cases of Bayesian inference.
This is reflected in the actual implementation, where the most basic gRPC service implementation -- the ArraysToArraysService -- is wrapped by a few implementation flavors, specifically for common use cases in Bayesian inference.
At the core, everything is built around an ArraysToArrays gRPC service, which takes any number of (NumPy) arrays as parameters, and returns any number of (NumPy) arrays as outputs.
The arrays can have arbitrary dtype or shape, as long as the buffer interface is supported (meaning dtype=object doesn't work, but datetime dtypes are ok).
This ArraysToArraysService can be used to wrap arbitrary model functions, thereby enabling to run model simulations and MCMC/optimization on different machines.
The protobuf files that specify the data types and gRPC interface can be compiled to other programming languages, such that the model implementation could be C++, while MCMC/optimization run in Python.
For the Bayesian inference or optimization use case, it helps to first understand the inputs and outputs of the undelying computation graph. For example, parameter estimation with a differential equation model requires...
observationsto which the model should be fittedtimepointsat which there were observations- parameters (including initial states)
theta, some of which are to be estimated
From timepoints and parameters theta, the model predicts trajectories.
Together with observations, these predictions are fed into some kind of likelihood function, which produces a scalar log-likelihood log-likelihood as the output.
Different sub-graphs of this example could be wrapped by an ArraysToArraysService:
[theta,] -> [log-likelihood,][timepoints, theta] -> [trajectories,][timepoints, observations, theta] -> [log-likelihood,]
If the entire model is differentiable, one can even return gradients.
For example, with a linear model: [slope, intercept] -> [LL, dLL_dslope, dLL_dintercept].
The role of PyTensor here is purely technical:
PyTensor is a graph computation framework that implements auto-differentiation.
Wrapping the ArraysToArraysServiceClient in PyTensor Ops simply makes it easier to build more sophisticated compute graphs.
PyTensor is also the computatation backend for PyMC, which is the most popular framework for Bayesian inference in Python.
Installation & Contributing
conda env create -f environment.yml
Additional dependencies are needed to compile the protobufs:
conda install -c conda-forge libprotobuf-static
pip install --pre betterproto[compiler]
python protobufs/generate.py
Set up pre-commit for automated code style enforcement:
pip install pre-commit
pre-commit install
Metadata
Release files for pytensor-federated 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytensor_federated-2.0.1.tar.gz | 34.9 kB | Without provenance | Details for pytensor_federated-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytensor_federated-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for pytensor_federated-2.0.1-py3-none-any.whl |
Total release size: 73.9 kB
Release files / pytensor_federated-2.0.1.tar.gz
| Download URL | pytensor_federated-2.0.1.tar.gz |
|---|---|
| Size | 34.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eb91cc0dc5b2953bc40b06aad24a09969e378b302caf9b104bf679d4b112394f
|
|
BLAKE2b-256 checksum How to use checksums |
e60b8e1cdb6d95810c25da10b536e2cad346a0b7170b0ea5a3fccfb41f735f9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / pytensor_federated-2.0.1-py3-none-any.whl
| Download URL | pytensor_federated-2.0.1-py3-none-any.whl |
|---|---|
| Size | 39.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e3d9c688d2e1accc0d5633072e094f12c9390df088f3c56d7313f8664917aa9f
|
|
BLAKE2b-256 checksum How to use checksums |
730e541ca4351edfc736ef6b7cafd81268e165dbfa266cdbc2c536afad765268
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for pytensor-federated 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.