Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Guidelines for Python code examples in derivative tests. #499

@rxwei

Description

@rxwei

What has really helped in assuring our layers' correctness is adding a Python reproducer per layer test like this example. Thank you @eaplatanios, @Shashi456, @jon-tow and @t-ae for doing this! As we make more progress towards finishing #402, we need to make sure all the reproducers we add are high-quality (@dan-zheng also mentioned this to me earlier). I propose that we follow the following guidelines in future Python code examples:

  1. Use TensorFlow 2.0 and tf.keras.
  2. Include all code necessary for reproducing the gradients. This includes any import statements.
  3. Use the same variable names for values being differentiated with respect to as the surrounding Swift code.
  4. Leave no blank lines.
  5. Call print() on the gradient, so that reproducing is as easy as copy-paste.
  6. Zero base indentation. Currently I'm seeing:
    // ```
    //   maxpool2D = tf.keras.layers.MaxPool2D(strides=(2, 2))
    //   with tf.GradientTape() as t:
    ... which should be changed to:
    // ```
    // import tensorflow as tf
    // maxpool2D = tf.keras.layers.MaxPool2D(strides=(2, 2))
    // with tf.GradientTape() as t:
  7. Add a sentence above the code block:
    // The expected value of the gradient was computed using the following Python code:
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions