tensorflow/models

View on GitHub
official/legacy/transformer/transformer_main.py

Summary

Maintainability
D
2 days
Test Coverage

Function train has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
Open

  def train(self):
    """Trains the model."""
    params = self.params
    flags_obj = self.flags_obj
    # Sets config options.
Severity: Minor
Found in official/legacy/transformer/transformer_main.py - About 1 day 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

File transformer_main.py has 373 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/legacy/transformer/transformer_main.py - About 4 hrs to fix

    Function __init__ has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def __init__(self, flags_obj):
        """Init function of TransformerMain.
    
        Args:
          flags_obj: Object containing parsed flag values, i.e., FLAGS.
    Severity: Minor
    Found in official/legacy/transformer/transformer_main.py - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                  for metric_obj in train_metrics:
                    tf.summary.scalar(metric_obj.name, metric_obj.result(),
                                      current_step)
                    summary_writer.flush()
      
      
      Severity: Major
      Found in official/legacy/transformer/transformer_main.py - About 45 mins to fix

        Function evaluate_and_log_bleu has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def evaluate_and_log_bleu(model,
        Severity: Minor
        Found in official/legacy/transformer/transformer_main.py - About 45 mins to fix

          Function translate_and_compute_bleu has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def translate_and_compute_bleu(model,
          Severity: Minor
          Found in official/legacy/transformer/transformer_main.py - About 45 mins to fix

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

            def _ensure_dir(log_dir):
              """Makes log dir if not existed."""
              if not tf.io.gfile.exists(log_dir):
                tf.io.gfile.makedirs(log_dir)
            Severity: Major
            Found in official/legacy/transformer/transformer_main.py and 1 other location - About 1 hr to fix
            official/vision/data/tfrecord_lib.py on lines 185..188

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 40.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

            if __name__ == "__main__":
              logging.set_verbosity(logging.INFO)
              misc.define_transformer_flags()
              app.run(main)
            Severity: Minor
            Found in official/legacy/transformer/transformer_main.py and 1 other location - About 55 mins to fix
            official/legacy/image_classification/resnet/resnet_ctl_imagenet_main.py on lines 192..195

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 37.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

              if flags_obj.tf_gpu_thread_mode:
                keras_utils.set_gpu_thread_mode_and_count(
                    per_gpu_thread_count=flags_obj.per_gpu_thread_count,
                    gpu_thread_mode=flags_obj.tf_gpu_thread_mode,
                    num_gpus=flags_obj.num_gpus,
            Severity: Minor
            Found in official/legacy/transformer/transformer_main.py and 1 other location - About 40 mins to fix
            official/legacy/image_classification/resnet/resnet_ctl_imagenet_main.py on lines 104..109

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 34.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status