Skip to content

Changing the hashing methodology for cache folder creation of models. #481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

quic-dhirajku
Copy link
Contributor

Detaching hash function for model cache path calculation. changes for QNN compilation not included yet.

Cache folder mechanism has been modified to have a parent directory for a model based on the architecture that we retrieve from the model config. The hash calculation for the ONNX export now incorporates all model kwargs as well as export kwargs and parameters. the parameters that were used to create the hash also gets dumped as a serialized JSON file in the ONNX folder, the same happens for the compile parameters inside the respective qpc folder.

… QNN compilation not included yet.

Cache folder mechanism has been modified to have a parent directory for a model based on the architecture that we retrieve from the model config.
The hash calculation for the ONNX export now incorporates all model kwargs as well as export kwargs and parameters.
the parameters that were used to create the hash also gets dumped as a serialized JSON file in the ONNX folder, the same happens for the compile parameters inside the respective qpc folder.

Signed-off-by: Dhiraj Kumar Sah <[email protected]>
Copy link
Contributor

@ochougul ochougul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review WIP.

@@ -5,7 +5,7 @@
#
# ----------------------------------------------------------------------------

import hashlib
# import hashlib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code.
Make sure that commented code is not there in ready to review PRs.

self.model_params.update(kwargs)
self.model_params["config"] = self.model.config.to_diff_dict()
self.model_params["_transform_names"] = self._transform_names()
self.compile_params = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialize this only when compile is called.
No point in creating this dictionary if user not calling compile.

Comment on lines +54 to +55
self.model_params = {}
self.model_params.update(kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to do self.model_params = copy.deepcopy(kwargs)
This lets other methods mutate kwargs.
Otherwise we would need to ensure that no other method mutates the kwargs.

Comment on lines +148 to +151
if export_kwargs is not None:
self.model_params.update(export_kwargs)
if onnx_transform_kwargs is not None:
self.model_params.update(onnx_transform_kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One liners are better

self.model_params.update(export_kwargs) if export_kwargs is not None else None
self.model_params.update(onnx_transform_kwargs) if export_kwargs is not None else None

Comment on lines +145 to +146
self.model_params["output_names"] = output_names
self.model_params["dynamic_axes"] = dynamic_axes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to keep them in one more level as
self.model_params["export_params"] = export_params
And add all exports params in export_params which is another dict.

Makes the dumped JSON readable by user.

Comment on lines +166 to +176
model_params_json = export_dir / "model_params.json"
with open(model_params_json, "w") as fp:
json.dump(
{
"model_params": [
{k: make_serializable(self.model_params[k]) for k in sorted(self.model_params.keys())}
]
},
fp,
indent=4,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dumping should happen after export.
If model errors out during export and we still dump the json, it does not make sense


self.pretrained_model_name_or_path = kwargs.get("pretrained_model_name_or_path", None)
# self.pretrained_model_name_or_path = kwargs.get("pretrained_model_name_or_path", None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants