You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using Helsinki-NLP/opus-mt-en-ro in translation task and make it quantized with intel neural compressor(version 1.7).
I would load it from a pre-trained model, fine-tune it, quantize it, then save its state_dict. The issue happens when saving and reloading this quantized version.
When DynamicQuantizedLinear generates keys, nn.quantized.Linear uses this format: model.encoder.layers.0.self_attn.k_proj._packed_params._packed_params
corresponding version=3, but by using trainer.save_model() to save it to version= 1 due to missing _metadata.
it will cause the quantized model reload failed.
For more information about version, you can see here in pytorch repo.
we found that the root cause is to rewrite state_dict in order to ignore keys, resulting in missing _metadata information which related with version choose.
I think your solution is very good, to avoid deleting that _metadata attribute of the state dict, would you like to make a PR out of it, since you found the fix?
Environment info
transformers
version: 4.12.0.dev0Who can help
function: self.model.save_pretrained() in trainer.py @sgugger
root cause: the rewrite state_dict code in modeling_utils.py added by @stas00 in PR(#8737) to ignore keys
Information
I am using
Helsinki-NLP/opus-mt-en-ro
in translation task and make it quantized withintel neural compressor(version 1.7)
.I would load it from a pre-trained model, fine-tune it, quantize it, then save its state_dict. The issue happens when saving and reloading this quantized version.
When DynamicQuantizedLinear generates keys,
nn.quantized.Linear
uses this format:model.encoder.layers.0.self_attn.k_proj._packed_params._packed_params
corresponding version=3, but by using
trainer.save_model()
to save it to version= 1 due to missing _metadata.it will cause the quantized model reload failed.
For more information about version, you can see here in pytorch repo.
we found that the root cause is to rewrite state_dict in order to ignore keys, resulting in missing _metadata information which related with version choose.
code link: https://github.com/huggingface/transformers/blob/master/src/transformers/modeling_utils.py#L1052
To reproduce
Steps to reproduce the behavior:
Helsinki-NLP/opus-mt-en-ro
, fine-tune it, quantize it with dynamic,error
modify
the rewrite state_dict code in modeling_utils.py line 1052.
origin
change
Expected behavior
You can modify it as I mentioned, it will be better if you have a more effective solution.
The text was updated successfully, but these errors were encountered: