TrainingArguments now Immutable. Why?
The TrainingArguments class was once mutable after creation. Now it is not:transformers/training_args.pydef __setattr__(self, name, value):
        # Once fully through the `__post_init__`, `TrainingArguments` are immutable
        if not name.startswith("_") and getattr(self, "_frozen", False):
            raise FrozenInstanceError(f"cannot assign to field {name}")
        else:
            super().__setattr__(name, value)I configure the majority of my arguments from the command line, but I dynamically determine the output_dir at runtime. I also have certain scenarios where I need to dynamically adjust the batch size. Now none of this is possible anymore. This is pretty annoying. For now, my workaround isobject.__setattr__(training_args, "output_dir", "foo/bar/")but this is rather annoying.Why was this change made? Does anyone have a better solution?
2023-08-30T00:31:58Z
I am also not fully sure why this change was made.The PR for the change is here:github.com/huggingface/transformersMake training args fully immutablehuggingface:main←huggingface:muellerzr-immutableopened12:44PM - 10 Aug 23 UTCmuellerzr+54-30# What does this PR do?

This PR ensures that the `TrainingArguments` are a fu…lly immutable dataclass after the `__post_init__` has been ran. We'll find that the tests suddenly fail now 😉 Should be merged after https://github.com/huggingface/transformers/pull/25390

## 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](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? 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](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] 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.

@amyeroberts @sguggerThe recommended workaround seems to be to use dataclasses.replace as was doneherefrom dataclasses import replace
...
training_args = replace(training_args, **kwargs_to_set)
...
2023-08-30T02:33:21Z
The TrainingArguments were never meant to be mutable, so if you truly need to change them, the solution there is the right one
2023-08-30T12:51:50Z
Thanks for the dataclasses tip!Is the immutability meant to make multiprocessing safer? Just curious, but I don’t see any reason off the top of my head why this is necessary.
2023-08-30T12:57:05Z
lkurlandski:Just curious, but I don’t see any reason off the top of my head why this is necessary.A design paradigm, users really shouldn’t be messing with these at all, unless under specific circumstances