TypeError: Object of type Florence2LanguageConfig is not JSON serializable

#28
by ShravanP - opened

TypeError Traceback (most recent call last)
Cell In[3], line 1
----> 1 model = AutoModelForCausalLM.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True)
2 processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large", trust_remote_code=True)

File ~/anaconda3/envs/hf/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py:456, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
453 if kwargs.get("torch_dtype", None) == "auto":
454 _ = kwargs.pop("torch_dtype")
--> 456 config, kwargs = AutoConfig.from_pretrained(
457 pretrained_model_name_or_path,
458 return_unused_kwargs=True,
459 trust_remote_code=trust_remote_code,
460 **hub_kwargs,
461 **kwargs,
462 )
464 # if torch_dtype=auto was passed here, ensure to pass it on
465 if kwargs_orig.get("torch_dtype", None) == "auto":

File ~/anaconda3/envs/hf/lib/python3.11/site-packages/transformers/models/auto/configuration_auto.py:955, in AutoConfig.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
953 config_class = get_class_from_dynamic_module(class_ref, pretrained_model_name_or_path, **kwargs)
954 _ = kwargs.pop("code_revision", None)
--> 955 return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
956 elif "model_type" in config_dict:
957 config_class = CONFIG_MAPPING[config_dict["model_type"]]

File ~/anaconda3/envs/hf/lib/python3.11/site-packages/transformers/configuration_utils.py:554, in PretrainedConfig.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
548 if "model_type" in config_dict and hasattr(cls, "model_type") and config_dict["model_type"] != cls.model_type:
549 logger.warning(
550 f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
551 f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."
552 )
--> 554 return cls.from_dict(config_dict, **kwargs)

File ~/anaconda3/envs/hf/lib/python3.11/site-packages/transformers/configuration_utils.py:725, in PretrainedConfig.from_dict(cls, config_dict, **kwargs)
722 for key in to_remove:
723 kwargs.pop(key, None)
--> 725 logger.info(f"Model config {config}")
726 if return_unused_kwargs:
727 return config, kwargs

File ~/anaconda3/envs/hf/lib/python3.11/site-packages/transformers/configuration_utils.py:757, in PretrainedConfig.repr(self)
756 def repr(self):
--> 757 return f"{self.class.name} {self.to_json_string()}"

File ~/anaconda3/envs/hf/lib/python3.11/site-packages/transformers/configuration_utils.py:843, in PretrainedConfig.to_json_string(self, use_diff)
841 else:
842 config_dict = self.to_dict()
--> 843 return json.dumps(config_dict, indent=2, sort_keys=True) + "\n"

File ~/anaconda3/envs/hf/lib/python3.11/json/init.py:238, 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/hf/lib/python3.11/json/encoder.py:202, in JSONEncoder.encode(self, o)
200 chunks = self.iterencode(o, _one_shot=True)
201 if not isinstance(chunks, (list, tuple)):
--> 202 chunks = list(chunks)
203 return ''.join(chunks)

File ~/anaconda3/envs/hf/lib/python3.11/json/encoder.py:432, in _make_iterencode.._iterencode(o, _current_indent_level)
430 yield from _iterencode_list(o, _current_indent_level)
431 elif isinstance(o, dict):
--> 432 yield from _iterencode_dict(o, _current_indent_level)
433 else:
434 if markers is not None:

File ~/anaconda3/envs/hf/lib/python3.11/json/encoder.py:406, in _make_iterencode.._iterencode_dict(dct, _current_indent_level)
404 else:
405 chunks = _iterencode(value, _current_indent_level)
--> 406 yield from chunks
407 if newline_indent is not None:
408 _current_indent_level -= 1

File ~/anaconda3/envs/hf/lib/python3.11/json/encoder.py:439, in _make_iterencode.._iterencode(o, _current_indent_level)
437 raise ValueError("Circular reference detected")
438 markers[markerid] = o
--> 439 o = _default(o)
440 yield from _iterencode(o, _current_indent_level)
441 if markers is not None:

File ~/anaconda3/envs/hf/lib/python3.11/json/encoder.py:180, in JSONEncoder.default(self, o)
161 def default(self, o):
162 """Implement this method in a subclass such that it returns
163 a serializable object for o, or calls the base implementation
164 (to raise a TypeError).
(...)
178
179 """
--> 180 raise TypeError(f'Object of type {o.class.name} '
181 f'is not JSON serializable')

TypeError: Object of type Florence2LanguageConfig is not JSON serializable

Same problem here

try: pip install -U transformers

Sign up or log in to comment