Create a new Optimizer. This must be called by the constructors of subclasses. Args: use_locking: Bool. If True apply use locks to prevent concurrent updates to variables. name: A non-empty string. The name to use for accumulators created for the optimizer.
(self, use_locking, name)
| 361 | GATE_GRAPH = 2 |
| 362 | |
| 363 | def __init__(self, use_locking, name): |
| 364 | """Create a new Optimizer. |
| 365 | |
| 366 | This must be called by the constructors of subclasses. |
| 367 | |
| 368 | Args: |
| 369 | use_locking: Bool. If True apply use locks to prevent concurrent updates |
| 370 | to variables. |
| 371 | name: A non-empty string. The name to use for accumulators created |
| 372 | for the optimizer. |
| 373 | |
| 374 | Raises: |
| 375 | ValueError: If name is malformed. |
| 376 | """ |
| 377 | if not name: |
| 378 | raise ValueError("Must specify the optimizer name") |
| 379 | self._use_locking = use_locking |
| 380 | self._name = name |
| 381 | # Dictionary of slots. |
| 382 | # {slot_name : |
| 383 | # {_var_key(variable_to_train): slot_for_the_variable, ... }, |
| 384 | # ... } |
| 385 | self._slots = {} |
| 386 | self._non_slot_dict = {} |
| 387 | # For implementing Trackable. Stores information about how to restore |
| 388 | # slot variables which have not yet been created |
| 389 | # (trackable._CheckpointPosition objects). |
| 390 | # {slot_name : |
| 391 | # {_var_key(variable_to_train): [checkpoint_position, ... ], ... }, |
| 392 | # ... } |
| 393 | self._deferred_slot_restorations = {} |
| 394 | |
| 395 | self._loss_scale = None |
| 396 | if 'TF_ENABLE_AUTO_MIXED_PRECISION_LOSS_SCALING' in os.environ: |
| 397 | if os.environ['TF_ENABLE_AUTO_MIXED_PRECISION_LOSS_SCALING'] == "1": |
| 398 | self._loss_scale = loss_scale_module.DynamicLossScale() |
| 399 | self._track_trackable(self._loss_scale, 'loss_scale') |
| 400 | elif os.environ.get('TF_ENABLE_AUTO_MIXED_PRECISION') == "1": |
| 401 | self._loss_scale = loss_scale_module.DynamicLossScale() |
| 402 | self._track_trackable(self._loss_scale, 'loss_scale') |
| 403 | |
| 404 | # TODO(isaprykin): When using a DistributionStrategy, and when an |
| 405 | # optimizer is created in each replica, it might be dangerous to |
| 406 | # rely on some Optimizer methods. When such methods are called on a |
| 407 | # per-replica optimizer, an exception needs to be thrown. We do |
| 408 | # allow creation per-replica optimizers however, because the |
| 409 | # compute_gradients()->apply_gradients() sequence is safe. |
| 410 | |
| 411 | def get_name(self): |
| 412 | return self._name |
nothing calls this directly
no test coverage detected