File distribute_lib.py
has 3253 lines of code (exceeds 250 allowed). Consider refactoring. Open
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Function reduce
has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring. Open
def reduce(self, reduce_op, value, axis):
"""Reduce `value` across replicas and return result on current device.
>>> strategy = tf.distribute.MirroredStrategy(["GPU:0", "GPU:1"])
>>> def step_fn():
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
StrategyExtendedV2
has 37 functions (exceeds 20 allowed). Consider refactoring. Open
class StrategyExtendedV2(object):
"""Additional APIs for algorithms that need to be distribution-aware.
Note: For most usage of `tf.distribute.Strategy`, there should be no need to
call these methods, since TensorFlow libraries (such as optimizers) already
_DefaultDistributionExtended
has 29 functions (exceeds 20 allowed). Consider refactoring. Open
class _DefaultDistributionExtended(StrategyExtendedV1):
"""Implementation of _DefaultDistributionStrategy."""
def __init__(self, container_strategy):
super(_DefaultDistributionExtended, self).__init__(container_strategy)
StrategyBase
has 22 functions (exceeds 20 allowed). Consider refactoring. Open
class StrategyBase(object):
"""A state & compute distribution policy on a list of devices.
See [the guide](https://www.tensorflow.org/guide/distributed_training)
for overview and examples. See `tf.distribute.StrategyExtended` and
Function _scope
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def _scope(self, strategy):
"""Implementation of tf.distribute.Strategy.scope()."""
def creator_with_resource_vars(next_creator, **kwargs):
"""Variable creator to use in `_CurrentDistributionContext`."""
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function __exit__
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def __exit__(self, exception_type, exception_value, traceback):
if hasattr(self._context.strategy.extended, "_lazy_variable_tracker"):
self._context.strategy.extended._lazy_variable_tracker.initialize_all()
if self._same_scope_again_count > 0:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function all_reduce
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def all_reduce(self, reduce_op, value, options=None):
"""All-reduces `value` across all replicas.
>>> strategy = tf.distribute.MirroredStrategy(["GPU:0", "GPU:1"])
>>> def step_fn():
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function __enter__
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def __enter__(self):
# Allow this scope to be entered if this strategy is already in scope.
if has_strategy():
_require_cross_replica_or_default_context_extended(
self._context.strategy.extended)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function update
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def update(self, var, fn, args=(), kwargs=None, group=True):
Function _update
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _update(self, var, fn, args, kwargs, group):
Function _update
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _update(self, var, fn, args=(), kwargs=None, group=True):
Function _update
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _update(self, var, fn, args, kwargs, group):
Function _update_non_slot
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _update_non_slot(self, colocate_with, fn, args, kwargs, group):
Function _update_non_slot
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _update_non_slot(self, colocate_with, fn, args, kwargs, should_group):
Function _replica_ctx_update
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _replica_ctx_update(self, var, fn, args=(), kwargs=None, group=True):
Function __init__
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(
Function update_non_slot
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def update_non_slot(
Function _get_default_strategy
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _get_default_strategy():
if _defaults["strategy"] is None:
# Avoid race condition causing two defaults to be created
with _default_strategy_lock:
if _defaults["strategy"] is None:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _local_results
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _local_results(self, val):
"""Returns local results per replica as a tuple."""
if isinstance(val, ds_types.DistributedValues):
return val._values # pylint: disable=protected-access
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function all_gather
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def all_gather(self, value, axis, options=None):
"""All-gathers `value` across all replicas along `axis`.
Note: An `all_gather` method can only be called in replica context. For
a cross-replica context counterpart, see `tf.distribute.Strategy.gather`.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"