File tpu_embedding_v3.py
has 1975 lines of code (exceeds 250 allowed). Consider refactoring. Open
# Copyright 2023 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 _create_variables
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
def _create_variables(
self,
stacked_tables: List[tpu_embedding_v2_utils.TableConfig],
stacked_table_name: str,
) -> Dict[str, tf_variables.Variable]:
- 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
TPUEmbeddingV2
has 24 functions (exceeds 20 allowed). Consider refactoring. Open
class TPUEmbeddingV2(tpu_embedding_base.TPUEmbeddingBase):
"""The TPUEmbedding mid level API running on TPU with sparse core accelerator."""
def __init__(
self,
Function _experimental_convert_input_feature_to_list_of_coo_tensors
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def _experimental_convert_input_feature_to_list_of_coo_tensors(
input_feature: Union[
tensor.Tensor, sparse_tensor.SparseTensor, ragged_tensor.RaggedTensor
],
weight: Optional[tensor.Tensor],
- 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 _convert_input_feature_to_coo
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def _convert_input_feature_to_coo(
input_feature: Union[
tensor.Tensor, sparse_tensor.SparseTensor, ragged_tensor.RaggedTensor
],
weight: Optional[tensor.Tensor],
- 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 _experimental_preprocess_features
has 12 arguments (exceeds 4 allowed). Consider refactoring. Open
def _experimental_preprocess_features(
Function _stack_tables_with_same_table_dim_and_optimizer
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def _stack_tables_with_same_table_dim_and_optimizer(self):
"""Stack tables with the same table dim and optimizer."""
logging.info(
"Number of tables before stacking is %d", len(self._table_config)
)
- 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 preprocess_features
has 11 arguments (exceeds 4 allowed). Consider refactoring. Open
def preprocess_features(
Function apply_gradients
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def apply_gradients(
self,
gradients: Any,
preserved_outputs: Dict[str, PartitionedCsrFormatTensor],
):
- 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 _experimental_convert_input_feature_to_list_of_coo_tensors
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
def _experimental_convert_input_feature_to_list_of_coo_tensors(
Function _experimental_stack_gradients
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def _experimental_stack_gradients(self, gradients):
"""Stack the incoming gradients to per table gradients."""
# Gradients are stacked in a particular order. That order is the order
# features appear in the self._flat_features.
- 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 _experimental_preprocess_inputs_and_weights_to_list_of_coo_tensors
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
def _experimental_preprocess_inputs_and_weights_to_list_of_coo_tensors(
Function _create_sharded_variable
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def _create_sharded_variable(next_creator, *args, **kwargs):
"""Create a TPUEmbeddingShardedVariable."""
# Avoid the default mirror variable creator.
kwargs["skip_mirrored_creator"] = True
- 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 _raise_error_for_incorrect_control_flow_context
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def _raise_error_for_incorrect_control_flow_context(self):
"""Raises an error if we are not in the TPUReplicateContext."""
# Do not allow any XLA control flow (i.e. control flow in between a
# TPUStrategy's run call and the call to this function), as we can't
# extract the enqueue from the head when in XLA control flow.
- 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 _round_table_sizes
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def _round_table_sizes(self):
num_shards = self._num_sc_shards * 8
self._table_to_padding_columns = {}
self._table_to_padding_rows = {}
- 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 _experimental_get_multiple_minibatches_from_sorted_coo_tensor
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def _experimental_get_multiple_minibatches_from_sorted_coo_tensor(
Function _experimental_get_single_minibatch_from_sorted_coo_tensor
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def _experimental_get_single_minibatch_from_sorted_coo_tensor(
Function _get_minibatches_from_sorted_coo_tensor
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def _get_minibatches_from_sorted_coo_tensor(
Function _convert_input_feature_to_coo
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def _convert_input_feature_to_coo(
Function _preprocess_inputs_and_weights_to_coo_tensor
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def _preprocess_inputs_and_weights_to_coo_tensor(
Function _stack_gradients
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def _stack_gradients(self, gradients):
"""Stack the incoming gradients to per table gradients."""
# Gradients are stacked in a particular order. That order is the order
# features appear in the self._flat_features.
- 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 __init__
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(
Function __init__
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(
Function _experimental_get_minibatch_splits_from_sorted_coo_tensor
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _experimental_get_minibatch_splits_from_sorted_coo_tensor(
Function enqueue
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def enqueue(
self,
features: Any,
weights: Optional[Any] = None,
device: Optional[str] = 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 dequeue
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def dequeue(
self,
partitioned_tensors: Tuple[
Dict[str, PartitionedCsrFormatTensor], int, int
],
- 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"