TypeError: Object of type Florence2LanguageConfig is not JSON serializable
from transformers import AutoProcessor, AutoModelForCausalLM
7 model_id = '/home/D/wjb/data/Florence-2-base'
----> 8 model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True,revision=True).eval().cuda()
9 processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
File ~/anaconda3/envs/chat/lib/python3.8/site-packages/transformers/models/auto/auto_factory.py:441, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
438 if kwargs_copy.get("torch_dtype", None) == "auto":
439 _ = kwargs_copy.pop("torch_dtype")
--> 441 config, kwargs = AutoConfig.from_pretrained(
442 pretrained_model_name_or_path,
443 return_unused_kwargs=True,
444 trust_remote_code=trust_remote_code,
445 **hub_kwargs,
446 **kwargs_copy,
447 )
448 if hasattr(config, "auto_map") and cls.name in config.auto_map:
449 if not trust_remote_code:
File ~/anaconda3/envs/chat/lib/python3.8/site-packages/transformers/models/auto/configuration_auto.py:935, in AutoConfig.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
931 config_class = get_class_from_dynamic_module(
932 pretrained_model_name_or_path, module_file + ".py", class_name, **kwargs
933 )
934 config_class.register_for_auto_class()
--> 935 return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
936 elif "model_type" in config_dict:
937 config_class = CONFIG_MAPPING[config_dict["model_type"]]
File ~/anaconda3/envs/chat/lib/python3.8/site-packages/transformers/configuration_utils.py:553, in PretrainedConfig.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
547 if "model_type" in config_dict and hasattr(cls, "model_type") and config_dict["model_type"] != cls.model_type:
548 logger.warning(
549 f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
550 f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."
551 )
--> 553 return cls.from_dict(config_dict, **kwargs)
File ~/anaconda3/envs/chat/lib/python3.8/site-packages/transformers/configuration_utils.py:720, in PretrainedConfig.from_dict(cls, config_dict, **kwargs)
717 for key in to_remove:
718 kwargs.pop(key, None)
--> 720 logger.info(f"Model config {config}")
721 if return_unused_kwargs:
722 return config, kwargs
File ~/anaconda3/envs/chat/lib/python3.8/site-packages/transformers/configuration_utils.py:752, in PretrainedConfig.repr(self)
751 def repr(self):
--> 752 return f"{self.class.name} {self.to_json_string()}"
File ~/anaconda3/envs/chat/lib/python3.8/site-packages/transformers/configuration_utils.py:831, in PretrainedConfig.to_json_string(self, use_diff)
829 else:
830 config_dict = self.to_dict()
--> 831 return json.dumps(config_dict, indent=2, sort_keys=True) + "\n"
File ~/anaconda3/envs/chat/lib/python3.8/json/init.py:234, in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
232 if cls is None:
233 cls = JSONEncoder
--> 234 return cls(
235 skipkeys=skipkeys, ensure_ascii=ensure_ascii,
236 check_circular=check_circular, allow_nan=allow_nan, indent=indent,
237 separators=separators, default=default, sort_keys=sort_keys,
238 **kw).encode(obj)
File ~/anaconda3/envs/chat/lib/python3.8/json/encoder.py:201, in JSONEncoder.encode(self, o)
199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
--> 201 chunks = list(chunks)
202 return ''.join(chunks)
File ~/anaconda3/envs/chat/lib/python3.8/json/encoder.py:431, in _make_iterencode.._iterencode(o, _current_indent_level)
429 yield from _iterencode_list(o, _current_indent_level)
430 elif isinstance(o, dict):
--> 431 yield from _iterencode_dict(o, _current_indent_level)
432 else:
433 if markers is not None:
File ~/anaconda3/envs/chat/lib/python3.8/json/encoder.py:405, in _make_iterencode.._iterencode_dict(dct, _current_indent_level)
403 else:
404 chunks = _iterencode(value, _current_indent_level)
--> 405 yield from chunks
406 if newline_indent is not None:
407 _current_indent_level -= 1
File ~/anaconda3/envs/chat/lib/python3.8/json/encoder.py:438, in _make_iterencode.._iterencode(o, _current_indent_level)
436 raise ValueError("Circular reference detected")
437 markers[markerid] = o
--> 438 o = _default(o)
439 yield from _iterencode(o, _current_indent_level)
440 if markers is not None:
File ~/anaconda3/envs/chat/lib/python3.8/json/encoder.py:179, in JSONEncoder.default(self, o)
160 def default(self, o):
161 """Implement this method in a subclass such that it returns
162 a serializable object for o
, or calls the base implementation
163 (to raise a TypeError
).
(...)
177
178 """
--> 179 raise TypeError(f'Object of type {o.class.name} '
180 f'is not JSON serializable')
TypeError: Object of type Florence2LanguageConfig is not JSON serializable
this error occurred when I load model from files.
Me too, did you find a work-around ?
run pip install -U transformers
I am also getting same error, even after pip install -U transformers