From 9bdc53e5ca06f0b16fefa5d56f53e7d655385aed Mon Sep 17 00:00:00 2001 From: Prem Jha Date: Sun, 19 Mar 2023 15:27:33 +0530 Subject: [PATCH 1/2] Adding more data for tensorflow --- scripts/data/tensorflow.ts | 111 ++++++++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 15 deletions(-) diff --git a/scripts/data/tensorflow.ts b/scripts/data/tensorflow.ts index e1646e1f..71cc0787 100644 --- a/scripts/data/tensorflow.ts +++ b/scripts/data/tensorflow.ts @@ -28,12 +28,11 @@ def _is_known_loaded_type(f, module_name, entity_name): if isinstance(f.__func__, type_entity): return True return False -` +`, }, { path: "/tensorflow/python/framework/combinations.py", - code: - ` + code: ` class EagerGraphCombination(test_combinations.TestCombination): """ The optional \`mode\` parameter controls the test's execution mode. Its @@ -64,12 +63,11 @@ class TFVersionCombination(test_combinations.TestCombination): elif tf_api_version == 2 and not tf2.enabled(): return (False, "Skipping a TF2 test when TF2 is not enabled.") return (True, None) -` +`, }, { path: "/tensorflow/core/kernels/linalg/determinant_op.cc", - code: - ` + code: ` namespace tensorflow { template static typename Eigen::NumTraits::Real SLogDet( @@ -96,12 +94,11 @@ namespace tensorflow { return log_abs_det; } } -` +`, }, { path: "/tensorflow/core/grappler/graph_topology_view.cc", - code: - ` + code: ` template inline void SortAndRemoveDuplicates(T* v) { std::sort(v->begin(), v->end()); @@ -128,12 +125,11 @@ Status GraphTopologyView::InitializeFromGraph( node_name_to_index_.emplace(node.name(), node_idx); index_to_node_name_.emplace_back(node.name()); } -` +`, }, { path: "/tensorflow/core/common_runtime/gpu/gpu_cudamalloc_allocator.cc", - code: - ` + code: ` void* GPUcudaMallocAllocator::AllocateRaw(size_t alignment, size_t num_bytes) { #ifdef GOOGLE_CUDA // allocate with cudaMalloc @@ -157,7 +153,92 @@ void* GPUcudaMallocAllocator::AllocateRaw(size_t alignment, size_t num_bytes) { return nullptr; #endif // GOOGLE_CUDA } -` - } +`, + }, + { + path: "tensorflow/tensorflow/examples/speech_commands/accuracy_utils.py", + code: ` + def print_accuracy_stats(self): + """Write a human-readable description of the statistics to stdout.""" + if self._how_many_gt == 0: + tf.compat.v1.logging.info('No ground truth yet, {}false positives'.format( + self._how_many_fp)) + else: + any_match_percentage = self._how_many_gt_matched / self._how_many_gt * 100 + correct_match_percentage = self._how_many_c / self._how_many_gt * 100 + wrong_match_percentage = self._how_many_w / self._how_many_gt * 100 + false_positive_percentage = self._how_many_fp / self._how_many_gt * 100 + tf.compat.v1.logging.info( + '{:.1f}% matched, {:.1f}% correct, {:.1f}% wrong, ' + '{:.1f}% false positive'.format(any_match_percentage, + correct_match_percentage, + wrong_match_percentage, + false_positive_percentage)) + `, + }, + { + path: "tensorflow/tensorflow/dtensor/python/accelerator_util.py", + code: ` + global _INITIALIZED_ACCELERATOR_SYSTEM_TYPE + assert context.executing_eagerly() + + if is_initialized(): + raise ValueError( + "Accelerator system has already been initialized. " + "Call tf.experimental.dtensor.shutdown_accelerator_system() first.") + + if experimental_reset_context: + logging.warn( + "experimental_reset_context is True. " + "Resetting TensorFlow context. Existing TensorFlow objects " + "(e.g. Tensors and resources) are invalidated." + ) + context.context().ensure_uninitialized() # pylint: disable=protected-access + + if context.context()._initialized: # pylint: disable=protected-access + raise ValueError( + "TensorFlow has already been initialized. " + "tf.experimental.dtensor.initialize_accelerator_system() must be " + "called before TensorFlow is initialized.") + + context.context()._clear_caches() # pylint: disable=protected-access + + if device_type is None: + device_type = config.preferred_device_type() + + device_type = device_type.upper() + if device_type not in {"CPU", "GPU", "TPU"}: + raise ValueError(f"Unknown device_type {device_type}. " + "Allowed values are CPU, GPU, or TPU") + + `, + }, + { + path: "tensorflow/tensorflow/python/framework/auto_control_deps_test.py", + code: ` + class AutomaticControlDependenciesTest(test.TestCase): + + def setUp(self): + super().setUp() + self.must_run_order_insensitive_stateful_ops = ( + acd.MUST_RUN_ORDER_INSENSITIVE_STATEFUL_OPS) + + def tearDown(self): + acd.MUST_RUN_ORDER_INSENSITIVE_STATEFUL_OPS = ( + self.must_run_order_insensitive_stateful_ops) + super().tearDown() + + def testBasic(self): + with context.graph_mode(), self.cached_session(): + v = resource_variable_ops.ResourceVariable(1.0) + self.evaluate(variables.global_variables_initializer()) + with acd.AutomaticControlDependencies() as c: + v.assign(v + 1) + v.assign(2 * v) + val = v.read_value() + val = c.mark_as_return(val) + self.assertAllEqual(val, 4.0) + `, + }, ], -} +}; From 3570c84035bca0a3f4fc7e4ae586e2766d1eefe1 Mon Sep 17 00:00:00 2001 From: Prem Jha Date: Sun, 19 Mar 2023 18:35:48 +0530 Subject: [PATCH 2/2] Removing tensorflow from the path --- scripts/data/tensorflow.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/data/tensorflow.ts b/scripts/data/tensorflow.ts index 71cc0787..d36483f8 100644 --- a/scripts/data/tensorflow.ts +++ b/scripts/data/tensorflow.ts @@ -156,7 +156,7 @@ void* GPUcudaMallocAllocator::AllocateRaw(size_t alignment, size_t num_bytes) { `, }, { - path: "tensorflow/tensorflow/examples/speech_commands/accuracy_utils.py", + path: "tensorflow/examples/speech_commands/accuracy_utils.py", code: ` def print_accuracy_stats(self): """Write a human-readable description of the statistics to stdout.""" @@ -177,7 +177,7 @@ void* GPUcudaMallocAllocator::AllocateRaw(size_t alignment, size_t num_bytes) { `, }, { - path: "tensorflow/tensorflow/dtensor/python/accelerator_util.py", + path: "tensorflow/dtensor/python/accelerator_util.py", code: ` global _INITIALIZED_ACCELERATOR_SYSTEM_TYPE assert context.executing_eagerly() @@ -214,7 +214,7 @@ void* GPUcudaMallocAllocator::AllocateRaw(size_t alignment, size_t num_bytes) { `, }, { - path: "tensorflow/tensorflow/python/framework/auto_control_deps_test.py", + path: "tensorflow/python/framework/auto_control_deps_test.py", code: ` class AutomaticControlDependenciesTest(test.TestCase):