Repository navigation
Conversation
global_norm was only tested through clip_by_global_norm. Add direct tests for the documented behavior: list and tuple inputs, ignored None entries, IndexedSlices (only the values count), a zero norm for an empty or all-None list, keeping the float16, bfloat16 and float64 dtypes, and the TypeError for inputs that are not sequences.
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds comprehensive unit tests for the global_norm operation in tensorflow/python/kernel_tests/math_ops/clip_ops_test.py. The new tests cover standard global norm calculations, handling of IndexedSlices, empty or None inputs, preservation of data types (such as float16, bfloat16, and float64), and verification that appropriate exceptions are raised for non-sequence inputs. There are no review comments, and I have no feedback to provide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tf.linalg.global_norm(used bytf.clip_by_global_normfor gradient clipping) had no direct tests. It was only covered throughclip_by_global_norm, which does not check its dtype handling or its input validation.This adds tests to
clip_ops_test.pyfor the behavior described in its docstring:Noneentries ignoredIndexedSlices, where only the values countNoneTypeErrorfor a tensor, a string or a dict instead of a sequenceTest only, no library changes and no new dependencies.
Testing: I did not run Bazel locally. I ran
clip_ops_test.pywith Python against tf-nightly 2.23.0-dev20261107 (itsclip_ops.pyis identical to master):global_normin five ways (keepingNoneentries, removing the TypeError check, a wrong norm value, returning float32 for every input, counting theIndexedSlicesdense shape). The new tests fail for all five. The existing tests miss two of them: the removed TypeError check and the lost dtype.pylint --rcfile=tensorflow/tools/ci_build/pylintrcon the changed file: 10.00/10