Closed MinionAttack closed 2 years ago
@MinionAttack Hi, have you checked that the model you provide is indeed loadable?
>>> AutoModel.from_pretrained('models/Universal_Dependencies/Basque/BDT/Model_berteus-base-cased_1_baseline')
Hi @yzhangcs,
I'm using SuPar from command line but I have tried your code in a terminal with the full path of the model:
(venv) iago@zape:~/Escritorio/SuPar_Pre-finetuning$ python3
Python 3.9.10 (main, Jan 15 2022, 18:56:52)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import supar
>>> from transformers import AutoModel
>>> AutoModel.from_pretrained('/home/iago/Escritorio/SuPar_Pre-finetuning/models/Universal_Dependencies/Basque/BDT/Model_berteus-base-cased_1_baseline')
Traceback (most recent call last):
File "/home/iago/Escritorio/SuPar_Pre-finetuning/venv/lib/python3.9/site-packages/transformers/configuration_utils.py", line 561, in get_config_dict
config_dict = cls._dict_from_json_file(resolved_config_file)
File "/home/iago/Escritorio/SuPar_Pre-finetuning/venv/lib/python3.9/site-packages/transformers/configuration_utils.py", line 650, in _dict_from_json_file
text = reader.read()
File "/usr/lib/python3.9/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/iago/Escritorio/SuPar_Pre-finetuning/venv/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py", line 396, in from_pretrained
config, kwargs = AutoConfig.from_pretrained(
File "/home/iago/Escritorio/SuPar_Pre-finetuning/venv/lib/python3.9/site-packages/transformers/models/auto/configuration_auto.py", line 558, in from_pretrained
config_dict, _ = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
File "/home/iago/Escritorio/SuPar_Pre-finetuning/venv/lib/python3.9/site-packages/transformers/configuration_utils.py", line 583, in get_config_dict
raise EnvironmentError(msg)
OSError: Couldn't reach server at '/home/iago/Escritorio/SuPar_Pre-finetuning/models/Universal_Dependencies/Basque/BDT/Model_berteus-base-cased_1_baseline' to download configuration file or configuration file is not a valid JSON file. Please check network or file content here: /home/iago/Escritorio/SuPar_Pre-finetuning/models/Universal_Dependencies/Basque/BDT/Model_berteus-base-cased_1_baseline.
>>>
And I get the same error, it tries to download it from HugginFace.
For clarification, I'm using: BiaffineSemanticDependencyParser
@MinionAttack Sorry, I misunderstood your question. So let me make some clarifications: what you intend to do is some sort of continual learning, right? Actually in this case, all you need to do is to remove the --build
option, i.e., avoid building the model from scratch, and then keep all other options the same as before.
If you do not wish to reload all well-trained params except BERT, you might need to save BERT params individually (rather than the whole model) to somewhere and then specify --bert
to this path.
@yzhangcs Yes, maybe I did not explain very well... sorry. What I'm trying to do is train a SDP model and save that model, then load that model and train it again but with another train/dev/test files and try to finetune it.
I have removed the --build
parameter and I get the same error. Debugging the code I have found that:
In supar/cmds/biaffine_sdp.py
at line 39 calls parse(parser)
from supar.cmds.cmd.py
and in that method (lines 27 to 29):
if args.mode == 'train':
parser = Parser.load(**args) if args.checkpoint else Parser.build(**args)
parser.train(**args)
Unless I specify the --checkpoint
argument the code will always build the model. Following the code, because I'm using a BiaffineSemanticDependencyParser
instance the build
method is called from supar/parsers/sdp.py
and in the line 221:
if os.path.exists(path) and not args.build:
The path
variable has models/Experiment/Basque/Model_berteus-base-cased_1_finetuned
(the new model I want to save) as value instead of the model models/Universal_Dependencies/Basque/BDT/Model_berteus-base-cased_1_baseline
which it's the one I'm trying to load. Because of that the check fails and the code goes on and the error it's thrown at line 233:
t = AutoTokenizer.from_pretrained(args.bert)
.
Because of this, I'm a bit confuse and I'm not quite sure of understand how SuPar works. Why SuPar tries to load the model to be created during training instead of the one specified with the --bert
parameter? If SuPar tries to load the model from the one to be created during training, where will the model to be created during training be saved?
I apologise in advance if my head is a bit thick and I don't see how to use it properly.
@MinionAttack Thank you for your thoughtful trials, which recalls some details for me.
It seems that my current code is not very well adapted to continual learning.
--checkpoint
is designed to restore the interrupted training process, rather than training the model again.
You might not be able to meet your needs using the code of supar/cmds/biaffine_sdp.py
. I would recommend you to write some scripts yourself to implement:
Parser.build
).parser.model
). I'm sorry if some of my poorly thought out code has confused you.
No problem, thanks for your recommendation! And your code is not bad, it's very good as I was able to trace it very quickly :)
Hi,
I am trying to load a BERT model trained with SuPar but I am not able to do it because it tries to download it from HugginFace and gives an error.
First I train a model using a HugginFace identifier:
And the model it's saved here:
models/Universal_Dependencies/Basque/BDT/Model_berteus-base-cased_1_baseline
So now I want to load that model and train it again to do some experiments:
But all the time it tries to download it from HugginFace instead of loading it from disk.
What I'm doing wrong? I have tried with and without the --build parameter but I get the same result.
How can I load a previously trained model that is on disk?
Regards.