{"id":13443653,"url":"https://github.com/BlackHC/tfpyth","last_synced_at":"2025-03-20T17:30:54.156Z","repository":{"id":38271816,"uuid":"195428791","full_name":"BlackHC/tfpyth","owner":"BlackHC","description":"Putting TensorFlow back in PyTorch, back in TensorFlow (differentiable TensorFlow PyTorch adapters).","archived":false,"fork":false,"pushed_at":"2020-11-30T19:46:39.000Z","size":15,"stargazers_count":644,"open_issues_count":4,"forks_count":97,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-03-13T02:09:23.261Z","etag":null,"topics":["machine-learning","pytorch","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BlackHC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-05T15:08:50.000Z","updated_at":"2024-12-21T13:23:03.000Z","dependencies_parsed_at":"2022-08-18T06:10:34.941Z","dependency_job_id":null,"html_url":"https://github.com/BlackHC/tfpyth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackHC%2Ftfpyth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackHC%2Ftfpyth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackHC%2Ftfpyth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlackHC%2Ftfpyth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlackHC","download_url":"https://codeload.github.com/BlackHC/tfpyth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244660240,"owners_count":20489303,"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":["machine-learning","pytorch","tensorflow"],"created_at":"2024-07-31T03:02:06.322Z","updated_at":"2025-03-20T17:30:53.843Z","avatar_url":"https://github.com/BlackHC.png","language":"Python","readme":"# TfPyTh\n\n[![Build Status](https://travis-ci.com/BlackHC/tfpyth.svg?branch=master)](https://travis-ci.com/BlackHC/tfpyth) [![codecov](https://codecov.io/gh/BlackHC/tfpyth/branch/master/graph/badge.svg)](https://codecov.io/gh/BlackHC/tfpyth)\n\n\u003e Putting TensorFlow back in PyTorch, back in TensorFlow (with differentiable TensorFlow PyTorch adapters).\n\nDo you have a codebase that uses TensorFlow and one that uses PyTorch and want to train a model that uses both end-to-end?\n\nThis library makes it possible without having to rewrite either codebase! \n\nIt allows you to wrap a TensorFlow graph to make it callable (and differentiable) through PyTorch, and vice-versa, using simple functions.\n\nThe only caveat is that tensors have to be copied and routed through the CPU until TensorFlow supports `__cuda_array_interface` (please star the [GitHub issue](https://github.com/tensorflow/tensorflow/issues/29039)).\n\n## Install\n\n```\npip install tfpyth\n```\n\n### Example\n\n```python\nimport tensorflow as tf\nimport torch as th\nimport numpy as np\nimport tfpyth\n\nsession = tf.Session()\n\ndef get_torch_function():\n    a = tf.placeholder(tf.float32, name='a')\n    b = tf.placeholder(tf.float32, name='b')\n    c = 3 * a + 4 * b * b\n\n    f = tfpyth.torch_from_tensorflow(session, [a, b], c).apply\n    return f\n\nf = get_torch_function()\na = th.tensor(1, dtype=th.float32, requires_grad=True)\nb = th.tensor(3, dtype=th.float32, requires_grad=True)\nx = f(a, b)\n\nassert x == 39.\n\nx.backward()\n\nassert np.allclose((a.grad, b.grad), (3., 24.))\n```\n\n## What it's got\n\n### `torch_from_tensorflow`\n\nCreates a PyTorch function that is differentiable by evaluating a TensorFlow output tensor given input placeholders.\n\n### `eager_tensorflow_from_torch`\n\nCreates an eager Tensorflow function from a PyTorch function.\n\n### `tensorflow_from_torch`\n\nCreates a TensorFlow op/tensor from a PyTorch function.\n\n## Future work\n\n- [ ] support JAX\n- [ ] support higher-order derivatives\n","funding_links":[],"categories":["Toolbox","Python"],"sub_categories":["Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlackHC%2Ftfpyth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBlackHC%2Ftfpyth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlackHC%2Ftfpyth/lists"}