You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def load_config(stream, *, file=None):
if file is not None:
fpath = str(file)
if fpath.endswith(".toml"):
with config_type("toml"):
return load_config(stream)
elif fpath.endswith(".json"):
with config_type("json"):
return load_config(stream)
elif fpath.endswith(".yaml") or fpath.endswith(".yml"):
with config_type("yaml"):
return load_config(stream)
parser = Options.get_config_type().value
return parser.load_config(stream)
We see that the load function does not pass a file into the load_config function, which would result in load_config processing the stream as a str, not a file stream.
The error message looks like this:
Traceback (most recent call last):
File "{MYPATH}\draccus_check\train.py", line 151, in <module>
main()
File "{MYPATH}\draccus_check\train.py", line 148, in main
train_cfg = draccus.load(TrainConfig, train_cfg.model_cfg_path)
File "{MYPATH}\draccus_check\.venv\lib\site-packages\draccus\cfgparsing.py", line 38, in load
return decode(t, dictionary)
File "{MYPATH}\draccus_check\.venv\lib\site-packages\draccus\parsers\registry_utils.py", line 78, in wrapper
return base_func(*args, **kw)
File "{MYPATH}\draccus_check\.venv\lib\site-packages\draccus\parsers\decoding.py", line 48, in decode
return get_decoding_fn(cls)(raw_value, ()) # type: ignore
File "{MYPATH}\draccus_check\.venv\lib\site-packages\draccus\parsers\decoding.py", line 109, in decode_dataclass
obj_dict: Dict[str, Any] = d.copy()
AttributeError: 'str' object has no attribute 'copy'
In argparsing.py, this is handled by first open the file stream
if config_path is not None:
with open(config_path, "r") as f:
file_args = cfgparsing.load_config(f, file=config_path)
And in my own experiment, I was able to do
with open('config/train/freeze_vision_tower.yaml', "r") as f:
train_cfg = draccus.load(TrainConfig, f)
with both json and yaml config file, and I was able to verify that load indeed overwrites default config settings.
So, do we want to update the documentation or maybe refactor the codebase a bit?
I am happy to open a pull request to work on whichever direction you see fit
The text was updated successfully, but these errors were encountered:
Thank you for this excellent project!
My understanding is that we can use
draccus.load
to load a local yaml/json file to overwrite some dataclass.However, if we see the
draccus.load
defined here, we see thatWe see that the
load
function does not pass a file into theload_config
function, which would result inload_config
processing the stream as a str, not a file stream.The error message looks like this:
In argparsing.py, this is handled by first open the file stream
And in my own experiment, I was able to do
with both json and yaml config file, and I was able to verify that
load
indeed overwrites default config settings.So, do we want to update the documentation or maybe refactor the codebase a bit?
I am happy to open a pull request to work on whichever direction you see fit
The text was updated successfully, but these errors were encountered: