Skip to content

Commit

Permalink
support tf2.16.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jq committed Sep 10, 2024
1 parent 852fa2e commit dddd38b
Show file tree
Hide file tree
Showing 17 changed files with 416 additions and 63 deletions.
1 change: 1 addition & 0 deletions .github/workflows/make_wheel_Linux_x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if [[ "$TF_VERSION" =~ ^2\.(16)\.[0-9]+$ ]] ; then
export BUILD_IMAGE="tfra/nosla-cuda12.3-cudnn8.9-ubuntu20.04-manylinux2014-python$PY_VERSION"
export TF_CUDA_VERSION="12.3"
export TF_CUDNN_VERSION="8.9"
export TF_USE_LEGACY_KERAS=1
elif [[ "$TF_VERSION" =~ ^2\.(15)\.[0-9]+$ ]] ; then
export BUILD_IMAGE="tfra/nosla-cuda12.2-cudnn8.9-ubuntu20.04-manylinux2014-python$PY_VERSION"
export TF_CUDA_VERSION="12.2"
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/make_wheel_Windows_x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ fi

python -m pip install --upgrade protobuf~=$PROTOBUF_VERSION

if [[ "$TF_VERSION" =~ ^2\.(16|17)\.[0-9]+$ ]] ; then
export TF_USE_LEGACY_KERAS=1
fi

bash ./tools/testing/build_and_run_tests.sh

python configure.py
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/make_wheel_macOS_arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ if [[ "$TF_VERSION" == "2.11.0" && ( "$PYTHON_VERSION" == "3.9" || "$PYTHON_VERS
python -m pip install numpy==1.26.4 --force-reinstall
fi

if [[ "$TF_VERSION" =~ ^2\.(16|17)\.[0-9]+$ ]] ; then
export TF_USE_LEGACY_KERAS=1
fi

python configure.py

bazel build \
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/make_wheel_macOS_x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ if [[ "$TF_VERSION" == "2.11.0" && ( "$PYTHON_VERSION" == "3.9" || "$PYTHON_VERS
python -m pip install numpy==1.26.4 --force-reinstall
fi

if [[ "$TF_VERSION" =~ ^2\.(16|17)\.[0-9]+$ ]] ; then
export TF_USE_LEGACY_KERAS=1
fi

python -m pip install tensorflow-io
python -m pip install --upgrade protobuf~=$PROTOBUF_VERSION

Expand Down
36 changes: 29 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
# TODO: add back 'windows-latest' when it can be compiled.
os: ['macos-14', 'macos-12', 'ubuntu-20.04']
py-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
tf-version: ['2.11.0', '2.15.1']
tf-version: ['2.11.0', '2.15.1', '2.16.2']
tf-need-cuda: ['0']
cpu: ['x86', 'arm64']
exclude:
Expand All @@ -55,6 +55,10 @@ jobs:
py-version: '3.7'
- tf-version: '2.15.1'
py-version: '3.8'
- tf-version: '2.16.2'
py-version: '3.7'
- tf-version: '2.16.2'
py-version: '3.8'
- os: 'macos-14'
cpu: 'x86'
- os: 'ubuntu-20.04'
Expand All @@ -77,7 +81,7 @@ jobs:
script: |
const commit_details = await github.git.getCommit({owner: context.repo.owner, repo: context.repo.repo, commit_sha: context.sha});
return commit_details.data.author.date
- if: matrix.tf-version != '2.15.1'
- if: matrix.tf-version < '2.15.1'
shell: bash
run: echo "SKIP_CUSTOM_OP_TESTS=--skip-custom-ops" >> $GITHUB_ENV
- if: github.event_name == 'push'
Expand All @@ -87,6 +91,11 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.py-version }}
- if: matrix.tf-version > '2.15.1'
shell: bash
run: |
export TF_USE_LEGACY_KERAS=1
pip install --default-timeout=1000 tensorflow-estimator tf-keras==2.16.0
- name: Setup Bazel
# Ubuntu bazel is run inside of the docker image
if: matrix.os != 'ubuntu-20.04'
Expand All @@ -111,7 +120,7 @@ jobs:
cond: ${{ matrix.tf-need-cuda == '1' }}
if_true: "gpu"
if_false: "cpu"
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v4
with:
name: ${{ runner.os }}-${{ matrix.py-version }}-tf${{ matrix.tf-version }}-${{ steps.device.outputs.value }}-${{ matrix.cpu }}-wheel
path: wheelhouse
Expand All @@ -123,7 +132,7 @@ jobs:
# TODO: add back 'windows-latest' when it can be compiled.
os: ['ubuntu-20.04']
py-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
tf-version: ['2.11.0', '2.15.1']
tf-version: ['2.11.0', '2.15.1', '2.16.2']
tf-need-cuda: ['1']
cpu: ['x86']
exclude:
Expand All @@ -133,6 +142,10 @@ jobs:
py-version: '3.7'
- tf-version: '2.15.1'
py-version: '3.8'
- tf-version: '2.16.2'
py-version: '3.7'
- tf-version: '2.16.2'
py-version: '3.8'
fail-fast: false
runs-on: [self-hosted, Linux, X64]
steps:
Expand All @@ -145,7 +158,7 @@ jobs:
script: |
const commit_details = await github.git.getCommit({owner: context.repo.owner, repo: context.repo.repo, commit_sha: context.sha});
return commit_details.data.author.date
- if: matrix.tf-version != '2.15.1'
- if: matrix.tf-version < '2.15.1'
shell: bash
run: echo "SKIP_CUSTOM_OP_TESTS=--skip-custom-ops" >> $GITHUB_ENV
- if: github.event_name == 'push'
Expand All @@ -155,6 +168,11 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.py-version }}
- if: matrix.tf-version > '2.15.1'
shell: bash
run: |
export TF_USE_LEGACY_KERAS=1
pip install --default-timeout=1000 tf-keras==2.16.0 tensorflow-estimator
- name: Setup Bazel
# Ubuntu bazel is run inside of the docker image
if: matrix.os != 'ubuntu-20.04'
Expand All @@ -179,7 +197,7 @@ jobs:
cond: ${{ matrix.tf-need-cuda == '1' }}
if_true: "gpu"
if_false: "cpu"
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v4
with:
name: ${{ runner.os }}-${{ matrix.py-version }}-tf${{ matrix.tf-version }}-${{ steps.device.outputs.value }}-${{ matrix.cpu }}-wheel
path: wheelhouse
Expand All @@ -192,7 +210,7 @@ jobs:
# TODO: add back 'Windows' when it can be compiled.
os: ['macOS', 'Linux']
py-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
tf-version: ['2.15.1']
tf-version: ['2.15.1', '2.16.2']
tf-need-cuda: ['0', '1']
cpu: ['x86', 'arm64']
exclude:
Expand All @@ -205,6 +223,10 @@ jobs:
py-version: '3.7'
- tf-version: '2.15.1'
py-version: '3.8'
- tf-version: '2.16.2'
py-version: '3.7'
- tf-version: '2.16.2'
py-version: '3.8'
- os: 'Linux'
cpu: 'arm64'
- os: 'Linux'
Expand Down
4 changes: 2 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_tf_version_integer():
2.4.1 get 2041
2.6.3 get 2063
2.8.3 get 2083
2.15.1 get 2151
get 2151
The 4-digits-string will be passed to C macro to discriminate different
Tensorflow versions.
Expand All @@ -150,7 +150,7 @@ def get_tf_version_integer():
'\nPlease install a TensorFlow on your compiling machine, '
'The compiler needs to know the version of Tensorflow '
'and get TF c++ headers according to the installed TensorFlow. '
'\nNote: Only TensorFlow 2.15.1 2.8.3, 2.6.3, 2.4.1, 1.15.2 are supported.'
'\nNote: Only TensorFlow 2.16.2 2.15.1 2.8.3, 2.6.3, 2.4.1, 1.15.2 are supported.'
)
try:
major, minor, patch = version.split('.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,56 +975,55 @@ def test_table_save_load_local_file_system(self):

del table

try: # only test for tensorflow <= 2.15
def test_table_save_load_local_file_system_for_estimator(self):

def test_table_save_load_local_file_system_for_estimator(self):
def input_fn():
return {"x": constant_op.constant([1], dtype=dtypes.int64)}

def input_fn():
return {"x": constant_op.constant([1], dtype=dtypes.int64)}

def model_fn(features, labels, mode, params):
file_system_saver = de.FileSystemSaver()
embedding = de.get_variable(
name="embedding",
dim=3,
trainable=False,
key_dtype=dtypes.int64,
value_dtype=dtypes.float32,
initializer=-1.0,
kv_creator=de.CuckooHashTableCreator(saver=file_system_saver),
)
lookup = de.embedding_lookup(embedding, features["x"])
upsert = embedding.upsert(features["x"],
constant_op.constant([[1.0, 2.0, 3.0]]))

with ops.control_dependencies([lookup, upsert]):
train_op = state_ops.assign_add(training.get_global_step(), 1)

scaffold = training.Scaffold(
saver=saver.Saver(sharded=True,
max_to_keep=1,
keep_checkpoint_every_n_hours=None,
defer_build=True,
save_relative_paths=True))
est = estimator_lib.EstimatorSpec(mode=mode,
scaffold=scaffold,
loss=constant_op.constant(0.),
train_op=train_op,
predictions=lookup)
return est
def model_fn(features, labels, mode, params):
file_system_saver = de.FileSystemSaver()
embedding = de.get_variable(
name="embedding",
dim=3,
trainable=False,
key_dtype=dtypes.int64,
value_dtype=dtypes.float32,
initializer=-1.0,
kv_creator=de.CuckooHashTableCreator(saver=file_system_saver),
)
lookup = de.embedding_lookup(embedding, features["x"])
upsert = embedding.upsert(features["x"],
constant_op.constant([[1.0, 2.0, 3.0]]))

with ops.control_dependencies([lookup, upsert]):
train_op = state_ops.assign_add(training.get_global_step(), 1)

scaffold = training.Scaffold(
saver=saver.Saver(sharded=True,
max_to_keep=1,
keep_checkpoint_every_n_hours=None,
defer_build=True,
save_relative_paths=True))
est = estimator_lib.EstimatorSpec(mode=mode,
scaffold=scaffold,
loss=constant_op.constant(0.),
train_op=train_op,
predictions=lookup)
return est

save_dir = os.path.join(self.get_temp_dir(), "save_restore")
save_path = os.path.join(tempfile.mkdtemp(prefix=save_dir), "hash")
save_dir = os.path.join(self.get_temp_dir(), "save_restore")
save_path = os.path.join(tempfile.mkdtemp(prefix=save_dir), "hash")

# train and save
# train and save
try: # only test for tensorflow <= 2.15
est = estimator.Estimator(model_fn=model_fn, model_dir=save_path)
est.train(input_fn=input_fn, steps=1)

# restore and predict
predict_results = next(est.predict(input_fn=input_fn))
self.assertAllEqual(predict_results, [1.0, 2.0, 3.0])
except:
pass
except:
pass

def test_save_restore_only_table(self):
if context.executing_eagerly():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,15 @@ def _model_fn(features, labels, mode, params):
predictions=emb,
prediction_hooks=[warm_start_hook])

predictor = tf.estimator.Estimator(model_fn=_model_fn)
predictions = predictor.predict(_input_fn)
pred_vals = []
for pred in predictions:
pred_vals.append(pred)
self.assertAllEqual(pred_vals, val_list)
try: # tf version <= 2.15
predictor = tf.estimator.Estimator(model_fn=_model_fn)
predictions = predictor.predict(_input_fn)
pred_vals = []
for pred in predictions:
pred_vals.append(pred)
self.assertAllEqual(pred_vals, val_list)
except:
pass

def test_warm_start(self):
for num_shards in [1, 3]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_compatible_version(self, mock_get_distribution):
mock_pkg = Mock()
mock_requirement = Mock()
mock_requirement.name = 'tensorflow'
mock_requirement.specs = [('>=', '2.11.0'), ('<=', '2.15.1')]
mock_requirement.specs = [('>=', '2.11.0'), ('<=', '2.16.2')]
mock_pkg.requires.return_value = [mock_requirement]
mock_get_distribution.return_value = mock_pkg
self.assertTrue(abi_is_compatible())
Expand All @@ -26,7 +26,7 @@ def test_incompatible_version_below_range(self, mock_get_distribution):
mock_pkg = Mock()
mock_requirement = Mock()
mock_requirement.name = 'tensorflow'
mock_requirement.specs = [('>=', '2.11.0'), ('<=', '2.15.1')]
mock_requirement.specs = [('>=', '2.11.0'), ('<=', '2.16.2')]
mock_pkg.requires.return_value = [mock_requirement]
mock_get_distribution.return_value = mock_pkg
self.assertFalse(abi_is_compatible())
Expand All @@ -37,7 +37,7 @@ def test_incompatible_version_above_range(self, mock_get_distribution):
mock_pkg = Mock()
mock_requirement = Mock()
mock_requirement.name = 'tensorflow'
mock_requirement.specs = [('>=', '2.11.0'), ('<=', '2.15.1')]
mock_requirement.specs = [('>=', '2.11.0'), ('<=', '2.16.2')]
mock_pkg.requires.return_value = [mock_requirement]
mock_get_distribution.return_value = mock_pkg
self.assertFalse(abi_is_compatible())
Expand All @@ -48,7 +48,7 @@ def test_dev_version(self, mock_get_distribution):
mock_pkg = Mock()
mock_requirement = Mock()
mock_requirement.name = 'tensorflow'
mock_requirement.specs = [('>=', '2.11.0'), ('<=', '2.15.1')]
mock_requirement.specs = [('>=', '2.11.0'), ('<=', '2.16.2')]
mock_pkg.requires.return_value = [mock_requirement]
mock_get_distribution.return_value = mock_pkg
self.assertFalse(abi_is_compatible())
4 changes: 2 additions & 2 deletions tensorflow_recommenders_addons/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def is_arm64():
# Required TensorFlow version [min, max]
if (is_macos() and is_arm64()):
MIN_TF_VERSION = "2.15.1"
MAX_TF_VERSION = "2.15.1"
MAX_TF_VERSION = "2.16.2"
else:
MIN_TF_VERSION = "2.11.0"
MAX_TF_VERSION = "2.15.1"
MAX_TF_VERSION = "2.16.2"

# We follow Semantic Versioning (https://semver.org/)
_MAJOR_VERSION = "0"
Expand Down
2 changes: 1 addition & 1 deletion tools/build_dev_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fi
export TF_NEED_CUDA=1
export TF_NAME='tensorflow'

# if tensorflow version >= 2.6.0 and <= 2.15.9
# if tensorflow version >= 2.6.0 and <= 2.16.9
if [[ "$TF_VERSION" =~ ^2\.(16)\.[0-9]+$ ]] ; then
export BUILD_IMAGE="tfra/nosla-cuda12.3-cudnn8.9-ubuntu20.04-manylinux2014-python$PY_VERSION"
export TF_CUDA_VERSION="12.3"
Expand Down
Loading

0 comments on commit dddd38b

Please sign in to comment.