TypeError: Object of type ListConfig is not JSON serializable
I’m encountering an error while working with the peft package. The error occurs when trying to save the pretrained model using the save_pretrained method. Here’s the traceback:File "/pubhome/bozhang/anaconda3/envs/protein_design/lib/python3.8/site-packages/peft/peft_model.py", line 283, in save_pretrained
    peft_config.save_pretrained(output_dir, auto_mapping_dict=auto_mapping_dict)
  File "/pubhome/bozhang/anaconda3/envs/protein_design/lib/python3.8/site-packages/peft/config.py", line 80, in save_pretrained
    writer.write(json.dumps(output_dict, indent=2, sort_keys=True))
  File "/pubhome/bozhang/anaconda3/envs/protein_design/lib/python3.8/json/__init__.py", line 234, in dumps
    return cls(
  File "/pubhome/bozhang/anaconda3/envs/protein_design/lib/python3.8/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/pubhome/bozhang/anaconda3/envs/protein_design/lib/python3.8/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/pubhome/bozhang/anaconda3/envs/protein_design/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/pubhome/bozhang/anaconda3/envs/protein_design/lib/python3.8/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/pubhome/bozhang/anaconda3/envs/protein_design/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ListConfig is not JSON serializableIt seems that there’s an issue with JSON serialization of the ListConfig object in the peft package. Can someone provide guidance on how to resolve this issue? Any help would be greatly appreciated. Thank you!
2024-05-21T13:11:28Z
chatgpt gave me thisimport json
from omegaconf import OmegaConf

# Assuming `config` is your ListConfig object
config = OmegaConf.create(['item1', 'item2', 'item3'])

# Convert to a native Python list
config_list = OmegaConf.to_container(config, resolve=True)

# Now you can serialize it to JSON
json_data = json.dumps(config_list)You only need thisOmegaConf.to_container.
2024-05-21T15:33:30Z
Thanks, I find if I use list(config) this can be fixed too.