Skip to content

fix: optimize some APIs #1129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2023
Merged

Conversation

Beacontownfc
Copy link
Contributor

@Beacontownfc Beacontownfc commented Jul 3, 2023

tf.nn.moments : There may be a problem where the gradient is null during the training, it seems that removing the 681st line of code from the [TensorFlowNET.Core/Operations/array_ops.cs] can solve this issue.

tf.nn.batch_normalization: Use nn_impl.batch_normalization to reuse code.

@Beacontownfc Beacontownfc requested a review from Oceania2018 as a code owner July 3, 2023 13:40
@Oceania2018 Oceania2018 merged commit adc90af into SciSharp:master Jul 3, 2023
@Beacontownfc Beacontownfc deleted the mybranch3 branch July 7, 2023 00:19
@@ -678,7 +678,6 @@ public static Tensor stop_gradient(Tensor input, string name = null)
var tape = tf.GradientTape().stop_recording();
var result = gen_array_ops.stop_gradient(input, name);
tape.StartRecord();
tf.GradientTape().PushTape(tape);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this removal looks highly suspicious. Does anyone even know why this statement is here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks fine when I run though all the examples.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of the examples test this specific method though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not deleting this line of code will result in NULL gradient when using the stop_gradient API.

Copy link
Contributor Author

@Beacontownfc Beacontownfc Jul 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LayerNorm uses tf.nn.moments and tf.nn.moments uses the stop_gradient API. If this line of code is not deleted, an error will be reported. Deleting this line of code will enable normal training.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants