swift-apis icon indicating copy to clipboard operation
swift-apis copied to clipboard

Guidelines for Python code examples in derivative tests.

Open rxwei opened this issue 5 years ago • 2 comments

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:
    

rxwei avatar Aug 29 '19 03:08 rxwei

What about adding the variable used in the code as well? We don't exactly add x/input to the reproducers.

Shashi456 avatar Aug 29 '19 04:08 Shashi456

Yes, good point. Updated.

rxwei avatar Aug 29 '19 04:08 rxwei