• Stars
    star
    140
  • Rank 261,473 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 6 years ago

Reviews

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

Repository Details

Forward-mode Automatic Differentiation for TensorFlow

tensorflow-forward-ad

Forward-mode Automatic Differentiation for TensorFlow

Installation

Prerequisites

  • tensorflow 0.12+ (compatible with 1.0+)
  • Cython
  • NumPy
  • Python 2 or 3

Option 1: using pip

pip install tensorflow_forward_ad

Option 2: building from source

git clone https://github.com/renmengye/tensorflow-forward-ad.git
cd tensorflow-forward-ad
python setup.py install

Option 3: building from source using Bazel

git clone https://github.com/renmengye/tensorflow-forward-ad.git
cd tensorflow-forward-ad
bazel build //tensorflow_forward_ad:all
# Run all unit tests (with tensorflow-gpu only).
bazel test //tensorflow_forward_ad:all

Forward-Mode AD Usage

import tensorflow as tf
from tensorflow_forward_ad import forward_gradients

# Automatic differentiation.
x = tf.constant(1.0)
y = tf.square(x)
dydx = forward_gradients(y, x)
sess = tf.Session()
print(sess.run(dydx))  # [2.0].

# Computes Jacobian-vector product.
x = tf.ones([5, 10])
y = tf.square(x)
v = tf.ones([5, 10]) * 2
Jv = forward_gradients(y, x, v)
sess = tf.Session()
print(sess.run(Jv))  # [array([[ 4.,  4.,  4.,  4., ...

# A list of inputs.
x1 = tf.ones([5, 10])
x2 = tf.ones([10, 8])
y1 = tf.square(tf.matmul(x1, x2))
y2 = tf.sigmoid(tf.matmul(x1, x2))
v1 = tf.ones([5, 10]) * 0.5
v2 = tf.ones([10, 8]) * 2.0
J1v, J2v = forward_gradients([y1, y2], [x1, x2], [v1, v2])

Second-Order Matrix Vector Product

import tensorflow as tf

x = tf.ones([5, 10])
w = tf.ones([10, 8])
z = tf.square(tf.matmul(x, w))
v = tf.ones_like(x)
y_ = tf.range(5)
f = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=y_, logits=z)

# Hessian vector product
from tensorflow_forward_ad.second_order import hessian_vec_fw
Hv = hessian_vec_fw(f, x, v)

# Fisher vector product
from tensorflow_forward_ad.second_order import fisher_vec_fw
Fv = fisher_vec_fw(f, x, v)

# Gauss-Newton vector product
from tensorflow_forward_ad.second_order import gauss_newton_vec
Gv = gauss_newton_vec(f, z, x, v)

More Repositories

1

few-shot-ssl-public

Meta Learning for Semi-Supervised Few-Shot Classification
Python
553
star
2

revnet-public

Code for "The Reversible Residual Network: Backpropagation Without Storing Activations"
Python
351
star
3

inc-few-shot-attractor-public

Code for Paper "Incremental Few-Shot Learning with Attention Attractor Networks"
Python
118
star
4

rec-attend-public

Code that implements paper "End-to-End Instance Segmentation with Recurrent Attention"
Python
109
star
5

imageqa-public

Code for paper "Exploring Models and Data for Image Question Answering"
Python
83
star
6

base62-csharp

Base62 Encoding C# implementation
C#
47
star
7

deep-dashboard

Deep Dashboard: Machine Learning Training Visualizer
JavaScript
44
star
8

meta-optim-public

Understanding Short-Horizon Bias in Stochastic Meta-Optimization
Python
37
star
9

oc-fewshot-public

Code associated with paper "Wandering Within a World: Online Contextualized Few-Shot Learning"
Python
24
star
10

imageqa-qgen

A question generator described in paper "Exploring Model and Data for Image Question Answering"
Python
24
star
11

np-conv2d

2D Convolution using NumPy
Python
17
star
12

cityscapes-api

API for Cityscapes Dataset
Python
11
star
13

CoursePlanner

Planner tool for college course selection and timetable scheduling
C#
10
star
14

pysched

Pipeline based scheduler made in Python
Python
9
star
15

online-unsup-proto-net

Python
7
star
16

div-norm

Implementation of divisive normalization in TensorFlow
Python
7
star
17

resnet

Modified from the original tensorflow version.
Python
3
star
18

csc467

CSC467 Compiler Project
C
2
star
19

neural-lm

Neural Language Model Implementation
C++
2
star
20

tfplus

Deep learning utility library based on Tensorflow
Python
2
star
21

deep-tracker

Python
2
star
22

AutoTetris

An automatic solution to the classic game Tetris
Java
2
star
23

bazel-docker

Build Docker container with Bazel
Python
1
star
24

grade-school-math-relational

Abstract relation annotations of the GSM-8k dataset
1
star
25

imageqa_icml2015_poster

TeX
1
star