xref: /aosp_15_r20/external/federated-compute/fcp/tensorflow/example_selector_fuser.py (revision 14675a029014e728ec732f129a32e299b2da0601)
1# Copyright 2022 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Provides the `example_selector_fuser` operation.
15
16This wraps the generated op and ensures that necessary shared libraries
17are loaded.
18"""
19
20from typing import Optional
21
22import tensorflow as tf
23
24from fcp.tensorflow import gen_example_selector_fuser_op
25
26_example_selector_fuser_op_so = tf.load_op_library(
27    tf.compat.v1.resource_loader.get_path_to_datafile(
28        './_example_selector_fuser_op.so'))
29
30
31def example_selector_fuser(example_selector: tf.Tensor,
32                           resumption_token_type_url: tf.Tensor,
33                           resumption_token_content: tf.Tensor,
34                           name: Optional[str] = None) -> tf.Operation:
35  """Fills the resumption token of an existing ExampleSelector message.
36
37  Args:
38    example_selector: The serialized ExampleSelector message.
39    resumption_token_type_url: The type URL of the resumption token.
40    resumption_token_content: The serialized content of the resumption token.
41    name: A name for the operation (optional).
42
43  Returns:
44    The created `Operation`.
45  """
46  return gen_example_selector_fuser_op.example_selector_fuser(
47      example_selector,
48      resumption_token_type_url,
49      resumption_token_content,
50      name=name)
51