This is an automated email from the ASF dual-hosted git repository.
ruihangl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 410cc2f153 [Docker] Fix ml_dtypes downgrade issue introduced by
TensorFlow (#17691)
410cc2f153 is described below
commit 410cc2f15381effdbc2982b070734150effc80e2
Author: Yong Wu <[email protected]>
AuthorDate: Fri Feb 28 07:52:41 2025 -0800
[Docker] Fix ml_dtypes downgrade issue introduced by TensorFlow (#17691)
The ml_dtypes>=0.5.1 was installed in the install python packages
script, but the tensorflow 2.18 installation later will uninstall the
ml_dtypes and install an old ml_dtypes version 0.4 instead.
(https://ci.tlcpack.ai/blue/rest/organizations/jenkins/pipelines/tvm-docker/branches/main/runs/2062/nodes/50/steps/114/log/?start=0).
We can install ml_dtypes right after tensorflow.
---
docker/install/ubuntu_install_tensorflow.sh | 4 +
python/tvm/contrib/tf_op/__init__.py | 20 -----
python/tvm/contrib/tf_op/module.py | 126 ----------------------------
3 files changed, 4 insertions(+), 146 deletions(-)
diff --git a/docker/install/ubuntu_install_tensorflow.sh
b/docker/install/ubuntu_install_tensorflow.sh
index 45dd2f95dd..48e83ae2ff 100755
--- a/docker/install/ubuntu_install_tensorflow.sh
+++ b/docker/install/ubuntu_install_tensorflow.sh
@@ -23,3 +23,7 @@ set -o pipefail
pip3 install \
keras==3.5.0 \
tensorflow==2.18.0
+
+# tensorflow 2.18.0 requires ml-dtypes<0.5.0,>=0.4.0
+# ml_dtypes needs to be installed after tensorflow
+pip3 install ml_dtypes==0.5.1 --no-deps
diff --git a/python/tvm/contrib/tf_op/__init__.py
b/python/tvm/contrib/tf_op/__init__.py
deleted file mode 100644
index 05d0ecc1dd..0000000000
--- a/python/tvm/contrib/tf_op/__init__.py
+++ /dev/null
@@ -1,20 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you 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.
-"""Module container of TensorFlow TVMDSO op"""
-from . import module
-
-OpModule = module.OpModule
diff --git a/python/tvm/contrib/tf_op/module.py
b/python/tvm/contrib/tf_op/module.py
deleted file mode 100644
index bcff274163..0000000000
--- a/python/tvm/contrib/tf_op/module.py
+++ /dev/null
@@ -1,126 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you 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.
-"""Module container of TensorFlow TVMDSO op"""
-import tensorflow as tf
-from tensorflow.python.framework import load_library
-from tensorflow.python import platform
-
-
-class OpModule:
- """Module container of TensorFlow TVMDSO op which wraps exported
- TVM op implementation library to be called on TensorFlow side"""
-
- def __init__(self, lib_path):
- self.lib_path = lib_path
-
- def func(self, name, output_dtype=None, output_shape=None):
- """Get tvm op function wrapped as TensorFlow tensor to tensor function
-
- Parameters
- ----------
- name: str
- function name
- output_dtype: str or TensorFlow datatype
- Output datatype, default is float32
- output_shape: List of integer/tf scalar tensor or tf shape tensor
- Output shape, default the same with first input's shape
-
- Returns
- ----------
- Func object that acts as TensorFlow tensor to tensor function.
- """
- return TensorFunc(self.lib_path, name, output_dtype, output_shape)
-
- def __getitem__(self, func_name):
- return self.func(func_name)
-
-
-class TensorFunc:
- """Function object that acts as TensorFlow tensor to tensor function."""
-
- def __init__(self, lib_path, func_name, output_dtype, output_shape):
- self.lib_path = lib_path
- self.func_name = func_name
- self.output_dtype = output_dtype
-
- # const(0) indicate invalid dynamic shape
- self.dynamic_output_shape = tf.constant(0, tf.int64)
- self.static_output_shape = None
- self.has_static_output_shape = False # extra flag is required
-
- if self._is_static_shape(output_shape):
- self.static_output_shape = output_shape
- self.has_static_output_shape = True
- elif output_shape is not None:
- self.dynamic_output_shape = self._pack_shape_tensor(output_shape)
-
- self.module = self._load_platform_specific_library("libtvm_dso_op")
- self.tvm_dso_op = self.module.tvm_dso_op
-
- def apply(self, *params):
- return self.tvm_dso_op(
- params,
- dynamic_output_shape=self.dynamic_output_shape,
- static_output_shape=self.static_output_shape,
- has_static_output_shape=self.has_static_output_shape,
- lib_path=self.lib_path,
- func_name=self.func_name,
- output_dtype=self.output_dtype,
- )
-
- def __call__(self, *params):
- return self.apply(*params)
-
- def _load_platform_specific_library(self, lib_name):
- system = platform.system()
- if system == "Darwin":
- lib_file_name = lib_name + ".dylib"
- elif system == "Windows":
- lib_file_name = lib_name + ".dll"
- else:
- lib_file_name = lib_name + ".so"
- return load_library.load_op_library(lib_file_name)
-
- def _is_static_shape(self, shape):
- if shape is None or not isinstance(shape, list):
- return False
- for dim_value in shape:
- if not isinstance(dim_value, int):
- return False
- if dim_value < 0:
- raise Exception(f"Negative dimension is illegal: {dim_value}")
- return True
-
- def _pack_shape_tensor(self, shape):
- if isinstance(shape, tf.Tensor):
- if shape.dtype == tf.int32:
- shape = tf.cast(shape, tf.int64)
- elif isinstance(shape, list):
- shape_dims = []
- for dim_value in shape:
- if isinstance(dim_value, int):
- shape_dims.append(tf.constant(dim_value, tf.int64))
- elif isinstance(dim_value, tf.Tensor) and dim_value.shape.rank
== 0:
- if dim_value.dtype == tf.int32:
- dim_value = tf.cast(dim_value, tf.int64)
- shape_dims.append(dim_value)
- else:
- raise TypeError("Input shape dimension is neither scalar
tensor nor int")
- shape = tf.stack(shape_dims)
- else:
- raise TypeError("Input shape is neither tensor nor list")
- return shape