# MBART50 .generate() is very slow

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fmbart50-generate-is-very-slow%2F8551%3E%5C
**Category:** Beginners\
**Created:** [July 21, 2021, 2:20pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fmbart50-generate-is-very-slow%2F8551 "2021-07-21T14:20:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoshi](https://avatars.discourse-cdn.com/v4/letter/y/aeb1de/32.png) [@yoshi](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fyoshi)%5C
**Post date:** [July 21, 2021, 2:20pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fmbart50-generate-is-very-slow%2F8551%2F1 "2021-07-21T14:20:54Z")

</div>

Hello,

I am currently working on the [MBART50 many-to-one](https://huggingface.co/facebook/mbart-large-50-many-to-one-mmt) model for translation. The model takes a really long time to generate the translation. **Is this normal? How can we optimize it?**

I tried in CPU and GPU but both remain slow :

`model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-many-to-one-mmt")`

Inference time in seconds for `model.generate(**input, max_length=max_length)` where `input` is a tokenized string with 1024 tokens :

| max\_length | 8 CPUs | 1 GPU |
| --- | --- | --- |
| 200 | ~38s | ~4s |
| 512 | ~105s | ~11s |
| 750 | ~160s | ~16s |
| 1024 | ~237s | ~22s |

It takes this long just for one string… Doing it in batch does not make it faster 😕. **Any idea what’s wrong or how to optimize?**

Thank you !
