def sort(values, axis=-1, direction='ASCENDING', name=None):
    with framework_ops.name_scope(name, 'sort'):
        return _sort_or_argsort(values, axis, direction, return_argsort=False)

Sorts a tensor.

Usage:

>>> a = [1, 10, 26.9, 2.8, 166.32, 62.3]
>>> tf.sort(a).numpy()
array([  1.  ,   2.8 ,  10.  ,  26.9 ,  62.3 , 166.32], dtype=float32)

>>> tf.sort(a, direction='DESCENDING').numpy()
array([166.32,  62.3 ,  26.9 ,  10.  ,   2.8 ,   1.  ], dtype=float32)

For multidimensional inputs you can control which axis the sort is applied
along. The default `axis=-1` sorts the innermost axis.

>>> mat = [[3,2,1],
...        [2,1,3],
...        [1,3,2]]
>>> tf.sort(mat, axis=-1).numpy()
array([[1, 2, 3],
       [1, 2, 3],
       [1, 2, 3]], dtype=int32)
>>> tf.sort(mat, axis=0).numpy()
array([[1, 1, 1],
       [2, 2, 2],
       [3, 3, 3]], dtype=int32)

See also:

  * `tf.argsort`: Like sort, but it returns the sort indices.
  * `tf.math.top_k`: A partial sort that returns a fixed number of top values
    and corresponding indices.

Args:
  values: 1-D or higher **numeric** `Tensor`.
  axis: The axis along which to sort. The default is -1, which sorts the last
    axis.
  direction: The direction in which to sort the values (`'ASCENDING'` or
    `'DESCENDING'`).
  name: Optional name for the operation.

Returns:
  A `Tensor` with the same dtype and shape as `values`, with the elements
      sorted along the given `axis`.

Raises:
  tf.errors.InvalidArgumentError: If the `values.dtype` is not a `float` or
      `int` type.
  ValueError: If axis is not a constant scalar, or the direction is invalid.


def to_type(self, entry: dict) -> str:
    t = entry.get('type')
    f = entry.get('format')
    if t == 'any':
        return 'STRING'
    elif t == 'array':
        return 'REPEATED'
    elif t == 'boolean':
        return 'BOOLEAN'
    elif t == 'integer':
        return 'INT64'
    elif t == 'number':
        if f == 'double':
            return 'FLOAT64'
        else:
            return 'FLOAT'
    elif t == 'object':
        return 'STRUCT'
    elif t == 'string':
        if f == 'byte':
            return 'BYTES'
        elif f == 'date':
            return 'DATE'
        elif f == 'date-time':
            return 'TIMESTAMP'
        elif f == 'int64':
            return 'INT64'
        elif f == 'uint64':
            return 'INT64'
        else:
            return 'STRING'
    else:
        return 'STRING'

Convert a Discovery API Document type to a BigQuery type.

Called internally but exposed for convenience.

Args:
  entry: discovery type format: https://developers.google.com/discovery/v1/type-format

Returns:
  Bigquery type: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types


def visit_membership(self, relation: _evaluation.MembershipRelationNode) -> _sql_data_types.Select:
    lhs_result = self.visit(relation.left)
    rhs_result = self.visit(relation.right)
    in_lhs = lhs_result if isinstance(relation, _evaluation.InNode) else rhs_result
    in_rhs = rhs_result if isinstance(relation, _evaluation.InNode) else lhs_result
    sql_expr = f'({in_lhs.as_operand()}) IN ({in_rhs.as_operand()})'
    return _sql_data_types.Select(select_part=_sql_data_types.RawExpression(sql_expr, _sql_data_type=_sql_data_types.Boolean, _sql_alias='mem_'), from_part=None, sql_dialect=_sql_data_types.SqlDialect.SPARK)

Translates a FHIRPath membership relation to Spark SQL.

For the `IN` relation, the LHS operand is assumed to be a collection of a
single value. For 'CONTAINS', the RHS operand is assumed to be a collection
of a single value. Equality is handled in the visit_equality function.

Args:
  relation: The FHIRPath AST `MembershipRelation` node.

Returns:
  A compiled Spark SQL expression.


def recipe_google_api_to_bigquery(config, auth_read, api, version, function, kwargs, kwargs_remote, api_key, developer_token, login_customer_id, dataset, table):
    google_api(config, {'auth': auth_read, 'api': api, 'version': version, 'function': function, 'kwargs': kwargs, 'kwargs_remote': kwargs_remote, 'key': api_key, 'headers': {'developer-token': developer_token, 'login-customer-id': login_customer_id}, 'results': {'bigquery': {'dataset': dataset, 'table': table}}})

Execute any Google API function and store results to BigQuery.

Args:
  auth_read (authentication) - Credentials used for reading data.
  api (string) - See developer guide.
  version (string) - Must be supported version.
  function (string) - Full function dot notation path.
  kwargs (json) - Dictionray object of name value pairs.
  kwargs_remote (json) - Fetch arguments from remote source.
  api_key (string) - Associated with a Google Cloud Project.
  developer_token (string) - Associated with your organization.
  login_customer_id (string) - Associated with your Adwords account.
  dataset (string) - Existing dataset in BigQuery.
  table (string) - Table to write API call results to.


def sample_frames(self, video: 'torch.Tensor', metadata: Union[VideoMetadata, dict], num_frames: Optional[int]=None, fps: Optional[int]=None, skip_secs: Optional[int]=1):
    num_frames = num_frames if num_frames is not None else self.num_frames
    fps = fps if fps is not None else self.fps
    total_num_frames = video.shape[0]
    estimated_frames = int(round(fps * metadata['duration']))
    desired_frames = min(estimated_frames, num_frames)
    if desired_frames < 1:
        desired_frames = 1
    start_idx = 0
    end_idx = total_num_frames - 1
    if skip_secs > 0 and metadata['duration'] - 2 * skip_secs > num_frames * fps:
        start_idx = int(skip_secs * metadata['fps'])
        end_idx = int(total_num_frames - skip_secs * metadata['fps'])
    start_idx = max(0, start_idx)
    end_idx = min(end_idx, total_num_frames - 1)
    if start_idx >= end_idx:
        start_idx, end_idx = (0, total_num_frames - 1)
    indices = np.linspace(start_idx, end_idx, desired_frames, dtype=int)
    indices = np.unique(indices)
    video = video[indices].contiguous()
    timestamps = []
    for idx in indices:
        sec = idx / metadata['fps']
        mm = int(sec // 60)
        ss = int(sec % 60)
        timestamps.append([mm, ss])
    return (video, timestamps, int(metadata['duration']))

Video sampling function which:
    - Uses `num_frames` (if provided) or calculates it from `fps` and metadata.
    - Applies a basic center-skip if fewer frames than available, otherwise
        optionally skips `skip_secs` from both the start and end.
    - Uniformly samples the desired number of frames between the start and end indices.

Args:
    video (`torch.Tensor`):
        Video that need to be sampled.
    metadata (`VideoMetadata`):
        Metadata of the video containing information about total duration, fps and total number of frames.
    num_frames (`int`, *optional*):
        Maximum number of frames to sample. Defaults to `self.num_frames`.
    fps (`int`, *optional*):
        Target frames to sample per second. Defaults to `self.fps`.
    skip_secs (`float`, *optional*, defaults to `1`):
        Number of seconds to skip from the start and end if the video is long enough.

Returns:
    torch.Tensor:
        Sampled video frames.


class Multimodal2VisionEncoder(nn.Module):

    def __init__(self, config):
        super().__init__()
        self.config = config
        self.layers = nn.ModuleList([Multimodal2VisionEncoderLayer(config) for _ in range(config.num_hidden_layers)])
        self.gradient_checkpointing = False

    @can_return_tuple
    def forward(self, inputs_embeds, attention_mask: Optional[torch.Tensor]=None, causal_attention_mask: Optional[torch.Tensor]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None) -> BaseModelOutput:
        """
        Args:
            inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
                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.
            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)
            causal_attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
                Causal mask for the text model. 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)
            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.
        """
        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
        encoder_states = () if output_hidden_states else None
        all_attentions = () if output_attentions else None
        hidden_states = inputs_embeds
        for idx, encoder_layer in enumerate(self.layers):
            if output_hidden_states:
                encoder_states = encoder_states + (hidden_states,)
            if self.gradient_checkpointing and self.training:
                layer_outputs = self._gradient_checkpointing_func(encoder_layer.__call__, hidden_states, attention_mask, causal_attention_mask, output_attentions)
            else:
                layer_outputs = encoder_layer(hidden_states, attention_mask, causal_attention_mask, output_attentions=output_attentions)
            hidden_states = layer_outputs[0]
            if output_attentions:
                all_attentions = all_attentions + (layer_outputs[1],)
        if output_hidden_states:
            encoder_states = encoder_states + (hidden_states,)
        return BaseModelOutput(last_hidden_state=hidden_states, hidden_states=encoder_states, attentions=all_attentions)

Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
[`Multimodal2VisionEncoderLayer`].

Args:
    config: Multimodal2VisionConfig


def subtract_period_and_roll(self, date_tensor, period_tensor, roll_convention=constants.BusinessDayConvention.NONE):
    minus_period_tensor = periods.PeriodTensor(-period_tensor.quantity(), period_tensor.period_type())
    return self.add_period_and_roll(date_tensor, minus_period_tensor, roll_convention)

Subtracts given periods from given dates and rolls to business days.

The original dates are not rolled prior to subtraction.

Args:
  date_tensor: `DateTensor` of dates to subtract from.
  period_tensor: PeriodTensor broadcastable to `date_tensor`.
  roll_convention: BusinessDayConvention. Determines how to roll a date that
    falls on a holiday.

Returns:
  The resulting `DateTensor`.


def to_json(value: Any, **kwargs) -> Any:
    if isinstance(value, Symbolic):
        return value.sym_jsonify(**kwargs)
    return utils.to_json(value, **kwargs)

Serializes a (maybe) symbolic value into a plain Python object.

Example::

  @pg.members([
    ('x', pg.typing.Any())
  ])
  class A(pg.Object):
    pass

  a1 = A(1)
  json = a1.to_json()
  a2 = pg.from_json(json)
  assert pg.eq(a1, a2)

Args:
  value: value to serialize. Applicable value types are:

    * Builtin python types: None, bool, int, float, string;
    * JSONConvertible types;
    * List types;
    * Tuple types;
    * Dict types.

  **kwargs: Keyword arguments to pass to value.to_json if value is
    JSONConvertible.

Returns:
  JSON value.


class Orthogonal(Initializer):

    def __init__(self, gain=1.0, seed=None):
        self.gain = gain
        self.seed = seed
        self._random_generator = _RandomGenerator(seed)

    def __call__(self, shape, dtype=None, **kwargs):
        """Returns a tensor object initialized to an orthogonal matrix.

    Args:
      shape: Shape of the tensor.
      dtype: Optional dtype of the tensor. Only floating point types are
        supported. If not specified, `tf.keras.backend.floatx()` is used,
       which default to `float32` unless you configured it otherwise
       (via `tf.keras.backend.set_floatx(float_dtype)`)
      **kwargs: Additional keyword arguments.
    """
        _validate_kwargs(self.__class__.__name__, kwargs, support_partition=False)
        dtype = _assert_float_dtype(_get_dtype(dtype))
        if len(shape) < 2:
            raise ValueError('The tensor to initialize must be at least two-dimensional')
        num_rows = 1
        for dim in shape[:-1]:
            num_rows *= dim
        num_cols = shape[-1]
        flat_shape = (max(num_cols, num_rows), min(num_cols, num_rows))
        a = self._random_generator.random_normal(flat_shape, dtype=dtype)
        q, r = gen_linalg_ops.qr(a, full_matrices=False)
        d = array_ops.tensor_diag_part(r)
        q *= math_ops.sign(d)
        if num_rows < num_cols:
            q = array_ops.matrix_transpose(q)
        return self.gain * array_ops.reshape(q, shape)

    def get_config(self):
        return {'gain': self.gain, 'seed': self.seed}

Initializer that generates an orthogonal matrix.

Also available via the shortcut function `tf.keras.initializers.orthogonal`.

If the shape of the tensor to initialize is two-dimensional, it is initialized
with an orthogonal matrix obtained from the QR decomposition of a matrix of
random numbers drawn from a normal distribution.
If the matrix has fewer rows than columns then the output will have orthogonal
rows. Otherwise, the output will have orthogonal columns.

If the shape of the tensor to initialize is more than two-dimensional,
a matrix of shape `(shape[0] * ... * shape[n - 2], shape[n - 1])`
is initialized, where `n` is the length of the shape vector.
The matrix is subsequently reshaped to give a tensor of the desired shape.

Examples:

>>> # Standalone usage:
>>> initializer = tf.keras.initializers.Orthogonal()
>>> values = initializer(shape=(2, 2))

>>> # Usage in a Keras layer:
>>> initializer = tf.keras.initializers.Orthogonal()
>>> layer = tf.keras.layers.Dense(3, kernel_initializer=initializer)

Args:
  gain: multiplicative factor to apply to the orthogonal matrix
  seed: A Python integer. An initializer created with a given seed will
    always produce the same random tensor for a given shape and dtype.

References:
    [Saxe et al., 2014](https://openreview.net/forum?id=_wzZwKpTDF_9C)
    ([pdf](https://arxiv.org/pdf/1312.6120.pdf))


class PartitionConfig:
    config: Config
    store: Store
    manifest: Manifest

    def _create_partition_config(self, option: t.Tuple) -> Config:
        """Create a config for a single partition option.

        Output a config dictionary, overriding the range of values for
        each key with the partition instance in 'selection'.
        Continuing the example from prepare_partitions, the selection section
        would be:
        { 'foo': ..., 'year': ['2020'], 'month': ['01'], ... }
        { 'foo': ..., 'year': ['2020'], 'month': ['02'], ... }
        { 'foo': ..., 'year': ['2020'], 'month': ['03'], ... }

        Args:
            option: A single item in the range of partition_keys.
            config: The download config, including the parameters and selection sections.

        Returns:
            A configuration with that selects a single download partition.
        """
        copy = cp.deepcopy(self.config.selection)
        out = cp.deepcopy(self.config)
        for idx, key in enumerate(self.config.partition_keys):
            copy[key] = [option[idx]]
        if 'hdate' in copy:
            copy['hdate'] = [generate_hdate(copy['date'][0], v) for v in copy['hdate']]
        out.selection = copy
        return out

    def skip_partition(self, config: Config) -> bool:
        """Return true if partition should be skipped."""
        if config.force_download:
            return False
        target = prepare_target_name(config)
        if self.store.exists(target):
            logger.info(f'file {target} found, skipping.')
            self.manifest.skip(config.config_name, config.dataset, config.selection, target, config.user_id)
            return True
        return False

    def prepare_partitions(self) -> t.Iterator[Config]:
        """Iterate over client parameters, partitioning over `partition_keys`.

        This produces a Cartesian-Cross over the range of keys.

        For example, if the keys were 'year' and 'month', it would produce
        an iterable like:
            ( ('2020', '01'), ('2020', '02'), ('2020', '03'), ...)

        Returns:
            An iterator of `Config`s.
        """
        for option in itertools.product(*[self.config.selection[key] for key in self.config.partition_keys]):
            yield self._create_partition_config(option)

    def new_downloads_only(self, candidate: Config) -> bool:
        """Predicate function to skip already downloaded partitions."""
        if self.store is None:
            self.store = FSStore()
        should_skip = self.skip_partition(candidate)
        return not should_skip

    def update_manifest_collection(self, partition: Config) -> Config:
        """Updates the DB."""
        location = prepare_target_name(partition)
        self.manifest.schedule(partition.config_name, partition.dataset, partition.selection, location, partition.user_id)
        logger.info(f'Created partition {location!r}.')

Partition a config into multiple data requests.

Partitioning involves four main operations: First, we fan-out shards based on
partition keys (a cross product of the values). Second, we filter out existing
downloads (unless we want to force downloads). Last, we assemble each partition
into a single Config.

Attributes:
    store: A cloud storage system, used for checking the existence of downloads.
    manifest: A download manifest to register preparation state.


def element(cls, tag: str, inner_html: Optional[utils.Nestable[WritableTypes]]=None, *, options: Union[str, Iterable[str], None]=None, css_classes: NestableStr=None, styles: Union[str, Dict[str, Any], None]=None, **properties) -> 'Html':
    s = cls()
    css_classes = cls.concate(css_classes)
    options = cls.concate(options)
    styles = cls.style_str(styles)
    s.write(f'<{tag}', f' {options}' if options else None, f' class="{css_classes}"' if css_classes else None, f' style="{styles}"' if styles else None)
    for k, v in properties.items():
        if v is not None:
            s.write(f' {k.replace('_', '-')}="{v}"')
    s.write('>')
    if inner_html:
        if isinstance(inner_html, list):
            for child in utils.flatten(inner_html).values():
                s.write(child)
        else:
            s.write(inner_html)
    s.write(f'</{tag}>')
    return s

Creates an HTML element.

Args:
  tag: The HTML tag name.
  inner_html: The inner HTML of the element.
  options: Positional options that will be added to the element. E.g. 'open'
    for `<details open>`.
  css_classes: The CSS class name or a list of CSS class names.
  styles: A single CSS style string or a dictionary of CSS properties.
  **properties: Keyword arguments for HTML properties. For properties with
    underscore in the name, the underscore will be replaced by dash in the
    generated HTML. E.g. `background_color` will be converted to
    `background-color`.

Returns:
  The opening tag of an HTML element.


class PerceiverProjectionDecoder(PerceiverAbstractDecoder):

    def __init__(self, config):
        super().__init__()
        self.classifier = nn.Linear(config.d_latents, config.num_labels)

    def decoder_query(self, inputs, modality_sizes=None, inputs_without_pos=None, subsampled_points=None):
        return None

    def forward(self, query: torch.Tensor, z: torch.FloatTensor, query_mask: Optional[torch.FloatTensor]=None) -> torch.FloatTensor:
        z = torch.mean(z, dim=1)
        logits = self.classifier(z)
        return logits

Baseline projection decoder (no cross-attention).

Args:
    config ([`PerceiverConfig`]):
        Model configuration.


class BitImageProcessor(BaseImageProcessor):
    model_input_names = ['pixel_values']

    def __init__(self, do_resize: bool=True, size: Optional[Dict[str, int]]=None, resample: PILImageResampling=PILImageResampling.BICUBIC, do_center_crop: bool=True, crop_size: Optional[Dict[str, int]]=None, do_rescale: bool=True, rescale_factor: Union[int, float]=1 / 255, do_normalize: bool=True, image_mean: Optional[Union[float, List[float]]]=None, image_std: Optional[Union[float, List[float]]]=None, do_convert_rgb: bool=True, **kwargs) -> None:
        super().__init__(**kwargs)
        size = size if size is not None else {'shortest_edge': 224}
        size = get_size_dict(size, default_to_square=False)
        crop_size = crop_size if crop_size is not None else {'height': 224, 'width': 224}
        crop_size = get_size_dict(crop_size, default_to_square=True, param_name='crop_size')
        self.do_resize = do_resize
        self.size = size
        self.resample = resample
        self.do_center_crop = do_center_crop
        self.crop_size = crop_size
        self.do_rescale = do_rescale
        self.rescale_factor = rescale_factor
        self.do_normalize = do_normalize
        self.image_mean = image_mean if image_mean is not None else OPENAI_CLIP_MEAN
        self.image_std = image_std if image_std is not None else OPENAI_CLIP_STD
        self.do_convert_rgb = do_convert_rgb

    def resize(self, image: np.ndarray, size: Dict[str, int], resample: PILImageResampling=PILImageResampling.BICUBIC, data_format: Optional[Union[str, ChannelDimension]]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None, **kwargs) -> np.ndarray:
        """
        Resize an image. The shortest edge of the image is resized to size["shortest_edge"], with the longest edge
        resized to keep the input aspect ratio.

        Args:
            image (`np.ndarray`):
                Image to resize.
            size (`Dict[str, int]`):
                Size of the output image.
            resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BICUBIC`):
                Resampling filter to use when resiizing the image.
            data_format (`str` or `ChannelDimension`, *optional*):
                The channel dimension format of the image. If not provided, it will be the same as the input image.
            input_data_format (`ChannelDimension` or `str`, *optional*):
                The channel dimension format of the input image. If not provided, it will be inferred.
        """
        default_to_square = True
        if 'shortest_edge' in size:
            size = size['shortest_edge']
            default_to_square = False
        elif 'height' in size and 'width' in size:
            size = (size['height'], size['width'])
        else:
            raise ValueError("Size must contain either 'shortest_edge' or 'height' and 'width'.")
        output_size = get_resize_output_image_size(image, size=size, default_to_square=default_to_square, input_data_format=input_data_format)
        return resize(image, size=output_size, resample=resample, data_format=data_format, input_data_format=input_data_format, **kwargs)

    @filter_out_non_signature_kwargs()
    def preprocess(self, images: ImageInput, do_resize: Optional[bool]=None, size: Optional[Dict[str, int]]=None, resample: PILImageResampling=None, do_center_crop: Optional[bool]=None, crop_size: Optional[int]=None, do_rescale: Optional[bool]=None, rescale_factor: Optional[float]=None, do_normalize: Optional[bool]=None, image_mean: Optional[Union[float, List[float]]]=None, image_std: Optional[Union[float, List[float]]]=None, do_convert_rgb: Optional[bool]=None, return_tensors: Optional[Union[str, TensorType]]=None, data_format: Optional[ChannelDimension]=ChannelDimension.FIRST, input_data_format: Optional[Union[str, ChannelDimension]]=None) -> PIL.Image.Image:
        """
        Preprocess an image or batch of images.

        Args:
            images (`ImageInput`):
                Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
                passing in images with pixel values between 0 and 1, set `do_rescale=False`.
            do_resize (`bool`, *optional*, defaults to `self.do_resize`):
                Whether to resize the image.
            size (`Dict[str, int]`, *optional*, defaults to `self.size`):
                Size of the image after resizing. Shortest edge of the image is resized to size["shortest_edge"], with
                the longest edge resized to keep the input aspect ratio.
            resample (`int`, *optional*, defaults to `self.resample`):
                Resampling filter to use if resizing the image. This can be one of the enum `PILImageResampling`. Only
                has an effect if `do_resize` is set to `True`.
            do_center_crop (`bool`, *optional*, defaults to `self.do_center_crop`):
                Whether to center crop the image.
            crop_size (`Dict[str, int]`, *optional*, defaults to `self.crop_size`):
                Size of the center crop. Only has an effect if `do_center_crop` is set to `True`.
            do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
                Whether to rescale the image.
            rescale_factor (`float`, *optional*, defaults to `self.rescale_factor`):
                Rescale factor to rescale the image by if `do_rescale` is set to `True`.
            do_normalize (`bool`, *optional*, defaults to `self.do_normalize`):
                Whether to normalize the image.
            image_mean (`float` or `List[float]`, *optional*, defaults to `self.image_mean`):
                Image mean to use for normalization. Only has an effect if `do_normalize` is set to `True`.
            image_std (`float` or `List[float]`, *optional*, defaults to `self.image_std`):
                Image standard deviation to use for normalization. Only has an effect if `do_normalize` is set to
                `True`.
            do_convert_rgb (`bool`, *optional*, defaults to `self.do_convert_rgb`):
                Whether to convert the image to RGB.
            return_tensors (`str` or `TensorType`, *optional*):
                The type of tensors to return. Can be one of:
                - Unset: Return a list of `np.ndarray`.
                - `TensorType.TENSORFLOW` or `'tf'`: Return a batch of type `tf.Tensor`.
                - `TensorType.PYTORCH` or `'pt'`: Return a batch of type `torch.Tensor`.
                - `TensorType.NUMPY` or `'np'`: Return a batch of type `np.ndarray`.
                - `TensorType.JAX` or `'jax'`: Return a batch of type `jax.numpy.ndarray`.
            data_format (`ChannelDimension` or `str`, *optional*, defaults to `ChannelDimension.FIRST`):
                The channel dimension format for the output image. Can be one of:
                - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
                - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
                - Unset: Use the channel dimension format of the input image.
            input_data_format (`ChannelDimension` or `str`, *optional*):
                The channel dimension format for the input image. If unset, the channel dimension format is inferred
                from the input image. Can be one of:
                - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
                - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
                - `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
        """
        do_resize = do_resize if do_resize is not None else self.do_resize
        size = size if size is not None else self.size
        size = get_size_dict(size, param_name='size', default_to_square=False)
        resample = resample if resample is not None else self.resample
        do_center_crop = do_center_crop if do_center_crop is not None else self.do_center_crop
        crop_size = crop_size if crop_size is not None else self.crop_size
        crop_size = get_size_dict(crop_size, param_name='crop_size', default_to_square=True)
        do_rescale = do_rescale if do_rescale is not None else self.do_rescale
        rescale_factor = rescale_factor if rescale_factor is not None else self.rescale_factor
        do_normalize = do_normalize if do_normalize is not None else self.do_normalize
        image_mean = image_mean if image_mean is not None else self.image_mean
        image_std = image_std if image_std is not None else self.image_std
        do_convert_rgb = do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb
        images = make_list_of_images(images)
        if not valid_images(images):
            raise ValueError('Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, torch.Tensor, tf.Tensor or jax.ndarray.')
        validate_preprocess_arguments(do_rescale=do_rescale, rescale_factor=rescale_factor, do_normalize=do_normalize, image_mean=image_mean, image_std=image_std, do_center_crop=do_center_crop, crop_size=crop_size, do_resize=do_resize, size=size, resample=resample)
        if do_convert_rgb:
            images = [convert_to_rgb(image) for image in images]
        images = [to_numpy_array(image) for image in images]
        if do_rescale and is_scaled_image(images[0]):
            logger.warning_once('It looks like you are trying to rescale already rescaled images. If the input images have pixel values between 0 and 1, set `do_rescale=False` to avoid rescaling them again.')
        if input_data_format is None:
            input_data_format = infer_channel_dimension_format(images[0])
        all_images = []
        for image in images:
            if do_resize:
                image = self.resize(image=image, size=size, resample=resample, input_data_format=input_data_format)
            if do_center_crop:
                image = self.center_crop(image=image, size=crop_size, input_data_format=input_data_format)
            if do_rescale:
                image = self.rescale(image=image, scale=rescale_factor, input_data_format=input_data_format)
            if do_normalize:
                image = self.normalize(image=image, mean=image_mean, std=image_std, input_data_format=input_data_format)
            all_images.append(image)
        images = [to_channel_dimension_format(image, data_format, input_channel_dim=input_data_format) for image in all_images]
        data = {'pixel_values': images}
        return BatchFeature(data=data, tensor_type=return_tensors)

Constructs a BiT image processor.

Args:
    do_resize (`bool`, *optional*, defaults to `True`):
        Whether to resize the image's (height, width) dimensions to the specified `size`. Can be overridden by
        `do_resize` in the `preprocess` method.
    size (`Dict[str, int]` *optional*, defaults to `{"shortest_edge": 224}`):
        Size of the image after resizing. The shortest edge of the image is resized to size["shortest_edge"], with
        the longest edge resized to keep the input aspect ratio. Can be overridden by `size` in the `preprocess`
        method.
    resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BICUBIC`):
        Resampling filter to use if resizing the image. Can be overridden by `resample` in the `preprocess` method.
    do_center_crop (`bool`, *optional*, defaults to `True`):
        Whether to center crop the image to the specified `crop_size`. Can be overridden by `do_center_crop` in the
        `preprocess` method.
    crop_size (`Dict[str, int]` *optional*, defaults to 224):
        Size of the output image after applying `center_crop`. Can be overridden by `crop_size` in the `preprocess`
        method.
    do_rescale (`bool`, *optional*, defaults to `True`):
        Whether to rescale the image by the specified scale `rescale_factor`. Can be overridden by `do_rescale` in
        the `preprocess` method.
    rescale_factor (`int` or `float`, *optional*, defaults to `1/255`):
        Scale factor to use if rescaling the image. Can be overridden by `rescale_factor` in the `preprocess`
        method.
    do_normalize:
        Whether to normalize the image. Can be overridden by `do_normalize` in the `preprocess` method.
    image_mean (`float` or `List[float]`, *optional*, defaults to `OPENAI_CLIP_MEAN`):
        Mean to use if normalizing the image. This is a float or list of floats the length of the number of
        channels in the image. Can be overridden by the `image_mean` parameter in the `preprocess` method.
    image_std (`float` or `List[float]`, *optional*, defaults to `OPENAI_CLIP_MEAN`):
        Standard deviation to use if normalizing the image. This is a float or list of floats the length of the
        number of channels in the image. Can be overridden by the `image_std` parameter in the `preprocess` method.
        Can be overridden by the `image_std` parameter in the `preprocess` method.
    do_convert_rgb (`bool`, *optional*, defaults to `True`):
        Whether to convert the image to RGB.


class ChineseCLIPProcessor(ProcessorMixin):
    attributes = ['image_processor', 'tokenizer']
    image_processor_class = ('ChineseCLIPImageProcessor', 'ChineseCLIPImageProcessorFast')
    tokenizer_class = ('BertTokenizer', 'BertTokenizerFast')

    def __init__(self, image_processor=None, tokenizer=None, **kwargs):
        feature_extractor = None
        if 'feature_extractor' in kwargs:
            warnings.warn('The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor` instead.', FutureWarning)
            feature_extractor = kwargs.pop('feature_extractor')
        image_processor = image_processor if image_processor is not None else feature_extractor
        if image_processor is None:
            raise ValueError('You need to specify an `image_processor`.')
        if tokenizer is None:
            raise ValueError('You need to specify a `tokenizer`.')
        super().__init__(image_processor, tokenizer)
        self.current_processor = self.image_processor

    def __call__(self, text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]=None, images: ImageInput=None, audio=None, videos=None, **kwargs: Unpack[ChineseClipProcessorKwargs]) -> BatchEncoding:
        """
        Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
        and `kwargs` arguments to BertTokenizerFast's [`~BertTokenizerFast.__call__`] if `text` is not `None` to encode
        the text. To prepare the image(s), this method forwards the `images` and `kwrags` arguments to
        CLIPImageProcessor's [`~CLIPImageProcessor.__call__`] if `images` is not `None`. Please refer to the docstring
        of the above two methods for more information.

        Args:
            text (`str`, `List[str]`, `List[List[str]]`):
                The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
                (pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
                `is_split_into_words=True` (to lift the ambiguity with a batch of sequences).
            images (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`, `List[torch.Tensor]`):
                The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch
                tensor. Both channels-first and channels-last formats are supported.

            return_tensors (`str` or [`~utils.TensorType`], *optional*):
                If set, will return tensors of a particular framework. Acceptable values are:
                    - `'tf'`: Return TensorFlow `tf.constant` objects.
                    - `'pt'`: Return PyTorch `torch.Tensor` objects.
                    - `'np'`: Return NumPy `np.ndarray` objects.
                    - `'jax'`: Return JAX `jnp.ndarray` objects.
        Returns:
            [`BatchEncoding`]: A [`BatchEncoding`] with the following fields:

            - **input_ids** -- List of token ids to be fed to a model. Returned when `text` is not `None`.
            - **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
              `return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names` and if `text` is not
              `None`).
            - **pixel_values** -- Pixel values to be fed to a model. Returned when `images` is not `None`.
        """
        if text is None and images is None:
            raise ValueError('You have to specify either text or images. Both cannot be none.')
        output_kwargs = self._merge_kwargs(ChineseClipProcessorKwargs, tokenizer_init_kwargs=self.tokenizer.init_kwargs, **kwargs)
        if text is not None:
            encoding = self.tokenizer(text, **output_kwargs['text_kwargs'])
        if images is not None:
            image_features = self.image_processor(images, **output_kwargs['images_kwargs'])
        if 'return_tensors' in output_kwargs['common_kwargs']:
            return_tensors = output_kwargs['common_kwargs'].pop('return_tensors', None)
        if text is not None and images is not None:
            encoding['pixel_values'] = image_features.pixel_values
            return encoding
        elif text is not None:
            return encoding
        else:
            return BatchEncoding(data=dict(**image_features), tensor_type=return_tensors)

    def batch_decode(self, *args, **kwargs):
        """
        This method forwards all its arguments to BertTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        """
        return self.tokenizer.batch_decode(*args, **kwargs)

    def decode(self, *args, **kwargs):
        """
        This method forwards all its arguments to BertTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
        the docstring of this method for more information.
        """
        return self.tokenizer.decode(*args, **kwargs)

    @property
    def model_input_names(self):
        tokenizer_input_names = self.tokenizer.model_input_names
        image_processor_input_names = self.image_processor.model_input_names
        return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))

    @property
    def feature_extractor_class(self):
        warnings.warn('`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.', FutureWarning)
        return self.image_processor_class

Constructs a Chinese-CLIP processor which wraps a Chinese-CLIP image processor and a Chinese-CLIP tokenizer into a
single processor.

[`ChineseCLIPProcessor`] offers all the functionalities of [`ChineseCLIPImageProcessor`] and [`BertTokenizerFast`].
See the [`~ChineseCLIPProcessor.__call__`] and [`~ChineseCLIPProcessor.decode`] for more information.

Args:
    image_processor ([`ChineseCLIPImageProcessor`], *optional*):
        The image processor is a required input.
    tokenizer ([`BertTokenizerFast`], *optional*):
        The tokenizer is a required input.


def forward(self, input_values: Optional[torch.Tensor], attention_mask: Optional[torch.Tensor]=None, mask_time_indices: Optional[torch.FloatTensor]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None) -> Union[Tuple, BaseModelOutput]:
    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
    return_dict = return_dict if return_dict is not None else self.config.use_return_dict
    extract_features = self.feature_extractor(input_values)
    extract_features = extract_features.transpose(1, 2)
    if attention_mask is not None:
        attention_mask = self._get_feature_vector_attention_mask(extract_features.shape[1], attention_mask)
    hidden_states = self.feature_projection(extract_features)
    hidden_states = self._mask_hidden_states(hidden_states, mask_time_indices=mask_time_indices)
    encoder_outputs = self.encoder(hidden_states, attention_mask=attention_mask, output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict)
    hidden_states = encoder_outputs[0]
    if not return_dict:
        return (hidden_states,) + encoder_outputs[1:]
    return BaseModelOutput(last_hidden_state=hidden_states, hidden_states=encoder_outputs.hidden_states, attentions=encoder_outputs.attentions)

mask_time_indices (`torch.BoolTensor` of shape `(batch_size, sequence_length)`, *optional*):
    Indices to mask extracted features for contrastive loss. When in training mode, model learns to predict
    masked extracted features in *config.proj_codevector_dim* space.

Example:

```python
>>> from transformers import AutoProcessor, HubertModel
>>> from datasets import load_dataset
>>> import soundfile as sf

>>> processor = AutoProcessor.from_pretrained("facebook/hubert-large-ls960-ft")
>>> model = HubertModel.from_pretrained("facebook/hubert-large-ls960-ft")

>>> def map_to_array(batch):
...     speech, _ = sf.read(batch["file"])
...     batch["speech"] = speech
...     return batch

>>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
>>> ds = ds.map(map_to_array)

>>> input_values = processor(ds["speech"][0], return_tensors="pt").input_values  # Batch size 1
>>> hidden_states = model(input_values).last_hidden_state
```


def _print_test_names(test_class):
    cls = test_class(config_parser.TestRunConfig())
    test_names = []
    try:
        cls._pre_run()
        if cls.tests:
            test_names = list(cls.tests)
        else:
            test_names = cls.get_existing_test_names()
    except Exception:
        logging.exception('Failed to retrieve generated tests.')
    finally:
        cls._clean_up()
    print('==========> %s <==========' % cls.TAG)
    for name in test_names:
        print(name)

Prints the names of all the tests in a test module.

If the module has generated tests defined based on controller info, this
may not be able to print the generated tests.

Args:
  test_class: module, the test module to print names from.


def compute_loss(self, x=None, y=None, y_pred=None, sample_weight=None, training=True):
    del x
    del training
    losses = []
    if self._compile_loss is not None:
        loss = self._compile_loss(y, y_pred, sample_weight)
        if loss is not None:
            losses.append(loss)
    for loss in self.losses:
        losses.append(self._aggregate_additional_loss(loss))
    if backend.backend() != 'jax' and len(losses) == 0:
        raise ValueError('No loss to compute. Provide a `loss` argument in `compile()`.')
    if len(losses) == 1:
        total_loss = losses[0]
    elif len(losses) == 0:
        total_loss = ops.zeros(())
    else:
        total_loss = ops.sum(losses)
    return total_loss

Compute the total loss, validate it, and return it.

Subclasses can optionally override this method to provide custom loss
computation logic.

Example:

```python
class MyModel(Model):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.loss_tracker = metrics.Mean(name='loss')

    def compute_loss(self, x, y, y_pred, sample_weight, training=True):
        loss = ops.mean((y_pred - y) ** 2)
        loss += ops.sum(self.losses)
        self.loss_tracker.update_state(loss)
        return loss

    def reset_metrics(self):
        self.loss_tracker.reset_state()

    @property
    def metrics(self):
        return [self.loss_tracker]

inputs = layers.Input(shape=(10,), name='my_input')
outputs = layers.Dense(10)(inputs)
model = MyModel(inputs, outputs)
model.add_loss(ops.sum(outputs))

optimizer = SGD()
model.compile(optimizer, loss='mse', steps_per_execution=10)
dataset = ...
model.fit(dataset, epochs=2, steps_per_epoch=10)
print(f"Custom loss: {model.loss_tracker.result()}")
```

Args:
    x: Input data.
    y: Target data.
    y_pred: Predictions returned by the model (output of `model(x)`)
    sample_weight: Sample weights for weighting the loss function.
    training: Whether we are training or evaluating the model.

Returns:
    The total loss as a scalar tensor, or `None` if no loss results
    (which is the case when called by `Model.test_step`).


def set_dna(self, dna: geno.DNA) -> None:
    self._dna = dna
    self._decoded_value = None

Use this DNA to generate value.

NOTE(daiyip): self._dna is only used in __call__.
Thus 'set_dna' can be called multiple times to generate different values.

Args:
  dna: DNA to use to decode the value.


def encode_plus_boxes(self, text: Union[TextInput, PreTokenizedInput], text_pair: Optional[PreTokenizedInput]=None, boxes: Optional[List[List[int]]]=None, word_labels: Optional[List[List[int]]]=None, add_special_tokens: bool=True, padding: Union[bool, str, PaddingStrategy]=False, truncation: Union[bool, str, TruncationStrategy]=None, max_length: Optional[int]=None, stride: int=0, is_split_into_words: 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:
    padding_strategy, truncation_strategy, max_length, kwargs = self._get_padding_truncation_strategies(padding=padding, truncation=truncation, max_length=max_length, pad_to_multiple_of=pad_to_multiple_of, verbose=verbose, **kwargs)
    return self._encode_plus_boxes(text=text, text_pair=text_pair, boxes=boxes, word_labels=word_labels, add_special_tokens=add_special_tokens, padding_strategy=padding_strategy, truncation_strategy=truncation_strategy, max_length=max_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)

Tokenize and prepare for the model a sequence or a pair of sequences.

<Tip warning={true}>

This method is deprecated, `__call__` should be used instead.

</Tip>

Args:
    text (`str`, `List[str]` or (for non-fast tokenizers) `List[int]`):
        The first sequence to be encoded. This can be a string, a list of strings (tokenized string using the
        `tokenize` method) or a list of integers (tokenized string ids using the `convert_tokens_to_ids`
        method).
    text_pair (`str`, `List[str]` or `List[int]`, *optional*):
        Optional second sequence to be encoded. This can be a string, a list of strings (tokenized string using
        the `tokenize` method) or a list of integers (tokenized string ids using the `convert_tokens_to_ids`
        method).


def element_spec(self):
    raise NotImplementedError('Optional.element_spec')

The type specification of an element of this optional.

>>> optional = tf.experimental.Optional.from_value(42)
>>> print(optional.element_spec)
tf.TensorSpec(shape=(), dtype=tf.int32, name=None)

Returns:
  A (nested) structure of `tf.TypeSpec` objects matching the structure of an
  element of this optional, specifying the type of individual components.


class SpatialDropout1D(BaseSpatialDropout):

    def __init__(self, rate, seed=None, name=None, dtype=None):
        super().__init__(rate, seed=seed, name=name, dtype=dtype)
        self.input_spec = InputSpec(ndim=3)

    def _get_noise_shape(self, inputs):
        input_shape = ops.shape(inputs)
        return (input_shape[0], 1, input_shape[2])

Spatial 1D version of Dropout.

This layer performs the same function as Dropout, however, it drops
entire 1D feature maps instead of individual elements. If adjacent frames
within feature maps are strongly correlated (as is normally the case in
early convolution layers) then regular dropout will not regularize the
activations and will otherwise just result in an effective learning rate
decrease. In this case, `SpatialDropout1D` will help promote independence
between feature maps and should be used instead.

Args:
    rate: Float between 0 and 1. Fraction of the input units to drop.

Call arguments:
    inputs: A 3D tensor.
    training: Python boolean indicating whether the layer
        should behave in training mode (applying dropout)
        or in inference mode (pass-through).

Input shape:
    3D tensor with shape: `(samples, timesteps, channels)`

Output shape: Same as input.

Reference:

- [Tompson et al., 2014](https://arxiv.org/abs/1411.4280)


def _build_all_reduce_ring(core_locations: List[_CoreLocation], rotate: bool=False) -> List[int]:
    permutation = list(range(len(core_locations)))
    if not permutation:
        return permutation
    logging.vlog(2, 'Core locations in: %s', core_locations)
    first_column = min([l.x for l in core_locations])
    first_row = min([l.y for l in core_locations])
    same_z = len(set([l.z for l in core_locations])) == 1
    logging.vlog(2, 'first_column: %d', first_column)
    logging.vlog(2, 'first_row: %d', first_row)
    logging.vlog(2, 'same_z: %s', same_z)

    def _cmp_2d(ia: int, ib: int) -> int:
        if not rotate:
            a = core_locations[ia]
            b = core_locations[ib]
            a_first = a.x == first_column and a.y != first_row
            b_first = b.x == first_column and b.y != first_row
            if a_first != b_first:
                return -1 if b_first else 1
            if a.y != b.y:
                return b.y - a.y if a_first else a.y - b.y
            if a.x != b.x:
                return a.x - b.x if a.y % 2 == 0 else b.x - a.x
            return a.core - b.core
        else:
            a = core_locations[ia]
            b = core_locations[ib]
            a_first = a.y == first_row and a.x != first_column
            b_first = b.y == first_row and b.x != first_column
            if a_first != b_first:
                return -1 if b_first else 1
            if a.x != b.x:
                return b.x - a.x if a_first else a.x - b.x
            if a.y != b.y:
                return a.y - b.y if a.x % 2 == 0 else b.y - a.y
            return a.core - b.core

    def _cmp_3d(ia: int, ib: int) -> int:
        a = core_locations[ia]
        b = core_locations[ib]
        a_corner = a.x == first_column and a.y == first_row
        b_corner = b.x == first_column and b.y == first_row
        if a_corner and b_corner:
            return b.z - a.z if a.z != b.z else a.core - b.core
        if a_corner != b_corner:
            return -1 if b_corner else 1
        if a.z == b.z:
            return _cmp_2d(ia, ib) if a.z % 2 == 0 else -_cmp_2d(ia, ib)
        return a.z - b.z
    if same_z:
        permutation.sort(key=functools.cmp_to_key(_cmp_2d))
    else:
        permutation.sort(key=functools.cmp_to_key(_cmp_3d))
    logging.vlog(2, 'Permutation out: %s', permutation)
    return permutation

Reorders a list of TPU cores to optimize for AllReduce performance.

This is ported from the C++ tensorflow::BuildAllReduceRing function,
mixed with some logic from TF TPU's device_assignment._ring_3d.

Args:
  core_locations: A list of core locations expressed as [x, y, z, core].
  rotate: If true, scan the cores in a column-major order. False by default.

Returns:
  A permutation of the input list such that neighbors in the sequence are
  nearby in the TPU topology.


def session(self, graph=None, config=None, target=None):
    config = self._create_config(config)
    if target is None:
        target = self._default_target
    with session.Session(graph=graph, config=config, target=target) as sess:
        yield sess

Create a test session with master target set to the testing cluster.

Creates a test session that connects to the local testing cluster.

Args:
  graph: Optional graph to use during the returned session.
  config: An optional config_pb2.ConfigProto to use to configure the
    session.
  target: the target of session to connect to.

Yields:
  A Session object that should be used as a context manager to surround
  the graph building and execution code in a test case.


def scatter_add(self, sparse_delta, use_locking=False, name=None):
    if not isinstance(sparse_delta, indexed_slices.IndexedSlices):
        raise TypeError('sparse_delta is not IndexedSlices: %s' % sparse_delta)
    return gen_state_ops.scatter_add(self._variable, sparse_delta.indices, sparse_delta.values, use_locking=use_locking, name=name)

Adds `tf.IndexedSlices` to this variable.

Args:
  sparse_delta: `tf.IndexedSlices` to be added to this variable.
  use_locking: If `True`, use locking during the operation.
  name: the name of the operation.

Returns:
  A `Tensor` that will hold the new value of this variable after
  the scattered addition has completed.

Raises:
  TypeError: if `sparse_delta` is not an `IndexedSlices`.


def load_file_system_library(library_filename):
    py_tf.TF_LoadLibrary(library_filename)

Loads a TensorFlow plugin, containing file system implementation.

Pass `library_filename` to a platform-specific mechanism for dynamically
loading a library. The rules for determining the exact location of the
library are platform-specific and are not documented here.

Args:
  library_filename: Path to the plugin.
    Relative or absolute filesystem path to a dynamic library file.

Returns:
  None.

Raises:
  RuntimeError: when unable to load the library.


def sheets_tab_range(sheet_tab, sheet_range):
    if sheet_range:
        return '%s!%s' % (sheet_tab, sheet_range)
    else:
        return sheet_tab

Helper for creating range format.

Args:
  sheet_tab - name of tab in sheet
  sheet_range - A1 notation

Returns:
  String containing full sheet range specification.


class BlenderbotDecoder(BlenderbotPreTrainedModel):

    def __init__(self, config: BlenderbotConfig, embed_tokens: Optional[nn.Embedding]=None):
        super().__init__(config)
        self.dropout = config.dropout
        self.layerdrop = config.decoder_layerdrop
        self.padding_idx = config.pad_token_id
        self.max_target_positions = config.max_position_embeddings
        embed_scale = math.sqrt(config.d_model) if config.scale_embedding else 1.0
        if embed_tokens is not None:
            self.embed_tokens = embed_tokens
        else:
            self.embed_tokens = BlenderbotScaledWordEmbedding(config.vocab_size, config.d_model, self.padding_idx, embed_scale=embed_scale)
        self.embed_positions = BlenderbotLearnedPositionalEmbedding(config.max_position_embeddings, config.d_model)
        self.layers = nn.ModuleList([BlenderbotDecoderLayer(config, layer_idx=i) for i in range(config.decoder_layers)])
        self.layer_norm = nn.LayerNorm(config.d_model)
        self.gradient_checkpointing = False
        self.post_init()

    def get_input_embeddings(self):
        return self.embed_tokens

    def set_input_embeddings(self, value):
        self.embed_tokens = value

    def forward(self, input_ids=None, attention_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, head_mask=None, cross_attn_head_mask=None, past_key_values=None, inputs_embeds=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None, cache_position: Optional[torch.Tensor]=None):
        """
        Args:
            input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
                Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
                provide it.

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

                [What are input IDs?](../glossary#input-ids)
            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 `(encoder_layers, encoder_attention_heads)`, *optional*):
                Mask to nullify selected heads of the attention modules in the encoder. 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
        if (input_ids is None) ^ (inputs_embeds is not None):
            raise ValueError('You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time')
        elif input_ids is not None:
            input = input_ids
            input_shape = input.shape
            input_ids = input_ids.view(-1, input_shape[-1])
        elif inputs_embeds is not None:
            input_shape = inputs_embeds.size()[:-1]
            input = inputs_embeds[:, :, -1]
        else:
            raise ValueError('You have to specify either decoder_input_ids or decoder_inputs_embeds')
        if inputs_embeds is None:
            inputs_embeds = self.embed_tokens(input)
        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
        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)
        batch_size, seq_length = inputs_embeds.size()[:-1]
        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 + seq_length, device=inputs_embeds.device)
        if attention_mask is None and (not is_torchdynamo_compiling()):
            mask_seq_length = past_key_values_length + seq_length
            attention_mask = torch.ones(batch_size, mask_seq_length, device=inputs_embeds.device)
        self_attn_cache = past_key_values.self_attention_cache if isinstance(past_key_values, EncoderDecoderCache) else past_key_values
        causal_mask = self._update_causal_mask(attention_mask, inputs_embeds, cache_position, self_attn_cache)
        encoder_attention_mask = self._update_cross_attn_mask(encoder_hidden_states, encoder_attention_mask, input_shape, inputs_embeds)
        position_ids = self.embed_positions((batch_size, seq_length), past_key_values_length, position_ids=cache_position)
        hidden_states = inputs_embeds + position_ids
        hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
        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, causal_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=causal_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],)
        hidden_states = self.layer_norm(hidden_states)
        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 [`BlenderbotDecoderLayer`]

Args:
    config: BlenderbotConfig
    embed_tokens (nn.Embedding): output embedding


def batch_dot(x0: FloatArray['... n'], x1: FloatArray['... n'], *, keepdims: bool=False, xnp: numpy_utils.NpModule=...) -> FloatArray['... 1?']:
    y = xnp.einsum('...m,...m->...', x0, x1)
    return y[..., None] if keepdims else y

Dot product on the last dimension, with broadcasting support.

Contrary to `np.dot`, the behavior is consistent for 1-dim vs n-dim (while
dot act as matmul).
First dimensions are always broadcasted.

Args:
  x0: Vector array
  x1: Vector array
  keepdims: If True, returns `FloatArray['... 1']`
  xnp: Numpy module to use

Returns:
  The dot product along the last axis.


async def get_log(self, pipeline_uuid: str, example_filepath: str) -> str:
    self._verify_pipeline_uuid(pipeline_uuid)
    request = api_pb2.GetLogsRequest(pipeline_uuid=pipeline_uuid)
    response = await self._stub.GetLogs(request, **self._kwargs)
    if response.output == '':
        logging.info('Log for %s is empty', example_filepath)
    return response.output

Get the result of pipeline execution.

Args:
    pipeline_uuid: uuid of the pipeline
    example_filepath: path to the file of the example

Returns:
    output: contain the result of pipeline execution


def __bool__(self):
    self._disallow_bool_casting()

Dummy method to prevent a tensor from being used as a Python `bool`.

This overload raises a `TypeError` when the user inadvertently
treats a `Tensor` as a boolean (most commonly in an `if` or `while`
statement), in code that was not converted by AutoGraph. For example:

```python
if tf.constant(True):  # Will raise.
  # ...

if tf.constant(5) < tf.constant(7):  # Will raise.
  # ...
```

Raises:
  `TypeError`.


def __init__(self, max_batch_size: int=5000, project: str=None, retry: Retry=None, timeout: float=120, metadata: Sequence[Tuple[str, str]]=(), catalog_name: str='default_catalog', event_store: str='default_event_store'):
    self.max_batch_size = max_batch_size
    self.project = project
    self.retry = retry
    self.timeout = timeout
    self.metadata = metadata
    self.catalog_name = catalog_name
    self.event_store = event_store

Initializes a :class:`WriteUserEvent` transform.

Args:
    batch_size (int): Required. Maximum number of catalogitems
      per request.
    project (str): Optional. GCP project name in which the catalog
      data will be imported.
    retry: Optional. Designation of what
      errors, if any, should be retried.
    timeout (float): Optional. The amount of time, in seconds, to wait
      for the request to complete.
    metadata: Optional. Strings which
      should be sent along with the request as metadata.
    catalog_name (str): Optional. Name of the catalog.
      Default: 'default_catalog'
    event_store (str): Optional. Name of the event store.
      Default: 'default_event_store'


def diff(self, obj):
    overlapping_nodes = self.match(obj)
    only_in_checkpoint_view = []
    only_in_trackable = []
    for node_id in self.descendants():
        if node_id not in overlapping_nodes.keys():
            only_in_checkpoint_view.append(node_id)
    for trackable in trackable_view.TrackableView(obj).descendants():
        if trackable not in object_identity.ObjectIdentitySet(overlapping_nodes.values()):
            only_in_trackable.append(trackable)
    return (overlapping_nodes, only_in_checkpoint_view, only_in_trackable)

Returns diff between CheckpointView and Trackable.

This method is intended to be used to compare the object stored in a
checkpoint vs a live model in Python. For example, if checkpoint
restoration fails the `assert_consumed()` or
`assert_existing_objects_matched()` checks, you can use this to list out
the objects/checkpoint nodes which were not restored.

Example Usage:

>>> class SimpleModule(tf.Module):
...   def __init__(self, name=None):
...     super().__init__(name=name)
...     self.a_var = tf.Variable(5.0)
...     self.b_var = tf.Variable(4.0)
...     self.vars = [tf.Variable(1.0), tf.Variable(2.0)]

>>> root = SimpleModule(name="root")
>>> leaf = root.leaf = SimpleModule(name="leaf")
>>> leaf.leaf3 = tf.Variable(6.0, name="leaf3")
>>> leaf.leaf4 = tf.Variable(7.0, name="leaf4")
>>> ckpt = tf.train.Checkpoint(root)
>>> save_path = ckpt.save('/tmp/tf_ckpts')
>>> checkpoint_view = tf.train.CheckpointView(save_path)

>>> root2 = SimpleModule(name="root")
>>> leaf2 = root2.leaf2 = SimpleModule(name="leaf2")
>>> leaf2.leaf3 = tf.Variable(6.0)
>>> leaf2.leaf4 = tf.Variable(7.0)

Pass `node_id=0` to `tf.train.CheckpointView.children()` to get the
dictionary of all children directly linked to the checkpoint root.

>>> checkpoint_view_diff = checkpoint_view.diff(root2)
>>> checkpoint_view_match = checkpoint_view_diff[0].items()
>>> for item in checkpoint_view_match:
...   print(item)
(0, ...)
(1, <tf.Variable 'Variable:0' shape=() dtype=float32, numpy=5.0>)
(2, <tf.Variable 'Variable:0' shape=() dtype=float32, numpy=4.0>)
(3, ListWrapper([<tf.Variable 'Variable:0' shape=() dtype=float32,
numpy=1.0>, <tf.Variable 'Variable:0' shape=() dtype=float32, numpy=2.0>]))
(6, <tf.Variable 'Variable:0' shape=() dtype=float32, numpy=1.0>)
(7, <tf.Variable 'Variable:0' shape=() dtype=float32, numpy=2.0>)

>>> only_in_checkpoint_view = checkpoint_view_diff[1]
>>> print(only_in_checkpoint_view)
[4, 5, 8, 9, 10, 11, 12, 13, 14]

>>> only_in_trackable = checkpoint_view_diff[2]
>>> print(only_in_trackable)
[..., <tf.Variable 'Variable:0' shape=() dtype=float32, numpy=5.0>,
<tf.Variable 'Variable:0' shape=() dtype=float32, numpy=4.0>,
ListWrapper([<tf.Variable 'Variable:0' shape=() dtype=float32, numpy=1.0>,
<tf.Variable 'Variable:0' shape=() dtype=float32, numpy=2.0>]),
<tf.Variable 'Variable:0' shape=() dtype=float32, numpy=6.0>,
<tf.Variable 'Variable:0' shape=() dtype=float32, numpy=7.0>,
<tf.Variable 'Variable:0' shape=() dtype=float32, numpy=1.0>,
<tf.Variable 'Variable:0' shape=() dtype=float32, numpy=2.0>]

Args:
  obj: `Trackable` root.

Returns:
  Tuple of (
  - Overlaps: Dictionary containing all overlapping trackables that maps
  `node_id` to `Trackable`, same as CheckpointView.match().
  - Only in CheckpointView: List of `node_id` that only exist in
  CheckpointView.
  - Only in Trackable: List of `Trackable` that only exist in Trackable.
  )


class ClapAudioConfig(PretrainedConfig):
    model_type = 'clap_audio_model'
    base_config_key = 'audio_config'

    def __init__(self, window_size=8, num_mel_bins=64, spec_size=256, hidden_act='gelu', patch_size=4, patch_stride=[4, 4], num_classes=527, hidden_size=768, projection_dim=512, depths=[2, 2, 6, 2], num_attention_heads=[4, 8, 16, 32], enable_fusion=False, hidden_dropout_prob=0.1, fusion_type=None, patch_embed_input_channels=1, flatten_patch_embeds=True, patch_embeds_hidden_size=96, enable_patch_layer_norm=True, drop_path_rate=0.0, attention_probs_dropout_prob=0.0, qkv_bias=True, mlp_ratio=4.0, aff_block_r=4, num_hidden_layers=4, projection_hidden_act='relu', layer_norm_eps=1e-05, initializer_factor=1.0, **kwargs):
        super().__init__(**kwargs)
        self.window_size = window_size
        self.num_mel_bins = num_mel_bins
        self.spec_size = spec_size
        self.patch_size = patch_size
        self.patch_stride = patch_stride
        self.num_classes = num_classes
        self.hidden_size = hidden_size
        self.depths = depths
        self.num_hidden_layers = num_hidden_layers
        self.num_attention_heads = num_attention_heads
        self.window_size = window_size
        self.enable_fusion = enable_fusion
        self.fusion_type = fusion_type
        self.hidden_act = hidden_act
        self.hidden_dropout_prob = hidden_dropout_prob
        self.projection_dim = projection_dim
        self.flatten_patch_embeds = flatten_patch_embeds
        self.patch_embeds_hidden_size = patch_embeds_hidden_size
        self.enable_patch_layer_norm = enable_patch_layer_norm
        self.drop_path_rate = drop_path_rate
        self.attention_probs_dropout_prob = attention_probs_dropout_prob
        self.qkv_bias = qkv_bias
        self.mlp_ratio = mlp_ratio
        self.patch_embed_input_channels = patch_embed_input_channels
        self.aff_block_r = aff_block_r
        self.layer_norm_eps = layer_norm_eps
        self.initializer_factor = initializer_factor
        self.projection_hidden_act = projection_hidden_act

This is the configuration class to store the configuration of a [`ClapAudioModel`]. It is used to instantiate a
CLAP 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 CLAP
[laion/clap-htsat-fused](https://huggingface.co/laion/clap-htsat-fused) architecture.

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

Args:
    window_size (`int`, *optional*, defaults to 8):
        Image size of the spectrogram
    num_mel_bins (`int`, *optional*, defaults to 64):
        Number of mel features used per frames. Should correspond to the value used in the `ClapProcessor` class.
    spec_size (`int`, *optional*, defaults to 256):
        Desired input size of the spectrogram that the model supports. It can be different from the output of the
        `ClapFeatureExtractor`, in which case the input features will be resized. Corresponds to the `image_size`
        of the audio models.
    hidden_act (`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.
    patch_size (`int`, *optional*, defaults to 4):
        Patch size for the audio spectrogram
    patch_stride (`list`, *optional*, defaults to `[4, 4]`):
        Patch stride for the audio spectrogram
    num_classes (`int`, *optional*, defaults to 527):
        Number of classes used for the head training
    hidden_size (`int`, *optional*, defaults to 768):
        Hidden size of the output of the audio encoder. Correspond to the dimension of the penultimate layer's
        output,which is sent to the projection MLP layer.
    projection_dim (`int`, *optional*, defaults to 512):
        Hidden size of the projection layer.
    depths (`list`, *optional*, defaults to `[2, 2, 6, 2]`):
        Depths used for the Swin Layers of the audio model
    num_attention_heads (`list`, *optional*, defaults to `[4, 8, 16, 32]`):
        Number of attention heads used for the Swin Layers of the audio model
    enable_fusion (`bool`, *optional*, defaults to `False`):
        Whether or not to enable patch fusion. This is the main contribution of the authors, and should give the
        best results.
    hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
        The dropout probability for all fully connected layers in the encoder.
    fusion_type (`[type]`, *optional*):
        Fusion type used for the patch fusion.
    patch_embed_input_channels (`int`, *optional*, defaults to 1):
        Number of channels used for the input spectrogram
    flatten_patch_embeds (`bool`, *optional*, defaults to `True`):
        Whether or not to flatten the patch embeddings
    patch_embeds_hidden_size (`int`, *optional*, defaults to 96):
        Hidden size of the patch embeddings. It is used as the number of output channels.
    enable_patch_layer_norm (`bool`, *optional*, defaults to `True`):
        Whether or not to enable layer normalization for the patch embeddings
    drop_path_rate (`float`, *optional*, defaults to 0.0):
        Drop path rate for the patch fusion
    attention_probs_dropout_prob (`float`, *optional*, defaults to 0.0):
        The dropout ratio for the attention probabilities.
    qkv_bias (`bool`, *optional*, defaults to `True`):
        Whether or not to add a bias to the query, key, value projections.
    mlp_ratio (`float`, *optional*, defaults to 4.0):
        Ratio of the mlp hidden dim to embedding dim.
    aff_block_r (`int`, *optional*, defaults to 4):
        downsize_ratio used in the AudioFF block
    num_hidden_layers (`int`, *optional*, defaults to 4):
        Number of hidden layers in the Transformer encoder.
    projection_hidden_act (`str`, *optional*, defaults to `"relu"`):
        The non-linear activation function (function or string) in the projection layer. If string, `"gelu"`,
        `"relu"`, `"silu"` and `"gelu_new"` are supported.
    layer_norm_eps (`[type]`, *optional*, defaults to 1e-05):
        The epsilon used by the layer normalization layers.
    initializer_factor (`float`, *optional*, defaults to 1.0):
        A factor for initializing all weight matrices (should be kept to 1, used internally for initialization
        testing).

Example:

```python
>>> from transformers import ClapAudioConfig, ClapAudioModel

>>> # Initializing a ClapAudioConfig with laion/clap-htsat-fused style configuration
>>> configuration = ClapAudioConfig()

>>> # Initializing a ClapAudioModel (with random weights) from the laion/clap-htsat-fused style configuration
>>> model = ClapAudioModel(configuration)

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


def dot(inputs, axes, normalize=False, **kwargs):
    return Dot(axes=axes, normalize=normalize, **kwargs)(inputs)

Functional interface to the `Dot` layer.

Args:
    inputs: A list of input tensors (at least 2).
    axes: Integer or tuple of integers,
        axis or axes along which to take the dot product.
    normalize: Whether to L2-normalize samples along the
        dot product axis before taking the dot product.
        If set to True, then the output of the dot product
        is the cosine proximity between the two samples.
    **kwargs: Standard layer keyword arguments.

Returns:
    A tensor, the dot product of the samples from the inputs.


def gelu(x, approximate=True):
    if any_symbolic_tensors((x,)):
        return Gelu(approximate).symbolic_call(x)
    return backend.nn.gelu(x, approximate)

Gaussian Error Linear Unit (GELU) activation function.

If `approximate` is `True`, it is defined as:
`f(x) = 0.5 * x * (1 + tanh(sqrt(2 / pi) * (x + 0.044715 * x^3)))`

Or if `approximate` is `False`, it is defined as:
`f(x) = x * P(X <= x) = 0.5 * x * (1 + erf(x / sqrt(2)))`,
where `P(X) ~ N(0, 1)`.

Args:
    x: Input tensor.
    approximate: Approximate version of GELU activation. Defaults to `True`.

Returns:
    A tensor with the same shape as `x`.

Example:

>>> x = np.array([-1., 0., 1.])
>>> x_gelu = keras.ops.gelu(x)
>>> print(x_gelu)
array([-0.15865525, 0., 0.84134475], shape=(3,), dtype=float64)


def reduce_std(input_tensor, axis=None, keepdims=False, name=None):
    name = name if name else 'reduce_std'
    with ops.name_scope(name):
        input_tensor = ops.convert_to_tensor(input_tensor)
        variance = reduce_variance(input_tensor, axis=axis, keepdims=keepdims)
        return gen_math_ops.sqrt(variance)

Computes the standard deviation of elements across dimensions of a tensor.

Reduces `input_tensor` along the dimensions given in `axis`.
Unless `keepdims` is true, the rank of the tensor is reduced by 1 for each
of the entries in `axis`, which must be unique. If `keepdims` is true, the
reduced dimensions are retained with length 1.

If `axis` is None, all dimensions are reduced, and a
tensor with a single element is returned.

For example:

>>> x = tf.constant([[1., 2.], [3., 4.]])
>>> tf.math.reduce_std(x)
<tf.Tensor: shape=(), dtype=float32, numpy=1.118034>
>>> tf.math.reduce_std(x, 0)
<tf.Tensor: shape=(2,), dtype=float32, numpy=array([1., 1.], dtype=float32)>
>>> tf.math.reduce_std(x, 1)
<tf.Tensor: shape=(2,), dtype=float32, numpy=array([0.5, 0.5], dtype=float32)>

Args:
  input_tensor: The tensor to reduce. Should have real or complex type.
  axis: The dimensions to reduce. If `None` (the default), reduces all
    dimensions. Must be in the range `[-rank(input_tensor),
    rank(input_tensor))`.
  keepdims: If true, retains reduced dimensions with length 1.
  name: A name scope for the associated operations (optional).

Returns:
  The reduced tensor, of the same dtype as the input_tensor. Note,  for
  `complex64` or `complex128` input, the returned `Tensor` will be of type
  `float32` or `float64`, respectively.

@compatibility(numpy)
Equivalent to np.std

Please note `np.std` has a `dtype` parameter that could be used to specify the
output type. By default this is `dtype=float64`. On the other hand,
`tf.math.reduce_std` has aggressive type inference from `input_tensor`.
@end_compatibility


def __init__(self, sess, bad_init_action=None, bad_run_start_action=None, bad_debug_urls=None):
    self._bad_init_action = bad_init_action
    self._bad_run_start_action = bad_run_start_action
    self._bad_debug_urls = bad_debug_urls
    framework.BaseDebugWrapperSession.__init__(self, sess)

Constructor.

Args:
  sess: The TensorFlow Session object to be wrapped.
  bad_init_action: (str) bad action value to be returned during the
    on-session-init callback.
  bad_run_start_action: (str) bad action value to be returned during the
    the on-run-start callback.
  bad_debug_urls: Bad URL values to be returned during the on-run-start
    callback.


class Graph(collections.namedtuple('Graph', ['entry', 'exit', 'error', 'index', 'stmt_prev', 'stmt_next'])):

    def __repr__(self):
        return self.as_dot()

    def as_dot(self):
        """Print CFG in DOT format."""
        result = 'digraph CFG {\n'
        for node in self.index.values():
            result += '  %s [label="%s"];\n' % (id(node), node)
        for node in self.index.values():
            for next_ in node.next:
                result += '  %s -> %s;\n' % (id(node), id(next_))
        result += '}'
        return result

A Control Flow Graph.

The CFG maintains an index to allow looking up a CFG node by the AST node to
which it is associated. The index can also be enumerated in top-down, depth
first order.

Walking the graph in forward or reverse order is supported by double
parent-child links.

Note: the error nodes are not wired to their corresponding finally guards,
because these are shared, and wiring them would create a reverse path from
normal control flow into the error nodes, which we want to avoid.

The graph also maintains edges corresponding to higher level statements
like for-else loops. A node is considered successor of a statement if there
is an edge from a node that is lexically a child of that statement to a node
that is not. Statement predecessors are analogously defined.

Attributes:
  entry: Node, the entry node
  exit: FrozenSet[Node, ...], the exit nodes
  error: FrozenSet[Node, ...], nodes that exit due to an explicitly raised
    error (errors propagated from function calls are not accounted)
  index: Dict[ast.Node, Node], mapping AST nodes to the respective CFG node
  stmt_prev: Dict[ast.Node, FrozenSet[Node, ...]], mapping statement AST nodes
    to their predecessor CFG nodes
  stmt_next: Dict[ast.Node, FrozenSet[Node, ...]], mapping statement AST nodes
    to their successor CFG nodes


def throttle_request(self, now):
    throttling_probability = self._throttling_probability(now)
    self._all_requests.add(now, 1)
    return self._random.uniform(0, 1) < throttling_probability

Determines whether one RPC attempt should be throttled.

This should be called once each time the caller intends to send an RPC; if
it returns true, drop or delay that request (calling this function again
after the delay).

Args:
  now: int, time in ms since the epoch
Returns:
  bool, True if the caller should throttle or delay the request.


def reduce(self, initial_state, reduce_func, name=None):
    with ops.name_scope('initial_state'):
        initial_state = structure.normalize_element(initial_state)
    state_structure = structure.type_spec_from_value(initial_state)
    need_to_rerun = True
    while need_to_rerun:
        wrapped_func = structured_function.StructuredFunctionWrapper(reduce_func, 'reduce()', input_structure=(state_structure, self.element_spec), add_to_graph=False)
        output_classes = wrapped_func.output_classes
        state_classes = nest.map_structure(lambda component_spec: component_spec._to_legacy_output_classes(), state_structure)
        for new_state_class, state_class in zip(nest.flatten(output_classes), nest.flatten(state_classes)):
            if not issubclass(new_state_class, state_class):
                raise TypeError(f'The element classes for the new state must match the initial state. Expected {state_classes} but got {wrapped_func.output_classes}.')
        output_types = wrapped_func.output_types
        state_types = nest.map_structure(lambda component_spec: component_spec._to_legacy_output_types(), state_structure)
        for new_state_type, state_type in zip(nest.flatten(output_types), nest.flatten(state_types)):
            if new_state_type != state_type:
                raise TypeError(f'The element types for the new state must match the initial state. Expected {state_types} but got {wrapped_func.output_types}.')
        output_shapes = wrapped_func.output_shapes
        state_shapes = nest.map_structure(lambda component_spec: component_spec._to_legacy_output_shapes(), state_structure)
        flat_state_shapes = nest.flatten(state_shapes)
        flat_new_state_shapes = nest.flatten(output_shapes)
        weakened_state_shapes = [original.most_specific_compatible_shape(new) for original, new in zip(flat_state_shapes, flat_new_state_shapes)]
        need_to_rerun = False
        for original_shape, weakened_shape in zip(flat_state_shapes, weakened_state_shapes):
            if original_shape.ndims is not None and (weakened_shape.ndims is None or original_shape.as_list() != weakened_shape.as_list()):
                need_to_rerun = True
                break
        if need_to_rerun:
            state_structure = structure.convert_legacy_structure(state_types, nest.pack_sequence_as(state_shapes, weakened_state_shapes), state_classes)
    reduce_func = wrapped_func.function
    reduce_func.add_to_graph(ops.get_default_graph())
    dataset = self._apply_debug_options()
    metadata = dataset_metadata_pb2.Metadata()
    if name:
        metadata.name = _validate_and_encode(name)
    return structure.from_compatible_tensor_list(state_structure, gen_dataset_ops.reduce_dataset(dataset._variant_tensor, structure.to_tensor_list(state_structure, initial_state), reduce_func.captured_inputs, f=reduce_func, output_shapes=structure.get_flat_tensor_shapes(state_structure), output_types=structure.get_flat_tensor_types(state_structure), metadata=metadata.SerializeToString()))

Reduces the input dataset to a single element.

The transformation calls `reduce_func` successively on every element of
the input dataset until the dataset is exhausted, aggregating information in
its internal state. The `initial_state` argument is used for the initial
state and the final state is returned as the result.

>>> tf.data.Dataset.range(5).reduce(np.int64(0), lambda x, _: x +
...   1).numpy().item()
5
>>> tf.data.Dataset.range(5).reduce(np.int64(0), lambda x, y: x +
...   y).numpy().item()
10

Args:
  initial_state: An element representing the initial state of the
    transformation.
  reduce_func: A function that maps `(old_state, input_element)` to
    `new_state`. It must take two arguments and return a new element The
    structure of `new_state` must match the structure of `initial_state`.
  name: (Optional.) A name for the tf.data operation.

Returns:
  A dataset element corresponding to the final state of the transformation.


def get_record_schema_from_dict_table_schema(schema_name: str, table_schema: Dict[str, Any], namespace: str='apache_beam.io.gcp.bigquery') -> Dict[str, Any]:
    avro_fields = [table_field_to_avro_field(field, '.'.join((namespace, schema_name))) for field in table_schema['fields']]
    return {'type': 'record', 'name': schema_name, 'fields': avro_fields, 'doc': 'Translated Avro Schema for {}'.format(schema_name), 'namespace': namespace}

Convert a table schema into an Avro schema.

Args:
  schema_name (str): The name of the record.
  table_schema (Dict[str, Any]): A BigQuery table schema in dict form.
  namespace (str): The namespace of the Avro schema.

Returns:
  Dict[str, Any]: The schema as an Avro RecordSchema.


def sampled_softmax_loss_v2(weights, biases, labels, inputs, num_sampled, num_classes, num_true=1, sampled_values=None, remove_accidental_hits=True, seed=None, name='sampled_softmax_loss'):
    return sampled_softmax_loss(weights, biases, labels, inputs, num_sampled, num_classes, num_true=num_true, sampled_values=sampled_values, remove_accidental_hits=remove_accidental_hits, partition_strategy='div', name=name, seed=seed)

Computes and returns the sampled softmax training loss.

This is a faster way to train a softmax classifier over a huge number of
classes.

This operation is for training only.  It is generally an underestimate of
the full softmax loss.

A common use case is to use this method for training, and calculate the full
softmax loss for evaluation or inference as in the following example:

```python
if mode == "train":
  loss = tf.nn.sampled_softmax_loss(
      weights=weights,
      biases=biases,
      labels=labels,
      inputs=inputs,
      ...)
elif mode == "eval":
  logits = tf.matmul(inputs, tf.transpose(weights))
  logits = tf.nn.bias_add(logits, biases)
  labels_one_hot = tf.one_hot(labels, n_classes)
  loss = tf.nn.softmax_cross_entropy_with_logits(
      labels=labels_one_hot,
      logits=logits)
```

See our [Candidate Sampling Algorithms Reference]
(https://www.tensorflow.org/extras/candidate_sampling.pdf)

Also see Section 3 of [Jean et al., 2014](http://arxiv.org/abs/1412.2007)
([pdf](http://arxiv.org/pdf/1412.2007.pdf)) for the math.

Note: when doing embedding lookup on `weights` and `bias`, "div" partition
strategy will be used. Support for other partition strategy will be added
later.

Args:
  weights: A `Tensor` of shape `[num_classes, dim]`, or a list of `Tensor`
    objects whose concatenation along dimension 0 has shape [num_classes,
    dim].  The (possibly-sharded) class embeddings.
  biases: A `Tensor` of shape `[num_classes]`.  The class biases.
  labels: A `Tensor` of type `int64` and shape `[batch_size, num_true]`. The
    target classes.  Note that this format differs from the `labels` argument
    of `nn.softmax_cross_entropy_with_logits`.
  inputs: A `Tensor` of shape `[batch_size, dim]`.  The forward activations of
    the input network.
  num_sampled: An `int`.  The number of classes to randomly sample per batch.
  num_classes: An `int`. The number of possible classes.
  num_true: An `int`.  The number of target classes per training example.
  sampled_values: a tuple of (`sampled_candidates`, `true_expected_count`,
    `sampled_expected_count`) returned by a `*_candidate_sampler` function.
    (if None, we default to `log_uniform_candidate_sampler`)
  remove_accidental_hits:  A `bool`.  whether to remove "accidental hits"
    where a sampled class equals one of the target classes.  Default is True.
  seed: random seed for candidate sampling. Default to None, which doesn't set
    the op-level random seed for candidate sampling.
  name: A name for the operation (optional).

Returns:
  A `batch_size` 1-D tensor of per-example sampled softmax losses.


def __init__(self, trainable=None, caching_device=None, name=None, shape=None, dtype=None, constraint=None, synchronization=None, aggregation=None, extra_handle_data=None, distribute_strategy=None, **unused_kwargs):
    with ops.init_scope():
        self._in_graph_mode = not context.executing_eagerly()
        with ops.name_scope(name, 'Variable', skip_on_eager=False) as name:
            handle_name = ops.name_from_scope_name(name)
            if self._in_graph_mode:
                shared_name = handle_name
                unique_id = shared_name
            else:
                unique_id = '%s_%d' % (handle_name, ops.uid())
                shared_name = None
            handle = _variable_handle_from_shape_and_dtype(shape=shape, dtype=dtype, shared_name=shared_name, name=name, graph_mode=self._in_graph_mode, initial_value=extra_handle_data)
            handle._parent_trackable = weakref.ref(self)
            handle._name = handle_name + ':0'
            handle._unique_id = unique_id
            if self._in_graph_mode:
                with ops.name_scope('Read'):
                    with ops.device(handle.device):
                        value = gen_resource_variable_ops.read_variable_op(handle, dtype)
                        _maybe_set_handle_data(dtype, handle, value)
                    graph_element = value
                ops.add_to_collection(ops.GraphKeys.GLOBAL_VARIABLES, self)
            else:
                graph_element = None
    super(UninitializedVariable, self).__init__(distribute_strategy=distribute_strategy, shape=shape, dtype=dtype, unique_id=unique_id, handle_name=handle_name, constraint=constraint, handle=handle, graph_element=graph_element, trainable=trainable, synchronization=synchronization, aggregation=aggregation, in_graph_mode=self._in_graph_mode, **unused_kwargs)

Creates the variable handle.

Args:
  trainable: If `True`, GradientTapes automatically watch uses of this
    Variable.
  caching_device: Optional device string or function describing where the
    Variable should be cached for reading.  Defaults to the Variable's
    device.  If not `None`, caches on another device.  Typical use is to
    cache on the device where the Ops using the Variable reside, to
    deduplicate copying through `Switch` and other conditional statements.
  name: Optional name for the variable. Defaults to `'Variable'` and gets
    uniquified automatically.
  shape: The variable's shape.
  dtype: The variable's dtype.
  constraint: An optional projection function to be applied to the variable
    after being updated by an `Optimizer` (e.g. used to implement norm
    constraints or value constraints for layer weights). The function must
    take as input the unprojected Tensor representing the value of the
    variable and return the Tensor for the projected value (which must have
    the same shape). Constraints are not safe to use when doing asynchronous
    distributed training.
  synchronization: Indicates when a distributed a variable will be
    aggregated. Accepted values are constants defined in the class
    `tf.VariableSynchronization`. By default the synchronization is set to
    `AUTO` and the current `DistributionStrategy` chooses when to
    synchronize.
  aggregation: Indicates how a distributed variable will be aggregated.
    Accepted values are constants defined in the class
    `tf.VariableAggregation`.
  extra_handle_data: Optional, another resource handle or Tensor with handle
    data to merge with `shape` and `dtype`.
  distribute_strategy: The tf.distribute.Strategy this variable is being
    created inside of.