From de738820c200390d242340c1069fd6b40bcd5dc1 Mon Sep 17 00:00:00 2001 From: poinwater Date: Sat, 9 Sep 2023 16:10:53 -0700 Subject: [PATCH] [build]Disable EV build --- tensorflow_recommenders_addons/BUILD | 1 - .../dynamic_embedding/python/ops/tf_patch.py | 25 +-- .../embedding_variable/__init__.py | 5 - .../embedding_variable/python/ops/BUILD | 12 -- .../python/ops/embedding_variable_ops_test.py | 158 ------------------ tools/docker/build_wheel.Dockerfile | 1 + 6 files changed, 8 insertions(+), 194 deletions(-) delete mode 100644 tensorflow_recommenders_addons/embedding_variable/python/ops/embedding_variable_ops_test.py diff --git a/tensorflow_recommenders_addons/BUILD b/tensorflow_recommenders_addons/BUILD index 0c91334e5..e34967c59 100644 --- a/tensorflow_recommenders_addons/BUILD +++ b/tensorflow_recommenders_addons/BUILD @@ -20,7 +20,6 @@ py_library( srcs = glob(["**/*.py"]), deps = [ "//tensorflow_recommenders_addons/dynamic_embedding/python/ops:dynamic_embedding", - "//tensorflow_recommenders_addons/embedding_variable/python:embedding_variable", "//tensorflow_recommenders_addons/utils", ], ) diff --git a/tensorflow_recommenders_addons/dynamic_embedding/python/ops/tf_patch.py b/tensorflow_recommenders_addons/dynamic_embedding/python/ops/tf_patch.py index b852801c4..cb81f21ea 100644 --- a/tensorflow_recommenders_addons/dynamic_embedding/python/ops/tf_patch.py +++ b/tensorflow_recommenders_addons/dynamic_embedding/python/ops/tf_patch.py @@ -16,7 +16,6 @@ """patch on tensorflow""" from tensorflow_recommenders_addons import dynamic_embedding as de -from tensorflow_recommenders_addons import embedding_variable as ev try: from tensorflow.python.keras.initializers import initializers_v2 as kinit2 @@ -133,8 +132,6 @@ def _get_processor(v): if (rvo.is_resource_variable(v) and not v._in_graph_mode): # pylint: disable=protected-access # True if and only if `v` was initialized eagerly. return optimizer._DenseResourceVariableProcessor(v) - if isinstance(v, ev.EmbeddingVariable): - return optimizer._DenseResourceVariableProcessor(v) if v.op.type == "VarHandleOp": return optimizer._DenseResourceVariableProcessor(v) if isinstance(v, variables.Variable): @@ -167,21 +164,13 @@ def _create_slot_var(primary, use_resource = False else: use_resource = None - if isinstance(primary, ev.EmbeddingVariable): - slot = ev.get_variable(scope, - embedding_dim=shape[1:], - initializer=val, - trainable=False, - key_dtype=primary._ktype, - value_dtype=primary.dtype) - else: - slot = variable_scope.get_variable(scope, - initializer=val, - trainable=False, - use_resource=use_resource, - shape=shape, - dtype=dtype, - validate_shape=validate_shape) + slot = variable_scope.get_variable(scope, + initializer=val, + trainable=False, + use_resource=use_resource, + shape=shape, + dtype=dtype, + validate_shape=validate_shape) variable_scope.get_variable_scope().set_partitioner(current_partitioner) # pylint: disable=protected-access diff --git a/tensorflow_recommenders_addons/embedding_variable/__init__.py b/tensorflow_recommenders_addons/embedding_variable/__init__.py index dedf36fbf..e69de29bb 100644 --- a/tensorflow_recommenders_addons/embedding_variable/__init__.py +++ b/tensorflow_recommenders_addons/embedding_variable/__init__.py @@ -1,5 +0,0 @@ -from tensorflow_recommenders_addons.embedding_variable.python.ops.embedding_variable_ops import * -from tensorflow_recommenders_addons.embedding_variable.python.ops.embedding_variable import * -from tensorflow_recommenders_addons.embedding_variable.python.optimizers.gradient_descent import * -from tensorflow_recommenders_addons.embedding_variable.python.optimizers.adagrad import * -from tensorflow_recommenders_addons.embedding_variable.python.optimizers.adam import * diff --git a/tensorflow_recommenders_addons/embedding_variable/python/ops/BUILD b/tensorflow_recommenders_addons/embedding_variable/python/ops/BUILD index 305d8b4dc..7630685aa 100644 --- a/tensorflow_recommenders_addons/embedding_variable/python/ops/BUILD +++ b/tensorflow_recommenders_addons/embedding_variable/python/ops/BUILD @@ -16,15 +16,3 @@ py_library( ], srcs_version = "PY2AND3", ) - -py_test( - name = "embedding_variable_ops_test", - srcs = ["embedding_variable_ops_test.py"], - data = [ - "//tensorflow_recommenders_addons/embedding_variable/core:_ev_ops.so", - ], - srcs_version = "PY2AND3", - deps = [ - "//tensorflow_recommenders_addons", - ], -) diff --git a/tensorflow_recommenders_addons/embedding_variable/python/ops/embedding_variable_ops_test.py b/tensorflow_recommenders_addons/embedding_variable/python/ops/embedding_variable_ops_test.py deleted file mode 100644 index 4a8d64f31..000000000 --- a/tensorflow_recommenders_addons/embedding_variable/python/ops/embedding_variable_ops_test.py +++ /dev/null @@ -1,158 +0,0 @@ -# Copyright 2020 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -# Copyright (c) 2017, Alibaba Inc. -# All right reserved. -# -# Author: Chen Ding -# Created: 2018/03/26 -# Description: -# ============================================================================== -"""Tests for tensorflow_recommenders_addons.python.ops.embedding_variable.""" -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import numpy as np -import os - -import tensorflow as tf - -from tensorflow.python.client import session -from tensorflow.python.framework import errors -from tensorflow.python.framework import ops -from tensorflow.python.framework import test_util -from tensorflow.python.platform import test -from tensorflow.python.ops import string_ops -from tensorflow.python.ops import array_ops -from tensorflow.python.ops import embedding_ops -from tensorflow.python.ops import math_ops -from tensorflow.python.ops import init_ops -from tensorflow.python.ops import nn_ops -from tensorflow.python.ops import partitioned_variables -from tensorflow.python.ops import variable_scope -from tensorflow.python.framework import dtypes -from tensorflow.python.framework import meta_graph -from tensorflow.python.framework import sparse_tensor -from tensorflow.python.training import saver as saver_module -from tensorflow.python.training import training_util -from tensorflow.python.ops import variables -from tensorflow.python.training import checkpoint_utils -from tensorflow.python.saved_model import builder as saved_model_builder -from tensorflow.python.saved_model import loader - -from tensorflow_recommenders_addons.embedding_variable.python.ops import embedding_variable_ops -from tensorflow_recommenders_addons.embedding_variable.python.optimizers import gradient_descent - - -# TODO(Candy.ding): Remove `run_v2_only` after EV is compatible with TF1.x -@test_util.run_all_in_graph_and_eager_modes -class EmbeddingVariableTest(test.TestCase): - - @test_util.run_v2_only() - def testEmbeddingVariableForTypeNotMatch(self): - with self.assertRaises(errors.InvalidArgumentError): - ev = embedding_variable_ops.EmbeddingVariable( - embedding_dim=3, - ktype=dtypes.int32, - initializer=init_ops.ones_initializer(dtypes.float32)) - emb = embedding_ops.embedding_lookup( - ev, math_ops.cast([0, 1, 2, 5, 6, 7], dtypes.int64)) - - @test_util.run_v2_only() - def testEmbeddingVariableForGetShape(self): - ev = embedding_variable_ops.EmbeddingVariable( - embedding_dim=3, initializer=init_ops.ones_initializer(dtypes.float32)) - emb = embedding_ops.embedding_lookup( - ev, math_ops.cast([0, 1, 2, 5, 6, 7], dtypes.int32)) - shape = ev.total_count() - init = variables.global_variables_initializer() - self.assertEqual(None, self.evaluate(init)) - self.evaluate(emb) - self.assertAllEqual([6, 3], self.evaluate(shape)) - - @test_util.run_v2_only() - def testEmbeddingVariableForGeneralConstInitializer(self): - ev = embedding_variable_ops.EmbeddingVariable( - embedding_dim=3, - ktype=dtypes.int64, - initializer=init_ops.ones_initializer(dtypes.float32)) - emb = embedding_ops.embedding_lookup(ev, math_ops.cast([1, 6], - dtypes.int64)) - init = variables.global_variables_initializer() - self.assertEqual(None, self.evaluate(init)) - self.assertAllEqual([[1., 1., 1.]] * 2, self.evaluate(emb)) - - @test_util.run_v2_only() - def testEmbeddingVariableForGradientDescent(self): - ev = embedding_variable_ops.EmbeddingVariable( - embedding_dim=3, - ktype=dtypes.int64, - initializer=init_ops.ones_initializer(dtypes.float32)) - - def loss_fn(ev): - emb = embedding_ops.embedding_lookup( - ev, math_ops.cast([0, 1, 2, 5, 6, 7], dtypes.int64)) - fun = math_ops.multiply(emb, 2.0, name='multiply') - loss = math_ops.reduce_sum(fun, name='reduce_sum') - return loss - - gs = training_util.get_or_create_global_step() - opt = gradient_descent.GradientDescentOptimizer(0.1) - g_v = opt.compute_gradients(lambda: loss_fn(ev), [ev]) - train_op = opt.apply_gradients(g_v) - emb = embedding_ops.embedding_lookup( - ev, math_ops.cast([0, 1, 2, 5, 6, 7], dtypes.int64)) - init = variables.global_variables_initializer() - self.assertEqual(None, self.evaluate(init)) - self.assertEqual(None, self.evaluate(train_op)) - emb_result = self.evaluate(emb) - grad_result = self.evaluate(g_v[0][0]) - for i in range(6): - for j in range(3): - self.assertAlmostEqual(.8, emb_result[i][j], delta=1e-05) - self.assertAlmostEqual(2., grad_result.values[i][j], delta=1e-05) - - @test_util.deprecated_graph_mode_only - @test_util.run_v2_only() - def testEmbeddingVariableForSaveRestore(self): - ev = embedding_variable_ops.EmbeddingVariable( - embedding_dim=2, - initializer=init_ops.random_normal_initializer(), - ktype=dtypes.int64) - var_emb = embedding_ops.embedding_lookup( - ev, math_ops.cast([0, 1, 2], dtypes.int64)) - loss = math_ops.reduce_sum(var_emb) - optimizer = gradient_descent.GradientDescentOptimizer(0.1) - with ops.control_dependencies([var_emb]): - opt = optimizer.minimize(loss) - saver = saver_module.Saver() - init = variables.global_variables_initializer() - with session.Session() as sess: - sess.run([init]) - sess.run([opt, var_emb]) - sess.run([opt, var_emb]) - sess.run([opt, var_emb]) - save = sess.run(var_emb) - saver.save(sess, "ckpt") - with session.Session() as sess: - saver.restore(sess, "ckpt") - restore = sess.run(var_emb) - for i in range(3): - for j in range(2): - self.assertAlmostEqual(save[i][j], restore[i][j], delta=1e-05) - - -if __name__ == "__main__": - test.main() diff --git a/tools/docker/build_wheel.Dockerfile b/tools/docker/build_wheel.Dockerfile index 01c0f4390..d000e4035 100644 --- a/tools/docker/build_wheel.Dockerfile +++ b/tools/docker/build_wheel.Dockerfile @@ -32,6 +32,7 @@ ARG TF_VERSION ARG TF_NAME ARG HOROVOD_VERSION +RUN python -m pip install --upgrade pip RUN python -m pip install --default-timeout=1000 $TF_NAME==$TF_VERSION COPY tools/docker/install/install_horovod.sh /install/