This is an automated email from the ASF dual-hosted git repository.
tqchen 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 0d42dc411d [Refactor] Phrase out python dependency `decorator` (#17661)
0d42dc411d is described below
commit 0d42dc411d8729a97a7d6cc89266da2b50045897
Author: Lei Wang <[email protected]>
AuthorDate: Tue Feb 18 23:30:10 2025 +0800
[Refactor] Phrase out python dependency `decorator` (#17661)
* Refactor decorate function to use functools.wraps
Replace decorator package with functools.wraps for simpler and more
standard function wrapping. This change removes an external dependency and uses
Python's built-in functools module for function decoration.
* Remove decorator package dependency
Remove the decorator package from various installation scripts and
requirements files. This follows the previous refactoring of decorators to use
functools.wraps, eliminating an external dependency and simplifying the
project's package requirements.
* Modify decorate function to support more flexible function wrapping
Update the decorate function to create a wrapper that allows more flexible
function decoration. The new implementation passes the original function as the
first argument to the wrapped function, enabling more dynamic decoration
behavior while maintaining the functools.wraps functionality.
* Remove decorate function and replace with functools.wraps
Remove the custom decorate function from base.py and update multiple files
to use functools.wraps directly. This change eliminates the need for a custom
decorator implementation and simplifies the codebase by leveraging Python's
built-in functools module.
* Remove generic_func.py as upstream did
* Fix dominant issues of decorator
* fix for pickle memoize
---
conda/recipe/meta.yaml | 1 -
docker/Dockerfile.demo_opencl | 2 +-
docker/install/ubuntu2004_install_python_package.sh | 1 -
docker/install/ubuntu_install_python_package.sh | 1 -
docs/install/from_source.rst | 2 +-
python/gen_requirements.py | 2 --
python/tvm/_ffi/base.py | 16 ----------------
python/tvm/contrib/pickle_memoize.py | 9 +++++----
python/tvm/te/tag.py | 9 +++++----
9 files changed, 12 insertions(+), 31 deletions(-)
diff --git a/conda/recipe/meta.yaml b/conda/recipe/meta.yaml
index e7294b71b2..9aa0746a30 100644
--- a/conda/recipe/meta.yaml
+++ b/conda/recipe/meta.yaml
@@ -82,7 +82,6 @@ outputs:
- {{ pin_subpackage(pkg_name + '-libs', exact=True) }}
run:
- python
- - decorator
- psutil
- scipy
- typing_extensions
diff --git a/docker/Dockerfile.demo_opencl b/docker/Dockerfile.demo_opencl
index f7f1ebe200..9112ccc0d8 100644
--- a/docker/Dockerfile.demo_opencl
+++ b/docker/Dockerfile.demo_opencl
@@ -40,7 +40,7 @@ RUN apt-install-and-clear -y apt-utils sudo cmake g++ llvm
git libopenblas-dev
RUN echo "Installing Python"
RUN apt-install-and-clear -y python3-dev python3-pip
-RUN pip3 install setuptools numpy pytest cython decorator scipy tornado psutil
xgboost
+RUN pip3 install setuptools numpy pytest cython scipy tornado psutil xgboost
RUN echo "Installing Jupyter notebook"
RUN pip3 install matplotlib Image "Pillow<7" jupyter[notebook]
diff --git a/docker/install/ubuntu2004_install_python_package.sh
b/docker/install/ubuntu2004_install_python_package.sh
index b79221885d..7bb75f718c 100644
--- a/docker/install/ubuntu2004_install_python_package.sh
+++ b/docker/install/ubuntu2004_install_python_package.sh
@@ -25,7 +25,6 @@ pip3 install --upgrade \
"Pygments>=2.4.0" \
cloudpickle \
cython \
- decorator \
mypy \
numpy==1.21.* \
orderedset \
diff --git a/docker/install/ubuntu_install_python_package.sh
b/docker/install/ubuntu_install_python_package.sh
index ba02b9ffdc..e815c25165 100755
--- a/docker/install/ubuntu_install_python_package.sh
+++ b/docker/install/ubuntu_install_python_package.sh
@@ -25,7 +25,6 @@ pip3 install --upgrade \
"Pygments>=2.4.0" \
cloudpickle \
cython \
- decorator \
mypy \
numpy==1.21.* \
orderedset \
diff --git a/docs/install/from_source.rst b/docs/install/from_source.rst
index 86d11e9a1b..cc50f9fec9 100644
--- a/docs/install/from_source.rst
+++ b/docs/install/from_source.rst
@@ -209,7 +209,7 @@ The following commands can be used to install the extra
Python dependencies:
.. code:: bash
- pip3 install numpy decorator
+ pip3 install numpy
* If you want to use RPC Tracker
diff --git a/python/gen_requirements.py b/python/gen_requirements.py
index b5d8a56657..32674e6a65 100644
--- a/python/gen_requirements.py
+++ b/python/gen_requirements.py
@@ -64,7 +64,6 @@ REQUIREMENTS_BY_PIECE: RequirementsByPieceType = [
"Base requirements needed to install tvm",
[
"cloudpickle",
- "decorator",
"ml_dtypes",
"numpy",
"packaging",
@@ -192,7 +191,6 @@ CONSTRAINTS = [
("commonmark", ">=0.7.3"), # From PR #213.
("coremltools", None),
("cpplint", None),
- ("decorator", None),
(
"docutils",
"<0.17",
diff --git a/python/tvm/_ffi/base.py b/python/tvm/_ffi/base.py
index b0a63700b7..263ab0bdb3 100644
--- a/python/tvm/_ffi/base.py
+++ b/python/tvm/_ffi/base.py
@@ -121,22 +121,6 @@ def c_array(ctype, values):
return (ctype * len(values))(*values)
-def decorate(func, fwrapped):
- """A wrapper call of decorator package, differs to call time
-
- Parameters
- ----------
- func : function
- The original function
-
- fwrapped : function
- The wrapped function
- """
- import decorator
-
- return decorator.decorate(func, fwrapped)
-
-
# -----------------------------------------
# Base code for structured error handling.
# -----------------------------------------
diff --git a/python/tvm/contrib/pickle_memoize.py
b/python/tvm/contrib/pickle_memoize.py
index 4f3aff8fb5..72efb80643 100644
--- a/python/tvm/contrib/pickle_memoize.py
+++ b/python/tvm/contrib/pickle_memoize.py
@@ -22,7 +22,7 @@ import os
import pathlib
import sys
-from decorator import decorate
+import functools
from .._ffi.base import string_types
try:
@@ -123,7 +123,8 @@ def memoize(key, save_at_exit=False):
cargs = tuple(x.cell_contents for x in f.__closure__) if f.__closure__
else ()
cargs = (len(cargs),) + cargs
- def _memoized_f(func, *args, **kwargs):
+ @functools.wraps(f)
+ def _memoized_f(*args, **kwargs):
assert not kwargs, "Only allow positional call"
key = cargs + args
for arg in key:
@@ -134,11 +135,11 @@ def memoize(key, save_at_exit=False):
assert isinstance(arg, allow_types)
if key in cache.cache:
return cache.cache[key]
- res = func(*args)
+ res = f(*args)
cache.cache[key] = res
cache.dirty = True
return res
- return decorate(f, _memoized_f)
+ return _memoized_f
return _register
diff --git a/python/tvm/te/tag.py b/python/tvm/te/tag.py
index 87a0034400..ec7d3377b0 100644
--- a/python/tvm/te/tag.py
+++ b/python/tvm/te/tag.py
@@ -16,7 +16,7 @@
# under the License.
"""Tag class for TVM operators."""
import warnings
-from tvm._ffi.base import decorate
+import functools
class TagScope(object):
@@ -51,11 +51,12 @@ class TagScope(object):
TagScope._current = self._old_scope
def __call__(self, fdecl):
- def tagged_fdecl(func, *args, **kwargs):
+ @functools.wraps(fdecl)
+ def tagged_fdecl(*args, **kwargs):
with self:
- return func(*args, **kwargs)
+ return fdecl(*args, **kwargs)
- return decorate(fdecl, tagged_fdecl)
+ return tagged_fdecl
def tag_scope(tag):