Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numba 0.54.0: unexpected assignment behavior within objmode context. #7356

Closed
BenjaminChoou opened this issue Aug 31, 2021 · 4 comments · Fixed by #7388
Closed

Numba 0.54.0: unexpected assignment behavior within objmode context. #7356

BenjaminChoou opened this issue Aug 31, 2021 · 4 comments · Fixed by #7388
Labels
bug - regression A regression against a previous version of Numba
Milestone

Comments

@BenjaminChoou
Copy link

Reporting a bug

import numba
from numba import objmode


class Test(object):
    a = None

@numba.jit(nopython=True)
def test():
    with objmode():
        Test.a = 100
        print(Test.a)
    
    with objmode():
        print(Test.a)


test()

The above code runs as expected if Numba <= 0.53.1. The expected outputs are:

100
100

However, after update Numba to 0.54.0, the outputs are:

100
None

, which is not consistent with pure python.

@stuartarchibald
Copy link
Contributor

Thanks for the report, I can reproduce.

git bisect suggests:

The first bad commit could be any of:

b9a7fc1
e13d80c
033452b
58c4e32
34db404

We cannot bisect more!

Which are all #6977.

CC @sklam

@stuartarchibald stuartarchibald added the bug - regression A regression against a previous version of Numba label Aug 31, 2021
@stuartarchibald stuartarchibald added this to the Numba 0.54.1 milestone Aug 31, 2021
@sklam
Copy link
Member

sklam commented Sep 7, 2021

I found out that cloudpickle is serializing Test when it is not importable. A class (e.g. Test) is usually importable when it is defined as a global of a module. However, the failing case is when the class is defined in the __main__ module. The cloudpickle code is rejecting to import from __main__ even though it appears to be possible.

Since Test is serialized allow with the code in objmode(), it is creating a fresh Test class everytime.

@sklam
Copy link
Member

sklam commented Sep 7, 2021

The problem is pretty much down to this if-statement in cloudpickle: https://github.com/cloudpipe/cloudpickle/blob/343da119685f622da2d1658ef7b3e2516a01817f/cloudpickle/cloudpickle.py#L300-L301
Why does cloudpickle reject handling __main__? Commenting it out appears to work for this issue.

@sklam
Copy link
Member

sklam commented Sep 8, 2021

Why does cloudpickle reject handling main? Commenting it out appears to work for this issue.

answer: cloudpipe/cloudpickle#131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - regression A regression against a previous version of Numba
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants