tensorflow/models

View on GitHub
official/core/train_utils.py

Summary

Maintainability
C
1 day
Test Coverage

File train_utils.py has 492 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2024 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
Severity: Minor
Found in official/core/train_utils.py - About 7 hrs to fix

    Function try_count_flops has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def try_count_flops(model: Union[tf.Module, tf_keras.Model],
                        inputs_kwargs: Optional[Dict[str, Any]] = None,
                        output_path: Optional[str] = None):
      """Counts and returns model FLOPs.
    
    
    Severity: Minor
    Found in official/core/train_utils.py - About 55 mins to fix

    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 try_count_params has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def try_count_params(
        model: Union[tf.Module, tf_keras.Model],
        trainable_only: bool = False):
      """Count the number of parameters if model is possible.
    
    
    Severity: Minor
    Found in official/core/train_utils.py - About 45 mins to fix

    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 create_trainer has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def create_trainer(params: config_definitions.ExperimentConfig,
    Severity: Minor
    Found in official/core/train_utils.py - About 45 mins to fix

      Function _einsum_flops has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def _einsum_flops(graph, node):
        """Calculates the compute resources needed for Einsum."""
        assert len(node.input) == 2
        x_shape = tf.compat.v1.graph_util.tensor_shape_from_node_def_name(
            graph, node.input[0])
      Severity: Minor
      Found in official/core/train_utils.py - About 35 mins to fix

      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 create_optimizer has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def create_optimizer(task: base_task.Task,
                           params: config_definitions.ExperimentConfig
                           ) -> tf_keras.optimizers.Optimizer:
        """A create optimizer util to be backward compatability with new args."""
        if 'dp_config' in inspect.signature(task.create_optimizer).parameters:
      Severity: Minor
      Found in official/core/train_utils.py - About 35 mins to fix

      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 _new_metric_is_better has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def _new_metric_is_better(self, old_logs, new_logs):
          """Check if the metric in new_logs is better than the metric in old_logs."""
          old_value = float(
              orbit.utils.get_value(
                  get_leaf_nested_dict(old_logs, self._metric_name)))
      Severity: Minor
      Found in official/core/train_utils.py - About 25 mins to fix

      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

      There are no issues that match your filters.

      Category
      Status