Introduce a somewhat usable "metatize" for TF helper functions #66
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This addresses #56 in another way; namely, it uses an intermediate/temporary TF graph that mirrors a given meta graph with the meta tensor terms replaced by
Placeholder
s. The temporary TF graph is given to the TF function we want to metatize, the result is turned into a meta graph (i.e. "metatized") and thePlaceholder
stand-ins are replaced by the original meta tensors.The reason this seems like a worthwhile approach:
Placeholders
have some flexibility for unknown shape and dtype information, so, when meta tensors use logic variables for those values, we have a workable mapping between meta tensors and valid TF tensors.Naturally, this approach has its limits, and the reason is that some TF helper functions simply do not accept unknown shape and dtype input (i.e. "variant" dtype). However, the better we are about inferring/specifying dtype and shape information (when it's possible to do so) for meta objects, the better this approach will work.
Example
We start by making the TF graph we ultimately want in meta form:
In an ideal world, there would be an
OpDef
behind the functiontf.eye
, but, since there isn't, we have to build an equivalent meta graph by hand. The meta graph should mirror the TF graph forI_A_tf
, so we can always inspectI_A_tf
to see whattf.eye
constructed from its inputs (i.e.A_rows_tf
):Basically, reconstructing graphs like these by hand involves reproducing the steps in the function
tf.eye
.With the TF function "metatizing" in this PR, the process is much simpler:
Now, if we convert the meta graph
I_A_mt
into a TF graph and print the results, we see essentially the same results as the originaltf.eye
, which verifies the correspondence between the two graphs: