END_PUBLIC I dropped the following commit because it doesn't compile. I will follow up with Andrew to fix it or revert it. Commit003deb88bauthored by osdamv<osdamv@gmail.com> Committed by Vijay Vasudevan<vrv@google.com>: Refactor and implementation of the camera API 1, it fixes #8736 (#10771) List of commits in this CL: --- Commit446450369authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Use identity of param variable in cudnn_rnn.RNNParamsSaveable instead of parameter variable directly. The RNNParamsSaveable is usually used in a graph which also has a saver for the cudnn param variable itself, if the same op is used for both, fails with a two savers for same op error. PiperOrigin-RevId: 163431826 --- Commitd629a8316authored by RJ Ryan<rjryan@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Increase bound on tf.contrib.signal.inverse_stft gradient error to avoid flakiness on macOS. PiperOrigin-RevId: 163426631 --- Commit253bcbb71authored by Kay Zhu<kayzhu@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: [XLA] Use HloEvaluator for convolution in reference_util. Also Speed up HloEvaluator's HandleConvolution in non-opt build, by moving calls to HloInstruction::shape() out of the inner loop. PiperOrigin-RevId: 163416183 --- Commit569a00e68authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Update API to traffic in unique_ptrs rather than owning raw pointers PiperOrigin-RevId: 163414320 --- Commit31a77bc77authored by Asim Shankar<ashankar@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Java: Update release to 1.3.0-rc1 PiperOrigin-RevId: 163413736 --- Commit1ebbf4325authored by Jonathan Hseu<vomjom@vomjom.net> Committed by GitHub<noreply@github.com>: Add missing grpc dependency (#11828) --- Commit905abb1f9authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Test asserts should have `expected` first. PiperOrigin-RevId: 163409348 --- Commitd5cc143e2authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Increase timeout to deflake the test. PiperOrigin-RevId: 163407824 --- Commitce1c7f02aauthored by Eli Bendersky<eliben@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Properly include logging header in xla_internal_test_main PiperOrigin-RevId: 163405986 --- Commit22241cd42authored by joetoth<joetoth@gmail.com> Committed by Vijay Vasudevan<vrv@google.com>: External leveldb link changed (#11833) table_format.txt was renamed to table_format.md --- Commit6b7314de4authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Consolidating the code to fill the partition's function library into one place. Previously, Partition() and MasterSession::RegisterPartition() both fills in the partitioned graph's function library. PiperOrigin-RevId: 163400992 --- Commit28373cfe7authored by Frank Chen<frankchn@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Adds preliminary support for Cloud TPUs with Cluster Resolvers. This aims to allow users to have a better experienec when specifying one or multiple Cloud TPUs for their training jobs by allowing users to use names rather than IP addresses. PiperOrigin-RevId: 163393443 --- Commite5353c941authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Don't prune nodes that have reference inputs. PiperOrigin-RevId: 163390862 --- Commit226510834authored by Asim Shankar<ashankar@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: C API: Groundwork for experimenting with TF_Tensor in device memory. TF_Tensor objects are always backed by host memory. This commit lays the groundwork for allowing TF_Tensor objects to refer to tensor data on device (e.g., GPU) memory. PiperOrigin-RevId: 163388079 --- Commit613bf1c7cauthored by Yuefeng Zhou<yuefengz@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: fix asan test failure in SingleMachineTest::ReleaseMemoryAfterDestruction. PiperOrigin-RevId: 163386941 --- Commit4653d37a3authored by Eli Bendersky<eliben@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: [XLA] Change type to appease GPU builds. PiperOrigin-RevId: 163384927 --- Commit9f131bd15authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Internal change PiperOrigin-RevId: 163378484 --- Commit8bc0236c8authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: PiperOrigin-RevId: 163366493 --- Commit3b97f1f9bauthored by Yangzihao Wang<yangzihao@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Change to only run one round of matmul benchmark. PiperOrigin-RevId: 163364341 --- Commita4a3a3335authored by Yun Peng<pcloudy@google.com> Committed by Vijay Vasudevan<vrv@google.com>: Fix ./configure on Windows (#11775) * Fix ./configure on Windows * Disable bitwise_ops_test on Windows --- Commitae3119d16authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Small changes to op framework. PiperOrigin-RevId: 163361071 --- Commitf40189d26authored by qjivy<ji.qiu@spreadtrum.com> Committed by Vijay Vasudevan<vrv@google.com>: PR again: Enable building label_image with jpeg/gif/png decoder for Android. (#11475) * Enable building label_image with jpeg/gif/png decoder for Android. Add dependency "android_tesnorflow_image_op" to label_image, which is not overlapped with android_tensorflow_kernels. * Running buildifier to reformat the BUILD files for sanity check. --- Commit599165861authored by KB Sriram<kbsriram@gmail.com> Committed by Vijay Vasudevan<vrv@google.com>: Add the Constant operator class (#11559) Create a custom operator class to create constants in the Graph, and introduce the Operator marker annotation to identify operator classes. Please see #7149 for the master tracking issue. --- Commit86ca3506fauthored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Further BUILD cleanup PiperOrigin-RevId: 163360750 --- Commit376bb063bauthored by Pete Warden<petewarden@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Look inside functions to see which node types are used. PiperOrigin-RevId: 163360375 --- Commit2139e7d8bauthored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: [tf.contrib.data] map expects a nested structure. Fixes #11786 PiperOrigin-RevId: 163359134 --- Commitd09304fcaauthored by Jonathan Hseu<vomjom@vomjom.net> Committed by Vijay Vasudevan<vrv@google.com>: Upgrade gRPC (#11768) * BUILD rule modifications * More build fixes * Code changes * More code fixes * Working tests * CMake build * Fix pprof * Fix header includes * CMake fix test * Bazel clean * Fix verbs * More verbs fixes * bazel clean for XLA * Windows build fix test * Add openssl/rand.h * New cmake build command * --config Release --- Commit3cd828474authored by David Norman<DavidNorman@users.noreply.github.com> Committed by Vijay Vasudevan<vrv@google.com>: Fix error with default python path selection (#11814) * Fix error with default python path selection * Move setting of environment var outside if / else --- Commitddd8e21b7authored by Eli Bendersky<eliben@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: [XLA] Consolidate all similar main()s in tests into a single target. PiperOrigin-RevId: 163354724 --- Commita36bca25bauthored by Tayo Oguntebi<tayo@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Remove ShapeWithoutPadding() utility function, as it is no longer needed. PiperOrigin-RevId: 163353430 --- Commitb26f9cd44authored by David Norman<DavidNorman@users.noreply.github.com> Committed by Vijay Vasudevan<vrv@google.com>: Ensure that the multi-instruction fuse can take shared inputs (#11748) * Ensure that the multi-instruction fuse can take shared inputs Note that the fuse action only works when the shared input / constant appears after all of its consumers in the list of instructions. * Add a comment describing the test --- Commit34cbf161dauthored by Jiri Simsa<jsimsa@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Update Dataset API documentation. PiperOrigin-RevId: 163349457 --- Commit2381ce5c3authored by Abdullah Alrasheed<a.rasheed@tc-sa.com> Committed by Vijay Vasudevan<vrv@google.com>: DOC: Fix typo. (#11813) you could could be I/O bottlenecked. TO: you could be I/O bottlenecked. --- Commite4a5c5356authored by Toby Boyd<tobyboyd@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: ["Variable", "VariableV2", "VarHandleOp"] is the default for ps_ops=None PiperOrigin-RevId: 163344629 --- Commit722f6f361authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Fix TensorForest's saveable object names so loading a savedmodel works. PiperOrigin-RevId: 163332598 --- Commitcda80a785authored by Eric Liu<ioeric@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: [tpu profiler] Dump HLO graphs in profile responses to the log directory. PiperOrigin-RevId: 163318992 --- Commitcea9ef6f5authored by horance<horance-liu@users.noreply.github.com> Committed by Vijay Vasudevan<vrv@google.com>: Refactoring device name utils (#11797) * remove duplicated code for full_name and legacy_name for DeviceNameUtils * replace tabs * Real->Device --- Commit1f7c0f917authored by Kongsea<kongsea@gmail.com> Committed by Vijay Vasudevan<vrv@google.com>: Refine docstrings (#11800) --- Commitdd1f0cdddauthored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Supports lookup devices by fullname either in the canonical form or the legacy form. This makes DeviceSet behaves the same as DeviceMgr's FindDevice method. PiperOrigin-RevId: 163300346 --- Commit631a364cdauthored by Kay Zhu<kayzhu@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: [XLA] Add Reduce, DynamicSlice and DynamicSliceUpdate to HloEvaluator. - Reduce is disabled explicitly for constant folding, as not all types of embedded computation can be currently supported by the evaluator. - Added support to evaluate HloModule to HloEvaluator. - Minor signature change to Evaluate(). PiperOrigin-RevId: 163299238 --- Commita52470172authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Sets the incarnation number even when the attribute is set. PiperOrigin-RevId: 163299121 --- Commita49fe0366authored by Suharsh Sivakumar<suharshs@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Remove platform bridge for grpc_response_reader. PiperOrigin-RevId: 163295986 --- Commit4404aa7cbauthored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: [XLA] Add TODO comment explaining why the IsScalar check exists. PiperOrigin-RevId: 163292777 --- Commit43036ac16authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Remove unnecessary break statements. PiperOrigin-RevId: 163291947 --- Commitfd5de4690authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: [XLA] Add regression test for a corner case using Reduce that currently fails with the GPU backend. PiperOrigin-RevId: 163287986 --- Commit32e198f2dauthored by Chris Leary<leary@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: [TF:XLA] Add tf.cross support. See #11788 PiperOrigin-RevId: 163287731 --- Commit88abddbc3authored by Alan Yee<alyee@ucsd.edu> Committed by Vijay Vasudevan<vrv@google.com>: Update README.md (#11793) Remove bad practices of sudo pip and install use safer pip install commands --- Commit9b30dc3a8authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Remove final mentions of `get_shape` in docstring. PiperOrigin-RevId: 163282839 --- Commit423c1eea0authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: BREAKING CHANGE: Fix semantic error in how maybe_batch* handles sparse tensors. PiperOrigin-RevId: 163276613 --- Commit6028c071bauthored by Justin Lebar<jlebar@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Highlight incoming/outgoing edges on hover in HLO graphviz dumps, and other improvements. Other improvements: - Don't show tooltips for nodes and clusters. Previously we'd show a tooltip containing a pointer value expressed as decimal. Not so useful. - Show tooltips on edges with the to/from node names. - Fix bug wherein if we had - a node at the "edge" of the graph (so its operands aren't included unless they're referenced by another node), - with all of its operands included in the graph save one or more constants, and - those constants weren't referenced by any nodes not at the edge of the graph, we would incorrectly draw the node as "grayed out", indicating that one of its operands (namely, its constant operand) wasn't present in the graph. This is wrong because constants are inlined into their users, so they should always count as "displayed" for the purposes of determining whether a node is grayed out. PiperOrigin-RevId: 163276108 --- Commitce7a355bdauthored by Joshua V. Dillon<jvdillon@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Update contrib/distributions/estimator_test build dependency. PiperOrigin-RevId: 163272464 --- Commit1b8458a1cauthored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Shorten docstring line. PiperOrigin-RevId: 163269709 --- Commit69e323cc6authored by Asim Shankar<ashankar@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Fix comment ypo PiperOrigin-RevId: 163266376 --- Commit08790e73dauthored by Chris Leary<leary@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: [XLA] Fix a bug in cloning outfeeds, carried the wrong shape. PiperOrigin-RevId: 163265592 --- Commit1bad826d6authored by Yangzihao Wang<yangzihao@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Rollback of GPU kernel implementation of transpose for tensors with one small dimension. END_PUBLIC BEGIN_PUBLIC BEGIN_PUBLIC Automated g4 rollback of changelist 162525519 PiperOrigin-RevId: 163490703
25 KiB
Writing TensorFlow Documentation
We welcome contributions to the Tensorflow documentation from the community. This document explains how you can contribute to that documentation. In particular, this document explains the following:
- Where the documentation is located.
- How to make conformant edits.
- How to build and test your documentation changes before you submit them.
You can view Tensorflow documentation on https://www.tensorflow.org, and you can view and edit the raw files on Github. We're publishing our docs on Github so everybody can contribute. Whatever gets checked in tensorflow/docs_src will be published soon after on https://www.tensorflow.org.
Republishing TensorFlow documentation in different forms is absolutely allowed, but we are unlikely to accept other documentation formats (or the tooling to generate them) into our repository. If you do choose to republish our documentation in another form, please be sure to include:
- The version of the API this represents (i.e. r1.0, master, etc.)
- The commit or version from which the documentation was generated
- Where to get the latest documentation (that is, https://www.tensorflow.org)
- The Apache 2.0 license.
A Note on Versions
tensorflow.org, at root, shows documentation for the latest stable binary. This
is the documentation you should be reading if you are using pip to install
TensorFlow.
However, most developers will contribute documentation into the master Github branch, which is published, occasionally, at tensorflow.org/versions/master.
If you want documentation changes to appear at root, you will need to also contribute that change to the current stable binary branch (and/or cherrypick).
Reference vs. non-reference documentation
The following reference documentation is automatically generated from comments in the code:
- C++ API reference docs
- Java API reference docs
- Python API reference docs
To modify the reference documentation, you edit the appropriate code comments.
Non-reference documentation (for example, the TensorFlow installation guides) is
authored by humans. This documentation is located in the tensorflow/docs_src
directory. Each subdirectory of docs_src contains a set of related Tensorflow
documentation. For example, the TensorFlow installation guides are all in the
docs_src/install directory.
The C++ documentation is generated from XML files generated via doxygen; however, those tools are not available in open source at this time.
Markdown
Editable TensorFlow documentation is written in Markdown. With a few exceptions, TensorFlow uses the standard Markdown rules.
This section explains the primary differences between standard Markdown rules and the Markdown rules that editable TensorFlow documentation uses.
Math in Markdown
You may use MathJax within TensorFlow when editing Markdown files, but note the following:
- MathJax renders properly on tensorflow.org
- MathJax does not render properly on github.
When writing MathJax, you can use $$ and \\( and \\) to
surround your math. $$ guards will cause line breaks, so
within text, use \\( \\) instead.
Links in Markdown
Links fall into a few categories:
- Links to a different part of the same file
- Links to a URL outside of tensorflow.org
- Links from a Markdown file (or code comments) to another file within tensorflow.org
For the first two link categories, you may use standard Markdown links, but put the link entirely on one line, rather than splitting it across lines. For example:
[text](link) # Good link[text]\n(link) # Bad link[text](\nlink) # Bad link
For the final link category (links to another file within tensorflow.org), please use a special link parameterization mechanism. This mechanism enables authors to move and reorganize files without breaking links.
The parameterization scheme is as follows. Use:
-
@{tf.symbol}to make a link to the reference page for a Python symbol. Note that class members don't get their own page, but the syntax still works, since@{tf.MyClass.method}links to the proper part of the tf.MyClass page. -
@{tensorflow::symbol}to make a link to the reference page for a C++ symbol. -
@{$doc_page}to make a link to another (not an API reference) doc page. To link to-
red/green/blue/index.mduse@{$blue}or@{$green/blue}, -
foo/bar/baz.mduse@{$baz}or@{$bar/baz}.
The shorter one is preferred, so we can move pages around without breaking these references. The main exception is that the Python API guides should probably be referred to using
@{$python/}to avoid ambiguity. -
-
@{$doc_page#anchor-tag$link-text}to link to an anchor in that doc and use different link text (by default, the link text is the title of the target page).To override the link text only, omit the
#anchor-tag.
To link to source code, use a link starting with:
https://www.tensorflow.org/code/, followed by
the file name starting at the github root. For instance, a link to the file you
are currently reading should be written as
https://www.tensorflow.org/code/tensorflow/docs_src/community/documentation.md.
This URL naming scheme ensures that tensorflow.org can forward the link to the branch of the code corresponding to the version of the documentation you're viewing. Do not include url parameters in the source code URL.
Generating docs and previewing links
Before building the documentation, you must first set up your environment by doing the following:
-
If pip isn't installed on your machine, install it now by issuing the following command:
$ sudo easy_install pip -
Use pip to install codegen, mock, and pandas by issuing the following command (Note: If you are using a virtualenv to manage your dependencies, you may not want to use sudo for these installations):
$ sudo pip install codegen mock pandas -
If bazel is not installed on your machine, install it now. If you are on Linux, install bazel by issuing the following command:
$ sudo apt-get install bazel # LinuxIf you are on Mac OS, find bazel installation instructions on this page.
-
Change directory to the top-level
tensorflowdirectory of the TensorFlow source code. -
Run the
configurescript and answer its prompts appropriately for your system.$ ./configure
Then, change to the tensorflow directory which contains docs_src (cd tensorflow). Run the following command to compile TensorFlow and generate the
documentation in the /tmp/tfdocs dir:
bazel run tools/docs:generate -- \
--src_dir="$(pwd)/docs_src/" \
--output_dir=/tmp/tfdocs/
Note: You must set src_dir and output_dir to absolute file paths.
Generating Python API Documentation
Ops, classes, and utility functions are defined in Python modules, such as
image_ops.py. Python modules contain a module docstring. For example:
"""Image processing and decoding ops."""
The documentation generator places this module docstring at the beginning of the Markdown file generated for the module, in this case, tf.image.
It used to be a requirement to list every member of a module inside the module
file at the beginning, putting a @@ before each member. The @@member_name
syntax is deprecated and no longer generates any docs. But depending on how a
module is sealed it may still be necessary to mark the
elements of the module’s contents as public. The called-out op, function, or
class does not have to be defined in the same file. The next few sections of
this document discuss sealing and how to add elements to the public
documentation.
The new documentation system automatically documents public symbols, except for the following:
- Private symbols whose names start with an underscore.
- Symbols originally defined in
objector protobuf’sMessage. - Some class members, such as
__base__,__class__, which are dynamically created but generally have no useful documentation.
Only top level modules (currently just tf and tfdbg) need to be manually
added to the generate script.
Sealing Modules
Because the doc generator walks all visible symbols, and descends into anything it finds, it will document any accidentally exposed symbols. If a module only exposes symbols that are meant to be part of the public API, we call it sealed. Because of Python’s loose import and visibility conventions, naively written Python code will inadvertently expose a lot of modules which are implementation details. Improperly sealed modules may expose other unsealed modules, which will typically lead the doc generator to fail. This failure is the intended behavior. It ensures that our API is well defined, and allows us to change implementation details (including which modules are imported where) without fear of accidentally breaking users.
If a module is accidentally imported, it typically breaks the doc generator
(generate_test). This is a clear sign you need to seal your modules. However,
even if the doc generator succeeds, unwanted symbols may show up in the
docs. Check the generated docs to make sure that all symbols that are documented
are expected. If there are symbols that shouldn’t be there, you have the
following options for dealing with them:
- Private symbols and imports
- The
remove_undocumentedfilter - A traversal blacklist.
We'll discuss these options in detail below.
Private Symbols and Imports
The easiest way to conform to the API sealing expectations is to make non-public
symbols private (by prepending an underscore _). The doc generator respects
private symbols. This also applies to modules. If the only problem is that there
is a small number of imported modules that show up in the docs (or break the
generator), you can simply rename them on import, e.g.: import sys as _sys.
Because Python considers all files to be modules, this applies to files as well. If you have a directory containing the following two files/modules:
module/__init__.py
module/private_impl.py
Then, after module is imported, it will be possible to access
module.private_impl. Renaming private_impl.py to _private_impl.py solves
the problem. If renaming modules is awkward, read on.
Use the remove_undocumented filter
Another way to seal a module is to split your implementation from the API. To do
so, consider using remove_undocumented, which takes a list of allowed symbols,
and deletes everything else from the module. For example, the following snippet
demonstrates how to put remove_undocumented in the __init__.py file for a
module:
init.py:
# Use * imports only if __all__ defined in some_file
from tensorflow.some_module.some_file import *
# Otherwise import symbols directly
from tensorflow.some_module.some_other_file import some_symbol
from tensorflow.python.util.all_util import remove_undocumented
_allowed_symbols = [‘some_symbol’, ‘some_other_symbol’]
remove_undocumented(__name__, allowed_exception_list=_allowed_symbols)
The @@member_name syntax is deprecated, but it still exists in some places in
the documentation as an indicator to remove_undocumented that those symbols
are public. All @@s will eventually be removed. If you see them, however,
please do not randomly delete them as they are still in use by some of our
systems.
Traversal Blacklist
If all else fails, you may add entries to the traversal blacklist in
generate_lib.py. Almost all entries in this list are an abuse of its
purpose; avoid adding to it if you can!
The traversal blacklist maps qualified module names (without the leading tf.)
to local names that are not to be descended into. For instance, the following
entry will exclude some_module from traversal.
{ ...
‘contrib.my_module’: [‘some_module’]
...
}
That means that the doc generator will show that some_module exists, but it
will not enumerate its content.
This blacklist was originally intended to make sure that system modules (mock, flags, ...) included for platform abstraction can be documented without documenting their interior. Its use beyond this purpose is a shortcut that may be acceptable for contrib, but not for core tensorflow.
Op Documentation Style Guide
Long, descriptive module-level documentation for modules should go in the API
Guides in docs_src/api_guides/python.
For classes and ops, ideally, you should provide the following information, in order of presentation:
- A short sentence that describes what the op does.
- A short description of what happens when you pass arguments to the op.
- An example showing how the op works (pseudocode is best).
- Requirements, caveats, important notes (if there are any).
- Descriptions of inputs, outputs, and Attrs or other parameters of the op constructor.
Each of these is described in more detail below.
Write your text in Markdown format. A basic syntax reference is here. You are allowed to use MathJax notation for equations (see above for restrictions).
Writing About Code
Put backticks around these things when they're used in text:
- Argument names (for example,
input,x,tensor) - Returned tensor names (for example,
output,idx,out) - Data types (for example,
int32,float,uint8) - Other op names referenced in text (for example,
list_diff(),shuffle()) - Class names (for example,
Tensorwhen you actually mean aTensorobject; don't capitalize or use backticks if you're just explaining what an op does to a tensor, or a graph, or an operation in general) - File names (for example,
image_ops.py, or/path-to-your-data/xml/example-name) - Math expressions or conditions (for example,
-1-input.dims() <= dim <= input.dims())
Put three backticks around sample code and pseudocode examples. And use ==>
instead of a single equal sign when you want to show what an op returns. For
example:
```
# 'input' is a tensor of shape [2, 3, 5]
(tf.expand_dims(input, 0)) ==> [1, 2, 3, 5]
```
If you're providing a Python code sample, add the python style label to ensure proper syntax highlighting:
```python
# some Python code
```
Two notes about backticks for code samples in Markdown:
- You can use backticks for pretty printing languages other than Python, if necessary. A full list of languages is available here.
- Markdown also allows you to indent four spaces to specify a code sample. However, do NOT indent four spaces and use backticks simultaneously. Use one or the other.
Tensor Dimensions
When you're talking about a tensor in general, don't capitalize the word tensor.
When you're talking about the specific object that's provided to an op as an
argument or returned by an op, then you should capitalize the word Tensor and
add backticks around it because you're talking about a Tensor object.
Don't use the word Tensors to describe multiple Tensor objects unless you
really are talking about a Tensors object. Better to say "a list of Tensor
objects."
Use the term "dimension" to refer to the size of a tensor. If you need to be specific about the size, use these conventions:
- Refer to a scalar as a "0-D tensor"
- Refer to a vector as a "1-D tensor"
- Refer to a matrix as a "2-D tensor"
- Refer to tensors with 3 or more dimensions as 3-D tensors or n-D tensors. Use the word "rank" only if it makes sense, but try to use "dimension" instead. Never use the word "order" to describe the size of a tensor.
Use the word "shape" to detail the dimensions of a tensor, and show the shape in square brackets with backticks. For example:
If `input` is a 3-D tensor with shape `[3, 4, 3]`, this operation
returns a 3-D tensor with shape `[6, 8, 6]`.
Ops defined in C++
All Ops defined in C++ (and accessible from other languages) must be documented
with a REGISTER_OP declaration. The docstring in the C++ file is processed to
automatically add some information for the input types, output types, and Attr
types and default values.
For example:
```c++
REGISTER_OP("PngDecode")
.Input("contents: string")
.Attr("channels: int = 0")
.Output("image: uint8")
.Doc(R"doc(
Decodes the contents of a PNG file into a uint8 tensor.
contents: PNG file contents.
channels: Number of color channels, or 0 to autodetect based on the input.
Must be 0 for autodetect, 1 for grayscale, 3 for RGB, or 4 for RGBA.
If the input has a different number of channels, it will be transformed
accordingly.
image:= A 3-D uint8 tensor of shape `[height, width, channels]`.
If `channels` is 0, the last dimension is determined
from the png contents.
)doc");
```
Results in this piece of Markdown:
### tf.image.png_decode(contents, channels=None, name=None) {#png_decode}
Decodes the contents of a PNG file into a uint8 tensor.
#### Args:
* <b>contents</b>: A string Tensor. PNG file contents.
* <b>channels</b>: An optional int. Defaults to 0.
Number of color channels, or 0 to autodetect based on the input.
Must be 0 for autodetect, 1 for grayscale, 3 for RGB, or 4 for RGBA. If the
input has a different number of channels, it will be transformed accordingly.
* <b>name</b>: A name for the operation (optional).
#### Returns:
A 3-D uint8 tensor of shape `[height, width, channels]`. If `channels` is
0, the last dimension is determined from the png contents.
Much of the argument description is added automatically. In particular, the doc
generator automatically adds the name and type of all inputs, attrs, and
outputs. In the above example, <b>contents</b>: A string Tensor. was added
automatically. You should write your additional text to flow naturally after
that description.
For inputs and output, you can prefix your additional text with an equal sign to
prevent the automatically added name and type. In the above example, the
description for the output named image starts with = to prevent the addition
of A uint8 Tensor. before our text A 3-D uint8 Tensor.... You cannot prevent
the addition of the name, type, and default value of attrs this way, so write
your text carefully.
Ops defined in Python
If your op is defined in a python/ops/*.py file, then you need to provide text
for all of the arguments and output (returned) tensors. The doc generator does
not auto-generate any text for ops that are defined in Python, so what you write
is what you get.
You should conform to the usual Python docstring conventions, except that you should use Markdown in the docstring.
Here's a simple example:
def foo(x, y, name="bar"):
"""Computes foo.
Given two 1-D tensors `x` and `y`, this operation computes the foo.
Example:
x is [1, 1]
y is [2, 2]
tf.foo(x, y) ==> [3, 3]
Args:
x: A `Tensor` of type `int32`.
y: A `Tensor` of type `int32`.
name: A name for the operation (optional).
Returns:
A `Tensor` of type `int32` that is the foo of `x` and `y`.
Raises:
ValueError: If `x` or `y` are not of type `int32`.
"""
Description of the Docstring Sections
This section details each of the elements in docstrings.
Short sentence describing what the op does
Examples:
Concatenates tensors.
Flips an image horizontally from left to right.
Computes the Levenshtein distance between two sequences.
Saves a list of tensors to a file.
Extracts a slice from a tensor.
Short description of what happens when you pass arguments to the op
Examples:
Given a tensor input of numerical type, this operation returns a tensor of
the same type and size with values reversed along dimension `seq_dim`. A
vector `seq_lengths` determines which elements are reversed for each index
within dimension 0 (usually the batch dimension).
This operation returns a tensor of type `dtype` and dimensions `shape`, with
all elements set to zero.
Example demonstrating the op
Good code samples are short and easy to understand, typically containing a brief snippet of code to clarify what the example is demonstrating. When an op manipulates the shape of a Tensor it is often useful to include an example of the before and after, as well.
The squeeze() op has a nice pseudocode example:
# 't' is a tensor of shape [1, 2, 1, 3, 1, 1]
shape(squeeze(t)) ==> [2, 3]
The tile() op provides a good example in descriptive text:
For example, tiling `[a, b, c, d]` by `[2]` produces `[a b c d a b c d]`.
It is often helpful to show code samples in Python. Never put them in the C++ Ops file, and avoid putting them in the Python Ops doc. We recommend, if possible, putting code samples in the API guides. Otherwise, add them to the module or class docstring where the Ops constructors are called out.
Here's an example from the module docstring in api_guides/python/math_ops.md:
## Segmentation
TensorFlow provides several operations that you can use to perform common
math computations on tensor segments.
...
In particular, a segmentation of a matrix tensor is a mapping of rows to
segments.
For example:
```python
c = tf.constant([[1,2,3,4], [-1,-2,-3,-4], [5,6,7,8]])
tf.segment_sum(c, tf.constant([0, 0, 1]))
==> [[0 0 0 0]
[5 6 7 8]]
```
Requirements, caveats, important notes
Examples:
This operation requires that: `-1-input.dims() <= dim <= input.dims()`
Note: This tensor will produce an error if evaluated. Its value must
be fed using the `feed_dict` optional argument to `Session.run()`,
`Tensor.eval()`, or `Operation.run()`.
Descriptions of arguments and output (returned) tensors.
Keep the descriptions brief and to the point. You should not have to explain how the operation works in the argument sections.
Mention if the Op has strong constraints on the dimensions of the input or
output tensors. Remember that for C++ Ops, the type of the tensor is
automatically added as either as "A ..type.. Tensor" or "A Tensor with type in
{...list of types...}". In such cases, if the Op has a constraint on the
dimensions either add text such as "Must be 4-D" or start the description with
= (to prevent the tensor type to be added) and write something like "A 4-D
float tensor".
For example, here are two ways to document an image argument of a C++ op (note the "=" sign):
image: Must be 4-D. The image to resize.
image:= A 4-D `float` tensor. The image to resize.
In the documentation, these will be rendered to markdown as
image: A `float` Tensor. Must be 4-D. The image to resize.
image: A 4-D `float` Tensor. The image to resize.
Optional arguments descriptions ("attrs")
The doc generator always describes the type for each attr and their default value, if any. You cannot override that with an equal sign because the description is very different in the C++ and Python generated docs.
Phrase any additional attr description so that it flows well after the type and default value. The type and defaults are displayed first, and additional descriptions follow afterwards. Therefore, complete sentences are best.
Here's an example from image_ops.cc:
REGISTER_OP("DecodePng")
.Input("contents: string")
.Attr("channels: int = 0")
.Attr("dtype: {uint8, uint16} = DT_UINT8")
.Output("image: dtype")
.SetShapeFn(DecodeImageShapeFn)
.Doc(R"doc(
Decode a PNG-encoded image to a uint8 or uint16 tensor.
The attr `channels` indicates the desired number of color channels for the
decoded image.
Accepted values are:
* 0: Use the number of channels in the PNG-encoded image.
* 1: output a grayscale image.
* 3: output an RGB image.
* 4: output an RGBA image.
If needed, the PNG-encoded image is transformed to match the requested
number of color channels.
contents: 0-D. The PNG-encoded image.
channels: Number of color channels for the decoded image.
image: 3-D with shape `[height, width, channels]`.
)doc");
This generates the following Args section in
api_docs/python/tf/image/decode_png.md:
#### Args:
* <b>`contents`</b>: A `Tensor` of type `string`. 0-D. The PNG-encoded
image.
* <b>`channels`</b>: An optional `int`. Defaults to `0`. Number of color
channels for the decoded image.
* <b>`dtype`</b>: An optional `tf.DType` from: `tf.uint8,
tf.uint16`. Defaults to `tf.uint 8`.
* <b>`name`</b>: A name for the operation (optional).