• Stars
    star
    641
  • Rank 70,212 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

TfPyTh

Build Status codecov

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

Do you have a codebase that uses TensorFlow and one that uses PyTorch and want to train a model that uses both end-to-end?

This library makes it possible without having to rewrite either codebase!

It allows you to wrap a TensorFlow graph to make it callable (and differentiable) through PyTorch, and vice-versa, using simple functions.

The 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).

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's got

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.

Future work

  • support JAX
  • support higher-order derivatives

More Repositories

1

llm-strategy

Directly Connecting Python to LLMs via Strongly-Typed Functions, Dataclasses, Interfaces & Generic Types
Python
376
star
2

toma

Helps you write algorithms in PyTorch that adapt to the available (CUDA) memory
Python
354
star
3

BatchBALD

Efficient and Diverse Batch Acquisition for Deep Bayesian Active Learning.
Python
219
star
4

dart_repl

Proof of concept REPL shell for Dart
Dart
81
star
5

batchbald_redux

Reusable BatchBALD implementation
Jupyter Notebook
71
star
6

mdp

Make it easy to specify simple MDPs that are compatible with the OpenAI Gym.
Python
37
star
7

mnist_by_zip

Compression algorithms (like the well-known zip file compression) can be used for machine learning purposes, specifically for classifying hand-written digits (MNIST)
Jupyter Notebook
35
star
8

llmtracer

Trace LLM calls (and others) and visualize them in WandB, as interactive SVG or using a streaming local webapp
Python
12
star
9

player_of_jeopardy

ChatGPT can solve Jeopardy! clues really well!
Python
10
star
10

chatplayground

Chat Playground for LLMs
Python
9
star
11

ddu_dirty_mnist

Dirty-MNIST dataset introduced in "Deterministic Neural Networks with Inductive Biases Capture Epistemic and Aleatoric Uncertainty" (https://arxiv.org/abs/2102.11582)
Jupyter Notebook
7
star
12

pbt

Jupyter notebooks to play around with population based training, as described in https://arxiv.org/abs/1711.09846
Jupyter Notebook
7
star
13

blackboard-pagi

Python
7
star
14

2302.08981

Jupyter Notebook
5
star
15

batch_pong_poc

Instead of running one environment at a time or one per thread, run everything in batch using numpy on a single core.
Jupyter Notebook
4
star
16

hello-slurm

Shell
4
star
17

pytorch_datadiet

Python
3
star
18

laaos

Logs as append-only source.
Python
3
star
19

implicit_lambda

This package adds support for implicit lambdas, so you can write `map(_ + 5, a_list)` instead of `map(lambda x: x + 5, a_list)`.
Python
3
star
20

dlb_chapter2

TeX
1
star
21

WML

Whitespace Markup Language
C++
1
star
22

2020_ebm_presentation

A presentation about EBMs and Hopfield networks @ OATML
HTML
1
star
23

2202.01851

Repository for 'A Note on "Assessing Generalization of SGD via Disagreement"'
Jupyter Notebook
1
star
24

algo_fairness

Jupyter Notebook
1
star
25

2208.00549

Unifying Approaches in Data Subset Selection - Experiments
Jupyter Notebook
1
star