cjlin1 / libsvm

LIBSVM -- A Library for Support Vector Machines
https://www.csie.ntu.edu.tw/~cjlin/libsvm/
BSD 3-Clause "New" or "Revised" License
4.55k stars 1.64k forks source link

Python libsvm 3.33 crashes due to unexpected argument to jit #218

Open nilfm99 opened 2 months ago

nilfm99 commented 2 months ago

See this build: https://github.com/Netflix/vmaf/actions/runs/10284246506/job/28459862846

Sample test failure:

____________________ ERROR collecting test/doctest_test.py _____________________
test/doctest_test.py:12: in <module>
    from vmaf.core import quality_runner
vmaf/core/quality_runner.py:9: in <module>
    from libsvm import svmutil
.tox/py311/lib/python3.11/site-packages/libsvm/svmutil.py:2: in <module>
    from .svm import *
.tox/py311/lib/python3.11/site-packages/libsvm/svm.py:144: in <module>
    @jit(nopython=True)
E   TypeError: <lambda>() got an unexpected keyword argument 'nopython'

The previous tag, 3.32, does not have this problem. It seems this commit is responsible. One solution could be to modify the "fallback" definition of jit here to take *args and **kwargs and do nothing with them.

advilbn commented 2 months ago

You could also yank the current version 3.33.0 in pypi, that way no one would need to pin/exclude manually this version.

@nilfm99 , in your PR (https://github.com/cjlin1/libsvm/pull/219), you could use a version of the decorator using, functools.wrapps

try:
    from numba import jit
    jit_enabled = True
except:
    from functools import wraps as functools_wraps
 
    def jit(_func=None, *args, **kwargs):
        def decorator_jit(func):
            @functools_wraps(func)
            def wrapper_jit(*args, **kwargs):
                return func(*args, **kwargs)
            return wrapper_jit

        return decorator_jit if _func is None else decorator_jit(_func)
 
    jit_enabled = False
nilfm99 commented 2 months ago

@advilbn I am not a maintainer of this project, but I agree it should be yanked. As it stands, just importing the python code without numba installed breaks.

Regarding the suggested code, I agree it looks better this way and will update it.

cjlin1 commented 2 months ago

We now see the problem and will do a new release as soon as possible

On 2024-08-08 19:58, Nil Fons Miret wrote:

@advilbn [1] I am not a maintainer of this project, but I agree it should be yanked. As it stands, just importing the python code without numba installed breaks.

Regarding the suggested code, I agree it looks better this way and will update it.

-- Reply to this email directly, view it on GitHub [2], or unsubscribe [3]. You are receiving this because you are subscribed to this thread.Message ID: @.> [ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/cjlin1/libsvm/issues/218#issuecomment-2275642079", "url": "https://github.com/cjlin1/libsvm/issues/218#issuecomment-2275642079", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.***": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

Links:

[1] https://github.com/advilbn [2] https://github.com/cjlin1/libsvm/issues/218#issuecomment-2275642079 [3] https://github.com/notifications/unsubscribe-auth/ABI3BHV2OXT7H7TRFKZDZY3ZQNMORAVCNFSM6AAAAABMESKTD2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZVGY2DEMBXHE

advilbn commented 2 months ago

@cjlin1 , Could you also yanked the version 3.33.0 ? As i mentioned before this prevents users or automatic cicd pipelines to fail installing this version. Yanking gives time to not rush patching but providing a good user event/issue experience.

NoteL You could yank the package in the pypi website using you account.

Thank in advances, for all you help on this.

Sinacam commented 2 months ago

@advilbn Version 3.33.0 has been yanked from PyPI, thanks for the reminder.

Sinacam commented 2 months ago

@nilfm99 We are in the process of releasing 3.33.1, and we opted to use the original commit 8802a107 in your PR. functools.wraps seems to be more complicated than necessary for our purpose because jit is never going to be anything other than identity, which doesn't have issues with function attributes. Are there other concerns I missed?

advilbn commented 2 months ago

@Sinacam , please check functools.wraps documentations, https://docs.python.org/3/library/functools.html#functools.wraps. Using it is more a technicality to avoid loosing the name and docstrings when using decorators. the documentation has an example, that illustrates it.

Sinacam commented 2 months ago

@advilbn Yes, I am aware functools.wraps forwards function attributes such as name and docstrings. As mentioned, jit being the identity doesn't suffer from those problems, there isn't a wrapper to begin with. For example

def jit(func=None, *args, **kwargs):
    if func is None:
        return lambda x: x
    else:
        return func

@jit
def f():
    """docstring f"""

@jit(nopython=True)
def g():
    """docstring g"""

print(f.__name__) # f
print(f.__doc__) # docstring f
print(g.__name__) # g
print(g.__doc__) # docstring g

If there are no other concerns, we will proceed as planned.

advilbn commented 2 months ago

@Sinacam , thanks for the explanation and your help on this. No concerns from my end.