Open EthanMarx opened 1 day ago
Thanks for reporting!
I looked at it and the problem is not because of ray's __module__
attribute modification. Can be reproduced with:
from jsonargparse import ArgumentParser
from dataclasses import dataclass
from typing import TYPE_CHECKING, Optional
if TYPE_CHECKING:
from ray.train import SyncConfig
@dataclass
class RunConfig:
name: Optional[str] = None
storage_path: Optional[str] = None
sync_config: Optional["SyncConfig"] = None
parser = ArgumentParser()
parser.add_class_arguments(RunConfig, "run_config")
if __name__ == "__main__":
parser.parse_args()
The problem is the forward ref combined with a dataclass. Since SyncConfig
is imported inside a TYPE_CHECKING
block, this can be fixed. I will look at it later.
But there is a second problem here ay/air/config.py#L652-L654. That is just an invalid type which does not make sense to support. It is just weird that they did that.
Thanks for taking a look at this. Yeah I did notice that invalid type as well. Curious why thats there.
🐛 Bug report
I found an interesting edge case when trying to build out a CLI for the
ray.tune.Tuner
.Not sure if this should be considered a bug on the
jsonargparse
side, or an odd (mis?)use of python flexibility byRay
.The issue stems when trying to build a CLI for the
ray.train.RunConfig
. It is the combination of the following that leads to problems:RunConfig
class definition lives inray.air.config
__module__
attribute of theray.train.RunConfig
import to beray.train
.RunConfig
class usesForwardRefs
(e.g. for theSyncConfig
)Due to the above, the following parser isn't able to add any forward referenced arguments in
RunConfig
Specifically, the
SyncConfig
and other attributes that use forward references aren't able to be resolved, and thus aren't added to the parser:After some debugging, the main issue is that, since the
__module__
attribute has been changed by ray,jsonargparse
can't import the proper objects here when resolving references.Environment