neulab/docprompting-conala huggingface dataset:
tf.test.Benchmark     View source on GitHub    Abstract class that provides helpers for TensorFlow benchmarks.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.test.Benchmark  
tf.test.Benchmark()
 Methods evaluate View source 
evaluate(
    tensors
)
 Evaluates tensors and returns numpy values.
 


 Args
  tensors   A Tensor or a nested list/tuple of Tensors.   
 


 Returns   tensors numpy values.  
 is_abstract View source 
@classmethod
is_abstract()
 report_benchmark View source 
report_benchmark(
    iters=None, cpu_time=None, wall_time=None, throughput=None, extras=None,
    name=None, metrics=None
)
 Report a benchmark.
 


 Args
  iters   (optional) How many iterations were run  
  cpu_time   (optional) Median or mean cpu time in seconds.  
  wall_time   (optional) Median or mean wall time in seconds.  
  throughput   (optional) Throughput (in MB/s)  
  extras   (optional) Dict mapping string keys to additional benchmark info. Values may be either floats or values that are convertible to strings.  
  name   (optional) Override the BenchmarkEntry name with name. Otherwise it is inferred from the top-level method name.  
  metrics   (optional) A list of dict, where each dict has the keys below name (required), string, metric name value (required), double, metric value min_value (optional), double, minimum acceptable metric value max_value (optional), double, maximum acceptable metric value    run_op_benchmark View source 
run_op_benchmark(
    sess, op_or_tensor, feed_dict=None, burn_iters=2, min_iters=10,
    store_trace=False, store_memory_usage=True, name=None, extras=None, mbs=0
)
 Run an op or tensor in the given session. Report the results.
 


 Args
  sess   Session object to use for timing.  
  op_or_tensor   Operation or Tensor to benchmark.  
  feed_dict   A dict of values to feed for each op iteration (see the feed_dict parameter of Session.run).  
  burn_iters   Number of burn-in iterations to run.  
  min_iters   Minimum number of iterations to use for timing.  
  store_trace   Boolean, whether to run an extra untimed iteration and store the trace of iteration in returned extras. The trace will be stored as a string in Google Chrome trace format in the extras field "full_trace_chrome_format". Note that trace will not be stored in test_log_pb2.TestResults proto.  
  store_memory_usage   Boolean, whether to run an extra untimed iteration, calculate memory usage, and store that in extras fields.  
  name   (optional) Override the BenchmarkEntry name with name. Otherwise it is inferred from the top-level method name.  
  extras   (optional) Dict mapping string keys to additional benchmark info. Values may be either floats or values that are convertible to strings.  
  mbs   (optional) The number of megabytes moved by this op, used to calculate the ops throughput.   
 


 Returns   A dict containing the key-value pairs that were passed to report_benchmark. If store_trace option is used, then full_chrome_trace_format will be included in return dictionary even though it is not passed to report_benchmark with extras.
tf.test.benchmark_config     View source on GitHub    Returns a tf.compat.v1.ConfigProto for disabling the dependency optimizer.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.test.benchmark_config  
tf.test.benchmark_config()

 


 Returns   A TensorFlow ConfigProto object.
tf.test.compute_gradient     View source on GitHub    Computes the theoretical and numeric Jacobian of f. 
tf.test.compute_gradient(
    f, x, delta=0.001
)
 With y = f(x), computes the theoretical and numeric Jacobian dy/dx.
 


 Args
  f   the function.  
  x   the arguments for the function as a list or tuple of values convertible to a Tensor.  
  delta   (optional) perturbation used to compute numeric Jacobian.   
 


 Returns   A pair of lists, where the first is a list of 2-d numpy arrays representing the theoretical Jacobians for each argument, and the second list is the numerical ones. Each 2-d array has "y_size" rows and "x_size" columns where "x_size" is the number of elements in the corresponding argument and "y_size" is the number of elements in f(x).  

 


 Raises
  ValueError   If result is empty but the gradient is nonzero.  
  ValueError   If x is not list, but any other type.    Example: @tf.function
def test_func(x):
  return x*x

theoretical, numerical = tf.test.compute_gradient(test_func, [1.0])
theoretical, numerical
# ((array([[2.]], dtype=float32),), (array([[2.000004]], dtype=float32),))
tf.test.create_local_cluster     View source on GitHub    Create and start local servers and return the associated Server objects.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.test.create_local_cluster  
tf.test.create_local_cluster(
    num_workers, num_ps, protocol='grpc', worker_config=None,
    ps_config=None
)
 "PS" stands for "parameter server": a task responsible for storing and updating the model's parameters. Other tasks send updates to these parameters as they work on optimizing the parameters. This particular division of labor between tasks is not required, but is common for distributed training. Read more at https://www.tensorflow.org/guide/extend/architecture  Figure illustrates the interaction of these components. "/job:worker/task:0" and "/job:ps/task:0" are both tasks with worker services. Example: workers, _ = tf.test.create_local_cluster(num_workers=2, num_ps=2)

worker_sessions = [tf.compat.v1.Session(w.target) for w in workers]

with tf.device("/job:ps/task:0"):
  ...
with tf.device("/job:ps/task:1"):
  ...
with tf.device("/job:worker/task:0"):
  ...
with tf.device("/job:worker/task:1"):
  ...

worker_sessions[0].run(...)

 


 Args
  num_workers   Number of worker servers to start.  
  num_ps   Number of PS servers to start.  
  protocol   Communication protocol. Allowed values are documented in the documentation of tf.distribute.Server.  
  worker_config   (optional) tf.ConfigProto to initialize workers. Can be used to instantiate multiple devices etc.  
  ps_config   (optional) tf.ConfigProto to initialize PS servers.   
 


 Returns   A tuple (worker_servers, ps_servers). worker_servers is a list of num_workers objects of type tf.distribute.Server (all running locally); and ps_servers is a list of num_ps objects of similar type.  

 


 Raises
  ImportError   if portpicker module was not found at load time
tf.test.gpu_device_name     View source on GitHub    Returns the name of a GPU device if available or the empty string.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.test.gpu_device_name  
tf.test.gpu_device_name()
tf.test.is_built_with_cuda     View source on GitHub    Returns whether TensorFlow was built with CUDA (GPU) support.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.test.is_built_with_cuda  
tf.test.is_built_with_cuda()
tf.test.is_built_with_gpu_support     View source on GitHub    Returns whether TensorFlow was built with GPU (i.e. CUDA or ROCm) support.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.test.is_built_with_gpu_support  
tf.test.is_built_with_gpu_support()
tf.test.is_built_with_rocm     View source on GitHub    Returns whether TensorFlow was built with ROCm (GPU) support.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.test.is_built_with_rocm  
tf.test.is_built_with_rocm()
tf.test.is_built_with_xla Returns whether TensorFlow was built with XLA support.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.test.is_built_with_xla  
tf.test.is_built_with_xla()
tf.test.is_gpu_available     View source on GitHub    Returns whether TensorFlow can access a GPU. (deprecated)  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.test.is_gpu_available  
tf.test.is_gpu_available(
    cuda_only=False, min_cuda_compute_capability=None
)
 Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use tf.config.list_physical_devices('GPU') instead.Warning: if a non-GPU version of the package is installed, the function would also return False. Use tf.test.is_built_with_cuda to validate if TensorFlow was build with CUDA support.
 


 Args
  cuda_only   limit the search to CUDA GPUs.  
  min_cuda_compute_capability   a (major,minor) pair that indicates the minimum CUDA compute capability required, or None if no requirement.    Note that the keyword arg name "cuda_only" is misleading (since routine will return true when a GPU device is available irrespective of whether TF was built with CUDA support or ROCm support. However no changes here because ++ Changing the name "cuda_only" to something more generic would break backward compatibility ++ Adding an equivalent "rocm_only" would require the implementation check the build type. This in turn would require doing the same for CUDA and thus potentially break backward compatibility ++ Adding a new "cuda_or_rocm_only" would not break backward compatibility, but would require most (if not all) callers to update the call to use "cuda_or_rocm_only" instead of "cuda_only"
 


 Returns   True if a GPU device of the requested kind is available.
tf.test.main     View source on GitHub    Runs all unit tests.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.test.main  
tf.test.main(
    argv=None
)
tf.test.TestCase.failureException Assertion failed.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.test.TestCase.failureException  
tf.test.TestCase.failureException(
    *args, **kwargs
)
tf.tile Constructs a tensor by tiling a given tensor.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.manip.tile, tf.compat.v1.tile  
tf.tile(
    input, multiples, name=None
)
 This operation creates a new tensor by replicating input multiples times. The output tensor's i'th dimension has input.dims(i) * multiples[i] elements, and the values of input are replicated multiples[i] times along the 'i'th dimension. For example, tiling [a b c d] by [2] produces [a b c d a b c d]. 
a = tf.constant([[1,2,3],[4,5,6]], tf.int32)
b = tf.constant([1,2], tf.int32)
tf.tile(a, b)
<tf.Tensor: shape=(2, 6), dtype=int32, numpy=
array([[1, 2, 3, 1, 2, 3],
       [4, 5, 6, 4, 5, 6]], dtype=int32)>
c = tf.constant([2,1], tf.int32)
tf.tile(a, c)
<tf.Tensor: shape=(4, 3), dtype=int32, numpy=
array([[1, 2, 3],
       [4, 5, 6],
       [1, 2, 3],
       [4, 5, 6]], dtype=int32)>
d = tf.constant([2,2], tf.int32)
tf.tile(a, d)
<tf.Tensor: shape=(4, 6), dtype=int32, numpy=
array([[1, 2, 3, 1, 2, 3],
       [4, 5, 6, 4, 5, 6],
       [1, 2, 3, 1, 2, 3],
       [4, 5, 6, 4, 5, 6]], dtype=int32)>

 


 Args
  input   A Tensor. 1-D or higher.  
  multiples   A Tensor. Must be one of the following types: int32, int64. 1-D. Length must be the same as the number of dimensions in input  
  name   A name for the operation (optional).   
 


 Returns   A Tensor. Has the same type as input.
tf.timestamp Provides the time since epoch in seconds.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.timestamp  
tf.timestamp(
    name=None
)
 Returns the timestamp as a float64 for seconds since the Unix epoch. 
Note: the timestamp is computed when the op is executed, not when it is added to the graph.

 


 Args
  name   A name for the operation (optional).   
 


 Returns   A Tensor of type float64.
Module: tf.tpu Ops related to Tensor Processing Units. Modules experimental module: Public API for tf.tpu.experimental namespace.
Module: tf.tpu.experimental Public API for tf.tpu.experimental namespace. Modules embedding module: Public API for tf.tpu.experimental.embedding namespace. Classes class DeviceAssignment: Mapping from logical cores in a computation to the physical TPU topology. class TPUSystemMetadata: Describes some metadata about the TPU system. class Topology: Describes a set of TPU devices. Functions initialize_tpu_system(...): Initialize the TPU devices. shutdown_tpu_system(...): Shuts down the TPU devices.
tf.tpu.experimental.DeviceAssignment     View source on GitHub    Mapping from logical cores in a computation to the physical TPU topology.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.tpu.experimental.DeviceAssignment  
tf.tpu.experimental.DeviceAssignment(
    topology, core_assignment
)
 Prefer to use the DeviceAssignment.build() helper to construct a DeviceAssignment; it is easier if less flexible than constructing a DeviceAssignment directly.
 


 Args
  topology   A Topology object that describes the physical TPU topology.  
  core_assignment   A logical to physical core mapping, represented as a rank 3 numpy array. See the description of the core_assignment property for more details.   
 


 Raises
  ValueError   If topology is not Topology object.  
  ValueError   If core_assignment is not a rank 3 numpy array.   
 


 Attributes
  core_assignment   The logical to physical core mapping.  
  num_cores_per_replica   The number of cores per replica.  
  num_replicas   The number of replicas of the computation.  
  topology   A Topology that describes the TPU topology.    Methods build View source 
@staticmethod
build(
    topology, computation_shape=None, computation_stride=None, num_replicas=1
)
 coordinates View source 
coordinates(
    replica, logical_core
)
 Returns the physical topology coordinates of a logical core. host_device View source 
host_device(
    replica=0, logical_core=0, job=None
)
 Returns the CPU device attached to a logical core. lookup_replicas View source 
lookup_replicas(
    task_id, logical_core
)
 Lookup replica ids by task number and logical core.
 


 Args
  task_id   TensorFlow task number.  
  logical_core   An integer, identifying a logical core.   
 


 Returns   A sorted list of the replicas that are attached to that task and logical_core.  

 


 Raises
  ValueError   If no replica exists in the task which contains the logical core.    tpu_device View source 
tpu_device(
    replica=0, logical_core=0, job=None
)
 Returns the name of the TPU device assigned to a logical core. tpu_ordinal View source 
tpu_ordinal(
    replica=0, logical_core=0
)
 Returns the ordinal of the TPU device assigned to a logical core.
Module: tf.tpu.experimental.embedding Public API for tf.tpu.experimental.embedding namespace. Classes class Adagrad: Optimization parameters for Adagrad with TPU embeddings. class Adam: Optimization parameters for Adam with TPU embeddings. class FeatureConfig: Configuration data for one embedding feature. class SGD: Optimization parameters for stochastic gradient descent for TPU embeddings. class TPUEmbedding: The TPUEmbedding mid level API. class TableConfig: Configuration data for one embedding table. Functions serving_embedding_lookup(...): Apply standard lookup ops with tf.tpu.experimental.embedding configs.
tf.tpu.experimental.embedding.FeatureConfig Configuration data for one embedding feature.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.tpu.experimental.embedding.FeatureConfig  
tf.tpu.experimental.embedding.FeatureConfig(
    table: tf.tpu.experimental.embedding.TableConfig,
    max_sequence_length: int = 0,
    name: Optional[Text] = None
)
 This class holds the configuration data for a single embedding feature. The main use is to assign features to tf.tpu.experimental.embedding.TableConfigs via the table parameter: table_config_one = tf.tpu.experimental.embedding.TableConfig(
    vocabulary_size=...,
    dim=...)
table_config_two = tf.tpu.experimental.embedding.TableConfig(
    vocabulary_size=...,
    dim=...)
feature_config = {
    'feature_one': tf.tpu.experimental.embedding.FeatureConfig(
        table=table_config_one),
    'feature_two': tf.tpu.experimental.embedding.FeatureConfig(
        table=table_config_one),
    'feature_three': tf.tpu.experimental.embedding.FeatureConfig(
        table=table_config_two)}
embedding = tf.tpu.experimental.embedding.TPUEmbedding(
    feature_config=feature_config,
    batch_size=...
    optimizer=tf.tpu.experimental.embedding.Adam(0.1))
 The above configuration has 2 tables, and three features. The first two features will be looked up in the first table and the third feature will be looked up in the second table. When feeding features into embedding.enqueue they can be tf.Tensors, tf.SparseTensors or tf.RaggedTensors. When the argument max_sequence_length is 0, the default, you should expect a output of embedding.dequeue for this feature of shape (batch_size, dim). If max_sequence_length is greater than 0, the feature is embedded as a sequence and padded up to the given length. The shape of the output for this feature will be (batch_size, max_sequence_length, dim).
 


 Args
  table   An instance of tf.tpu.experimental.embedding.TableConfig, describing the table in which this feature should be looked up.  
  max_sequence_length   If positive, the feature is a sequence feature with the corresponding maximum sequence length. If the sequence is longer than this, it will be truncated. If 0, the feature is not a sequence feature.  
  name   An optional name for the feature, useful for debugging.   
 


 Raises
  ValueError   if table is not an instance of tf.tpu.experimental.embedding.TableConfig.  
  ValueError   if max_sequence_length not an integer or is negative.
tf.tpu.experimental.embedding.serving_embedding_lookup Apply standard lookup ops with tf.tpu.experimental.embedding configs.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.tpu.experimental.embedding.serving_embedding_lookup  
tf.tpu.experimental.embedding.serving_embedding_lookup(
    inputs, weights, tables, feature_config
)
 This function is a utility which allows using the tf.tpu.experimental.embedding config objects with standard lookup functions. This can be used when exporting a model which uses tf.tpu.experimental.embedding.TPUEmbedding for serving on CPU. In particular tf.tpu.experimental.embedding.TPUEmbedding only supports lookups on TPUs and should not be part of your serving graph. Note that TPU specific options (such as max_sequence_length) in the configuration objects will be ignored. In the following example we take take a trained model (see the documentation for tf.tpu.experimental.embedding.TPUEmbedding for the context) and create a saved model with a serving function that will perform the embedding lookup and pass the results to your model: model = model_fn(...)
embedding = tf.tpu.experimental.embedding.TPUEmbedding(
    feature_config=feature_config,
    batch_size=1024,
    optimizer=tf.tpu.experimental.embedding.SGD(0.1))
checkpoint = tf.train.Checkpoint(model=model, embedding=embedding)
checkpoint.restore(...)

@tf.function(input_signature=[{'feature_one': tf.TensorSpec(...),
                               'feature_two': tf.TensorSpec(...),
                               'feature_three': tf.TensorSpec(...)}])
def serve_tensors(embedding_featurese):
  embedded_features = tf.tpu.experimental.embedding.serving_embedding_lookup(
      embedding_features, None, embedding.embedding_tables,
      feature_config)
  return model(embedded_features)

model.embedding_api = embedding
tf.saved_model.save(model,
                    export_dir=...,
                    signatures={'serving_default': serve_tensors})



Note: Its important to assign the embedding api object to a member of your model as tf.saved_model.save only supports saving variables one Trackable object. Since the model's weights are in model and the embedding table are managed by embedding, we assign embedding to and attribute of model so that tf.saved_model.save can find the embedding variables.


Note: The same serve_tensors function and tf.saved_model.save call will work directly from training.

 


 Args
  inputs   a nested structure of Tensors, SparseTensors or RaggedTensors.  
  weights   a nested structure of Tensors, SparseTensors or RaggedTensors or None for no weights. If not None, structure must match that of inputs, but entries are allowed to be None.  
  tables   a dict of mapping TableConfig objects to Variables.  
  feature_config   a nested structure of FeatureConfig objects with the same structure as inputs.   
 


 Returns   A nested structure of Tensors with the same structure as inputs.
tf.tpu.experimental.embedding.SGD Optimization parameters for stochastic gradient descent for TPU embeddings.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.tpu.experimental.embedding.SGD  
tf.tpu.experimental.embedding.SGD(
    learning_rate: Union[float, Callable[[], float]] = 0.01,
    clip_weight_min: Optional[float] = None,
    clip_weight_max: Optional[float] = None,
    weight_decay_factor: Optional[float] = None,
    multiply_weight_decay_factor_by_learning_rate: bool = None,
    clipvalue: Optional[ClipValueType] = None
)
 Pass this to tf.tpu.experimental.embedding.TPUEmbedding via the optimizer argument to set the global optimizer and its parameters: embedding = tf.tpu.experimental.embedding.TPUEmbedding(
    ...
    optimizer=tf.tpu.experimental.embedding.SGD(0.1))
 This can also be used in a tf.tpu.experimental.embedding.TableConfig as the optimizer parameter to set a table specific optimizer. This will override the optimizer and parameters for global embedding optimizer defined above: table_one = tf.tpu.experimental.embedding.TableConfig(
    vocabulary_size=...,
    dim=...,
    optimizer=tf.tpu.experimental.embedding.SGD(0.2))
table_two = tf.tpu.experimental.embedding.TableConfig(
    vocabulary_size=...,
    dim=...)

feature_config = (
    tf.tpu.experimental.embedding.FeatureConfig(
        table=table_one),
    tf.tpu.experimental.embedding.FeatureConfig(
        table=table_two))

embedding = tf.tpu.experimental.embedding.TPUEmbedding(
    feature_config=feature_config,
    batch_size=...
    optimizer=tf.tpu.experimental.embedding.SGD(0.1))
 In the above example, the first feature will be looked up in a table that has a learning rate of 0.2 while the second feature will be looked up in a table that has a learning rate of 0.1. See 'tensorflow/core/protobuf/tpu/optimization_parameters.proto' for a complete description of these parameters and their impacts on the optimizer algorithm.
 


 Args
  learning_rate   The learning rate. It should be a floating point value or a callable taking no arguments for a dynamic learning rate.  
  clip_weight_min   the minimum value to clip by; None means -infinity.  
  clip_weight_max   the maximum value to clip by; None means +infinity.  
  weight_decay_factor   amount of weight decay to apply; None means that the weights are not decayed. Weights are decayed by multiplying the weight by this factor each step.  
  multiply_weight_decay_factor_by_learning_rate   if true, weight_decay_factor is multiplied by the current learning rate.  
  clipvalue   Controls clipping of the gradient. Set to either a single positive scalar value to get clipping or a tiple of scalar values (min, max) to set a separate maximum or minimum. If one of the two entries is None, then there will be no clipping that direction. Note if this is set, you may see a decrease in performance as gradient accumulation will be enabled (it is normally off for SGD as it has no affect on accuracy). See 'tensorflow/core/protobuf/tpu/optimization_parameters.proto' for more information on gradient accumulation and its impact on tpu embeddings.