From 86fa511c3c193146f523860e226c0e405522f334 Mon Sep 17 00:00:00 2001 From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> Date: Thu, 25 May 2023 08:59:07 -0700 Subject: [PATCH] PR #17971: [keras/legacy_tf_layers] Standardise docstring usage of "Default to" Imported from GitHub PR https://github.com/keras-team/keras/pull/17971 This is one of many PRs. Discussion + request to split into multiple PRs @ #17748 Copybara import of the project: -- 5331dac9283c92091517b04f6a42342d8e123722 by Samuel Marks <807580+SamuelMarks@users.noreply.github.com>: [keras/legacy_tf_layers/base.py,keras/legacy_tf_layers/migration_utils.py,keras/legacy_tf_layers/variable_scope_shim.py] Standardise docstring usage of "Default to" -- 1801651eda912e2d16914141a2e81b994ccf4afb by Samuel Marks <807580+SamuelMarks@users.noreply.github.com>: [keras/legacy_tf_layers/migration_utils.py] Move docstring from method to class and document `seed` Merging this change closes #17971 FUTURE_COPYBARA_INTEGRATE_REVIEW=https://github.com/keras-team/keras/pull/17971 from SamuelMarks:keras.legacy_tf_layers-defaults-to 1801651eda912e2d16914141a2e81b994ccf4afb PiperOrigin-RevId: 535274600 --- keras/legacy_tf_layers/base.py | 4 ++-- keras/legacy_tf_layers/migration_utils.py | 7 +++++-- keras/legacy_tf_layers/variable_scope_shim.py | 15 ++++++++------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/keras/legacy_tf_layers/base.py b/keras/legacy_tf_layers/base.py index e2e925dba0e..fa2beea2f2d 100644 --- a/keras/legacy_tf_layers/base.py +++ b/keras/legacy_tf_layers/base.py @@ -365,8 +365,8 @@ def add_weight( or "non_trainable_variables" (e.g. BatchNorm mean, stddev). Note, if the current variable scope is marked as non-trainable then this parameter is ignored and any added variables are also - marked as non-trainable. `trainable` defaults to `True` unless - `synchronization` is set to `ON_READ`. + marked as non-trainable. `trainable` becomes `True` unless + `synchronization` is set to `ON_READ`. Defaults to `True`. constraint: constraint instance (callable). use_resource: Whether to use `ResourceVariable`. synchronization: Indicates when a distributed a variable will be diff --git a/keras/legacy_tf_layers/migration_utils.py b/keras/legacy_tf_layers/migration_utils.py index 61dfcf6b934..e1467beb66c 100644 --- a/keras/legacy_tf_layers/migration_utils.py +++ b/keras/legacy_tf_layers/migration_utils.py @@ -43,11 +43,14 @@ class DeterministicRandomTestTool(object): This applies both to the stateful random operations used for creating and initializing variables, and to the stateful random operations used in computation (such as for dropout layers). + + Args: + mode: Set mode to 'constant' or 'num_random_ops'. Defaults to + 'constant'. + seed: The random seed to use. """ def __init__(self, seed: int = 42, mode="constant"): - """Set mode to 'constant' or 'num_random_ops'. Defaults to - 'constant'.""" if mode not in {"constant", "num_random_ops"}: raise ValueError( "Mode arg must be 'constant' or 'num_random_ops'. " diff --git a/keras/legacy_tf_layers/variable_scope_shim.py b/keras/legacy_tf_layers/variable_scope_shim.py index ed08ac542e3..5eaf3f2fc49 100644 --- a/keras/legacy_tf_layers/variable_scope_shim.py +++ b/keras/legacy_tf_layers/variable_scope_shim.py @@ -215,7 +215,7 @@ def get_variable( Args: name: The name of the new or existing variable. shape: Shape of the new or existing variable. - dtype: Type of the new or existing variable (defaults to `DT_FLOAT`). + dtype: Type of the new or existing variable. Defaults to `DT_FLOAT`. initializer: Initializer for the variable. regularizer: A (Tensor -> Tensor or None) function; the result of applying it on a newly created variable will be added to the @@ -226,16 +226,16 @@ def get_variable( always forced to be False. trainable: If `True` also add the variable to the graph collection `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`). `trainable` - defaults to `True`, unless `synchronization` is set to `ON_READ`, in - which case it defaults to `False`. + becomes `True`, unless `synchronization` is set to `ON_READ`, in + which case it becomes `False`. Defaults to `True`. collections: List of graph collections keys to add the `Variable` to. Defaults to `[GraphKeys.GLOBAL_VARIABLES]` (see `tf.Variable`). caching_device: Optional device string or function describing where - the Variable should be cached for reading. Defaults to the + the Variable should be cached for reading. `None` to use the Variable's device. If not `None`, caches on another device. Typical use is to cache on the device where the Ops using the `Variable` reside, to deduplicate copying through `Switch` and other - conditional statements. + conditional statements. Defaults to `None`. partitioner: Optional callable that accepts a fully defined `TensorShape` and dtype of the `Variable` to be created, and returns a list of partitions for each axis (currently only one axis can be @@ -245,8 +245,9 @@ def get_variable( initial_value must be known. use_resource: If False, creates a regular Variable. If True, creates instead an experimental ResourceVariable which has well-defined - semantics. Defaults to False (will later change to True). When eager - execution is enabled this argument is always forced to be true. + semantics. When starting off as False it will later change to True. + When eager execution is enabled this argument always True. + Defaults to `False`. custom_getter: Callable that takes as a first argument the true getter, and allows overwriting the internal get_variable method. The signature of `custom_getter` should match that of this method, but