TypeError: 'NoneType' object is not iterable in ESM when using DDP training
Author: dbleyl
Pull request: no
Labels: name: bug

### System Info

2 machines:

- `transformers` version: 4.52.4
- Platform: Linux-6.14.10-arch1-1-x86_64-with-glibc2.41
- Python version: 3.12.10
- Huggingface_hub version: 0.32.4
- Safetensors version: 0.5.3
- Accelerate version: 1.7.0
- Accelerate config:    - compute_environment: LOCAL_MACHINE
        - distributed_type: MULTI_GPU
        - mixed_precision: bf16
        - use_cpu: False
        - debug: False
        - num_processes: 2
        - machine_rank: 0
        - num_machines: 1
        - gpu_ids: all
        - rdzv_backend: static
        - same_network: True
        - main_training_function: main
        - enable_cpu_affinity: False
        - downcast_bf16: no
        - tpu_use_cluster: False
        - tpu_use_sudo: False
        - tpu_env: []
- DeepSpeed version: not installed
- PyTorch version (GPU?): 2.7.1+cu128 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: yes
- Using GPU in script?: yes, via accelerate command.
- GPU type: NVIDIA GeForce RTX 4060 Ti
- `transformers` version: 4.52.4
- Platform: Linux-6.14.10-arch1-1-x86_64-with-glibc2.41
- Python version: 3.12.10
- Huggingface_hub version: 0.32.4
- Safetensors version: 0.5.3
- Accelerate version: 1.7.0
- Accelerate config:    - compute_environment: LOCAL_MACHINE
        - distributed_type: MULTI_GPU
        - mixed_precision: bf16
        - use_cpu: False
        - debug: False
        - num_processes: 2
        - machine_rank: 0
        - num_machines: 1
        - gpu_ids: all
        - rdzv_backend: static
        - same_network: True
        - main_training_function: main
        - enable_cpu_affinity: False
        - downcast_bf16: no
        - tpu_use_cluster: False
        - tpu_use_sudo: False
        - tpu_env: []
- DeepSpeed version: not installed
- PyTorch version (GPU?): 2.7.1+cu128 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: ddp via accelerate
- Using GPU in script?: yes
- GPU type: NVIDIA GeForce RTX 5090

### Who can help?

@MekkCyber @Cyrilvallez 

### Information

- [ ] The official example scripts
- [x] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [x] My own task or dataset (give details below)

### Reproduction

Just configure accelerate and load an ESM model other than `EsmModel`, such as `EsmForMaskedLM` or `EsmForSequenceClassification` using the `.from_pretrained(...)` syntax.

You will see:

```bash
transformers/modeling_utils.py", line 6031, in caching_allocator_warmup
[rank1]:     re.compile("|".join([re.escape(plan) for plan in model._tp_plan]))
[rank1]:                                                      ^^^^^^^^^^^^^^
[rank1]: TypeError: 'NoneType' object is not iterable
```

The issue is that `EsmModel` calls `post_init` in `__init__` but the other three classes do not.  This is the same problem in [Pull Request 37708](https://github.com/huggingface/transformers/pull/37708), which was rejected for proposing a check instead of fixing the model.

I have prepared a PR for this and ready to submit it.  I believe it follows all the guidelines.  I'm opening this for tracking purposes.

### Expected behavior

`tp_plan` should be initialized by `post_init` and not raise the error reported.  Pull request is ready to be requested.

Comments:
Hi @dbleyl, yes, `post_init()` should be called at the end of `__init__()`. If you can make a PR to fix it, that'd be great!

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](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.