xref: /aosp_15_r20/external/tensorflow/CONTRIBUTING.md (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1*b6fb3261SAndroid Build Coastguard Worker# Contributing guidelines
2*b6fb3261SAndroid Build Coastguard Worker
3*b6fb3261SAndroid Build Coastguard Worker## Pull Request Checklist
4*b6fb3261SAndroid Build Coastguard Worker
5*b6fb3261SAndroid Build Coastguard WorkerBefore sending your pull requests, make sure you do the following:
6*b6fb3261SAndroid Build Coastguard Worker
7*b6fb3261SAndroid Build Coastguard Worker-   Read the [contributing guidelines](CONTRIBUTING.md).
8*b6fb3261SAndroid Build Coastguard Worker-   Read the [Code of Conduct](CODE_OF_CONDUCT.md).
9*b6fb3261SAndroid Build Coastguard Worker-   Ensure you have signed the
10*b6fb3261SAndroid Build Coastguard Worker    [Contributor License Agreement (CLA)](https://cla.developers.google.com/).
11*b6fb3261SAndroid Build Coastguard Worker-   Check if your changes are consistent with the
12*b6fb3261SAndroid Build Coastguard Worker    [guidelines](#general-guidelines-and-philosophy-for-contribution).
13*b6fb3261SAndroid Build Coastguard Worker-   Changes are consistent with the [Coding Style](#c-coding-style).
14*b6fb3261SAndroid Build Coastguard Worker-   Run the [unit tests](#running-unit-tests).
15*b6fb3261SAndroid Build Coastguard Worker
16*b6fb3261SAndroid Build Coastguard Worker## How to become a contributor and submit your own code
17*b6fb3261SAndroid Build Coastguard Worker
18*b6fb3261SAndroid Build Coastguard Worker### Contributor License Agreements
19*b6fb3261SAndroid Build Coastguard Worker
20*b6fb3261SAndroid Build Coastguard WorkerWe'd love to accept your patches! Before we can take them, we have to jump a couple of legal hurdles.
21*b6fb3261SAndroid Build Coastguard Worker
22*b6fb3261SAndroid Build Coastguard WorkerPlease fill out either the individual or corporate Contributor License Agreement (CLA).
23*b6fb3261SAndroid Build Coastguard Worker
24*b6fb3261SAndroid Build Coastguard Worker  * If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an [individual CLA](https://code.google.com/legal/individual-cla-v1.0.html).
25*b6fb3261SAndroid Build Coastguard Worker  * If you work for a company that wants to allow you to contribute your work, then you'll need to sign a [corporate CLA](https://code.google.com/legal/corporate-cla-v1.0.html).
26*b6fb3261SAndroid Build Coastguard Worker
27*b6fb3261SAndroid Build Coastguard WorkerFollow either of the two links above to access the appropriate CLA and instructions for how to sign and return it. Once we receive it, we'll be able to accept your pull requests.
28*b6fb3261SAndroid Build Coastguard Worker
29*b6fb3261SAndroid Build Coastguard Worker***NOTE***: Only original source code from you and other people that have signed the CLA can be accepted into the main repository.
30*b6fb3261SAndroid Build Coastguard Worker
31*b6fb3261SAndroid Build Coastguard Worker### Contributing code
32*b6fb3261SAndroid Build Coastguard Worker
33*b6fb3261SAndroid Build Coastguard WorkerIf you have improvements to TensorFlow, send us your pull requests! For those
34*b6fb3261SAndroid Build Coastguard Workerjust getting started, Github has a
35*b6fb3261SAndroid Build Coastguard Worker[how to](https://help.github.com/articles/using-pull-requests/).
36*b6fb3261SAndroid Build Coastguard Worker
37*b6fb3261SAndroid Build Coastguard WorkerTensorFlow team members will be assigned to review your pull requests. Once the
38*b6fb3261SAndroid Build Coastguard Workerpull requests are approved and pass continuous integration checks, a TensorFlow
39*b6fb3261SAndroid Build Coastguard Workerteam member will apply `ready to pull` label to your change. This means we are
40*b6fb3261SAndroid Build Coastguard Workerworking on getting your pull request submitted to our internal repository. After
41*b6fb3261SAndroid Build Coastguard Workerthe change has been submitted internally, your pull request will be merged
42*b6fb3261SAndroid Build Coastguard Workerautomatically on GitHub.
43*b6fb3261SAndroid Build Coastguard Worker
44*b6fb3261SAndroid Build Coastguard WorkerIf you want to contribute, start working through the TensorFlow codebase,
45*b6fb3261SAndroid Build Coastguard Workernavigate to the
46*b6fb3261SAndroid Build Coastguard Worker[Github "issues" tab](https://github.com/tensorflow/tensorflow/issues) and start
47*b6fb3261SAndroid Build Coastguard Workerlooking through interesting issues. If you are not sure of where to start, then
48*b6fb3261SAndroid Build Coastguard Workerstart by trying one of the smaller/easier issues here i.e.
49*b6fb3261SAndroid Build Coastguard Worker[issues with the "good first issue" label](https://github.com/tensorflow/tensorflow/labels/good%20first%20issue)
50*b6fb3261SAndroid Build Coastguard Workerand then take a look at the
51*b6fb3261SAndroid Build Coastguard Worker[issues with the "contributions welcome" label](https://github.com/tensorflow/tensorflow/labels/stat%3Acontributions%20welcome).
52*b6fb3261SAndroid Build Coastguard WorkerThese are issues that we believe are particularly well suited for outside
53*b6fb3261SAndroid Build Coastguard Workercontributions, often because we probably won't get to them right now. If you
54*b6fb3261SAndroid Build Coastguard Workerdecide to start on an issue, leave a comment so that other people know that
55*b6fb3261SAndroid Build Coastguard Workeryou're working on it. If you want to help out, but not alone, use the issue
56*b6fb3261SAndroid Build Coastguard Workercomment thread to coordinate.
57*b6fb3261SAndroid Build Coastguard Worker
58*b6fb3261SAndroid Build Coastguard Worker### Contribution guidelines and standards
59*b6fb3261SAndroid Build Coastguard Worker
60*b6fb3261SAndroid Build Coastguard WorkerBefore sending your pull request for
61*b6fb3261SAndroid Build Coastguard Worker[review](https://github.com/tensorflow/tensorflow/pulls),
62*b6fb3261SAndroid Build Coastguard Workermake sure your changes are consistent with the guidelines and follow the
63*b6fb3261SAndroid Build Coastguard WorkerTensorFlow coding style.
64*b6fb3261SAndroid Build Coastguard Worker
65*b6fb3261SAndroid Build Coastguard Worker#### General guidelines and philosophy for contribution
66*b6fb3261SAndroid Build Coastguard Worker
67*b6fb3261SAndroid Build Coastguard Worker*   Include unit tests when you contribute new features, as they help to a)
68*b6fb3261SAndroid Build Coastguard Worker    prove that your code works correctly, and b) guard against future breaking
69*b6fb3261SAndroid Build Coastguard Worker    changes to lower the maintenance cost.
70*b6fb3261SAndroid Build Coastguard Worker*   Bug fixes also generally require unit tests, because the presence of bugs
71*b6fb3261SAndroid Build Coastguard Worker    usually indicates insufficient test coverage.
72*b6fb3261SAndroid Build Coastguard Worker*   Keep API compatibility in mind when you change code in core TensorFlow,
73*b6fb3261SAndroid Build Coastguard Worker    e.g., code in
74*b6fb3261SAndroid Build Coastguard Worker    [tensorflow/core](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core)
75*b6fb3261SAndroid Build Coastguard Worker    and
76*b6fb3261SAndroid Build Coastguard Worker    [tensorflow/python](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/python).
77*b6fb3261SAndroid Build Coastguard Worker    TensorFlow has passed version 1.0 and hence cannot make
78*b6fb3261SAndroid Build Coastguard Worker    non-backward-compatible API changes without a major release. Reviewers of
79*b6fb3261SAndroid Build Coastguard Worker    your pull request will comment on any API compatibility issues
80*b6fb3261SAndroid Build Coastguard Worker    [following API review practices](https://github.com/tensorflow/community/blob/master/governance/api-reviews.md).
81*b6fb3261SAndroid Build Coastguard Worker*   When you contribute a new feature to TensorFlow, the maintenance burden is
82*b6fb3261SAndroid Build Coastguard Worker    (by default) transferred to the TensorFlow team. This means that the benefit
83*b6fb3261SAndroid Build Coastguard Worker    of the contribution must be compared against the cost of maintaining the
84*b6fb3261SAndroid Build Coastguard Worker    feature.
85*b6fb3261SAndroid Build Coastguard Worker*   Full new features (e.g., a new op implementing a cutting-edge algorithm)
86*b6fb3261SAndroid Build Coastguard Worker    typically will live in
87*b6fb3261SAndroid Build Coastguard Worker    [tensorflow/addons](https://github.com/tensorflow/addons) to get some
88*b6fb3261SAndroid Build Coastguard Worker    airtime before a decision is made regarding whether they are to be migrated
89*b6fb3261SAndroid Build Coastguard Worker    to the core.
90*b6fb3261SAndroid Build Coastguard Worker*   As every PR requires several CPU/GPU hours of CI testing, we discourage
91*b6fb3261SAndroid Build Coastguard Worker    submitting PRs to fix one typo, one warning,etc. We recommend fixing the
92*b6fb3261SAndroid Build Coastguard Worker    same issue at the file level at least (e.g.: fix all typos in a file, fix
93*b6fb3261SAndroid Build Coastguard Worker    all compiler warning in a file, etc.)
94*b6fb3261SAndroid Build Coastguard Worker*   Tests should follow the
95*b6fb3261SAndroid Build Coastguard Worker    [testing best practices](https://www.tensorflow.org/community/contribute/tests)
96*b6fb3261SAndroid Build Coastguard Worker    guide.
97*b6fb3261SAndroid Build Coastguard Worker
98*b6fb3261SAndroid Build Coastguard Worker#### License
99*b6fb3261SAndroid Build Coastguard Worker
100*b6fb3261SAndroid Build Coastguard WorkerInclude a license at the top of new files.
101*b6fb3261SAndroid Build Coastguard Worker
102*b6fb3261SAndroid Build Coastguard Worker* [C/C++ license example](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/op.cc#L1)
103*b6fb3261SAndroid Build Coastguard Worker* [Python license example](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/nn.py#L1)
104*b6fb3261SAndroid Build Coastguard Worker* [Java license example](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/java/src/main/java/org/tensorflow/Graph.java#L1)
105*b6fb3261SAndroid Build Coastguard Worker* [Go license example](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/go/operation.go#L1)
106*b6fb3261SAndroid Build Coastguard Worker* [Bash license example](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/ci_build/ci_sanity.sh#L2)
107*b6fb3261SAndroid Build Coastguard Worker* [HTML license example](https://github.com/tensorflow/tensorboard/blob/master/tensorboard/components/tf_backend/tf-backend.html#L2)
108*b6fb3261SAndroid Build Coastguard Worker* [JavaScript/TypeScript license example](https://github.com/tensorflow/tensorboard/blob/master/tensorboard/components/tf_backend/backend.ts#L1)
109*b6fb3261SAndroid Build Coastguard Worker
110*b6fb3261SAndroid Build Coastguard WorkerBazel BUILD files also need to include a license section, e.g.,
111*b6fb3261SAndroid Build Coastguard Worker[BUILD example](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/BUILD#L61).
112*b6fb3261SAndroid Build Coastguard Worker
113*b6fb3261SAndroid Build Coastguard Worker#### C++ coding style
114*b6fb3261SAndroid Build Coastguard Worker
115*b6fb3261SAndroid Build Coastguard WorkerChanges to TensorFlow C++ code should conform to
116*b6fb3261SAndroid Build Coastguard Worker[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).
117*b6fb3261SAndroid Build Coastguard Worker
118*b6fb3261SAndroid Build Coastguard WorkerUse `clang-tidy` to check your C/C++ changes. To install `clang-tidy` on ubuntu:16.04, do:
119*b6fb3261SAndroid Build Coastguard Worker
120*b6fb3261SAndroid Build Coastguard Worker```bash
121*b6fb3261SAndroid Build Coastguard Workerapt-get install -y clang-tidy
122*b6fb3261SAndroid Build Coastguard Worker```
123*b6fb3261SAndroid Build Coastguard Worker
124*b6fb3261SAndroid Build Coastguard WorkerYou can check a C/C++ file by doing:
125*b6fb3261SAndroid Build Coastguard Worker
126*b6fb3261SAndroid Build Coastguard Worker
127*b6fb3261SAndroid Build Coastguard Worker```bash
128*b6fb3261SAndroid Build Coastguard Workerclang-format <my_cc_file> --style=google > /tmp/my_cc_file.cc
129*b6fb3261SAndroid Build Coastguard Workerdiff <my_cc_file> /tmp/my_cc_file.cc
130*b6fb3261SAndroid Build Coastguard Worker```
131*b6fb3261SAndroid Build Coastguard Worker
132*b6fb3261SAndroid Build Coastguard Worker#### Python coding style
133*b6fb3261SAndroid Build Coastguard Worker
134*b6fb3261SAndroid Build Coastguard WorkerChanges to TensorFlow Python code should conform to
135*b6fb3261SAndroid Build Coastguard Worker[Google Python Style Guide](https://github.com/google/styleguide/blob/gh-pages/pyguide.md)
136*b6fb3261SAndroid Build Coastguard Worker
137*b6fb3261SAndroid Build Coastguard WorkerUse `pylint` to check your Python changes. To install `pylint` and check a file
138*b6fb3261SAndroid Build Coastguard Workerwith `pylint` against TensorFlow's custom style definition:
139*b6fb3261SAndroid Build Coastguard Worker
140*b6fb3261SAndroid Build Coastguard Worker```bash
141*b6fb3261SAndroid Build Coastguard Workerpip install pylint
142*b6fb3261SAndroid Build Coastguard Workerpylint --rcfile=tensorflow/tools/ci_build/pylintrc myfile.py
143*b6fb3261SAndroid Build Coastguard Worker```
144*b6fb3261SAndroid Build Coastguard Worker
145*b6fb3261SAndroid Build Coastguard WorkerNote `pylint --rcfile=tensorflow/tools/ci_build/pylintrc` should run from the
146*b6fb3261SAndroid Build Coastguard Workertop level tensorflow directory.
147*b6fb3261SAndroid Build Coastguard Worker
148*b6fb3261SAndroid Build Coastguard Worker#### Coding style for other languages
149*b6fb3261SAndroid Build Coastguard Worker
150*b6fb3261SAndroid Build Coastguard Worker* [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html)
151*b6fb3261SAndroid Build Coastguard Worker* [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)
152*b6fb3261SAndroid Build Coastguard Worker* [Google Shell Style Guide](https://google.github.io/styleguide/shell.xml)
153*b6fb3261SAndroid Build Coastguard Worker* [Google Objective-C Style Guide](https://google.github.io/styleguide/objcguide.html)
154*b6fb3261SAndroid Build Coastguard Worker
155*b6fb3261SAndroid Build Coastguard Worker#### Running sanity check
156*b6fb3261SAndroid Build Coastguard Worker
157*b6fb3261SAndroid Build Coastguard WorkerIf you have Docker installed on your system, you can perform a sanity check on
158*b6fb3261SAndroid Build Coastguard Workeryour changes by running the command:
159*b6fb3261SAndroid Build Coastguard Worker
160*b6fb3261SAndroid Build Coastguard Worker```bash
161*b6fb3261SAndroid Build Coastguard Workertensorflow/tools/ci_build/ci_build.sh CPU tensorflow/tools/ci_build/ci_sanity.sh
162*b6fb3261SAndroid Build Coastguard Worker```
163*b6fb3261SAndroid Build Coastguard Worker
164*b6fb3261SAndroid Build Coastguard WorkerThis will catch most license, Python coding style and BUILD file issues that
165*b6fb3261SAndroid Build Coastguard Workermay exist in your changes.
166*b6fb3261SAndroid Build Coastguard Worker
167*b6fb3261SAndroid Build Coastguard Worker#### Running unit tests
168*b6fb3261SAndroid Build Coastguard Worker
169*b6fb3261SAndroid Build Coastguard WorkerThere are two ways to run TensorFlow unit tests.
170*b6fb3261SAndroid Build Coastguard Worker
171*b6fb3261SAndroid Build Coastguard Worker1.  Using tools and libraries installed directly on your system.
172*b6fb3261SAndroid Build Coastguard Worker
173*b6fb3261SAndroid Build Coastguard Worker    Refer to the
174*b6fb3261SAndroid Build Coastguard Worker    [CPU-only developer Dockerfile](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/dockerfiles/dockerfiles/devel-cpu.Dockerfile)
175*b6fb3261SAndroid Build Coastguard Worker    and
176*b6fb3261SAndroid Build Coastguard Worker    [GPU developer Dockerfile](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/dockerfiles/dockerfiles/devel-gpu.Dockerfile)
177*b6fb3261SAndroid Build Coastguard Worker    for the required packages. Alternatively, use the said
178*b6fb3261SAndroid Build Coastguard Worker    [Docker images](https://hub.docker.com/r/tensorflow/tensorflow/tags/), e.g.,
179*b6fb3261SAndroid Build Coastguard Worker    `tensorflow/tensorflow:devel` and `tensorflow/tensorflow:devel-gpu` for
180*b6fb3261SAndroid Build Coastguard Worker    development to avoid installing the packages directly on your system (in
181*b6fb3261SAndroid Build Coastguard Worker    which case remember to change directory from `/root` to `/tensorflow` once
182*b6fb3261SAndroid Build Coastguard Worker    you get into the running container so `bazel` can find the `tensorflow`
183*b6fb3261SAndroid Build Coastguard Worker    workspace).
184*b6fb3261SAndroid Build Coastguard Worker
185*b6fb3261SAndroid Build Coastguard Worker    Once you have the packages installed, you can run a specific unit test in
186*b6fb3261SAndroid Build Coastguard Worker    bazel by doing as follows:
187*b6fb3261SAndroid Build Coastguard Worker
188*b6fb3261SAndroid Build Coastguard Worker    ```bash
189*b6fb3261SAndroid Build Coastguard Worker    export flags="--config=opt -k"
190*b6fb3261SAndroid Build Coastguard Worker    ```
191*b6fb3261SAndroid Build Coastguard Worker
192*b6fb3261SAndroid Build Coastguard Worker    If the tests are to be run on GPU, add CUDA paths to LD_LIBRARY_PATH and add
193*b6fb3261SAndroid Build Coastguard Worker    the `cuda` option flag
194*b6fb3261SAndroid Build Coastguard Worker
195*b6fb3261SAndroid Build Coastguard Worker    ```bash
196*b6fb3261SAndroid Build Coastguard Worker    export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH"
197*b6fb3261SAndroid Build Coastguard Worker
198*b6fb3261SAndroid Build Coastguard Worker    export flags="--config=opt --config=cuda -k"
199*b6fb3261SAndroid Build Coastguard Worker    ```
200*b6fb3261SAndroid Build Coastguard Worker
201*b6fb3261SAndroid Build Coastguard Worker    For example, to run all tests under tensorflow/python, do:
202*b6fb3261SAndroid Build Coastguard Worker
203*b6fb3261SAndroid Build Coastguard Worker    ```bash
204*b6fb3261SAndroid Build Coastguard Worker    bazel test ${flags} //tensorflow/python/...
205*b6fb3261SAndroid Build Coastguard Worker    ```
206*b6fb3261SAndroid Build Coastguard Worker
207*b6fb3261SAndroid Build Coastguard Worker    For a single component e.g. softmax op:
208*b6fb3261SAndroid Build Coastguard Worker
209*b6fb3261SAndroid Build Coastguard Worker    ```bash
210*b6fb3261SAndroid Build Coastguard Worker    bazel test ${flags} tensorflow/python/kernel_tests:softmax_op_test
211*b6fb3261SAndroid Build Coastguard Worker    ```
212*b6fb3261SAndroid Build Coastguard Worker
213*b6fb3261SAndroid Build Coastguard Worker    For a single/parameterized test e.g. `test_capture_variables` in
214*b6fb3261SAndroid Build Coastguard Worker    `tensorflow/python/saved_model/load_test.py`:
215*b6fb3261SAndroid Build Coastguard Worker
216*b6fb3261SAndroid Build Coastguard Worker    (Requires `python>=3.7`)
217*b6fb3261SAndroid Build Coastguard Worker
218*b6fb3261SAndroid Build Coastguard Worker    ```bash
219*b6fb3261SAndroid Build Coastguard Worker    bazel test ${flags} //tensorflow/python/saved_model:load_test --test_filter=*LoadTest.test_capture_variables*
220*b6fb3261SAndroid Build Coastguard Worker    ```
221*b6fb3261SAndroid Build Coastguard Worker
222*b6fb3261SAndroid Build Coastguard Worker    **Note:** You can add `--test_sharding_strategy=disabled` to the `flags` to
223*b6fb3261SAndroid Build Coastguard Worker    disable the sharding so that all the test outputs are in one file. However,
224*b6fb3261SAndroid Build Coastguard Worker    it may slow down the tests for not running in parallel and may cause the
225*b6fb3261SAndroid Build Coastguard Worker    test to timeout but it could be useful when you need to execute a single
226*b6fb3261SAndroid Build Coastguard Worker    test or more in general your filtered/selected tests have a very low
227*b6fb3261SAndroid Build Coastguard Worker    execution time and the sharding
228*b6fb3261SAndroid Build Coastguard Worker    [could create an overhead on the test execution](https://github.com/bazelbuild/bazel/issues/2113#issuecomment-264054799).
229*b6fb3261SAndroid Build Coastguard Worker
230*b6fb3261SAndroid Build Coastguard Worker2.  Using [Docker](https://www.docker.com) and TensorFlow's CI scripts.
231*b6fb3261SAndroid Build Coastguard Worker
232*b6fb3261SAndroid Build Coastguard Worker    ```bash
233*b6fb3261SAndroid Build Coastguard Worker    # Install Docker first, then this will build and run cpu tests
234*b6fb3261SAndroid Build Coastguard Worker    tensorflow/tools/ci_build/ci_build.sh CPU bazel test //tensorflow/...
235*b6fb3261SAndroid Build Coastguard Worker    ```
236*b6fb3261SAndroid Build Coastguard Worker
237*b6fb3261SAndroid Build Coastguard Worker    See
238*b6fb3261SAndroid Build Coastguard Worker    [TensorFlow Builds](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/ci_build)
239*b6fb3261SAndroid Build Coastguard Worker    for details.
240*b6fb3261SAndroid Build Coastguard Worker
241*b6fb3261SAndroid Build Coastguard Worker#### Running doctest for testable docstring
242*b6fb3261SAndroid Build Coastguard Worker
243*b6fb3261SAndroid Build Coastguard WorkerThere are two ways to test the code in the docstring locally:
244*b6fb3261SAndroid Build Coastguard Worker
245*b6fb3261SAndroid Build Coastguard Worker1.  If you are only changing the docstring of a class/function/method, then you
246*b6fb3261SAndroid Build Coastguard Worker    can test it by passing that file's path to
247*b6fb3261SAndroid Build Coastguard Worker    [tf_doctest.py](https://www.tensorflow.org/code/tensorflow/tools/docs/tf_doctest.py).
248*b6fb3261SAndroid Build Coastguard Worker    For example:
249*b6fb3261SAndroid Build Coastguard Worker
250*b6fb3261SAndroid Build Coastguard Worker    ```bash
251*b6fb3261SAndroid Build Coastguard Worker    python tf_doctest.py --file=<file_path>
252*b6fb3261SAndroid Build Coastguard Worker    ```
253*b6fb3261SAndroid Build Coastguard Worker
254*b6fb3261SAndroid Build Coastguard Worker    This will run it using your installed version of TensorFlow. To be sure
255*b6fb3261SAndroid Build Coastguard Worker    you're running the same code that you're testing:
256*b6fb3261SAndroid Build Coastguard Worker
257*b6fb3261SAndroid Build Coastguard Worker    *   Use an up to date [tf-nightly](https://pypi.org/project/tf-nightly/)
258*b6fb3261SAndroid Build Coastguard Worker        `pip install -U tf-nightly`
259*b6fb3261SAndroid Build Coastguard Worker    *   Rebase your pull request onto a recent pull from
260*b6fb3261SAndroid Build Coastguard Worker        [TensorFlow's](https://github.com/tensorflow/tensorflow) master branch.
261*b6fb3261SAndroid Build Coastguard Worker
262*b6fb3261SAndroid Build Coastguard Worker2.  If you are changing the code and the docstring of a class/function/method,
263*b6fb3261SAndroid Build Coastguard Worker    then you will need to
264*b6fb3261SAndroid Build Coastguard Worker    [build TensorFlow from source](https://www.tensorflow.org/install/source).
265*b6fb3261SAndroid Build Coastguard Worker    Once you are setup to build from source, you can run the tests:
266*b6fb3261SAndroid Build Coastguard Worker
267*b6fb3261SAndroid Build Coastguard Worker    ```bash
268*b6fb3261SAndroid Build Coastguard Worker    bazel run //tensorflow/tools/docs:tf_doctest
269*b6fb3261SAndroid Build Coastguard Worker    ```
270*b6fb3261SAndroid Build Coastguard Worker
271*b6fb3261SAndroid Build Coastguard Worker    or
272*b6fb3261SAndroid Build Coastguard Worker
273*b6fb3261SAndroid Build Coastguard Worker    ```bash
274*b6fb3261SAndroid Build Coastguard Worker    bazel run //tensorflow/tools/docs:tf_doctest -- --module=ops.array_ops
275*b6fb3261SAndroid Build Coastguard Worker    ```
276*b6fb3261SAndroid Build Coastguard Worker
277*b6fb3261SAndroid Build Coastguard Worker    The `--module` is relative to `tensorflow.python`.
278*b6fb3261SAndroid Build Coastguard Worker
279*b6fb3261SAndroid Build Coastguard Worker#### Debug builds
280*b6fb3261SAndroid Build Coastguard Worker
281*b6fb3261SAndroid Build Coastguard WorkerWhen [building Tensorflow](https://www.tensorflow.org/install/source), passing
282*b6fb3261SAndroid Build Coastguard Worker`--config=dbg` to Bazel will build with debugging information and without
283*b6fb3261SAndroid Build Coastguard Workeroptimizations, allowing you to use GDB or other debuggers to debug C++ code. For
284*b6fb3261SAndroid Build Coastguard Workerexample, you can build the pip package with debugging information by running:
285*b6fb3261SAndroid Build Coastguard Worker
286*b6fb3261SAndroid Build Coastguard Worker```bash
287*b6fb3261SAndroid Build Coastguard Workerbazel build --config=dbg //tensorflow/tools/pip_package:build_pip_package
288*b6fb3261SAndroid Build Coastguard Worker```
289*b6fb3261SAndroid Build Coastguard Worker
290*b6fb3261SAndroid Build Coastguard WorkerTensorFlow kernels and TensorFlow's dependencies are still not built with
291*b6fb3261SAndroid Build Coastguard Workerdebugging information with `--config=dbg`, as issues occur on Linux if
292*b6fb3261SAndroid Build Coastguard Workerthere is too much debug info (see [this GitHub
293*b6fb3261SAndroid Build Coastguard Workerissue](https://github.com/tensorflow/tensorflow/issues/48919) for context). If
294*b6fb3261SAndroid Build Coastguard Workeryou want to debug a kernel, you can compile specific files with `-g` using the
295*b6fb3261SAndroid Build Coastguard Worker`--per_file_copt` bazel option. For example, if you want to debug the Identity
296*b6fb3261SAndroid Build Coastguard Workerop, which are in files starting with `identity_op`, you can run
297*b6fb3261SAndroid Build Coastguard Worker
298*b6fb3261SAndroid Build Coastguard Worker```bash
299*b6fb3261SAndroid Build Coastguard Workerbazel build --config=dbg --per_file_copt=+tensorflow/core/kernels/identity_op.*@-g //tensorflow/tools/pip_package:build_pip_package
300*b6fb3261SAndroid Build Coastguard Worker```
301*b6fb3261SAndroid Build Coastguard Worker
302*b6fb3261SAndroid Build Coastguard WorkerNote that the `--config=dbg` option is not officially supported.
303