tensorflow/models

View on GitHub
official/projects/pix2seq/modeling/transformer.py

Summary

Maintainability
F
3 days
Test Coverage

File transformer.py has 472 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/projects/pix2seq/modeling/transformer.py - About 7 hrs to fix

    Function __init__ has 15 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def __init__(
    Severity: Major
    Found in official/projects/pix2seq/modeling/transformer.py - About 1 hr to fix

      Function __init__ has 14 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        def __init__(
      Severity: Major
      Found in official/projects/pix2seq/modeling/transformer.py - About 1 hr to fix

        Function __init__ has 11 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def __init__(
        Severity: Major
        Found in official/projects/pix2seq/modeling/transformer.py - About 1 hr to fix

          Function __init__ has 10 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            def __init__(
          Severity: Major
          Found in official/projects/pix2seq/modeling/transformer.py - About 1 hr to fix

            Function __init__ has 8 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              def __init__(
            Severity: Major
            Found in official/projects/pix2seq/modeling/transformer.py - About 1 hr to fix

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

                def call(self, x, enc, caches, mask_self, mask_cross, training):
              Severity: Minor
              Found in official/projects/pix2seq/modeling/transformer.py - About 45 mins to fix

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

                  def call(self, x, enc, cache, mask_self, mask_cross, training):
                Severity: Minor
                Found in official/projects/pix2seq/modeling/transformer.py - About 45 mins to fix

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

                    def __init__(
                  Severity: Minor
                  Found in official/projects/pix2seq/modeling/transformer.py - About 45 mins to fix

                    Function __init__ has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def __init__(
                          self,
                          dim,
                          mlp_ratio,
                          num_heads,
                    Severity: Minor
                    Found in official/projects/pix2seq/modeling/transformer.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

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

                        updates = {
                            'num_layers': self._num_layers,
                            'dim': self._dim,
                            'mlp_ratio': self._mlp_ratio,
                            'num_heads': self._num_heads,
                    Severity: Major
                    Found in official/projects/pix2seq/modeling/transformer.py and 3 other locations - About 3 hrs to fix
                    official/nlp/modeling/layers/transformer_xl.py on lines 434..462
                    official/vision/modeling/layers/nn_blocks_3d.py on lines 236..250
                    research/object_detection/builders/model_builder.py on lines 149..177

                    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 63.

                    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 self_attention:
                          self.mha_ln = tf_keras.layers.LayerNormalization(
                              epsilon=1e-6,
                              center=ln_scale_shift,
                              scale=ln_scale_shift,
                    Severity: Major
                    Found in official/projects/pix2seq/modeling/transformer.py and 1 other location - About 2 hrs to fix
                    official/projects/pix2seq/modeling/transformer.py on lines 365..373

                    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 59.

                    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 self_attention:
                          self.self_ln = tf_keras.layers.LayerNormalization(
                              epsilon=1e-6,
                              center=ln_scale_shift,
                              scale=ln_scale_shift,
                    Severity: Major
                    Found in official/projects/pix2seq/modeling/transformer.py and 1 other location - About 2 hrs to fix
                    official/projects/pix2seq/modeling/transformer.py on lines 120..128

                    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 59.

                    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 use_ln:
                          self.ln = tf_keras.layers.LayerNormalization(
                              epsilon=1e-6,
                              center=ln_scale_shift,
                              scale=ln_scale_shift,
                    Severity: Major
                    Found in official/projects/pix2seq/modeling/transformer.py and 1 other location - About 1 hr to fix
                    official/projects/pix2seq/modeling/transformer.py on lines 382..390

                    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 44.

                    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 use_enc_ln:
                            self.enc_ln = tf_keras.layers.LayerNormalization(
                                epsilon=1e-6,
                                center=ln_scale_shift,
                                scale=ln_scale_shift,
                    Severity: Major
                    Found in official/projects/pix2seq/modeling/transformer.py and 1 other location - About 1 hr to fix
                    official/projects/pix2seq/modeling/transformer.py on lines 237..245

                    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 44.

                    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 5 locations. Consider refactoring.
                    Open

                        updates = {
                            'num_layers': self._num_layers,
                            'dim': self._dim,
                            'mlp_ratio': self._mlp_ratio,
                            'drop_path': self._drop_path,
                    Severity: Major
                    Found in official/projects/pix2seq/modeling/transformer.py and 4 other locations - About 45 mins to fix
                    research/deep_speech/deep_speech.py on lines 252..259
                    research/object_detection/builders/model_builder.py on lines 132..146
                    research/object_detection/builders/model_builder.py on lines 240..254
                    research/object_detection/model_lib.py on lines 53..67

                    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 35.

                    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

                            q_size, k_size = tf.shape(x)[1], tf.shape(cache)[1]
                    Severity: Minor
                    Found in official/projects/pix2seq/modeling/transformer.py and 1 other location - About 45 mins to fix
                    research/object_detection/utils/target_assigner_utils.py on lines 262..262

                    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 35.

                    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