OpenNMT / OpenNMT-tf

Neural machine translation and sequence learning using TensorFlow
https://opennmt.net/
MIT License
1.46k stars 392 forks source link

Can I change opennmt-py model to opennmt-tf model? #937

Closed 520jefferson closed 2 years ago

520jefferson commented 2 years ago

I want to do some knowledge distillation. The origin codes is pytorch, I can use it to migrate to opennmt-py code related model, and then transfer to opennmt-tf model. Can I change opennmt-py model to opennmt-tf model?

guillaumekln commented 2 years ago

Why not run the knowledge distillation with OpenNMT-py?

There are no scripts to convert an OpenNMT-py model to OpenNMT-tf. You should manually map the model weights, as done in this issue for example: https://github.com/OpenNMT/OpenNMT-tf/issues/905#issuecomment-982218912.

520jefferson commented 2 years ago

Yes, i will run the knowledge distillation from T5 big model(pytorch codes) to OpenNMT-py model. Becasue the online service model is tf serving (pb file) related system, then i want to change the openNMT-py model to openNMT-tf model(ckpt), then i can do some optimization and convert to pb file on tf model before service launch.

guillaumekln commented 2 years ago

If your serving platform requires a TensorFlow model, you might as well run the distillation training with OpenNMT-tf directly. It should be much easier than trying to convert the model.

I'm closing this issue since the original question has been answered (the conversion is technically possible but is a bit tricky).

520jefferson commented 2 years ago

If the small tf model train and distill, is it easy to transfer the data from tf model to pytorch model when getting the logits of pytorch model ?
I try with the tf.estimator and modify the model_fn and print the features and labels, i get nothing. Then input_fn is a generator, and load data from tf.data.Dataset.from_generator. I try to open tf.enable_eager_execution(), and it doesn't work.