# Beam Search without \`model.generate\`

**URL:** <https://discuss.huggingface.co/t/beam-search-without-model-generate/60671>\
**Category:** 🤗Transformers\
**Created:** [November 1, 2023, 7:23am UTC](https://discuss.huggingface.co/t/beam-search-without-model-generate/60671 "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](https://discuss.huggingface.co/u/dipta007)\
**Post date:** [November 1, 2023, 7:23am UTC](https://discuss.huggingface.co/t/beam-search-without-model-generate/60671/1 "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?
