Skip to main content

Putting TensorFlow back in PyTorch, back in Tensorflow (differentiable TensorFlow PyTorch adapters).

Project description

TfPyTh

Putting TensorFlow back in PyTorch, back in Tensorflow (differentiable TensorFlow PyTorch adapters).

A light-weight adapter library to make things interact that were not supposed to interact initially.

Install

pip install tfpyth

Example

import tensorflow as tf
import torch as th
import numpy as np
import tfpyth

session = tf.Session()

def get_torch_function():
    a = tf.placeholder(tf.float32, name='a')
    b = tf.placeholder(tf.float32, name='b')
    c = 3 * a + 4 * b * b

    f = tfpyth.torch_from_tensorflow(session, [a, b], c).apply
    return f

f = get_torch_function()
a = th.tensor(1, dtype=th.float32, requires_grad=True)
b = th.tensor(3, dtype=th.float32, requires_grad=True)
x = f(a, b)

assert x == 39.

x.backward()

assert np.allclose((a.grad, b.grad), (3., 24.))

What it haz

torch_from_tensorflow

Creates a PyTorch function that is differentiable by evaluating a TensorFlow output tensor given input placeholders.

eager_tensorflow_from_torch

Creates an eager Tensorflow function from a PyTorch function.

tensorflow_from_torch

Creates a TensorFlow op/tensor from a PyTorch function.

TODOs

  • [] support JAX
  • [] support higher-order derivatives

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tfpyth-1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

tfpyth-1.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file tfpyth-1.0.tar.gz.

File metadata

  • Download URL: tfpyth-1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for tfpyth-1.0.tar.gz
Algorithm Hash digest
SHA256 80fbf7c5e7d6664d5a6ab7f3609fbe6f497b2663586d8500bf1cbe8b2b211994
MD5 d9cca5447a5d146fff407dece198df2e
BLAKE2b-256 a624c2b6bc8b87d8afab7bdce80ff56fc62a928fc8614b2854d0553cd3543d18

See more details on using hashes here.

File details

Details for the file tfpyth-1.0-py3-none-any.whl.

File metadata

  • Download URL: tfpyth-1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for tfpyth-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c007737b4479291606f5578f379cda73156db674839f63c65ac0be58cd02cbf7
MD5 2bcecc99f6ac84824b3ffb903f98a9d8
BLAKE2b-256 3e1715ec62f99cb4d8118a899f4b97d2574f67e9d71db4c0c9f40866f09a0e1f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page