transformers icon indicating copy to clipboard operation
transformers copied to clipboard

Resize position embeddings in PreTrainedModel

Open PaulLerner opened this issue 1 year ago • 1 comments

Feature request

Add a method to resize position embeddings in PreTrainedModel, in the same way as there is resize_token_embeddings for word embeddings.

There are several ways to do that:

  • retrain everything from scratch
  • keep the pretrained embeddings but add new trained from scratch for the new positions (as done in PreTrainedModel._get_resized_embeddings if I understand correctly)
  • same but initialize new positions by interpolating pretrained ones instead of random init

Motivation

It would be nice to be able to resize position embeddings when the PreTrainedModel has too small max_position_embeddings. I found several related issues:

  • https://stackoverflow.com/questions/69820065/how-to-extend-a-pretrained-transformer-model-configured-with-small-max-position
  • https://github.com/huggingface/transformers/issues/1978

Your contribution

Willing to help :) From what I can tell, most of the job is already done in PreTrainedModel._get_resized_embeddings

PaulLerner avatar Sep 09 '22 09:09 PaulLerner

I have met the same issue.

jack-gits avatar Sep 17 '22 08:09 jack-gits

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

github-actions[bot] avatar Oct 11 '22 15:10 github-actions[bot]

I am also facing the same issue

rhnfzl avatar Jan 23 '23 08:01 rhnfzl

is this issue resolved? Why was it closed? I need to use different size, not, but I can't do it

lyriccoder avatar Mar 02 '23 06:03 lyriccoder

It was closed automatically because no one answered after one month :man_shrugging:

PaulLerner avatar Mar 06 '23 14:03 PaulLerner

They exactly a PR for the same issue, but only for some models. #13559 I think you can modify the resize_position_embeddings in your own model based on the example in this PR.

ImmortalSdm avatar Oct 30 '23 15:10 ImmortalSdm