swift-apis
swift-apis copied to clipboard
Guidelines for Python code examples in derivative tests.
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:
- Use TensorFlow 2.0 and tf.keras.
- Include all code necessary for reproducing the gradients. This includes any
import
statements. - Use the same variable names for values being differentiated with respect to as the surrounding Swift code.
- Leave no blank lines.
- Call
print()
on the gradient, so that reproducing is as easy as copy-paste. - Zero base indentation. Currently I'm seeing:
... which should be changed to:// ``` // maxpool2D = tf.keras.layers.MaxPool2D(strides=(2, 2)) // with tf.GradientTape() as t:
// ``` // import tensorflow as tf // maxpool2D = tf.keras.layers.MaxPool2D(strides=(2, 2)) // with tf.GradientTape() as t:
- Add a sentence above the code block:
// The expected value of the gradient was computed using the following Python code:
What about adding the variable used in the code as well? We don't exactly add x/input to the reproducers.
Yes, good point. Updated.