Skip to content

Error with serializing configs of efficientnet while pushing model to HF #98

@Sarvesh-Kesharwani

Description

@Sarvesh-Kesharwani

model_name = "efficientnet_b0"

imported_model1.push_to_huggingface(
repo_id=f"unifyai/{model_name}",
config_path = "config.json",
model_path = "model.pkl",
weights_path = "weights.hdf5",
repo_type = "model",
token = "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",
private = False,
revision = None,
commit_message = "adds {model_name} model",
commit_description = "Adding {model_name} model, config(specs), and weights",
create_pr= False,
safe_serialization = False,
push_config = True,
push_model = True,
push_weights = True,
)

Pushing config to Hugging Face...

TypeError Traceback (most recent call last)
Cell In[19], line 3
1 model_name = "efficientnet_b0"
----> 3 imported_model1.push_to_huggingface(
4 repo_id=f"unifyai/{model_name}",
5 config_path = "config.json",
6 model_path = "model.pkl",
7 weights_path = "weights.hdf5",
8 repo_type = "model",
9 token = "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",
10 private = False,
11 revision = None,
12 commit_message = "adds {model_name} model",
13 commit_description = "Adding {model_name} model, config(specs), and weights",
14 create_pr= False,
15 safe_serialization = False,
16 push_config = True,
17 push_model = True,
18 push_weights = True,
19 )

File /opt/conda/lib/python3.10/site-packages/ivy_models/base/model.py:72, in BaseModel.push_to_huggingface(self, repo_id, config_path, model_path, weights_path, repo_type, token, private, revision, commit_message, commit_description, create_pr, safe_serialization, push_config, push_model, push_weights)
70 if push_config:
71 print("Pushing config to Hugging Face...")
---> 72 self.spec.to_json_file()
73 api.upload_file(
74 path_or_fileobj=config_path,
75 repo_id=repo_id,
76 path_in_repo=config_path,
77 repo_type=repo_type,
78 )
79 os.remove(config_path)

File /opt/conda/lib/python3.10/site-packages/ivy_models/base/spec.py:77, in BaseSpec.to_json_file(self, save_directory)
75 os.makedirs(save_directory, exist_ok=True)
76 with open(os.path.join(save_directory, "config.json"), "w") as f:
---> 77 json.dump(self.dict, f)
78 print("Saved to directory:", save_directory)

File /opt/conda/lib/python3.10/json/init.py:179, in dump(obj, fp, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
173 iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
174 check_circular=check_circular, allow_nan=allow_nan, indent=indent,
175 separators=separators,
176 default=default, sort_keys=sort_keys, **kw).iterencode(obj)
177 # could accelerate with writelines in some versions of Python, at
178 # a debuggability cost
--> 179 for chunk in iterable:
180 fp.write(chunk)

File /opt/conda/lib/python3.10/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 /opt/conda/lib/python3.10/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 /opt/conda/lib/python3.10/json/encoder.py:325, in _make_iterencode.._iterencode_list(lst, _current_indent_level)
323 else:
324 chunks = _iterencode(value, _current_indent_level)
--> 325 yield from chunks
326 if newline_indent is not None:
327 _current_indent_level -= 1

File /opt/conda/lib/python3.10/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 /opt/conda/lib/python3.10/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 MBConvConfig is not JSON serializable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions