def Patch(self, request, global_params=None):
    config = self.GetMethodConfig('Patch')
    return self._RunMethod(config, request, global_params=global_params)

Update an association between a GCP project and a GitHub Enterprise server.

Args:
  request: (CloudbuildProjectsGithubEnterpriseConfigsPatchRequest) input message
  global_params: (StandardQueryParameters, default: None) global arguments
Returns:
  (Operation) The response message.


class PiecewiseConstantDecay(LearningRateSchedule):

    def __init__(self, boundaries, values, name='PiecewiseConstant'):
        super().__init__()
        if len(boundaries) != len(values) - 1:
            raise ValueError(f'The length of boundaries should be 1 less than the length of values. Received: boundaries={boundaries} of length {len(boundaries)}, and values={values} of length {len(values)}.')
        self.boundaries = boundaries
        self.values = values
        self.name = name

    def __call__(self, step):
        with ops.name_scope(self.name):
            boundaries = [ops.convert_to_tensor(x) for x in self.boundaries]
            values = [ops.convert_to_tensor(x) for x in self.values]
            step = ops.convert_to_tensor(step)
            for i, b in enumerate(boundaries):
                if b.dtype != step.dtype:
                    b = ops.cast(b, step.dtype)
                    boundaries[i] = b
            result_dtype = values[0].dtype
            result_value = ops.array(0, dtype=result_dtype)
            step_less_than_first_boundary = ops.cast(step <= boundaries[0], result_dtype)
            result_value += step_less_than_first_boundary * values[0]
            step_greater_than_last_boundary = ops.cast(step > boundaries[-1], result_dtype)
            result_value += step_greater_than_last_boundary * values[-1]
            for low, high, value in zip(boundaries[:-1], boundaries[1:], values[1:-1]):
                step_in_range = ops.cast((step > low) & (step <= high), result_dtype)
                result_value += step_in_range * value
            return result_value

    def get_config(self):
        return {'boundaries': self.boundaries, 'values': self.values, 'name': self.name}

A `LearningRateSchedule` that uses a piecewise constant decay schedule.

The function returns a 1-arg callable to compute the piecewise constant
when passed the current optimizer step. This can be useful for changing the
learning rate value across different invocations of optimizer functions.

Example: use a learning rate that's 1.0 for the first 100001 steps, 0.5
    for the next 10000 steps, and 0.1 for any additional steps.

```python
step = ops.array(0)
boundaries = [100000, 110000]
values = [1.0, 0.5, 0.1]
learning_rate_fn = keras.optimizers.schedules.PiecewiseConstantDecay(
    boundaries, values)

# Later, whenever we perform an optimization step, we pass in the step.
learning_rate = learning_rate_fn(step)
```

You can pass this schedule directly into a `keras.optimizers.Optimizer`
as the learning rate. The learning rate schedule is also serializable and
deserializable using `keras.optimizers.schedules.serialize` and
`keras.optimizers.schedules.deserialize`.

Args:
    boundaries: A list of Python numbers with strictly increasing
        entries, and with all elements having the same type as the
        optimizer step.
    values: A list of Python numbers that specifies the values for the
        intervals defined by `boundaries`. It should have one more
        element than `boundaries`, and all elements should have the same
        type.
    name: A string. Optional name of the operation. Defaults to
        `"PiecewiseConstant"`.

Returns:
    A 1-arg callable learning rate schedule that takes the current optimizer
    step and outputs the decayed learning rate, a scalar tensor of the
    same type as the boundary tensors.

    The output of the 1-arg function that takes the `step`
    is `values[0]` when `step <= boundaries[0]`,
    `values[1]` when `step > boundaries[0]` and `step <= boundaries[1]`,
    ..., and `values[-1]` when `step > boundaries[-1]`.

Raises:
    ValueError: if the number of elements in the `boundaries` and `values`
    lists do not match.


def _ScaleAndTranslateGrad(op, grad):
    grad0 = gen_image_ops.scale_and_translate_grad(grad, op.inputs[0], op.inputs[2], op.inputs[3], kernel_type=op.get_attr('kernel_type'), antialias=op.get_attr('antialias'))
    return [grad0, None, None, None]

The derivatives for ScaleAndTranslate transformation op.

Args:
  op: The ScaleAndTranslate op.
  grad: The tensor representing the gradient w.r.t. the output.

Returns:
  The gradients w.r.t. the input.


def get_uid(prefix=''):
    object_name_uids = global_state.get_global_attribute('object_name_uids', default=collections.defaultdict(int), set_to_default=True)
    object_name_uids[prefix] += 1
    return object_name_uids[prefix]

Associates a string prefix with an integer counter.

Args:
    prefix: String prefix to index.

Returns:
    Unique integer ID.

Example:

>>> get_uid('dense')
1
>>> get_uid('dense')
2


def exec_one_test(self, test_name, test_method, record=None):
    tr_record = record or records.TestResultRecord(test_name, self.TAG)
    tr_record.uid = getattr(test_method, 'uid', None)
    tr_record.test_begin()
    self.current_test_info = runtime_test_info.RuntimeTestInfo(test_name, self.log_path, tr_record)
    expects.recorder.reset_internal_states(tr_record)
    logging.info('%s %s', TEST_CASE_TOKEN, test_name)
    teardown_test_failed = False
    try:
        try:
            try:
                self._setup_test(test_name)
            except signals.TestFailure as e:
                _, _, traceback = sys.exc_info()
                raise signals.TestError(e.details, e.extras).with_traceback(traceback)
            test_method()
        except (signals.TestPass, signals.TestAbortSignal, signals.TestSkip):
            raise
        except Exception:
            logging.exception('Exception occurred in %s.', self.current_test_info.name)
            raise
        finally:
            before_count = expects.recorder.error_count
            try:
                self._teardown_test(test_name)
            except signals.TestAbortSignal:
                raise
            except Exception as e:
                logging.exception('Exception occurred in %s of %s.', STAGE_NAME_TEARDOWN_TEST, self.current_test_info.name)
                tr_record.test_error()
                tr_record.add_error(STAGE_NAME_TEARDOWN_TEST, e)
                teardown_test_failed = True
            else:
                if before_count < expects.recorder.error_count:
                    tr_record.test_error()
                    teardown_test_failed = True
    except (signals.TestFailure, AssertionError) as e:
        tr_record.test_fail(e)
    except signals.TestSkip as e:
        tr_record.test_skip(e)
    except signals.TestAbortSignal as e:
        tr_record.test_fail(e)
        raise
    except signals.TestPass as e:
        tr_record.test_pass(e)
    except Exception as e:
        tr_record.test_error(e)
    else:
        if expects.recorder.has_error and (not teardown_test_failed):
            tr_record.test_fail()
        elif not teardown_test_failed:
            tr_record.test_pass()
    finally:
        tr_record.update_record()
        try:
            if tr_record.result in (records.TestResultEnums.TEST_RESULT_ERROR, records.TestResultEnums.TEST_RESULT_FAIL):
                self._exec_procedure_func(self._on_fail, tr_record)
            elif tr_record.result == records.TestResultEnums.TEST_RESULT_PASS:
                self._exec_procedure_func(self._on_pass, tr_record)
            elif tr_record.result == records.TestResultEnums.TEST_RESULT_SKIP:
                self._exec_procedure_func(self._on_skip, tr_record)
        finally:
            logging.info(RESULT_LINE_TEMPLATE, tr_record.test_name, tr_record.result)
            self.results.add_record(tr_record)
            self.summary_writer.dump(tr_record.to_dict(), records.TestSummaryEntryType.RECORD)
            self.current_test_info = None
    return tr_record

Executes one test and update test results.

Executes setup_test, the test method, and teardown_test; then creates a
records.TestResultRecord object with the execution information and adds
the record to the test class's test results.

Args:
  test_name: string, Name of the test.
  test_method: function, The test method to execute.
  record: records.TestResultRecord, optional arg for injecting a record
    object to use for this test execution. If not set, a new one is created
    created. This is meant for passing information between consecutive test
    case execution for retry purposes. Do NOT abuse this for "magical"
    features.

Returns:
  TestResultRecord, the test result record object of the test execution.
  This object is strictly for read-only purposes. Modifying this record
  will not change what is reported in the test run's summary yaml file.


def apply_rotary_unpadded(qkv, cos, sin, cu_seqlens: Optional[torch.Tensor]=None, max_seqlen: Optional[int]=None):
    return ApplyRotaryEmbUnpad.apply(qkv, cos, sin, cu_seqlens, max_seqlen)

Arguments:
    qkv: (total_nnz, 3, nheads, headdim) - input tensor for packed QKV.
    cos, sin: (seqlen_rotary, rotary_dim / 2)
    interleaved: if True, rotate pairs of even and odd dimensions (GPT-J style) instead
        of 1st half and 2nd half (GPT-NeoX style).
    inplace: if True, apply rotary embedding in-place.
    seqlen_offsets: (batch_size,) or int. Each sequence in x is shifted by this amount.
        Most commonly used in inference when we have KV cache.
    cu_seqlens: (batch + 1,) or None
    max_seqlen: int
Return:
    out: (total_nnz, dim)
rotary_dim must be <= headdim
Apply rotary embedding to the first rotary_dim of x.


def __init__(self, topic_path, add_uuids=None, expansion_service=None):
    if add_uuids is None:
        add_uuids = False
    if expansion_service is None:
        expansion_service = _default_io_expansion_service()
    super().__init__('beam:transform:org.apache.beam:pubsublite_write:v1', NamedTupleBasedPayloadBuilder(_WriteSchema(topic_path=topic_path, add_uuids=add_uuids)), expansion_service)

Initializes a write operation to Pub/Sub Lite, writing the serialized bytes
of PubSubMessage protos.

Args:
  topic_path: A Pub/Sub Lite Topic path.
  add_uuids: Whether to add uuids to the 'x-goog-pubsublite-dataflow-uuid'
      uuid attribute.


def HasDefinition(self, name):
    return name in self.consts or name in self.roles or name in self.states or (name in self.qualifiers) or (name in self.messages) or (name in self.events) or (name in self.transitions)

Whether this module has a named object |name|.

Args:
  name: The string name of the object to look for.

Returns:
  True if this module has an object with name |name|, False otherwise.


def get_optimizer_experimental_options(self):
    rewrite_options = self.config.graph_options.rewrite_options
    options = {}

    def rewriter_toggle(option):
        attr = getattr(rewrite_options, option)
        if attr != 0:
            options[option] = attr == rewriter_config_pb2.RewriterConfig.ON

    def rewriter_bool(option):
        options[option] = getattr(rewrite_options, option)
    rewriter_toggle('layout_optimizer')
    rewriter_toggle('constant_folding')
    rewriter_toggle('shape_optimization')
    rewriter_toggle('remapping')
    rewriter_toggle('arithmetic_optimization')
    rewriter_toggle('dependency_optimization')
    rewriter_toggle('loop_optimization')
    rewriter_toggle('function_optimization')
    rewriter_toggle('debug_stripper')
    rewriter_bool('disable_model_pruning')
    rewriter_toggle('scoped_allocator_optimization')
    rewriter_toggle('pin_to_host_optimization')
    rewriter_toggle('implementation_selector')
    rewriter_toggle('auto_mixed_precision')
    rewriter_toggle('use_plugin_optimizers')
    rewriter_bool('disable_meta_optimizer')
    rewriter_toggle('auto_mixed_precision_onednn_bfloat16')
    rewriter_toggle('auto_mixed_precision_mkl')
    if rewrite_options.min_graph_nodes != 0:
        options['min_graph_nodes'] = rewrite_options.min_graph_nodes
    return options

Get experimental options for the optimizer.

Returns:
  Dictionary of current option values


def forward(self, input_ids: Optional[torch.Tensor]=None, attention_mask: Optional[torch.Tensor]=None, token_type_ids: Optional[torch.Tensor]=None, position_ids: Optional[torch.Tensor]=None, head_mask: Optional[torch.Tensor]=None, inputs_embeds: Optional[torch.Tensor]=None, encoder_hidden_states: Optional[torch.Tensor]=None, encoder_attention_mask: Optional[torch.Tensor]=None, output_attentions: Optional[bool]=None, return_dict: Optional[bool]=None, output_hidden_states: Optional[bool]=None) -> Union[Tuple, BaseModelOutputWithPoolingAndProjection]:
    return_dict = return_dict if return_dict is not None else self.config.use_return_dict
    outputs = self.roberta(input_ids=input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids, position_ids=position_ids, head_mask=head_mask, inputs_embeds=inputs_embeds, encoder_hidden_states=encoder_hidden_states, encoder_attention_mask=encoder_attention_mask, output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict)
    sequence_output = outputs[0]
    sequence_output = self.pre_LN(sequence_output)
    projection_state = self.transformation(sequence_output)
    pooler_output = projection_state[:, 0]
    if not return_dict:
        return (projection_state, pooler_output) + outputs[2:4]
    return BaseModelOutputWithPoolingAndProjection(last_hidden_state=projection_state, pooler_output=pooler_output, hidden_states=outputs.hidden_states, attentions=outputs.attentions)

Examples:

```python
>>> from transformers import AutoProcessor, AltCLIPTextModel

>>> model = AltCLIPTextModel.from_pretrained("BAAI/AltCLIP")
>>> processor = AutoProcessor.from_pretrained("BAAI/AltCLIP")

>>> texts = ["it's a cat", "it's a dog"]

>>> inputs = processor(text=texts, padding=True, return_tensors="pt")

>>> outputs = model(**inputs)
>>> last_hidden_state = outputs.last_hidden_state
>>> pooled_output = outputs.pooler_output  # pooled CLS states
```


def shutdown_tpu_system(cluster_resolver=None):
    tpu_strategy_util.shutdown_tpu_system_impl(cluster_resolver, TPUClusterResolver)

Shuts down the TPU devices.

This will clear all caches, even those that are maintained through sequential
calls to tf.tpu.experimental.initialize_tpu_system, such as the compilation
cache.

Args:
  cluster_resolver: A tf.distribute.cluster_resolver.TPUClusterResolver,
      which provides information about the TPU cluster.

Raises:
  RuntimeError: If no TPU devices found for eager execution or if run in a
      tf.function.


class PromptDepthAnythingPreActResidualLayer(nn.Module):

    def __init__(self, config):
        super().__init__()
        self.activation1 = nn.ReLU()
        self.convolution1 = nn.Conv2d(config.fusion_hidden_size, config.fusion_hidden_size, kernel_size=3, stride=1, padding=1, bias=True)
        self.activation2 = nn.ReLU()
        self.convolution2 = nn.Conv2d(config.fusion_hidden_size, config.fusion_hidden_size, kernel_size=3, stride=1, padding=1, bias=True)

    def forward(self, hidden_state: torch.Tensor) -> torch.Tensor:
        residual = hidden_state
        hidden_state = self.activation1(hidden_state)
        hidden_state = self.convolution1(hidden_state)
        hidden_state = self.activation2(hidden_state)
        hidden_state = self.convolution2(hidden_state)
        return hidden_state + residual

ResidualConvUnit, pre-activate residual unit.

Args:
    config (`[PromptDepthAnythingConfig]`):
        Model configuration class defining the model architecture.


def __call__(self, text: Union[TextInput, List[TextInput]], text_pair: Optional[Union[TextInput, List[TextInput]]]=None, entity_spans: Optional[Union[EntitySpanInput, List[EntitySpanInput]]]=None, entity_spans_pair: Optional[Union[EntitySpanInput, List[EntitySpanInput]]]=None, entities: Optional[Union[EntityInput, List[EntityInput]]]=None, entities_pair: Optional[Union[EntityInput, List[EntityInput]]]=None, add_special_tokens: bool=True, padding: Union[bool, str, PaddingStrategy]=False, truncation: Union[bool, str, TruncationStrategy]=None, max_length: Optional[int]=None, max_entity_length: Optional[int]=None, stride: int=0, is_split_into_words: Optional[bool]=False, pad_to_multiple_of: Optional[int]=None, padding_side: Optional[str]=None, return_tensors: Optional[Union[str, TensorType]]=None, return_token_type_ids: Optional[bool]=None, return_attention_mask: Optional[bool]=None, return_overflowing_tokens: bool=False, return_special_tokens_mask: bool=False, return_offsets_mapping: bool=False, return_length: bool=False, verbose: bool=True, **kwargs) -> BatchEncoding:
    is_valid_single_text = isinstance(text, str)
    is_valid_batch_text = isinstance(text, (list, tuple)) and (len(text) == 0 or isinstance(text[0], str))
    if not (is_valid_single_text or is_valid_batch_text):
        raise ValueError('text input must be of type `str` (single example) or `List[str]` (batch).')
    is_valid_single_text_pair = isinstance(text_pair, str)
    is_valid_batch_text_pair = isinstance(text_pair, (list, tuple)) and (len(text_pair) == 0 or isinstance(text_pair[0], str))
    if not (text_pair is None or is_valid_single_text_pair or is_valid_batch_text_pair):
        raise ValueError('text_pair input must be of type `str` (single example) or `List[str]` (batch).')
    is_batched = bool(isinstance(text, (list, tuple)))
    if is_batched:
        batch_text_or_text_pairs = list(zip(text, text_pair)) if text_pair is not None else text
        if entities is None:
            batch_entities_or_entities_pairs = None
        else:
            batch_entities_or_entities_pairs = list(zip(entities, entities_pair)) if entities_pair is not None else entities
        if entity_spans is None:
            batch_entity_spans_or_entity_spans_pairs = None
        else:
            batch_entity_spans_or_entity_spans_pairs = list(zip(entity_spans, entity_spans_pair)) if entity_spans_pair is not None else entity_spans
        return self.batch_encode_plus(batch_text_or_text_pairs=batch_text_or_text_pairs, batch_entity_spans_or_entity_spans_pairs=batch_entity_spans_or_entity_spans_pairs, batch_entities_or_entities_pairs=batch_entities_or_entities_pairs, add_special_tokens=add_special_tokens, padding=padding, truncation=truncation, max_length=max_length, max_entity_length=max_entity_length, stride=stride, is_split_into_words=is_split_into_words, pad_to_multiple_of=pad_to_multiple_of, padding_side=padding_side, return_tensors=return_tensors, return_token_type_ids=return_token_type_ids, return_attention_mask=return_attention_mask, return_overflowing_tokens=return_overflowing_tokens, return_special_tokens_mask=return_special_tokens_mask, return_offsets_mapping=return_offsets_mapping, return_length=return_length, verbose=verbose, **kwargs)
    else:
        return self.encode_plus(text=text, text_pair=text_pair, entity_spans=entity_spans, entity_spans_pair=entity_spans_pair, entities=entities, entities_pair=entities_pair, add_special_tokens=add_special_tokens, padding=padding, truncation=truncation, max_length=max_length, max_entity_length=max_entity_length, stride=stride, is_split_into_words=is_split_into_words, pad_to_multiple_of=pad_to_multiple_of, padding_side=padding_side, return_tensors=return_tensors, return_token_type_ids=return_token_type_ids, return_attention_mask=return_attention_mask, return_overflowing_tokens=return_overflowing_tokens, return_special_tokens_mask=return_special_tokens_mask, return_offsets_mapping=return_offsets_mapping, return_length=return_length, verbose=verbose, **kwargs)

Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of
sequences, depending on the task you want to prepare them for.

Args:
    text (`str`, `List[str]`, `List[List[str]]`):
        The sequence or batch of sequences to be encoded. Each sequence must be a string. Note that this
        tokenizer does not support tokenization based on pretokenized strings.
    text_pair (`str`, `List[str]`, `List[List[str]]`):
        The sequence or batch of sequences to be encoded. Each sequence must be a string. Note that this
        tokenizer does not support tokenization based on pretokenized strings.
    entity_spans (`List[Tuple[int, int]]`, `List[List[Tuple[int, int]]]`, *optional*):
        The sequence or batch of sequences of entity spans to be encoded. Each sequence consists of tuples each
        with two integers denoting character-based start and end positions of entities. If you specify
        `"entity_classification"` or `"entity_pair_classification"` as the `task` argument in the constructor,
        the length of each sequence must be 1 or 2, respectively. If you specify `entities`, the length of each
        sequence must be equal to the length of each sequence of `entities`.
    entity_spans_pair (`List[Tuple[int, int]]`, `List[List[Tuple[int, int]]]`, *optional*):
        The sequence or batch of sequences of entity spans to be encoded. Each sequence consists of tuples each
        with two integers denoting character-based start and end positions of entities. If you specify the
        `task` argument in the constructor, this argument is ignored. If you specify `entities_pair`, the
        length of each sequence must be equal to the length of each sequence of `entities_pair`.
    entities (`List[str]`, `List[List[str]]`, *optional*):
        The sequence or batch of sequences of entities to be encoded. Each sequence consists of strings
        representing entities, i.e., special entities (e.g., [MASK]) or entity titles of Wikipedia (e.g., Los
        Angeles). This argument is ignored if you specify the `task` argument in the constructor. The length of
        each sequence must be equal to the length of each sequence of `entity_spans`. If you specify
        `entity_spans` without specifying this argument, the entity sequence or the batch of entity sequences
        is automatically constructed by filling it with the [MASK] entity.
    entities_pair (`List[str]`, `List[List[str]]`, *optional*):
        The sequence or batch of sequences of entities to be encoded. Each sequence consists of strings
        representing entities, i.e., special entities (e.g., [MASK]) or entity titles of Wikipedia (e.g., Los
        Angeles). This argument is ignored if you specify the `task` argument in the constructor. The length of
        each sequence must be equal to the length of each sequence of `entity_spans_pair`. If you specify
        `entity_spans_pair` without specifying this argument, the entity sequence or the batch of entity
        sequences is automatically constructed by filling it with the [MASK] entity.
    max_entity_length (`int`, *optional*):
        The maximum length of `entity_ids`.


def bpe_decode(self, sequences):
    return self.bpe_tokenizer.batch_decode(sequences)

Convert a list of lists of bpe token ids into a list of strings by calling bpe tokenizer.

Args:
    sequences (`torch.Tensor`):
        List of tokenized input ids.
Returns:
    `List[str]`: The list of bpe decoded sentences.


class SeparableConv1D(SeparableConv):

    def __init__(self, filters, kernel_size, strides=1, padding='valid', data_format=None, dilation_rate=1, depth_multiplier=1, activation=None, use_bias=True, depthwise_initializer='glorot_uniform', pointwise_initializer='glorot_uniform', bias_initializer='zeros', depthwise_regularizer=None, pointwise_regularizer=None, bias_regularizer=None, activity_regularizer=None, depthwise_constraint=None, pointwise_constraint=None, bias_constraint=None, **kwargs):
        super(SeparableConv1D, self).__init__(rank=1, filters=filters, kernel_size=kernel_size, strides=strides, padding=padding, data_format=data_format, dilation_rate=dilation_rate, depth_multiplier=depth_multiplier, activation=activations.get(activation), use_bias=use_bias, depthwise_initializer=initializers.get(depthwise_initializer), pointwise_initializer=initializers.get(pointwise_initializer), bias_initializer=initializers.get(bias_initializer), depthwise_regularizer=regularizers.get(depthwise_regularizer), pointwise_regularizer=regularizers.get(pointwise_regularizer), bias_regularizer=regularizers.get(bias_regularizer), activity_regularizer=regularizers.get(activity_regularizer), depthwise_constraint=constraints.get(depthwise_constraint), pointwise_constraint=constraints.get(pointwise_constraint), bias_constraint=constraints.get(bias_constraint), **kwargs)

    def call(self, inputs):
        if self.padding == 'causal':
            inputs = array_ops.pad(inputs, self._compute_causal_padding(inputs))
        if self.data_format == 'channels_last':
            strides = (1,) + self.strides * 2 + (1,)
            spatial_start_dim = 1
        else:
            strides = (1, 1) + self.strides * 2
            spatial_start_dim = 2
        inputs = array_ops.expand_dims(inputs, spatial_start_dim)
        depthwise_kernel = array_ops.expand_dims(self.depthwise_kernel, 0)
        pointwise_kernel = array_ops.expand_dims(self.pointwise_kernel, 0)
        dilation_rate = (1,) + self.dilation_rate
        if self.padding == 'causal':
            op_padding = 'valid'
        else:
            op_padding = self.padding
        outputs = nn.separable_conv2d(inputs, depthwise_kernel, pointwise_kernel, strides=strides, padding=op_padding.upper(), rate=dilation_rate, data_format=conv_utils.convert_data_format(self.data_format, ndim=4))
        if self.use_bias:
            outputs = nn.bias_add(outputs, self.bias, data_format=conv_utils.convert_data_format(self.data_format, ndim=4))
        outputs = array_ops.squeeze(outputs, [spatial_start_dim])
        if self.activation is not None:
            return self.activation(outputs)
        return outputs

Depthwise separable 1D convolution.

This layer performs a depthwise convolution that acts separately on
channels, followed by a pointwise convolution that mixes channels.
If `use_bias` is True and a bias initializer is provided,
it adds a bias vector to the output.
It then optionally applies an activation function to produce the final output.

Args:
  filters: Integer, the dimensionality of the output space (i.e. the number
    of filters in the convolution).
  kernel_size: A single integer specifying the spatial
    dimensions of the filters.
  strides: A single integer specifying the strides
    of the convolution.
    Specifying any `stride` value != 1 is incompatible with specifying
    any `dilation_rate` value != 1.
  padding: One of `"valid"`, `"same"`, or `"causal"` (case-insensitive).
    `"valid"` means no padding. `"same"` results in padding with zeros evenly
    to the left/right or up/down of the input such that output has the same
    height/width dimension as the input. `"causal"` results in causal
    (dilated) convolutions, e.g. `output[t]` does not depend on `input[t+1:]`.
  data_format: A string, one of `channels_last` (default) or `channels_first`.
    The ordering of the dimensions in the inputs.
    `channels_last` corresponds to inputs with shape
    `(batch_size, length, channels)` while `channels_first` corresponds to
    inputs with shape `(batch_size, channels, length)`.
  dilation_rate: A single integer, specifying
    the dilation rate to use for dilated convolution.
    Currently, specifying any `dilation_rate` value != 1 is
    incompatible with specifying any stride value != 1.
  depth_multiplier: The number of depthwise convolution output channels for
    each input channel. The total number of depthwise convolution output
    channels will be equal to `num_filters_in * depth_multiplier`.
  activation: Activation function to use.
    If you don't specify anything, no activation is applied (
    see `keras.activations`).
  use_bias: Boolean, whether the layer uses a bias.
  depthwise_initializer: An initializer for the depthwise convolution kernel (
    see `keras.initializers`). If None, then the default initializer (
    'glorot_uniform') will be used.
  pointwise_initializer: An initializer for the pointwise convolution kernel (
    see `keras.initializers`). If None, then the default initializer
    ('glorot_uniform') will be used.
  bias_initializer: An initializer for the bias vector. If None, the default
    initializer ('zeros') will be used (see `keras.initializers`).
  depthwise_regularizer: Optional regularizer for the depthwise
    convolution kernel (see `keras.regularizers`).
  pointwise_regularizer: Optional regularizer for the pointwise
    convolution kernel (see `keras.regularizers`).
  bias_regularizer: Optional regularizer for the bias vector (
    see `keras.regularizers`).
  activity_regularizer: Optional regularizer function for the output (
    see `keras.regularizers`).
  depthwise_constraint: Optional projection function to be applied to the
    depthwise kernel after being updated by an `Optimizer` (e.g. used for
    norm constraints or value constraints for layer weights). The function
    must take as input the unprojected variable and must return the
    projected variable (which must have the same shape). Constraints are
    not safe to use when doing asynchronous distributed training (
    see `keras.constraints`).
  pointwise_constraint: Optional projection function to be applied to the
    pointwise kernel after being updated by an `Optimizer` (
    see `keras.constraints`).
  bias_constraint: Optional projection function to be applied to the
    bias after being updated by an `Optimizer` (
    see `keras.constraints`).
  trainable: Boolean, if `True` the weights of this layer will be marked as
    trainable (and listed in `layer.trainable_weights`).

Input shape:
  3D tensor with shape:
  `(batch_size, channels, steps)` if data_format='channels_first'
  or 5D tensor with shape:
  `(batch_size, steps, channels)` if data_format='channels_last'.

Output shape:
  3D tensor with shape:
  `(batch_size, filters, new_steps)` if data_format='channels_first'
  or 3D tensor with shape:
  `(batch_size,  new_steps, filters)` if data_format='channels_last'.
  `new_steps` value might have changed due to padding or strides.

Returns:
  A tensor of rank 3 representing
  `activation(separableconv1d(inputs, kernel) + bias)`.

Raises:
  ValueError: when both `strides` > 1 and `dilation_rate` > 1.


def run_independently(self, op):
    self._independent_ops.append(op)
    op._set_attr('_independent_side_effects', attr_value_pb2.AttrValue(b=True))

Marks the given op as independent.

Overrides any other rule for the op.

Independent ops are guaranteed to execute before the return values, but
are allowed to run in parallel with everything else. Use in programs which
can guarantee that an op has side effects that don't affect any other op.

Args:
  op: An operation


def _split_heads(self, fused_qkv: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
    batch_size, seq_length, three_times_hidden_size = fused_qkv.shape
    fused_qkv = fused_qkv.view(batch_size, seq_length, self.num_heads, 3, self.head_dim)
    return (fused_qkv[..., 0, :], fused_qkv[..., 1, :], fused_qkv[..., 2, :])

Split the last dimension into (num_heads, head_dim) without making any copies, results share same memory
storage as `fused_qkv`

Args:
    fused_qkv (`torch.tensor`): [batch_size, seq_length, num_heads * 3 * head_dim]

Returns:
    query: [batch_size, seq_length, num_heads, head_dim] key: [batch_size, seq_length, num_heads, head_dim]
    value: [batch_size, seq_length, num_heads, head_dim]


def call(self, inputs, **kwargs):
    return inputs

This is where the layer's logic lives.

Args:
    inputs: Input tensor, or list/tuple of input tensors.
    **kwargs: Additional keyword arguments.

Returns:
    A tensor or list/tuple of tensors.


def run_generate(verbose=True):
    parser = argparse.ArgumentParser()
    parser.add_argument('model_name', type=str, help='like facebook/bart-large-cnn,google-t5/t5-base, etc.')
    parser.add_argument('input_path', type=str, help='like cnn_dm/test.source')
    parser.add_argument('save_path', type=str, help='where to save summaries')
    parser.add_argument('--reference_path', type=str, required=False, help='like cnn_dm/test.target')
    parser.add_argument('--score_path', type=str, required=False, default='metrics.json', help='where to save metrics')
    parser.add_argument('--device', type=str, required=False, default=DEFAULT_DEVICE, help='cuda, cuda:1, cpu etc.')
    parser.add_argument('--prefix', type=str, required=False, default=None, help='will be added to the beginning of src examples')
    parser.add_argument('--task', type=str, default='summarization', help='used for task_specific_params + metrics')
    parser.add_argument('--bs', type=int, default=8, required=False, help='batch size')
    parser.add_argument('--n_obs', type=int, default=-1, required=False, help='How many observations. Defaults to all.')
    parser.add_argument('--fp16', action='store_true')
    parser.add_argument('--dump-args', action='store_true', help='print the custom hparams with the results')
    parser.add_argument('--info', nargs='?', type=str, const=datetime_now(), help="use in conjunction w/ --dump-args to print with the results whatever other info you'd like, e.g. lang=en-ru. If no value is passed, the current datetime string will be used.")
    args, rest = parser.parse_known_args()
    parsed_args = parse_numeric_n_bool_cl_kwargs(rest)
    if parsed_args and verbose:
        print(f'parsed the following generate kwargs: {parsed_args}')
    examples = [' ' + x.rstrip() if 't5' in args.model_name else x.rstrip() for x in open(args.input_path).readlines()]
    if args.n_obs > 0:
        examples = examples[:args.n_obs]
    Path(args.save_path).parent.mkdir(exist_ok=True)
    if args.reference_path is None and Path(args.score_path).exists():
        warnings.warn(f'score_path {args.score_path} will be overwritten unless you type ctrl-c.')
    if args.device == 'cpu' and args.fp16:
        raise ValueError("Can't mix --fp16 and --device cpu")
    runtime_metrics = generate_summaries_or_translations(examples, args.save_path, args.model_name, batch_size=args.bs, device=args.device, fp16=args.fp16, task=args.task, prefix=args.prefix, **parsed_args)
    if args.reference_path is None:
        return {}
    score_fn = calculate_bleu if 'translation' in args.task else calculate_rouge
    output_lns = [x.rstrip() for x in open(args.save_path).readlines()]
    reference_lns = [x.rstrip() for x in open(args.reference_path).readlines()][:len(output_lns)]
    scores: dict = score_fn(output_lns, reference_lns)
    scores.update(runtime_metrics)
    if args.dump_args:
        scores.update(parsed_args)
    if args.info:
        scores['info'] = args.info
    if verbose:
        print(scores)
    if args.score_path is not None:
        json.dump(scores, open(args.score_path, 'w'))
    return scores

Takes input text, generates output, and then using reference calculates the BLEU scores.

The results are saved to a file and returned to the caller, and printed out unless ``verbose=False`` is passed.

Args:
    verbose (:obj:`bool`, `optional`, defaults to :obj:`True`): print results to stdout

Returns:
    a tuple: ``(scores, params}``
    - ``scores``: a dict of scores data ``{'bleu': 39.6501, 'n_obs': 2000, 'runtime': 186, 'seconds_per_sample': 0.093}``
    - ``params``: a dict of custom params, e.g. ``{'num_beams': 5, 'length_penalty': 0.8}``


def recover_last_checkpoints(self, checkpoint_paths):
    checkpoints_with_mtimes = []
    for checkpoint_path in checkpoint_paths:
        try:
            mtime = checkpoint_management.get_checkpoint_mtimes([checkpoint_path])
        except errors.NotFoundError:
            continue
        if mtime:
            checkpoints_with_mtimes.append((checkpoint_path, mtime[0]))
    self.set_last_checkpoints_with_time(checkpoints_with_mtimes)

Recovers the internal saver state after a crash.

This method is useful for recovering the "self._last_checkpoints" state.

Globs for the checkpoints pointed to by `checkpoint_paths`.  If the files
exist, use their mtime as the checkpoint timestamp.

Args:
  checkpoint_paths: a list of checkpoint paths.


def _compute_sequence_length_from_mask(mask, batch_first):
    timestep_index = 0 if not batch_first else 1
    return torch.sum(mask.int(), dim=timestep_index)

Calculate the sequence length tensor (1-D) based on the masking tensor.

The masking tensor is a 2D boolean tensor with shape [batch, timestep]. For
any timestep that should be masked, the corresponding field will be False.
Consider the following example:
  a = [[True, True, False, False]
       [True, True, True, False]]
It is a (2, 4) tensor, and the corresponding sequence length result should
be 1D tensor with value [2, 3]. Note that the masking tensor must be right
padded that could be checked by, e.g., `is_sequence_right_padded()`.

Args:
    mask: Boolean tensor with shape [batch, timestep] or [timestep, batch]
        if time_major=True.
    time_major: Boolean, which indicates whether the mask is time major or
        batch major.

Returns:
    sequence_length: 1D int32 tensor.


class DataCollatorWithPadding:
    tokenizer: PreTrainedTokenizerBase
    padding: Union[bool, str, PaddingStrategy] = True
    max_length: Optional[int] = None
    pad_to_multiple_of: Optional[int] = None
    return_tensors: str = 'pt'

    def __call__(self, features: List[Dict[str, Any]]) -> Dict[str, Any]:
        batch = pad_without_fast_tokenizer_warning(self.tokenizer, features, padding=self.padding, max_length=self.max_length, pad_to_multiple_of=self.pad_to_multiple_of, return_tensors=self.return_tensors)
        if 'label' in batch:
            batch['labels'] = batch['label']
            del batch['label']
        if 'label_ids' in batch:
            batch['labels'] = batch['label_ids']
            del batch['label_ids']
        return batch

Data collator that will dynamically pad the inputs received.

Args:
    tokenizer ([`PreTrainedTokenizer`] or [`PreTrainedTokenizerFast`]):
        The tokenizer used for encoding the data.
    padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `True`):
        Select a strategy to pad the returned sequences (according to the model's padding side and padding index)
        among:

        - `True` or `'longest'` (default): Pad to the longest sequence in the batch (or no padding if only a single
          sequence is provided).
        - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
          acceptable input length for the model if that argument is not provided.
        - `False` or `'do_not_pad'`: No padding (i.e., can output a batch with sequences of different lengths).
    max_length (`int`, *optional*):
        Maximum length of the returned list and optionally padding length (see above).
    pad_to_multiple_of (`int`, *optional*):
        If set will pad the sequence to a multiple of the provided value.

        This is especially useful to enable the use of Tensor Cores on NVIDIA hardware with compute capability >=
        7.0 (Volta).
    return_tensors (`str`, *optional*, defaults to `"pt"`):
        The type of Tensor to return. Allowable values are "np", "pt" and "tf".


class Qwen2_5OmniAudioEncoderConfig(PretrainedConfig):
    model_type = 'qwen2_5_omni_audio_encoder'

    def __init__(self, num_mel_bins=128, encoder_layers=32, encoder_attention_heads=20, encoder_ffn_dim=5120, d_model=1280, dropout=0, attention_dropout=0, activation_function='gelu', activation_dropout=0, scale_embedding=False, initializer_range=0.02, max_source_positions=1500, n_window=100, output_dim=3584, **kwargs):
        super().__init__(**kwargs)
        self.num_mel_bins = num_mel_bins
        self.d_model = d_model
        self.encoder_layers = encoder_layers
        self.encoder_attention_heads = encoder_attention_heads
        self.encoder_ffn_dim = encoder_ffn_dim
        self.dropout = dropout
        self.attention_dropout = attention_dropout
        self.activation_function = activation_function
        self.activation_dropout = activation_dropout
        self.num_hidden_layers = encoder_layers
        self.initializer_range = initializer_range
        self.scale_embedding = scale_embedding
        self.max_source_positions = max_source_positions
        self.n_window = n_window
        self.output_dim = output_dim

This is the configuration class to store the configuration of a [`Qwen2_5OmniAudioEncoder`]. It is used to instantiate a
Qwen2.5-Omni-Thinker audio encoder according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yield a similar configuration to that of the audio encoder of the Qwen2-Audio
architecture.

e.g. [Qwen/Qwen2.5-Omni-7B](https://huggingface.co/Qwen/Qwen2.5-Omni-7B)

Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
documentation from [`PretrainedConfig`] for more information.

Args:
    num_mel_bins (`int`, *optional*, defaults to 128):
        Number of mel features used per input features. Should correspond to the value used in the
        `Qwen2_5OmniProcessor` class.
    encoder_layers (`int`, *optional*, defaults to 32):
        Number of encoder layers.
    encoder_attention_heads (`int`, *optional*, defaults to 20):
        Number of attention heads for each attention layer in the Transformer encoder.
    encoder_ffn_dim (`int`, *optional*, defaults to 5120):
        Dimensionality of the "intermediate" (often named feed-forward) layer in encoder.
    d_model (`int`, *optional*, defaults to 1280):
        Dimensionality of the layers.
    dropout (`float`, *optional*, defaults to 0.0):
        The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
    attention_dropout (`float`, *optional*, defaults to 0.0):
        The dropout ratio for the attention probabilities.
    activation_function (`str`, *optional*, defaults to `"gelu"`):
        The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
        `"relu"`, `"silu"` and `"gelu_new"` are supported.
    activation_dropout (`float`, *optional*, defaults to 0.0):
        The dropout ratio for activations inside the fully connected layer.
    scale_embedding (`bool`, *optional*, defaults to `False`):
        Scale embeddings by diving by sqrt(d_model).
    initializer_range (`float`, *optional*, defaults to 0.02):
        The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
    max_source_positions (`int`, *optional*, defaults to 1500):
        The maximum sequence length of log-mel filter-bank features that this model might ever be used with.
    n_window (`int`, *optional*, defaults to 100):
        The chunk for conv and flash attn in AudioEncoder.
    output_dim (`int`, *optional*, defaults to 3584):
        The output dimension of AudioEncoder.

Example:

```python
>>> from transformers import Qwen2_5OmniAudioEncoderConfig, Qwen2_5OmniAudioEncoder

>>> # Initializing a Qwen2_5OmniAudioEncoderConfig
>>> configuration = Qwen2_5OmniAudioEncoderConfig()

>>> # Initializing a Qwen2_5OmniAudioEncoder (with random weights)
>>> model = Qwen2_5OmniAudioEncoder(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config
```


def _BaseFusedBatchNormGrad(op: ops.Operation, version, *grad):
    x = op.inputs[0]
    grad_y = grad[0]
    scale = op.inputs[1]
    epsilon = op.get_attr('epsilon')
    data_format = op.get_attr('data_format')
    is_training = op.get_attr('is_training')
    if version == 2:
        grad_fun = gen_nn_ops.fused_batch_norm_grad_v3
    elif version == 1:
        grad_fun = gen_nn_ops.fused_batch_norm_grad_v2
    else:
        grad_fun = gen_nn_ops.fused_batch_norm_grad
    if is_training:
        args = {'y_backprop': grad_y, 'x': x, 'scale': scale, 'reserve_space_1': op.outputs[3], 'reserve_space_2': op.outputs[4], 'epsilon': epsilon, 'data_format': data_format, 'is_training': is_training}
        if version == 2:
            args['reserve_space_3'] = op.outputs[5]
        dx, dscale, doffset, _, _ = grad_fun(**args)
    else:
        pop_mean = op.inputs[3]
        pop_var = op.inputs[4]
        if data_format == b'NCHW':
            x = array_ops.transpose(x, [0, 2, 3, 1])
            grad_y = array_ops.transpose(grad_y, [0, 2, 3, 1])
        elif data_format == b'NCDHW':
            x = array_ops.transpose(x, [0, 2, 3, 4, 1])
            grad_y = array_ops.transpose(grad_y, [0, 2, 3, 4, 1])
        target_data_format = 'NHWC' if data_format in (b'NCHW', b'NHWC') else 'NDHWC'
        args = {'y_backprop': grad_y, 'x': x, 'scale': scale, 'reserve_space_1': pop_mean, 'reserve_space_2': pop_var, 'epsilon': epsilon, 'data_format': target_data_format, 'is_training': is_training}
        if version == 2:
            args['reserve_space_3'] = op.outputs[5]
        dx, dscale, doffset, _, _ = grad_fun(**args)
        if data_format == b'NCHW':
            dx = array_ops.transpose(dx, [0, 3, 1, 2])
        elif data_format == b'NCDHW':
            dx = array_ops.transpose(dx, [0, 4, 1, 2, 3])
    return (dx, dscale, doffset, None, None)

Return the gradients for the 3 inputs of BatchNorm.

Args:
  op: The BatchNormOp for which we need to compute gradients.
  version: Integer indicating which version to use of the fused batch
    norm gradient.
  *grad: An argument list for tensors of gradients wrt the outputs
    with grad[0] as grad_y.

Returns:
  grad_x: gradient for x, which is scale * rsqrt(variance + epsilon) *
          [grad_y - mean(grad_y) - (x - mean(x)) *
          mean(grad_y * (x - mean(x))) / (variance + epsilon)]
          in training mode; grad_y * scale * rsqrt(pop_variance + epsilon)
          in freeze mode.

  grad_scale: gradient for scale, which is sum(grad_y * (x - mean(x)) *
              rsqrt(variance + epsilon)) in training mode;
              sum(grad_y * (x - pop_mean) * rsqrt(pop_variance + epsilon))
              in freeze mode.

  grad_offset: gradient for offset, which is sum(grad_y) in training mode;
               sum(grad_y) in freeze mode.


def predict_on_batch(self, x):
    self._check_call_args('predict_on_batch')
    _disallow_inside_tf_function('predict_on_batch')
    with self.distribute_strategy.scope():
        iterator = data_adapter.single_batch_iterator(self.distribute_strategy, x)
        self.predict_function = self.make_predict_function()
        outputs = self.predict_function(iterator)
    return tf_utils.sync_to_numpy_or_python_type(outputs)

Returns predictions for a single batch of samples.

Args:
    x: Input data. It could be:
      - A Numpy array (or array-like), or a list of arrays (in case the
          model has multiple inputs).
      - A TensorFlow tensor, or a list of tensors (in case the model has
          multiple inputs).

Returns:
    Numpy array(s) of predictions.

Raises:
    RuntimeError: If `model.predict_on_batch` is wrapped in `tf.function`.
    ValueError: In case of mismatch between given number of inputs and
      expectations of the model.


def assert_eventual(self, func, required, allowed, timeout_secs=300.0):
    required = set(required)
    assert required
    seen = set()
    start_time = time.time()
    while timeout_secs is None or time.time() - start_time < timeout_secs:
        if seen == required:
            return
        value = func()
        if value not in allowed:
            self.fail(msg=f'Disallowed value: {value}.')
        if value in required:
            seen.add(value)
    missing = [v for v in required if v not in seen]
    self.fail(msg=f'Timed out. Missing values: {str([str(v) for v in missing])}.')

Tests that calls to the given function meet required and allowed values.

Args:
  func: function to test.
  required: iterable of required values. Must be hashable and non-empty.
  allowed: iterable of allowed values. Must be hashable and non-empty.
  timeout_secs: fails if more than this time is required.


def save_randomly_initialized_version(config_name: str, save_dir: str, **config_kwargs):
    cfg = AutoConfig.from_pretrained(config_name, **config_kwargs)
    model = AutoModelForSeq2SeqLM.from_config(cfg)
    model.save_pretrained(save_dir)
    AutoTokenizer.from_pretrained(config_name).save_pretrained(save_dir)
    return model

Save a randomly initialized version of a model using a pretrained config.
Args:
    config_name: which config to use
    save_dir: where to save the resulting model and tokenizer
    config_kwargs: Passed to AutoConfig

Usage::
    save_randomly_initialized_version("facebook/bart-large-cnn", "distilbart_random_cnn_6_3", encoder_layers=6, decoder_layers=3, num_beams=3)


def _calculate_expected_result(dist_per_cell, numeric_values, numeric_values_scale, input_mask_float, logits_aggregation, config):
    if config.use_gumbel_for_cells:
        gumbel_dist = tfp.distributions.RelaxedBernoulli(config.temperature, logits=dist_per_cell.logits_parameter() * config.temperature)
        scaled_probability_per_cell = gumbel_dist.sample()
    else:
        scaled_probability_per_cell = dist_per_cell.probs_parameter()
    scaled_probability_per_cell = scaled_probability_per_cell / numeric_values_scale * input_mask_float
    count_result = tf.reduce_sum(scaled_probability_per_cell, axis=1)
    numeric_values_masked = tf.where(tf.math.is_nan(numeric_values), tf.zeros_like(numeric_values), numeric_values)
    sum_result = tf.reduce_sum(scaled_probability_per_cell * numeric_values_masked, axis=1)
    avg_approximation = config.average_approximation_function
    if avg_approximation == AverageApproximationFunction.RATIO:
        average_result = sum_result / (count_result + EPSILON_ZERO_DIVISION)
    elif avg_approximation == AverageApproximationFunction.FIRST_ORDER:
        ex = tf.reduce_sum(scaled_probability_per_cell, axis=1, keepdims=True) - scaled_probability_per_cell + 1
        average_result = tf.reduce_sum(numeric_values_masked * scaled_probability_per_cell / ex, axis=1)
    elif avg_approximation == AverageApproximationFunction.SECOND_ORDER:
        ex = tf.reduce_sum(scaled_probability_per_cell, axis=1, keepdims=True) - scaled_probability_per_cell + 1
        pointwise_var = scaled_probability_per_cell * (1 - scaled_probability_per_cell)
        var = tf.reduce_sum(pointwise_var, axis=1, keepdims=True) - pointwise_var
        multiplier = (var / tf.math.square(ex) + 1) / ex
        average_result = tf.reduce_sum(numeric_values_masked * scaled_probability_per_cell * multiplier, axis=1)
    else:
        raise ValueError('Invalid average_approximation_function: %s', config.average_approximation_function)
    if config.use_gumbel_for_aggregation:
        gumbel_dist = tfp.distributions.RelaxedOneHotCategorical(config.aggregation_temperature, logits=logits_aggregation[:, 1:])
        aggregation_op_only_probs = gumbel_dist.sample()
    else:
        aggregation_op_only_probs = stable_softmax(logits_aggregation[:, 1:] / config.aggregation_temperature, axis=-1)
    all_results = tf.concat([tf.expand_dims(sum_result, axis=1), tf.expand_dims(average_result, axis=1), tf.expand_dims(count_result, axis=1)], axis=1)
    expected_result = tf.reduce_sum(all_results * aggregation_op_only_probs, axis=1)
    return expected_result

Calculates the expected result given cell and aggregation probabilities.

Args:
    dist_per_cell (`tfp.distributions.Bernoulli`):
        Cell selection distribution for each cell.
    numeric_values (`tf.Tensor` of shape `(batch_size, seq_length)`):
        Numeric values of every token. Nan for tokens which are not numeric values.
    numeric_values_scale (`tf.Tensor` of shape `(batch_size, seq_length)`):
        Scale of the numeric values of every token.
    input_mask_float (`tf.Tensor` of shape `(batch_size, seq_length)`):
        Mask for the table, without question tokens and table headers.
    logits_aggregation (`tf.Tensor` of shape `(batch_size, num_aggregation_labels)`):
        Logits per aggregation operation.
    config ([`TapasConfig`]):
        Model configuration class with all the hyperparameters of the model

Returns:
    expected_result (`tf.Tensor` of shape `(batch_size,)`): The expected result per example.


def from_sub_model_configs(cls, text_config: ClvpEncoderConfig, speech_config: ClvpEncoderConfig, decoder_config: ClvpDecoderConfig, **kwargs):
    return cls(text_config=text_config.to_dict(), speech_config=speech_config.to_dict(), decoder_config=decoder_config.to_dict(), **kwargs)

Instantiate a [`ClvpConfig`] (or a derived class) from CLVP text model configuration, CLVP speech model
configuration and CLVP decoder model configuration.

Args:
    text_config (`ClvpEncoderConfig`):
        Text model configuration of type [`ClvpEncoderConfig`].
    speech_config (`ClvpEncoderConfig`):
        Speech model configuration of type [`ClvpEncoderConfig`].
    decoder_config (`ClvpDecoderConfig`):
        Decoder model configuration of type [`ClvpDecoderConfig`].

Returns:
    [`ClvpConfig`]: An instance of a configuration object


def _build_node_error_message(op):
    node_error_message = [f'Detected at node {op.name!r} defined at (most recent call last):']
    field_dict = _compute_field_dict(op)
    for frame in field_dict['definition_traceback']:
        if '<embedded' not in frame:
            node_error_message.extend([f'  {line}' for line in frame.split('\n') if line.strip()])
    node_error_message.append(f'Node: {op.name!r}')
    return '\n'.join(node_error_message)

Returns the formatted error message for the given op.

Args:
  op: The node.

Returns:
  The formatted error message for the given op with traceback.


def maybe_update_along_axis(*, tensor, new_tensor, axis, ind, do_update, dtype=None, name=None):
    name = name or 'maybe_update_along_axis'
    with tf.name_scope(name):
        tensor = tf.convert_to_tensor(tensor, dtype=dtype, name='tensor')
        dtype = tensor.dtype
        new_tensor = tf.convert_to_tensor(new_tensor, dtype=dtype, name='new_tensor')
        ind = tf.convert_to_tensor(ind, name='ind')
        do_update = tf.convert_to_tensor(do_update, name='do_update')
        size_along_axis = tensor.shape.as_list()[axis]

        def _write_update_to_result():
            size_along_axis_dynamic = tf.shape(tensor)[axis]
            one_hot = tf.one_hot(ind, depth=size_along_axis_dynamic)
            mask_size = tensor.shape.rank
            mask_shape = tf.pad([size_along_axis_dynamic], paddings=[[axis, mask_size - axis - 1]], constant_values=1)
            mask = tf.reshape(one_hot > 0, mask_shape)
            return tf.where(mask, new_tensor, tensor)
        if size_along_axis is None or size_along_axis > 1:
            return tf.cond(do_update, _write_update_to_result, lambda: tensor)
        else:
            return new_tensor

Replace `tensor` entries with `new_tensor` along a given axis.

This updates elements of `tensor` that correspond to the elements returned by
`numpy.take(updated, ind, axis)` with the corresponding elements of
`new_tensor`.

# Example
```python
tensor = tf.ones([5, 4, 3, 2])
new_tensor = tf.zeros([5, 4, 3, 2])
updated_tensor = maybe_update_along_axis(tensor=tensor,
                                         new_tensor=new_tensor,
                                         axis=1,
                                         ind=2,
                                         do_update=True)
# Returns a `Tensor` of ones where
# `updated_tensor[:, 2, :, :].numpy() == 0`
```
If the `do_update` is set to `False`, then the update does not happen unless
the number of dimensions along the `axis` is equal to 1. This functionality
is useful when, for example, aggregating samples of an Ito process.

Args:
  tensor: A `Tensor` of any shape and `dtype`.
  new_tensor: A `Tensor` of the same `dtype` as `tensor` and of shape
    broadcastable with `tensor`.
  axis: A Python integer. The axis of `tensor` along which the elements have
    to be updated.
  ind: An int32 scalar `Tensor` that denotes an index on the `axis` which
    defines the updated slice of `tensor` (see example above).
  do_update: A bool scalar `Tensor`. If `False`, the output is the same as
    `tensor`, unless  the dimension of the `tensor` along the `axis` is equal
    to 1.
  dtype: The `dtype` of the input `Tensor`s.
    Default value: `None` which means that default dtypes inferred by
      TensorFlow are used.
  name: Python string. The name to give this op.
    Default value: `None` which maps to `maybe_update_along_axis`.

Returns:
  A `Tensor` of the same shape and `dtype` as `tensor`.


def get_all_plugin_assets(graph=None):
    if graph is None:
        graph = ops.get_default_graph()
    out = []
    for name in graph.get_collection(_PLUGIN_ASSET_PREFIX):
        collection = graph.get_collection(_PLUGIN_ASSET_PREFIX + name)
        if len(collection) != 1:
            raise ValueError('Collection for %s had %d items, expected 1' % (name, len(collection)))
        out.append(collection[0])
    return out

Retrieve all PluginAssets stored in the graph collection.

Args:
  graph: Optionally, the graph to get assets from. If unspecified, the default
    graph is used.

Returns:
  A list with all PluginAsset instances in the graph.

Raises:
  ValueError: if we unexpectedly find a collection with the wrong number of
    PluginAssets.


def replace_composites_with_components(structure):
    if isinstance(structure, CompositeTensor):
        return replace_composites_with_components(structure._type_spec._to_components(structure))
    elif not nest.is_nested(structure):
        return structure
    else:
        return nest.map_structure(replace_composites_with_components, structure, expand_composites=False)

Recursively replaces CompositeTensors with their components.

Args:
  structure: A `nest`-compatible structure, possibly containing composite
    tensors.

Returns:
  A copy of `structure`, where each composite tensor has been replaced by
  its components.  The result will contain no composite tensors.
  Note that `nest.flatten(replace_composites_with_components(structure))`
  returns the same value as `nest.flatten(structure)`.


def get_special_tokens_mask(self, token_ids_0: list, token_ids_1: Optional[list]=None, already_has_special_tokens: bool=False) -> list[int]:
    if already_has_special_tokens:
        if token_ids_1 is not None:
            raise ValueError('You should not supply a second sequence if the provided sequence of ids is already formatted with special tokens for the model.')
        return super().get_special_tokens_mask(token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True)
    return [0] * ((len(token_ids_1) if token_ids_1 else 0) + len(token_ids_0))

Retrieves sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer `prepare_for_model` or `encode_plus` methods.

Args:
    token_ids_0 (`List[int]`):
        List of ids of the first sequence.
    token_ids_1 (`List[int]`, *optional*):
        List of ids of the second sequence.
    already_has_special_tokens (`bool`, *optional*, defaults to `False`):
        Whether or not the token list is already formatted with special tokens for the model.

Returns:
    A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.


def _distribute(processing_mode, service, job_name=None, consumer_index=None, num_consumers=None, max_outstanding_requests=None, task_refresh_interval_hint_ms=None, data_transfer_protocol=None, compression='AUTO', cross_trainer_cache=None, target_workers='AUTO') -> Callable[dataset_ops.Dataset, dataset_ops.Dataset]:
    processing_mode = _get_validated_sharding_policy(processing_mode)
    _validate_compression(compression)

    def _apply_fn(dataset) -> dataset_ops.Dataset:
        dataset_id = _register_dataset(service, dataset, compression=compression)
        return _from_dataset_id(processing_mode, service, dataset_id, dataset.element_spec, job_name=job_name, consumer_index=consumer_index, num_consumers=num_consumers, max_outstanding_requests=max_outstanding_requests, task_refresh_interval_hint_ms=task_refresh_interval_hint_ms, data_transfer_protocol=data_transfer_protocol, cross_trainer_cache=cross_trainer_cache, target_workers=target_workers)
    return _apply_fn

A transformation that moves dataset processing to the tf.data service.

This transformation is similar to `distribute`, but supports additional
parameters which we do not yet want to add to the public Python API.

Args:
  processing_mode: A `tf.data.experimental.service.ShardingPolicy` specifying
    how to shard the dataset among tf.data workers. See
    `tf.data.experimental.service.ShardingPolicy` for details. For backwards
    compatibility, `processing_mode` may also be set to the strings
    `"parallel_epochs"` or `"distributed_epoch"`, which are respectively
    equivalent to `ShardingPolicy.OFF` and `ShardingPolicy.DYNAMIC`.
  service: A string or a tuple indicating how to connect to the tf.data
    service. If it's a string, it should be in the format
    `[<protocol>://]<address>`, where `<address>` identifies the dispatcher
    address and `<protocol>` can optionally be used to override the default
    protocol to use. If it's a tuple, it should be (protocol, address).
  job_name: (Optional.) The name of the job. If provided, it must be a
    non-empty string. This argument makes it possible for multiple datasets to
    share the same job. The default behavior is that the dataset creates
    anonymous, exclusively owned jobs.
  consumer_index: (Optional.) The index of the consumer in the range from `0`
    to `num_consumers`. Must be specified alongside `num_consumers`. When
    specified, consumers will read from the job in a strict round-robin order,
    instead of the default first-come-first-served order.
  num_consumers: (Optional.) The number of consumers which will consume from
    the job. Must be specified alongside `consumer_index`. When specified,
    consumers will read from the job in a strict round-robin order, instead of
    the default first-come-first-served order. When `num_consumers` is
    specified, the dataset must have infinite cardinality to prevent a
    producer from running out of data early and causing consumers to go out of
    sync.
  max_outstanding_requests: (Optional.) A limit on how many elements may be
    requested at the same time. You can use this option to control the amount
    of memory used, since `distribute` won't use more than `element_size` *
    `max_outstanding_requests` of memory.
  task_refresh_interval_hint_ms: (Optional.) A hint for how often to query the
    dispatcher for task changes.
  data_transfer_protocol: (Optional.) The protocol to use for transferring
    data with the tf.data service. If not provided, a protocol is determined
    at runtime.
  compression: How to compress the dataset's elements before transferring them
    over the network. "AUTO" leaves the decision of how to compress up to the
    tf.data service runtime. `None` indicates not to compress. "SNAPPY" forces
    snappy compression.
  cross_trainer_cache: (Optional.) If a `CrossTrainerCache` object is
    provided, dataset iteration will be shared across concurrently running
    trainers. See
    https://www.tensorflow.org/api_docs/python/tf/data/experimental/service#sharing_tfdata_service_with_concurrent_trainers
      for details.
  target_workers: (Optional.) Which workers to read from. If `"AUTO"`, tf.data
    runtime decides which workers to read from. If `"ANY"`, reads from any
    tf.data service workers. If `"LOCAL"`, only reads from local in-process
    tf.data service workers. `"AUTO"` works well for most cases, while users
    can specify other targets. For example, `"LOCAL"` helps avoid RPCs and
    data copy if every TF worker colocates with a tf.data service worker.
    Consumers of a shared job must use the same `target_workers`. Defaults to
    `"AUTO"`.

Returns:
  Dataset: A `Dataset` of the elements produced by the data service.


def matches_any(patterns: List[Pattern[str]], line: str) -> bool:
    stripped_line = line.strip()
    for pattern in patterns:
        if pattern.match(stripped_line):
            return True
    return False

Checks if the line matches any of the given patterns.

Args:
  patterns: A list of compiled regular expression patterns.
  line: The line to check for matches.

Returns:
  True if the line matches any of the patterns, False otherwise.


def forward(self, hidden_states: List[torch.Tensor], patch_height=None, patch_width=None) -> List[torch.Tensor]:
    if not isinstance(hidden_states, (tuple, list)):
        raise TypeError('hidden_states should be a tuple or list of tensors')
    if len(hidden_states) != len(self.config.neck_hidden_sizes):
        raise ValueError('The number of hidden states should be equal to the number of neck hidden sizes.')
    if self.reassemble_stage is not None:
        hidden_states = self.reassemble_stage(hidden_states, patch_height, patch_width)
    features = [self.convs[i](feature) for i, feature in enumerate(hidden_states)]
    output = self.fusion_stage(features)
    return output

Args:
    hidden_states (`List[torch.FloatTensor]`, each of shape `(batch_size, sequence_length, hidden_size)` or `(batch_size, hidden_size, height, width)`):
        List of hidden states from the backbone.


class TimeSeriesTransformerDecoder(TimeSeriesTransformerPreTrainedModel):

    def __init__(self, config: TimeSeriesTransformerConfig):
        super().__init__(config)
        self.dropout = config.dropout
        self.layerdrop = config.decoder_layerdrop
        if config.prediction_length is None:
            raise ValueError('The `prediction_length` config needs to be specified.')
        self.value_embedding = TimeSeriesValueEmbedding(feature_size=config.feature_size, d_model=config.d_model)
        self.embed_positions = TimeSeriesSinusoidalPositionalEmbedding(config.context_length + config.prediction_length, config.d_model)
        self.layers = nn.ModuleList([TimeSeriesTransformerDecoderLayer(config, layer_idx=i) for i in range(config.decoder_layers)])
        self.layernorm_embedding = nn.LayerNorm(config.d_model)
        self.gradient_checkpointing = False
        self.post_init()

    def forward(self, attention_mask: Optional[torch.Tensor]=None, encoder_hidden_states: Optional[torch.FloatTensor]=None, encoder_attention_mask: Optional[torch.LongTensor]=None, head_mask: Optional[torch.Tensor]=None, cross_attn_head_mask: Optional[torch.Tensor]=None, past_key_values: Optional[List[torch.FloatTensor]]=None, inputs_embeds: Optional[torch.FloatTensor]=None, use_cache: Optional[bool]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None, cache_position: Optional[torch.LongTensor]=None) -> Union[Tuple, BaseModelOutputWithPastAndCrossAttentions]:
        """
        Args:
            attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
                Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

                - 1 for tokens that are **not masked**,
                - 0 for tokens that are **masked**.

                [What are attention masks?](../glossary#attention-mask)
            encoder_hidden_states (`torch.FloatTensor` of shape `(batch_size, encoder_sequence_length, hidden_size)`, *optional*):
                Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention
                of the decoder.
            encoder_attention_mask (`torch.LongTensor` of shape `(batch_size, encoder_sequence_length)`, *optional*):
                Mask to avoid performing cross-attention on padding tokens indices of encoder input_ids. Mask values
                selected in `[0, 1]`:

                - 1 for tokens that are **not masked**,
                - 0 for tokens that are **masked**.

                [What are attention masks?](../glossary#attention-mask)
            head_mask (`torch.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the attention modules. Mask values selected in `[0, 1]`:

                - 1 indicates the head is **not masked**,
                - 0 indicates the head is **masked**.

            cross_attn_head_mask (`torch.Tensor` of shape `(decoder_layers, decoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the cross-attention modules in the decoder to avoid performing
                cross-attention on hidden heads. Mask values selected in `[0, 1]`:

                - 1 indicates the head is **not masked**,
                - 0 indicates the head is **masked**.

            past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
                Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
                shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`) and 2 additional tensors of
                shape `(batch_size, num_heads, encoder_sequence_length, embed_size_per_head)`.

                Contains pre-computed hidden-states (key and values in the self-attention blocks and in the
                cross-attention blocks) that can be used (see `past_key_values` input) to speed up sequential decoding.

                If `past_key_values` are used, the user can optionally input only the last `decoder_input_ids` (those
                that don't have their past key value states given to this model) of shape `(batch_size, 1)` instead of
                all `decoder_input_ids` of shape `(batch_size, sequence_length)`.
            inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
                Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
                This is useful if you want more control over how to convert `input_ids` indices into associated vectors
                than the model's internal embedding lookup matrix.
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
            output_hidden_states (`bool`, *optional*):
                Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors
                for more detail.
            return_dict (`bool`, *optional*):
                Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
            cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
                Indices depicting the position of the input sequence tokens in the sequence. It is used to update the
                cache in the correct position and to infer the complete sequence length.
        """
        output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
        output_hidden_states = output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
        use_cache = use_cache if use_cache is not None else self.config.use_cache
        return_dict = return_dict if return_dict is not None else self.config.use_return_dict
        input_shape = inputs_embeds.size()[:-1]
        return_legacy_cache = False
        if use_cache and (not isinstance(past_key_values, Cache)):
            return_legacy_cache = True
            logger.warning_once('Passing a tuple of `past_key_values` is deprecated and will be removed in Transformers v4.58.0. You should pass an instance of `EncoderDecoderCache` instead, e.g. `past_key_values=EncoderDecoderCache.from_legacy_cache(past_key_values)`.')
            past_key_values = EncoderDecoderCache.from_legacy_cache(past_key_values)
        past_key_values_length = past_key_values.get_seq_length() if past_key_values is not None else 0
        if cache_position is None:
            cache_position = torch.arange(past_key_values_length, past_key_values_length + input_shape[1], device=inputs_embeds.device)
        attention_mask = self._update_causal_mask(attention_mask, input_shape, inputs_embeds, past_key_values_length)
        encoder_attention_mask = self._update_cross_attn_mask(encoder_hidden_states, encoder_attention_mask, input_shape, inputs_embeds)
        hidden_states = self.value_embedding(inputs_embeds)
        embed_pos = self.embed_positions(inputs_embeds.size(), past_key_values_length=self.config.context_length)
        hidden_states = self.layernorm_embedding(hidden_states + embed_pos)
        hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
        if self.gradient_checkpointing and self.training:
            if use_cache:
                logger.warning_once('`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...')
                use_cache = False
        all_hidden_states = () if output_hidden_states else None
        all_self_attns = () if output_attentions else None
        all_cross_attentions = () if output_attentions and encoder_hidden_states is not None else None
        next_decoder_cache = None
        for attn_mask, mask_name in zip([head_mask, cross_attn_head_mask], ['head_mask', 'cross_attn_head_mask']):
            if attn_mask is not None:
                if attn_mask.size()[0] != len(self.layers):
                    raise ValueError(f'The `{mask_name}` should be specified for {len(self.layers)} layers, but it is for {head_mask.size()[0]}.')
        for idx, decoder_layer in enumerate(self.layers):
            if output_hidden_states:
                all_hidden_states += (hidden_states,)
            if self.training:
                dropout_probability = torch.rand([])
                if dropout_probability < self.layerdrop:
                    continue
            if self.gradient_checkpointing and self.training:
                layer_outputs = self._gradient_checkpointing_func(decoder_layer.__call__, hidden_states, attention_mask, encoder_hidden_states, encoder_attention_mask, head_mask[idx] if head_mask is not None else None, cross_attn_head_mask[idx] if cross_attn_head_mask is not None else None, None, output_attentions, use_cache, cache_position)
            else:
                layer_outputs = decoder_layer(hidden_states, attention_mask=attention_mask, encoder_hidden_states=encoder_hidden_states, encoder_attention_mask=encoder_attention_mask, layer_head_mask=head_mask[idx] if head_mask is not None else None, cross_attn_layer_head_mask=cross_attn_head_mask[idx] if cross_attn_head_mask is not None else None, past_key_value=past_key_values, output_attentions=output_attentions, use_cache=use_cache, cache_position=cache_position)
            hidden_states = layer_outputs[0]
            if use_cache:
                next_decoder_cache = layer_outputs[3 if output_attentions else 1]
            if output_attentions:
                all_self_attns += (layer_outputs[1],)
                if encoder_hidden_states is not None:
                    all_cross_attentions += (layer_outputs[2],)
        if output_hidden_states:
            all_hidden_states += (hidden_states,)
        next_cache = next_decoder_cache if use_cache else None
        if return_legacy_cache:
            next_cache = past_key_values.to_legacy_cache()
        if not return_dict:
            return tuple((v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns, all_cross_attentions] if v is not None))
        return BaseModelOutputWithPastAndCrossAttentions(last_hidden_state=hidden_states, past_key_values=next_cache, hidden_states=all_hidden_states, attentions=all_self_attns, cross_attentions=all_cross_attentions)

Transformer decoder consisting of *config.decoder_layers* layers. Each layer is a
[`TimeSeriesTransformerDecoderLayer`]

Args:
    config: TimeSeriesTransformerConfig


def global_step(self):
    return self._global_step

Return the global_step Tensor used by the supervisor.

Returns:
  An integer Tensor for the global_step.


def diagonal(x, offset=0, axis1=0, axis2=1):
    if any_symbolic_tensors((x,)):
        return Diagonal(offset=offset, axis1=axis1, axis2=axis2).symbolic_call(x)
    return backend.numpy.diagonal(x, offset=offset, axis1=axis1, axis2=axis2)

Return specified diagonals.

If `x` is 2-D, returns the diagonal of `x` with the given offset, i.e., the
collection of elements of the form `x[i, i+offset]`.

If `x` has more than two dimensions, the axes specified by `axis1`
and `axis2` are used to determine the 2-D sub-array whose diagonal
is returned.

The shape of the resulting array can be determined by removing `axis1`
and `axis2` and appending an index to the right equal to the size of
the resulting diagonals.

Args:
    x: Input tensor.
    offset: Offset of the diagonal from the main diagonal.
        Can be positive or negative. Defaults to `0`.(main diagonal).
    axis1: Axis to be used as the first axis of the 2-D sub-arrays.
        Defaults to `0`.(first axis).
    axis2: Axis to be used as the second axis of the 2-D sub-arrays.
        Defaults to `1` (second axis).

Returns:
    Tensor of diagonals.

Examples:
>>> from keras.src import ops
>>> x = ops.arange(4).reshape((2, 2))
>>> x
array([[0, 1],
       [2, 3]])
>>> x.diagonal()
array([0, 3])
>>> x.diagonal(1)
array([1])

>>> x = ops.arange(8).reshape((2, 2, 2))
>>> x
array([[[0, 1],
        [2, 3]],
       [[4, 5],
        [6, 7]]])
>>> x.diagonal(0, 0, 1)
array([[0, 6],
       [1, 7]])


def forward(self, input_ids: Optional[torch.LongTensor]=None, attention_mask: Optional[torch.FloatTensor]=None, head_mask: Optional[torch.FloatTensor]=None, inputs_embeds: Optional[torch.FloatTensor]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None) -> Union[Tuple[torch.FloatTensor], BaseModelOutput]:
    return_dict = return_dict if return_dict is not None else self.config.use_return_dict
    encoder_outputs = self.encoder(input_ids=input_ids, attention_mask=attention_mask, inputs_embeds=inputs_embeds, head_mask=head_mask, output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict)
    return encoder_outputs

input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
    Indices of input sequence tokens in the vocabulary. T5 is a model with relative position embeddings so you
    should be able to pad the inputs on both the right and the left.

    Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
    [`PreTrainedTokenizer.__call__`] for detail.

    To know more on how to prepare `input_ids` for pretraining take a look a [T5 Training](./t5#training).

Example:

```python
>>> from transformers import AutoTokenizer, T5EncoderModel

>>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-small")
>>> model = T5EncoderModel.from_pretrained("google-t5/t5-small")
>>> input_ids = tokenizer(
...     "Studies have been shown that owning a dog is good for you", return_tensors="pt"
... ).input_ids  # Batch size 1
>>> outputs = model(input_ids=input_ids)
>>> last_hidden_states = outputs.last_hidden_state
```


def create(self, batch_outs):
    raise NotImplementedError('Must be implemented in subclasses.')

Creates the initial results from the first batch outputs.

Args:
  batch_outs: A list of batch-level outputs.


def extract_imports(module_fname: str, cache: Optional[Dict[str, List[str]]]=None) -> List[str]:
    if cache is not None and module_fname in cache:
        return cache[module_fname]
    with open(PATH_TO_REPO / module_fname, 'r', encoding='utf-8') as f:
        content = f.read()
    splits = content.split('"""')
    content = ''.join(splits[::2])
    module_parts = str(module_fname).split(os.path.sep)
    imported_modules = []
    relative_imports = _re_single_line_relative_imports.findall(content)
    relative_imports = [(mod, imp) for mod, imp in relative_imports if '# tests_ignore' not in imp and imp.strip() != '(']
    multiline_relative_imports = _re_multi_line_relative_imports.findall(content)
    relative_imports += [(mod, imp) for mod, imp in multiline_relative_imports if '# tests_ignore' not in imp]
    for module, imports in relative_imports:
        level = 0
        while module.startswith('.'):
            module = module[1:]
            level += 1
        if len(module) > 0:
            dep_parts = module_parts[:len(module_parts) - level] + module.split('.')
        else:
            dep_parts = module_parts[:len(module_parts) - level]
        imported_module = os.path.sep.join(dep_parts)
        imported_modules.append((imported_module, [imp.strip() for imp in imports.split(',')]))
    direct_imports = _re_single_line_direct_imports.findall(content)
    direct_imports = [(mod, imp) for mod, imp in direct_imports if '# tests_ignore' not in imp and imp.strip() != '(']
    multiline_direct_imports = _re_multi_line_direct_imports.findall(content)
    direct_imports += [(mod, imp) for mod, imp in multiline_direct_imports if '# tests_ignore' not in imp]
    for module, imports in direct_imports:
        import_parts = module.split('.')[1:]
        dep_parts = ['src', 'transformers'] + import_parts
        imported_module = os.path.sep.join(dep_parts)
        imported_modules.append((imported_module, [imp.strip() for imp in imports.split(',')]))
    result = []
    for module_file, imports in imported_modules:
        if (PATH_TO_REPO / f'{module_file}.py').is_file():
            module_file = f'{module_file}.py'
        elif (PATH_TO_REPO / module_file).is_dir() and (PATH_TO_REPO / module_file / '__init__.py').is_file():
            module_file = os.path.sep.join([module_file, '__init__.py'])
        imports = [imp for imp in imports if len(imp) > 0 and re.match('^[A-Za-z0-9_]*$', imp)]
        if len(imports) > 0:
            result.append((module_file, imports))
    if cache is not None:
        cache[module_fname] = result
    return result

Get the imports a given module makes.

Args:
    module_fname (`str`):
        The name of the file of the module where we want to look at the imports (given relative to the root of
        the repo).
    cache (Dictionary `str` to `List[str]`, *optional*):
        To speed up this function if it was previously called on `module_fname`, the cache of all previously
        computed results.

Returns:
    `List[str]`: The list of module filenames imported in the input `module_fname` (a submodule we import from that
    is a subfolder will give its init file).


class BarkConfig(PretrainedConfig):
    model_type = 'bark'
    sub_configs = {'semantic_config': BarkSemanticConfig, 'coarse_acoustics_config': BarkCoarseConfig, 'fine_acoustics_config': BarkFineConfig, 'codec_config': AutoConfig}

    def __init__(self, semantic_config: Optional[Dict]=None, coarse_acoustics_config: Optional[Dict]=None, fine_acoustics_config: Optional[Dict]=None, codec_config: Optional[Dict]=None, initializer_range=0.02, **kwargs):
        if semantic_config is None:
            semantic_config = {}
            logger.info('semantic_config is None. initializing the semantic model with default values.')
        if coarse_acoustics_config is None:
            coarse_acoustics_config = {}
            logger.info('coarse_acoustics_config is None. initializing the coarse model with default values.')
        if fine_acoustics_config is None:
            fine_acoustics_config = {}
            logger.info('fine_acoustics_config is None. initializing the fine model with default values.')
        if codec_config is None:
            codec_config = {}
            logger.info('codec_config is None. initializing the codec model with default values.')
        self.semantic_config = BarkSemanticConfig(**semantic_config)
        self.coarse_acoustics_config = BarkCoarseConfig(**coarse_acoustics_config)
        self.fine_acoustics_config = BarkFineConfig(**fine_acoustics_config)
        codec_model_type = codec_config['model_type'] if 'model_type' in codec_config else 'encodec'
        self.codec_config = CONFIG_MAPPING[codec_model_type](**codec_config)
        self.initializer_range = initializer_range
        super().__init__(**kwargs)

    @classmethod
    def from_sub_model_configs(cls, semantic_config: BarkSemanticConfig, coarse_acoustics_config: BarkCoarseConfig, fine_acoustics_config: BarkFineConfig, codec_config: PretrainedConfig, **kwargs):
        """
        Instantiate a [`BarkConfig`] (or a derived class) from bark sub-models configuration.

        Returns:
            [`BarkConfig`]: An instance of a configuration object
        """
        return cls(semantic_config=semantic_config.to_dict(), coarse_acoustics_config=coarse_acoustics_config.to_dict(), fine_acoustics_config=fine_acoustics_config.to_dict(), codec_config=codec_config.to_dict(), **kwargs)

This is the configuration class to store the configuration of a [`BarkModel`]. It is used to instantiate a Bark
model according to the specified sub-models configurations, defining the model architecture.

Instantiating a configuration with the defaults will yield a similar configuration to that of the Bark
[suno/bark](https://huggingface.co/suno/bark) architecture.

Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
documentation from [`PretrainedConfig`] for more information.

Args:
semantic_config ([`BarkSemanticConfig`], *optional*):
    Configuration of the underlying semantic sub-model.
coarse_acoustics_config ([`BarkCoarseConfig`], *optional*):
    Configuration of the underlying coarse acoustics sub-model.
fine_acoustics_config ([`BarkFineConfig`], *optional*):
    Configuration of the underlying fine acoustics sub-model.
codec_config ([`AutoConfig`], *optional*):
    Configuration of the underlying codec sub-model.

Example:

```python
>>> from transformers import (
...     BarkSemanticConfig,
...     BarkCoarseConfig,
...     BarkFineConfig,
...     BarkModel,
...     BarkConfig,
...     AutoConfig,
... )

>>> # Initializing Bark sub-modules configurations.
>>> semantic_config = BarkSemanticConfig()
>>> coarse_acoustics_config = BarkCoarseConfig()
>>> fine_acoustics_config = BarkFineConfig()
>>> codec_config = AutoConfig.from_pretrained("facebook/encodec_24khz")

>>> # Initializing a Bark module style configuration
>>> configuration = BarkConfig.from_sub_model_configs(
...     semantic_config, coarse_acoustics_config, fine_acoustics_config, codec_config
... )

>>> # Initializing a model (with random weights)
>>> model = BarkModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config
```


def _call_with_structured_signature(self, args, kwargs):
    bound_args = function_type_utils.canonicalize_function_inputs(args, kwargs, self.function_type)
    filtered_flat_args = self.function_type.unpack_inputs(bound_args)
    return self._call_flat(filtered_flat_args, captured_inputs=self.captured_inputs)

Executes the wrapped function with the structured signature.

Args:
  args: Positional arguments to the concrete function.
  kwargs: Keyword arguments to the concrete function.

Returns:
  The result of applying the function on the Tensors/Variables contained in
  `args` and `kwargs`.
Raises:
  TypeError: if `args` and `kwargs` do not match the structured signature
    of this `ConcreteFunction`.


def ttft(self) -> float | None:
    return self._ttft

Returns the TTFT of the wrapped processor.

Returns:
  the TTFT of the wrapped processor or None if the processor has not been
  called yet.


def bigtable_error_code_to_grpc_status_string(grpc_status_code: Optional[int]) -> str:
    grpc_to_canonical_gcp_status = {0: 'ok', 1: 'cancelled', 2: 'unknown', 3: 'invalid_argument', 4: 'deadline_exceeded', 5: 'not_found', 6: 'already_exists', 7: 'permission_denied', 8: 'resource_exhausted', 9: 'failed_precondition', 10: 'aborted', 11: 'out_of_range', 12: 'unimplemented', 13: 'internal', 14: 'unavailable'}
    if grpc_status_code is None:
        return grpc_to_canonical_gcp_status[4]
    return grpc_to_canonical_gcp_status.get(grpc_status_code, str(grpc_status_code))

Converts the bigtable error code to a canonical GCP status code string.

This Bigtable client library is not using the canonical http status code
values (i.e. https://cloud.google.com/apis/design/errors)"
Instead they are numbered using an enum with these values corresponding
to each status code: https://cloud.google.com/bigtable/docs/status-codes

Args:
  grpc_status_code: An int that corresponds to an enum of status codes

Returns:
  A GCP status code string


def set_default(self, default: Any, use_default_apply: bool=True, root_path: Optional[utils.KeyPath]=None) -> 'ValueSpec':

Sets the default value and returns `self`.

Args:
  default: Default value.
  use_default_apply: If True, invoke `apply` to the value, otherwise use
    default value as is.
  root_path: (Optional) The path of the field.

Returns:
  ValueSpec itself.

Raises:
  ValueError: If default value cannot be applied when use_default_apply
    is set to True.


def enqueue_many(self, vals, name=None):
    with ops.name_scope(name, '%s_EnqueueMany' % self._name, self._scope_vals(vals)) as scope:
        vals = self._check_enqueue_dtypes(vals)
        batch_dim = tensor_shape.dimension_value(vals[0].get_shape().with_rank_at_least(1)[0])
        batch_dim = tensor_shape.Dimension(batch_dim)
        for val, shape in zip(vals, self._shapes):
            val_batch_dim = tensor_shape.dimension_value(val.get_shape().with_rank_at_least(1)[0])
            val_batch_dim = tensor_shape.Dimension(val_batch_dim)
            batch_dim = batch_dim.merge_with(val_batch_dim)
            val.get_shape()[1:].assert_is_compatible_with(shape)
        return gen_data_flow_ops.queue_enqueue_many_v2(self._queue_ref, vals, name=scope)

Enqueues zero or more elements to this queue.

This operation slices each component tensor along the 0th dimension to
make multiple queue elements. All of the tensors in `vals` must have the
same size in the 0th dimension.

If the queue is full when this operation executes, it will block
until all of the elements have been enqueued.

At runtime, this operation may raise an error if the queue is
`tf.QueueBase.close` before or during its execution. If the
queue is closed before this operation runs,
`tf.errors.CancelledError` will be raised. If this operation is
blocked, and either (i) the queue is closed by a close operation
with `cancel_pending_enqueues=True`, or (ii) the session is
`tf.Session.close`,
`tf.errors.CancelledError` will be raised.

>>> q = tf.queue.FIFOQueue(capacity=10, dtypes=tf.int32)
>>> q.enqueue_many(tf.constant([1, 2, 3, 4, 5], dtype=tf.int32))
>>> q.size()
<tf.Tensor: shape=(), dtype=int32, numpy=5>

Args:
  vals: A tensor, a list or tuple of tensors, or a dictionary
    from which the queue elements are taken.
  name: A name for the operation (optional).

Returns:
  The operation that enqueues a batch of tuples of tensors to the queue.


def parse(cls, json_value: Union[int, float, str, List[Any], Tuple[Any], None], spec: Optional[DNASpec]=None) -> 'DNA':
    return DNA(json_value, spec=spec)

Parse DNA from a nested structure of numbers.

Deprecated: use `DNA.__init__` instead.

Args:
  json_value: A nested structure of numbers.
  spec: DNA spec that will be applied to current DNA tree.

Returns:
  an instance of DNA object.

Raises:
  ValueError: Bad format for json_value or parsed DNA does not conform to
    the DNA spec.


def build_inputs_with_special_tokens(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None) -> List[int]:
    if token_ids_1 is None:
        return [self.cls_token_id] + token_ids_0 + [self.sep_token_id]
    cls = [self.cls_token_id]
    sep = [self.sep_token_id]
    return cls + token_ids_0 + sep + sep + token_ids_1 + sep

Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. A BART sequence has the following format:

- single sequence: `<s> X </s>`
- pair of sequences: `<s> A </s></s> B </s>`

Args:
    token_ids_0 (`List[int]`):
        List of IDs to which the special tokens will be added.
    token_ids_1 (`List[int]`, *optional*):
        Optional second list of IDs for sequence pairs.

Returns:
    `List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.


def run_inference(self, batch: Sequence[np.ndarray], engine: TensorRTEngine, inference_args: Optional[dict[str, Any]]=None) -> Iterable[PredictionResult]:
    return self.inference_fn(batch, engine, inference_args)

Runs inferences on a batch of Tensors and returns an Iterable of
TensorRT Predictions.

Args:
  batch: A np.ndarray or a np.ndarray that represents a concatenation
    of multiple arrays as a batch.
  engine: A TensorRT engine.
  inference_args: Any additional arguments for an inference
    that are not applicable to TensorRT.

Returns:
  An Iterable of type PredictionResult.


def get_resource(self, feature_column, resource_name):
    if feature_column not in self._cols_to_resources_map or resource_name not in self._cols_to_resources_map[feature_column]:
        raise ValueError('Resource does not exist.')
    return self._cols_to_resources_map[feature_column][resource_name]

Returns an already created resource.

Resources can be things such as tables, variables, trackables, etc.

Args:
  feature_column: A `FeatureColumn` object this variable corresponds to.
  resource_name: Name of the resource.


def set_in_parent_or_add(msg: message.Message, field: Union[descriptor.FieldDescriptor, str]) -> message.Message:
    if isinstance(field, str):
        field = _field_descriptor_for_name(msg, field)
    if field_is_primitive(field):
        raise ValueError(f'Expected a composite message type at: {field.name}.')
    if field_is_repeated(field):
        return getattr(msg, field.name).add()
    getattr(msg, field.name).SetInParent()
    return getattr(msg, field.name)

Creates a new default instance of the type at field in message.

If this field is repeated, this function is equivalent to calling <field>.add,
otherwise, this function is equivalent to calling <field>.SetInParent and
returning the reference.

Args:
  msg: The parent message whose composite message to create and return.
  field: The FieldDescriptor or name of the field that the composite message
    is stored in.

Returns:
  A reference to a newly created message of the type at field which is a child
  of parent_message.

Raises:
  ValueError: If the provided FieldDescriptor is a primitive type.


class DataCollatorSpeechSeq2SeqWithPadding:
    processor: Any
    decoder_start_token_id: int
    forward_attention_mask: bool

    def __call__(self, features: list[dict[str, Union[list[int], torch.Tensor]]]) -> dict[str, torch.Tensor]:
        model_input_name = self.processor.model_input_names[0]
        input_features = [{model_input_name: feature[model_input_name]} for feature in features]
        label_features = [{'input_ids': feature['labels']} for feature in features]
        batch = self.processor.feature_extractor.pad(input_features, return_tensors='pt')
        if self.forward_attention_mask:
            batch['attention_mask'] = torch.LongTensor([feature['attention_mask'] for feature in features])
        labels_batch = self.processor.tokenizer.pad(label_features, return_tensors='pt')
        labels = labels_batch['input_ids'].masked_fill(labels_batch.attention_mask.ne(1), -100)
        if (labels[:, 0] == self.decoder_start_token_id).all().cpu().item():
            labels = labels[:, 1:]
        batch['labels'] = labels
        return batch

Data collator that will dynamically pad the inputs received.
Args:
    processor ([`WhisperProcessor`])
        The processor used for processing the data.
    decoder_start_token_id (`int`)
        The begin-of-sentence of the decoder.
    forward_attention_mask (`bool`)
        Whether to return attention_mask.


def load_images(images: Union[list, tuple, str, 'PIL.Image.Image'], timeout: Optional[float]=None) -> Union['PIL.Image.Image', list['PIL.Image.Image'], list[list['PIL.Image.Image']]]:
    if isinstance(images, (list, tuple)):
        if len(images) and isinstance(images[0], (list, tuple)):
            return [[load_image(image, timeout=timeout) for image in image_group] for image_group in images]
        else:
            return [load_image(image, timeout=timeout) for image in images]
    else:
        return load_image(images, timeout=timeout)

Loads images, handling different levels of nesting.

Args:
  images: A single image, a list of images, or a list of lists of images to load.
  timeout: Timeout for loading images.

Returns:
  A single image, a list of images, a list of lists of images.


def _indexed_slices_to_tensor(value, dtype=None, name=None, as_ref=False):
    _ = as_ref
    if dtype and (not dtype.is_compatible_with(value.dtype)):
        raise ValueError(f'Incompatible tensor conversion requested to `dtype` {dtype.name} for IndexedSlices ({value}) with dtype {value.dtype.name}')
    if value.dense_shape is None:
        raise ValueError(f'Tensor conversion requested for IndexedSlices for argument `value` without dense_shape: {value!s}')
    if not context.executing_eagerly():
        dense_shape_value = tensor_util.constant_value(value.dense_shape)
        if dense_shape_value is not None:
            num_elements = np.prod(dense_shape_value)
            if num_elements >= _LARGE_SPARSE_NUM_ELEMENTS:
                warnings.warn('Converting sparse IndexedSlices to a dense Tensor with %d elements. This may consume a large amount of memory.' % num_elements)
    return gen_math_ops.unsorted_segment_sum(value.values, value.indices, value.dense_shape[0], name=name)

Converts an IndexedSlices object `value` to a Tensor.

NOTE(mrry): This function is potentially expensive.

Args:
  value: An ops.IndexedSlices object.
  dtype: The dtype of the Tensor to be returned.
  name: Optional name to use for the returned Tensor.
  as_ref: True if a ref is requested.

Returns:
  A dense Tensor representing the values in the given IndexedSlices.

Raises:
  ValueError: If the IndexedSlices does not have the same dtype.