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

fields() from DataClasses not working properly #1612

Closed
jebacpogotowietylkobukmozemnieleczyc opened this issue Mar 2, 2021 · 7 comments
Closed

Comments

@jebacpogotowietylkobukmozemnieleczyc
Copy link

jebacpogotowietylkobukmozemnieleczyc commented Mar 2, 2021

Hey I just wanted to ask about strange error I have.
fileds() from dataclasses not working properly if dataclass is declared outside running function.

Minimalistic example:

DataClass in function

from dataclasses import dataclass, fields

import submitit


def run():
    @dataclass
    class Test:
        test: str = "test"
        u: int = 1

    t = Test()
    print(f"Test: {fields(t)}")
    return 1


executor = submitit.AutoExecutor(folder="log_test")
executor.update_parameters(timeout_min=1, slurm_partition="dev")
job = executor.submit(run)
print(job.result())
print(job.stdout())

Print:

Test: (Field(name='test',type=<class 'str'>,default='test',default_factory=<dataclasses._MISSING_TYPE object at 0x7f5bceda6cd0>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), Field(name='u',type=<class 'int'>,default=1,default_factory=<dataclasses._MISSING_TYPE object at 0x7f5bceda6cd0>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD))

DataClass outside function

from dataclasses import dataclass, fields

import submitit

@dataclass
class Test:
    test: str = "test"
    u: int = 1

def run():
    t = Test()
    print(f"Test: {fields(t)}")
    return 1


executor = submitit.AutoExecutor(folder="log_test")
executor.update_parameters(timeout_min=1, slurm_partition="dev")
job = executor.submit(run)
print(job.result())
print(job.stdout())

Print:

Test: ()

The exact same thing happens on slurm cluster with python 3.7.4 and on my local computer without slurm with python 3.9.
Is this submitit or threading issue?

@gwenzek
Copy link
Contributor

gwenzek commented Mar 5, 2021

Hi, thanks for reporting.
Can you tell me which version of submitit and cloudpickle you're using ?

pip show submitit cloudpickle

Your bug sounds related to #30. Make sure you are using at least submitit 1.1.3

@jebacpogotowietylkobukmozemnieleczyc

I'm using the submitit 1.2.1 and cloudpickle 1.6.0. It doesn't matter which version of submitit or python I use, it always ends the same way.

@jebacpogotowietylkobukmozemnieleczyc

But it seems the problem comes from cloudpickle cloudpipe/cloudpickle#386.

@gwenzek
Copy link
Contributor

gwenzek commented Mar 9, 2021

I think it should work if you move the dataclass to another file and that you import it.

@jgbos
Copy link

jgbos commented May 18, 2021

Looks like we are all hitting this issue at the same time: facebookresearch/hydra#1621

@gwenzek
Copy link
Contributor

gwenzek commented Mar 2, 2023

closing since this is a cloudpickle / cpython

@gwenzek gwenzek closed this as completed Mar 2, 2023
@ZBB-XD
Copy link

ZBB-XD commented Mar 25, 2024

I'm a bit confused, this is happening for me still. Im using python 3.9.7 that comes with Maya 2023, and it also reproduces in my vanilla 3.12.2 python install. Do we need to go knock on cloudpickles door so that they fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants