Gpt2 generation of text larger than 1024
# ❓ Questions & Help

<!-- The GitHub issue tracker is primarly intended for bugs, feature requests,
     new models and benchmarks, and migration questions. For all other questions,
     we direct you to Stack Overflow (SO) where a whole community of PyTorch and
     Tensorflow enthusiast can help you out. Make sure to tag your question with the
     right deep learning framework as well as the huggingface-transformers tag: 
     https://stackoverflow.com/questions/tagged/huggingface-transformers 
     
     If your question wasn't answered after a period of time on Stack Overflow, you
     can always open a question on GitHub. You should then link to the SO question 
     that you posted.
     -->

## Details
<!-- Description of your issue -->

I know the context supported by GPT2 is 1024, but I assume there's some technique they utilized to train and generate text longer than that in their results. Also, I saw many gpt2-based repos training text with length longer than 1024. But when I tried generating text longer than 1024 it throws a runtime error :The size of tensor a (1025) must match the size of tensor b (1024) at non-singleton dimension 3. I have the following questions:
1) Shouldn't it be possible to generate longer text since a sliding window is used?
2) Can you please explain what's necessary to generate longer text? What changes will I have to make to the run_generation.py code?




<!-- You should first ask your question on SO, and only if
     you didn't get an answer ask it here on GitHub. -->


After looking over `modeling_utils.generate` (the function used for generation by `run_generation.py`), I believe that the sliding window approach is not yet implemented.

This method was implemented for CTRL generation in their repo, so you may be able to adapt some of their code for your use case: https://github.com/salesforce/ctrl/blob/master/generation.py#L186-L189<|||||>The iterative approach to generation (using `past`) may work better because you can control the sliding window manually.<|||||>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.
<|||||>@patrickvonplaten @rautnikita77 @minimaxir Has anyone attempted to implement this (using cached keys and values)?