Why Tensorflow Models are way slower than Pytorch models, for autoregressive modeling?
Hi,I was experimenting with many models include GPT2, T5 etc. But it seems like Tensorflow models are too slow for same type of generation comparing to Tensorflow, whether it is greedy, beam etc .Any specific reasons for this?Thanks
2020-10-02T03:13:57Z
@patrickvonplaten@sguggerFor a simple greedy decoding in gpt2 small tensorflow is taking 7 seconds, while pytorch is taking less than a second.
2020-10-05T15:23:15Z
@lysandre- Can anyone shed some light on this? will be great.
2020-10-05T21:08:04Z
Are you measuring epoch time or total runtime? I have no direct experience with tensorflow but I remember that the set up of the graph might take quite a bit file on TF. you should probably only time the steps themselves and not the set up.
2020-10-06T01:21:12Z
I mean for inference. Here is the snippet. Something is wrong.@thomwolf- Any thoughts? Thanks…image2402×1272 289 KB
2020-10-08T07:08:02Z
Maybe@jpluhas some insights!
2020-10-08T17:46:39Z
I think it is because PyTorch is more awesomeJust had a look at the example code, maybe the.to('cuda')call makes something much more faster
2020-10-09T00:31:56Z
.to(‘cuda’) is there , when I initialised.I expected a technical answer though, why tf is slower for generations.@ huggingface team , which means tensorflow implementation are not suitable for production right as latency is higher. Can we conclude it that way?
2020-10-12T12:43:24Z
Hello!The reason is because for now the TF models are not optimized for NLG, including the generate function, and we don’t recommend to use them for that task in production This is something we are working on, but cannot give you a specific date.
2020-10-13T01:47:01Z
I agree, you have to do a lot more things to optimize it. Especially the caching side.It would be great if there was a warning while using tf generate. Thanks for the most valuable reply here@jplu.
2022-07-25T20:26:32Z
@jplu: Calling .generate on TF models is still a lot slower (upto 80x) compared to PyTorch.  Are the TF models now optimized for NLG? Am I missing something here?