# What does the decoder with past values means

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-does-the-decoder-with-past-values-means%2F21088%3E%5C
**Category:** 🤗Optimum\
**Created:** [August 1, 2022, 9:47am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-does-the-decoder-with-past-values-means%2F21088 "2022-08-01T09:47:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rkoy](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@Rkoy](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FRkoy)%5C
**Post date:** [August 1, 2022, 9:47am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-does-the-decoder-with-past-values-means%2F21088%2F1 "2022-08-01T09:47:41Z")

</div>

> Those three parts consist of the encoder, the “decoder” (which actually consists of the decoder with the language modeling head), and the “decoder” with pre-computed key/values as additional inputs. This specific export comes from the fact that during the first pass, the decoder has no pre-computed key/values hidden-states, while during the rest of the generation past key/values will be used to speed up sequential decoding

Can you explain in detail about what is the difference between he decoder with the LM head and the decoder with the pre-computed the key/values. Both of them seems to be very confusing. Can you please explain it in detail and it is mentioned [here](https://huggingface.co/docs/optimum/v1.3.0/en/onnxruntime/modeling_ort#export-and-inference-of-sequencetosequence-models)

Also would like to know where the decoder\_with\_LM\_Head and decoder\_with\_Past\_head is used during the inference.

---

<div class="post-metadata">

**Author:** ![echarlaix](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/echarlaix/32/21754_2.png) [@echarlaix](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fecharlaix)%5C
**Post date:** [August 5, 2022, 3:38pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-does-the-decoder-with-past-values-means%2F21088%2F2 "2022-08-05T15:38:58Z")

</div>

Hi @Rkoy,

Since [#241](https://github.com/huggingface/optimum/pull/241), we have enabled the possibility to only export one decoder : the latter will not have pre-computed key/values as inputs. This will results in the `past_key_values` to be computed at each generation step. To enable this export you only need to set `use_cache` to `False` when calling the `from_pretrained` method. To speed up decoding by leveraging the key/values hidden-states which have already been computed in the previous generation step, you need to export a second decoder with additional pre-computed key/values as inputs.

---

<div class="post-metadata">

**Author:** ![Rkoy](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@Rkoy](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FRkoy)%5C
**Post date:** [July 7, 2025, 11:06am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fwhat-does-the-decoder-with-past-values-means%2F21088%2F3 "2025-07-07T11:06:34Z")

</div>

thanks @echarlaix
