# Beam Search without \`model.generate\`

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbeam-search-without-model-generate%2F60671%3E%5C
**Category:** 🤗Transformers\
**Created:** [November 1, 2023, 7:23am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbeam-search-without-model-generate%2F60671 "2023-11-01T07:23:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dipta007](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/dipta007/32/20816_2.png) [@dipta007](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdipta007)%5C
**Post date:** [November 1, 2023, 7:23am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbeam-search-without-model-generate%2F60671%2F1 "2023-11-01T07:23:50Z")

</div>

I know there is `model.generate` to use beam search.

But in my case, I am using the `BART` encoder and decoder in a variational autoencoder.  
As there are latent variables inside the autoencoder, I am not directly using the model.

In short,

```python
enc = bart.encoder(input)
latent_var = some_linear_layers(enc)
output = bart.decoder(latent_var)

```

Is there any built-in way to use beam search in my case?
