Add a clone method for model configs
What does this PR do?
Adding a convenience clone() method to PretrainedConfig that creates a deep copy of the current configuration. Useful to make changes to it without modifying the original.
Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the contributor guideline, Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the forum? Please add a link to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the documentation guidelines, and here are tips on formatting docstrings.
- [ ] Did you write any new necessary tests?
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR.
@sgugger @gante
This is a draft PR. Before working on tests and documentation, I wanted to make sure the change proposed in this PR was welcome.
Guidance on where to add the tests, and what changes to make to the docs would be welcome, too.
@FremyCompany so I can better understand the purpose behind this PR: new_config = copy.deepcopy(config) doesn't work in some settings, right? If so, in which situations?
The following works on my end:
import copy
from transformers import AutoConfig
config = AutoConfig.from_pretrained("gpt2")
new_config = copy.deepcopy(config)
@gante This probably works in most cases, but it requires knowing about this API and I'm not versed enough into the implementation details of deepcopy to guarantee it always works flawlessly. Additionally, whether it works (or not) is probably not backed by tests in the library.
But yeah, I'm mostly suggesting a convenience method, the functionality is not difficult to emulate.