Closed lyriccoder closed 5 years ago
@lyriccoder It looks like you missed optimizer near trainer = Trainer.from_param(...
Define optimizer and pass to the Trainer.from_param
as it was demonstrated in the tutorial.
(EDIT: consider only the next comments, I thought you're using init)
But the config describes the optimizer, doesn't it? Otherwise why do we need the config in this case? The config is passed here:
params = Params.from_file(config_file) trainer = Trainer.from_params(...)
Moreover, if I have a pretrained model, how can I get it's optimizer? I see only _model object in the returned object, I cannot see optimizer. How can I get it form the pretrained model? Cloud you please tell me?
@lyriccoder Okay, so the way you load: params = Params.from_file(config_file)
loads configuration of the run, however, Trainer.from_params
expects only config of the Trainer
module.
Consider passing like Trainer.from_params(..., params=params.get('trainer'), ...)
The problem is that there is not such the parameter(optimizer or trainer) for the _fromparams method: https://github.com/allenai/allennlp/blob/master/allennlp/training/trainer.py (659th line)
@lyriccoder You don't need optimizer
or trainer
parameter for the Trainer.from_params()
.
You need to pass params.get('trainer')
instead of plain params
to Trainer.from_params()
.
@lyriccoder, is there a reason you need to define a custom script for training? We normally just use allennlp train
. See https://github.com/allenai/allennlp/blob/master/tutorials/getting_started/walk_through_allennlp/training_and_evaluating.md.
Yes, @brendan-ai2 there is a serious reason. I am writing an application which whill allow to train different models with different language. There will be a server (tornado or flask). That's why I need only python code. Thanks, @mahnerak I will try it. Also, I need python code for fine-tuning since users will "fine-tune" their models.
Thanks for the help @mahnerak! @lyriccoder, I think you have the info you need, so I'm closing, but feel free to comment again if you run into trouble.
Also, feel free to copy code from our commands if that's helpful, e.g. for fine tuning. See https://github.com/allenai/allennlp/tree/master/allennlp/commands.
I can train or tune not a single model via Python code. I tried different configs, different pretrained models.
To Reproduce
During handling of the above exception, another exception occurred:
Expected behavior Training must begin
System:
Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-229.el7.x86_64 Architecture: x86-64
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit CPU(s): 32 On-line CPU(s) list: 0-31 Thread(s) per core: 2 Core(s) per socket: 8 Socket(s): 2 NUMA node(s): 2 CPU family: 6 Model: 62 Model name: Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz Stepping: 4 CPU MHz: 1207.273 BogoMIPS: 5205.48 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 20480K NUMA node0 CPU(s): 0-7,16-23 NUMA node1 CPU(s): 8-15,24-31
I tried to use both configs:
Also I tried to use the different model: model-2018.12.18.tar.gz. I saw the same error with that model too. Also, I tried to train a model manually with a command-line interface. It was trained successfully. And when I tried to tune it or to train again, I got the above-mentioned error.
Do I make smth wrong?
Here is the code I used:
@schmmd Could you please help? Seems you had the same issue.