tensorflow/models

View on GitHub
official/nlp/modeling/layers/block_sparse_attention.py

Summary

Maintainability
A
3 hrs
Test Coverage

Function _build_from_signature has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def _build_from_signature(self, query, value, key=None):
    # pytype: disable=attribute-error
    super()._build_from_signature(query, value, key)
    # pytype: enable=attribute-error
    # If block sizes are same as sequence lengths, we defer to default attn.
Severity: Minor
Found in official/nlp/modeling/layers/block_sparse_attention.py - About 1 hr 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 call has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

  def call(
Severity: Major
Found in official/nlp/modeling/layers/block_sparse_attention.py - About 50 mins to fix

    Function _compute_attention has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def _compute_attention(
    Severity: Minor
    Found in official/nlp/modeling/layers/block_sparse_attention.py - About 35 mins to fix

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

        def __init__(
      Severity: Minor
      Found in official/nlp/modeling/layers/block_sparse_attention.py - About 35 mins to fix

        Function _compute_attention has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def _compute_attention(
              self, query, key, value, attention_mask=None, training=None
          ):
            # If block sizes are same as sequence lengths, we defer to default attn.
            if (
        Severity: Minor
        Found in official/nlp/modeling/layers/block_sparse_attention.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