question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tensorflow2_gpt2 Slow speed

See original GitHub issue

❓ The speed of pytorch_gpt2 based on transformers is 4-5 times faster than that of tensorflow_gpt2, which is unreasonable. Where is my problem

pytorch_gpt2

tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
model = GPT2LMHeadModel.from_pretrained('gpt2')

model.to(dev)
raw_text_2 = "And if so be ye can descrive what ye bear,"

inputs = tokenizer.encode(raw_text_2, add_special_tokens=False, return_tensors="pt")
inputs = inputs.to(dev)
generated = model.generate(inputs, top_k=0, max_length=512)

tensorflow2_gpt2


tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
model = TFGPT2LMHeadModel.from_pretrained('gpt2')

raw_text = "And if so be ye can descrive what ye bear,"

tokens = tokenizer.encode(raw_text,  return_tensors="tf")
output_ids = model.generate(tokens, top_k = 0, max_length=512)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
only-yaocommented, May 29, 2020

With tf. Varibable model for packaging

    @tf.function(experimental_relax_shapes=True)
    def model_static(self, model_inputs):
        outputs = self(**model_inputs)
        return outputs

0reactions
stale[bot]commented, Aug 2, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is TensorFlow 2 much slower than TensorFlow 1?
Below is code benchmarking performance, TF1 vs. TF2 - with TF1 running anywhere from 47% to 276% faster. My question is: what is...
Read more >
Why is TensorFlow 2 much slower than TensorFlow 1? #33487
Below is code benchmarking performance, TF1 vs. TF2 - with TF1 running anywhere from 47% to 276% faster. My question is: what is...
Read more >
Tensorflow running slower after cuda installation
To avoid using the GPU, and the processing speed is slower than it was prior to the installation of CUDA. Using the commands...
Read more >
[D] Why is TensorFlow so slow? : r/MachineLearning - Reddit
I guess you have access to TPUs if you use TensorFlow but would it bring its speed to the same level as torch...
Read more >
Why is it so slow? | Apple Developer Forums
With tensorflow-metal the performance is 6x slower than pure CPU. Posted 1 year ago by. zhiyufu.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found