facebookresearch / fairseq

Facebook AI Research Sequence-to-Sequence Toolkit written in Python.
MIT License
30.57k stars 6.41k forks source link

Add an `auto_expand` option to `SinusoidalPositionalEmbedding` #5555

Closed MaigoAkisame closed 1 month ago

MaigoAkisame commented 1 month ago

Before submitting

What does this PR do?

In the fairseq SinusoidalPositionalEmbedding module, when the input length exceeds the number of pre-computed embeddings, the embeddings are expanded and written back to the weights field of the module. However, mutating fields of a module can cause subtle bugs in multithreading environments. This diff provides an auto_expand option to SinusoidalPositionalEmbedding to control whether the expanded embeddings are written back to the module. The default is set to True, so the default behavior is not changed. If you encounter bugs in multithreading environments, set auto_expand=False.

PR review

Anyone in the community is free to review the PR once the tests have passed. If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃