Skip to content

Java sig #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 87 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
9d5c52f
Adding a doc to deprecate collections
rohan100jain Sep 5, 2018
7d23ce4
Responding to Karmels comments
rohan100jain Oct 3, 2018
93601a4
Minor fix to VariableTracker sample code
rohan100jain Oct 3, 2018
161a272
RFC for random numbers in TensorFlow 2.0
wangpengmit Dec 17, 2018
03b32bd
Changes after some feedback
wangpengmit Dec 18, 2018
a1ab7c8
Removed 'global_seed' in the main code and showed the design with 'gl…
wangpengmit Dec 18, 2018
17c0827
Some changes after feedback
wangpengmit Dec 18, 2018
866dc70
A tweak
wangpengmit Dec 18, 2018
2ab40fc
Change after feedback
wangpengmit Dec 18, 2018
a1ae31a
A tweak
wangpengmit Dec 20, 2018
8e4d795
changes
alextp Aug 17, 2018
4462f33
changes
alextp Aug 17, 2018
5a40bf5
fix link
alextp Aug 22, 2018
389da84
new-rfc
alextp Dec 21, 2018
da21f50
changes
alextp Dec 21, 2018
5bbbb15
Update rfcs/20181225-tf-backend.md
tomhennigan Dec 21, 2018
6709287
Added some considerations about tf.function
wangpengmit Jan 2, 2019
71812a0
Renamed the internal name "op_generator" to "global_generator"
wangpengmit Jan 2, 2019
ca8f406
Changed seed size from 256 to 1024 bits
wangpengmit Jan 4, 2019
f889fe7
Initial signpost for community meetings
Jan 11, 2019
a25c449
Add iCal link too
Jan 11, 2019
d63d136
changes
alextp Jan 15, 2019
e0809bf
Merge pull request #44 from alextp/pr
goldiegadde Jan 15, 2019
ec9f7a0
Initial version of embedding and partitioned variable RFC.
Jan 17, 2019
25a9c17
Fix one formatting issue.
Jan 17, 2019
961e242
Fix another formatting issue.
Jan 17, 2019
05e6343
Use markdown language for the table instead of HTML.
Jan 17, 2019
401c1bc
Merge pull request #52 from tensorflow/ewilderj-community-meetings
dynamicwebpaige Jan 17, 2019
0512aeb
Add tensorflow/io R Package CRAN release instructions (#53)
terrytangyuan Jan 17, 2019
08e0849
Added Design Review Notes
wangpengmit Jan 18, 2019
850cc78
Make clear distinction between embedding variables and loadbalancing
Jan 18, 2019
3dfdda6
Added decisions below each question, and "how to use generators with …
wangpengmit Jan 18, 2019
a75427f
Adopted Dong Lin's suggestions
wangpengmit Jan 18, 2019
c15370c
Add a paragraph pointing out the problem with the `partition_strategy…
Jan 18, 2019
ef62689
RFC: Move from tf.contrib to addons (#37)
seanpmorgan Jan 18, 2019
f950423
Update alternatives since `DynamicPartition` and `DynamicStitch` do h…
Jan 29, 2019
e23208e
Add a section for saving and restore `PartitionedVariable`.
Jan 29, 2019
4d454c4
Mention that variable types can be nested, attention needs to be paid…
Jan 29, 2019
be5bf32
Create README.md (#57)
dynamicwebpaige Jan 29, 2019
847df88
Splitted `_state_var` into `_state_var` and `_alg_var` (because of co…
wangpengmit Jan 30, 2019
1aaa05d
Updated timestamp
wangpengmit Jan 30, 2019
3fded8b
Moved the auto-selection of algorithm from `create_rng_state` to `Gen…
wangpengmit Jan 31, 2019
39b617b
Merge pull request #38 from wangpengmit/master
goldiegadde Jan 31, 2019
fb6a161
Update according to the discussion
Feb 1, 2019
5ee14f6
Update relese binary build command for sig-io (#58)
yongtang Feb 1, 2019
70dc6de
Add Bryan to SIG IO release team (#59)
BryanCutler Feb 1, 2019
a3c96c1
Change to accepted
Feb 4, 2019
7c26f73
Merge pull request #55 from yuefengz/master
goldiegadde Feb 4, 2019
c906151
Add link to TensorFlow IO R package
terrytangyuan Feb 6, 2019
1321d74
Merge pull request #62 from terrytangyuan/patch-1
martinwicke Feb 6, 2019
acf19fa
Updated link for the friction log. (#64)
dynamicwebpaige Feb 7, 2019
05e08e1
Switch DistStrat revised API examples to TensorFlow 2 style. (#63)
chr1sj0nes Feb 7, 2019
9904c5c
RFC: Attention for Dense Networks on Keras (#54)
roumposg Feb 11, 2019
2c16981
RFC: Stateful Containers with tf.Module (#56)
tomhennigan Feb 21, 2019
0530779
RFC: New tf.print (#14)
tomerk Feb 21, 2019
4a3905d
Added design review notes
rohan100jain Feb 26, 2019
2442176
Marking doc as accepted
rohan100jain Feb 26, 2019
fc9b7f8
Merge pull request #17 from rohan100jain/master
goldiegadde Feb 26, 2019
da93389
Update cond_v2 design doc (#70)
skye Feb 27, 2019
0476683
Added the symbol map to the RFC.
dynamicwebpaige Mar 6, 2019
92ce007
Merge pull request #72 from tensorflow/dynamicwebpaige-patch-2
martinwicke Mar 6, 2019
4763e9d
Updated testing section of the Community site.
dynamicwebpaige Mar 9, 2019
a94ee56
Removed the 100%, formatting tweaks.
dynamicwebpaige Mar 10, 2019
e6d633d
Merge pull request #73 from tensorflow/dynamicwebpaige-patch-3
dynamicwebpaige Mar 10, 2019
99ee2f8
Update CHARTER.md
malmaud Mar 10, 2019
e003c95
Change contact email address
byronyi Mar 12, 2019
05aac1b
Create README.md
Mar 12, 2019
df458fc
Logos for SIGs
ewilderj Mar 12, 2019
9c989e7
Update README.md
Mar 12, 2019
060acc7
Update addons owners (#85)
seanpmorgan Apr 3, 2019
7739a24
Created a FAQ for TF 2.0. (#78)
dynamicwebpaige Apr 3, 2019
e9946c2
Request and charter for SIG JVM (#86)
karllessard Apr 4, 2019
721e701
Update CODEOWNERS
Apr 4, 2019
8a429d7
Update CODEOWNERS
Apr 4, 2019
1ad4a2e
Update CODEOWNERS
Apr 4, 2019
0975789
Update RFC with current information (#89)
seanpmorgan Apr 9, 2019
a89faae
RFC: TF on Demand Project (#69)
hyeygit Apr 10, 2019
c3402ac
RFC: SavedModel Save/Load in 2.x (#34)
allenlavoie Apr 10, 2019
06acb27
Update CHARTER.md
Apr 15, 2019
42c5ffd
Update 20180920-unify-rnn-interface.md (#81)
zh794390558 Apr 17, 2019
81a14f1
Update yyyymmdd-rfc-template.md
Apr 17, 2019
e022c80
Update while_v2 design doc (#71)
skye Apr 17, 2019
e406c2a
Update TF 2.0 FAQ to link to TensorBoard TF 2.0 tutorial (#94)
nfelt Apr 25, 2019
e949cdb
CLN: update sig addons logo png (#99)
facaiy May 1, 2019
320a18a
Add SIG Keras
May 2, 2019
391360e
RFC: String Tensor Unification (#91)
gharibian May 6, 2019
20f2062
Start RFC for tensor buffers
karllessard May 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ sigs/build/ @martinwicke @ewilderj @angersson @perfinion
sigs/addons/ @martinwicke @ewilderj @karmel @seanpmorgan @armando-fandango
sigs/networking/ @martinwicke @ewilderj @byronyi @jbedorf @poxvoculi
sigs/io/ @martinwicke @ewilderj @mrry @yongtang @dmitrievanthony
sigs/jvm/ @martinwicke @ewilderj @sjamesr @karllessard @tzolov
sigs/testing/ @ewilderj @dynamicwebpaige

# RFCs

Expand Down
13 changes: 13 additions & 0 deletions MEETINGS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# TensorFlow Community Meetings

[TensorFlow SIGs](https://github.com/tensorflow/community/tree/master/sigs)
and other groups hold regular meetings via videoconference. Usually
you will find these added to your calendar after you join the Google Group relevant
to the SIG or community group.

There is also a master calendar listing all community meetings:
[TensorFlow Community Calendar](https://calendar.google.com/calendar/embed?src=tensorflow.org_14t769n89qhsps949c3l0nhd9c%40group.calendar.google.com).

Google Calendar users can add the calendar to theirs using the button on the bottom of the master calendar page. If you want
to add the Community Calendar to your own calendar application, use [this iCal link](https://calendar.google.com/calendar/ical/tensorflow.org_14t769n89qhsps949c3l0nhd9c%40group.calendar.google.com/public/basic.ics).

62 changes: 38 additions & 24 deletions rfcs/20180507-cond-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
:-------------- |:---------------------------------------------------- |
| **Author(s)** | Skye Wanderman-Milne (skyewm@gmail.com) |
| **Created** | 2018-05-07 |
| **Updated** | 2018-08-22 |
| **Updated** | 2019-02-26 |
| **Implementation** | [cond_v2.py](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/cond_v2.py) |

## Objective

**Switch tf.cond to emit a single If op.**

We can do tf.while_loop next.

This would make mapping to XLA's control flow constructs easier/possible. In particular, just switching to the If op would be a big win (more work needed to get cond working with XLA than while_loop, which already had a lot of work done), and easier than while loop. It will also making debugging and analysis of cond constructs much simpler, e.g. to implement higher-order derivatives.
Benefits:
* Higher-order derivatives
* Better XLA/TPU integration
* Better error messages
* Fewer bugs

Note that cond will still support side-effecting ops (e.g. variable updates).


## Background material

Related tf.while_loop RFC: https://github.com/tensorflow/community/blob/master/rfcs/20180821-differentiable-functional-while.md

tf.cond API: https://www.tensorflow.org/api_docs/python/tf/cond

If op: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/ops/functional_ops.cc#L104
Expand All @@ -33,7 +38,7 @@ Overview of current control flow implementation: [Implementation of Control Flow

The signature of `tf.cond` will stay the same: boolean predicate Tensor, and Python callables for the two branches. The two callables each take no arguments (they instead close over any input tensors), and are required to return the same number and type of tensors.

We need to convert this to the If op signature, which is a boolean predicate, and FunctionDefs for the two branches. The FunctionDefs are required to have the same number and type of inputs and outputs. Luckily, tfe.defun already gives us the machinery to convert the Python callables into FunctionDefs, including converting closures to inputs and adding extra inputs to make the branch signatures match. This is done via an overloaded Graph subclass, [FuncGraph](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/eager/function.py#L191), which gives us the full flexibility of graphs while creating the branch functions.
We need to convert this to the If op signature, which is a boolean predicate, and FunctionDefs for the two branches. The FunctionDefs are required to have the same number and type of inputs and outputs. Luckily, tf.function already gives us the machinery to convert the Python callables into FunctionDefs, including converting closures to inputs and adding extra inputs to make the branch signatures match. This is done via an overloaded Graph subclass, [FuncGraph](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/framework/func_graph.py#L117), which gives us the full flexibility of graphs while creating the branch functions.

This conversion results in a single If op representing the `tf.cond`.

Expand Down Expand Up @@ -70,21 +75,17 @@ We don't want to lower If ops that will eventually be consumed by the [XLA encap

See the "Gradients" section. We somehow need to add intermediate tensors as outputs to the already-created forward-pass If op and its branch functions. Options:

Solution:\
Modify the existing If op in-place. We do this by replacing the branch functions, and changing the outputs of the op (tricky but doable).

Since this is mutating an existing graph element, if the graph has already been run by a Session, this theoretically invalidates the session! In practice the Session appears to still be usable though.

1. Create a new If op with the required outputs. To prevent running both the original and new ops, we need to rewire the outputs of the original op to use the new op (and ideally modify any existing Tensor objects as well).
1. Modify the existing If op in-place. This involves either modifying or replacing the branch functions, and changing the outputs of the op (tricky, but probably doable).

Note that both of these options require mutating existing graph elements. If the graph has already been run, **this will invalidate any existing Sessions!** Other options:

This is the same method that tf.function and [while_v2](https://github.com/tensorflow/community/blob/master/rfcs/20180821-differentiable-functional-while.md) use for intermediate gradients, making all of them compose nicely.


1. Use placeholders for intermediates during construction, then use a C++ rewrite (Grappler or GraphOptimizationPass) to rewire the graph.
1. Output every possible intermediate.
1. It might already work as-is.
1. Except for ExtendGraph -- solution could be to make C API and Session share Graph*

**Update**: we went with (2) output every possible intermediate
Alternatives considered:
1. Output every possible intermediate and rely on pruning to clean it up. The original implementation did this, but we changed it to match tf.function.
1. Create a new If op with the required outputs. To prevent running both the original and new ops, we need to rewire the outputs of the original op to use the new op (and ideally modify any existing Tensor objects as well). This also requires a Session-invalidating graph mutation.
1. Use placeholders for intermediates during construction, then use a C++ rewrite (Grappler or GraphOptimizationPass) to rewire the graph. This is effectively creating an alternative representation of the dataflow graph, which is undesireable (e.g. all graph traversal code would need to know about these special placeholders).


### Making branch function outputs match
Expand All @@ -93,26 +94,34 @@ After adding the intermediate outputs to the forward If op's branch functions, i

Note that the "mirror" tensors never need to be read. The original output is only consumed by the corresponding gradient function, which is only executed if the original output's branch is taken. Thus, if the mirror tensor is produced, no consumer of it will be run. However, without pruning and/or non-strict execution, the If op must still produce some value for the mirror tensor.

_Solution:_
Solution:\
Wrap all intermediate outputs in optionals. Optionals are like maybe or [optional types](https://en.wikipedia.org/wiki/Option_type) in TensorFlow. They are variant-type tensors that may or may not contain a value tensor, which are created and introspected by [these ops](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/ops/dataset_ops.cc#L629).

Introduce a special op to output mirror tensors. This op's shape inference function will claim to output the same shape and type of the mirrored output, but since the tensor isn't actually needed the kernel will produce some small value to avoid producing large unnecessary values. If/when the op doesn't need to produce a value (e.g. via lowering + pruning), the kernel can CHECK or similar.
In the branch where the intermediate is actually produced, the intermediate tensor is wrapped in an optional via the [`OptionalFromValue` op](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/ops/dataset_ops.cc#L629), meaning the output optional will contain the intermediate if that branch is taken. In the other branch, the "mirror" tensor is produced via the [`OptionalNone` op](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/ops/dataset_ops.cc#L635), meaning the output optional will have no value if the other branch is taken.

Each gradient branch then only unwraps the optionals from its corresponding forward branch to pass to the gradient computation.

### Taking the gradient of deserialized If ops
Alternatives considered:
1. Output dead tensors as the "mirror" tensors, similar to the current tf.cond implementation. This requires changes to the executor to make it not mark If ops, While ops, functions ops, and possibly other special cases as dead if they have dead inputs, and prevents us from someday simplifying the excutor by removing the dead tensor logic.
1. Introduce a special op to output mirror tensors. This op's shape inference function will claim to output the same shape and type of the mirrored output, but since the tensor isn't actually needed the kernel will produce some small value to avoid producing large unnecessary values.

We need a graph representing the branch function of an If op in order to take its gradient. We already have a graph as part of creating the function, but if the graph was loaded from a GraphDef, we no longer have this graph. Options:

### Taking the gradient of deserialized If ops

We need a graph representing the branch function of an If op in order to take its gradient. We already have a graph as part of creating the function, but if the graph was loaded from a GraphDef, we no longer have this graph. Options:

1. FunctionDef → Graph method
Solution:\
[function_def_to_graph method](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/framework/function_def_to_graph.py)


### Variable initialization
**TODO: this section needs updating**

Variables created in the `cond` input callables must be created in the main graph, not in the temporary `FuncGraphs`. Luckily this is already handled by [init_scope](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/framework/ops.py#L5230), which should already be used as necessary to handle creating variables in Defuns, etc.


### Collections
**TODO: this section needs updating**

We must support reading and writing to collections in the `cond` input callables.

Expand All @@ -133,13 +142,15 @@ For example, how are people using collections within `cond` branches? How do the


### Name/device/colocation scope
**TODO: this section needs updating**

Similar to reading collections, any graph-wide stacks and other state can be copied into the `FuncGraphs`. New scopes can then be added within the FuncGraph, and the semantics prevent any added state from persisting beyond the input callable.

For colocation, we can possibly use external tensor names as-is, since they'll either be lowered into the main graph or compiled by XLA.


### Control dependencies
**TODO: this section needs updating**

If the `tf.cond` call occurs inside a control_dependencies block, the control inputs will be added directly to the resulting If op.

Expand All @@ -149,6 +160,7 @@ _The following concerns are avoided by lowering If ops before execution (see "Ex


### Devices
**TODO: this section needs updating**

Akshay is working on allowing functions to run across multiple devices. My understanding is that it's mostly working, with a few limitations (e.g. all arguments to the function must go through the caller device, colocation with external tensors doesn't work).

Expand All @@ -165,6 +177,8 @@ The current `cond` implementation allows each op in the taken branch to be run a

## Future work

**tf.while_loop**. This effort will solve most of the problems with switching to a functional While representation (or a recursive function representation?). The remaining challenges are inserting stacks for the gradients, and support parallel iterations.

**C API support.** Ideally other language bindings support conditional execution as well. The C API already includes the primitives for other bindings to implement something similar to `tf.cond` that produces an `If` op, but the C API `TF_AddGradients` method would need to support `If` ops in order for other bindings to (easily) allow autodiff of conditionals.

## Update log

2019-02-26: Updated some sections to reflect what was built and added link to implementation. Marked other sections as still needing update; many of these concerns are common to cond_v2, while_v2, and functions, so we may wanna include these as part of a function design doc.
Loading