{"id":14983592,"url":"https://github.com/michaelosthege/pytensor-federated","last_synced_at":"2026-05-22T13:06:26.031Z","repository":{"id":194515293,"uuid":"507581558","full_name":"michaelosthege/pytensor-federated","owner":"michaelosthege","description":"Distributed differentiable graph computation using PyTensor","archived":false,"fork":false,"pushed_at":"2025-03-04T18:39:10.000Z","size":150,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-24T16:35:44.585Z","etag":null,"topics":["federated-learning","graph","grpc","pymc","pytensor"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaelosthege.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-26T13:27:09.000Z","updated_at":"2025-03-04T18:39:13.000Z","dependencies_parsed_at":"2024-01-23T10:26:31.356Z","dependency_job_id":"3bedde13-5b15-46f3-aa8a-aeabe53c1007","html_url":"https://github.com/michaelosthege/pytensor-federated","commit_stats":{"total_commits":93,"total_committers":3,"mean_commits":31.0,"dds":"0.24731182795698925","last_synced_commit":"839ff0048db80a7bf57bb86834fd9ee2f3ef75b6"},"previous_names":["michaelosthege/pytensor-federated"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelosthege%2Fpytensor-federated","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelosthege%2Fpytensor-federated/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelosthege%2Fpytensor-federated/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelosthege%2Fpytensor-federated/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaelosthege","download_url":"https://codeload.github.com/michaelosthege/pytensor-federated/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248271925,"owners_count":21075800,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["federated-learning","graph","grpc","pymc","pytensor"],"created_at":"2024-09-24T14:07:33.598Z","updated_at":"2026-05-22T13:06:20.984Z","avatar_url":"https://github.com/michaelosthege.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![PyPI version](https://img.shields.io/pypi/v/pytensor-federated)](https://pypi.org/project/pytensor-federated)\n[![pipeline](https://github.com/michaelosthege/pytensor-federated/workflows/test/badge.svg)](https://github.com/michaelosthege/pytensor-federated/actions)\n[![coverage](https://codecov.io/gh/michaelosthege/pytensor-federated/branch/main/graph/badge.svg)](https://codecov.io/gh/michaelosthege/pytensor-federated)\n\n# `pytensor-federated`\nThis package implements federated computing with [PyTensor](https://github.com/pymc-devs/pytensor).\n\nUsing `pytensor-federated`, differentiable cost functions can be computed on federated nodes.\nInputs and outputs are transmitted in binary via a bidirectional gRPC stream.\n\nA client side `LogpGradOp` is provided to conveniently embed federated compute operations in PyTensor graphs such as a [PyMC](https://github.com/pymc-devs/pymc) model.\n\nThe example code implements a simple Bayesian linear regression to data that is \"private\" to the federated compute process.\n\nRun each command in its own terminal:\n\n```bash\npython demo_node.py\n```\n\n```bash\npython demo_model.py\n```\n\n## Architecture\n`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.\nThis 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.\n\nAt 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.\nThe 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).\n\n![](docs/arrays_to_arrays.svg)\n\nThis `ArraysToArraysService` can be used to wrap arbitrary model functions, thereby enabling to run model simulations and MCMC/optimization on different machines.\nThe 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.\n\n![](docs/distributed.svg)\n\nFor the Bayesian inference or optimization use case, it helps to first understand the inputs and outputs of the undelying computation graph.\nFor example, parameter estimation with a differential equation model requires...\n* `observations` to which the model should be fitted\n* `timepoints` at which there were observations\n* parameters (including initial states) `theta`, some of which are to be estimated\n\nFrom `timepoints` and parameters `theta`, the `model` predicts `trajectories`.\nTogether with `observations`, these predictions are fed into some kind of likelihood function, which produces a scalar log-likelihood `log-likelihood` as the output.\n\nDifferent sub-graphs of this example could be wrapped by an `ArraysToArraysService`:\n* `[theta,] -\u003e [log-likelihood,]`\n* `[timepoints, theta] -\u003e [trajectories,]`\n* `[timepoints, observations, theta] -\u003e [log-likelihood,]`\n\n\n![](docs/theta_to_LL.svg)\n\nIf the entire model is differentiable, one can even return gradients.\nFor example, with a linear model: `[slope, intercept] -\u003e [LL, dLL_dslope, dLL_dintercept]`.\n\nThe role of PyTensor here is purely technical:\nPyTensor is a graph computation framework that implements auto-differentiation.\nWrapping the `ArraysToArraysServiceClient` in PyTensor `Op`s simply makes it easier to build more sophisticated compute graphs.\nPyTensor is also the computatation backend for PyMC, which is the most popular framework for Bayesian inference in Python.\n\n\n## Installation \u0026 Contributing\n```bash\nconda env create -f environment.yml\n```\n\nAdditional dependencies are needed to compile the [protobufs](./protobufs/):\n\n```bash\nconda install -c conda-forge libprotobuf-static\npip install --pre betterproto[compiler]\n```\n\n```bash\npython protobufs/generate.py\n```\n\nSet up `pre-commit` for automated code style enforcement:\n\n```bash\npip install pre-commit\npre-commit install\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelosthege%2Fpytensor-federated","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelosthege%2Fpytensor-federated","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelosthege%2Fpytensor-federated/lists"}