Skip to content
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

resolve line-too-long in initializers #16598

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions keras/initializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def populate_deserializable_objects():
LOCAL.ALL_OBJECTS["ZerosV2"] = initializers_v2.Zeros

# Out of an abundance of caution we also include these aliases that have
# a non-zero probability of having been included in saved configs in the past.
# a non-zero probability of having been included in saved configs in the
# past.
LOCAL.ALL_OBJECTS["glorot_normalV2"] = initializers_v2.GlorotNormal
LOCAL.ALL_OBJECTS["glorot_uniformV2"] = initializers_v2.GlorotUniform
LOCAL.ALL_OBJECTS["he_normalV2"] = initializers_v2.HeNormal
Expand Down Expand Up @@ -150,16 +151,16 @@ def deserialize(config, custom_objects=None):
def get(identifier):
"""Retrieve a Keras initializer by the identifier.

The `identifier` may be the string name of a initializers function or class (
case-sensitively).
The `identifier` may be the string name of a initializers function or class
(case-sensitively).

>>> identifier = 'Ones'
>>> tf.keras.initializers.deserialize(identifier)
<...keras.initializers.initializers_v2.Ones...>

You can also specify `config` of the initializer to this function by passing
dict containing `class_name` and `config` as an identifier. Also note that the
`class_name` must map to a `Initializer` class.
dict containing `class_name` and `config` as an identifier. Also note that
the `class_name` must map to a `Initializer` class.

>>> cfg = {'class_name': 'Ones', 'config': {}}
>>> tf.keras.initializers.deserialize(cfg)
Expand Down
15 changes: 9 additions & 6 deletions keras/initializers/initializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def _runner(
target_max=None,
target_min=None,
):
# The global seed is set so that we can get the same random streams between
# eager and graph mode when stateful op is used.
# The global seed is set so that we can get the same random streams
# between eager and graph mode when stateful op is used.
tf.random.set_seed(1337)
variable = backend.variable(init(shape))
output = backend.get_value(variable)
Expand Down Expand Up @@ -314,8 +314,9 @@ def test_partition(self, initializer_cls, kwargs):
self.assertEqual(result.shape, (2, 2))

if hasattr(initializer, "seed"):
# Make sure the result are different when the partition_shape is same,
# but partition_offset is different, for random related initializers.
# Make sure the result are different when the partition_shape is
# same, but partition_offset is different, for random related
# initializers.
result_2 = initializer(
shape=(4, 2),
partition_shape=(2, 2),
Expand All @@ -325,9 +326,11 @@ def test_partition(self, initializer_cls, kwargs):

# Make sure initializer produce same result when provide same
# partition offset.
# TODO(scottzhu): Enable this assert when initializer is fully stateless
# TODO(scottzhu): Enable this assert when initializer is fully
# stateless
# result_3 = initializer(
# shape=(4, 2), partition_shape=(2, 2), partition_offset=(1, 0))
# shape=(4, 2), partition_shape=(2, 2), partition_offset=(1,
# 0))
# self.assertAllClose(result_2, result_3)

@parameterized.named_parameters(
Expand Down
4 changes: 2 additions & 2 deletions keras/initializers/initializers_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class RandomNormal(tf.compat.v1.random_normal_initializer):
Args:
mean: a python scalar or a scalar tensor. Mean of the random values to
generate.
stddev: a python scalar or a scalar tensor. Standard deviation of the random
values to generate.
stddev: a python scalar or a scalar tensor. Standard deviation of the
random values to generate.
seed: A Python integer. Used to create random seeds. See
`tf.compat.v1.set_random_seed` for behavior.
dtype: Default data type, used if no `dtype` argument is provided when
Expand Down
Loading