Imports in multiline try blocks are not properly ignored when determining the necessary packages for a modeling file
### System Info

- `transformers` version: 4.29.2
- Platform: macOS-13.3.1-arm64-arm-64bit
- Python version: 3.10.11
- Huggingface_hub version: 0.14.1
- Safetensors version: not installed
- PyTorch version (GPU?): 2.0.1 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: N/A
- Using distributed or parallel set-up in script?: N/A

### Who can help?

@sgugger 

### Reproduction

The minimal repro is to just call https://github.com/huggingface/transformers/blob/v4.29.2/src/transformers/dynamic_module_utils.py#L118-L134 on a file that has a multiline try import, e.g.

```
try:
    from package import function
    from package2 import function
except:
    pass
```

and run the `get_imports` function on it. The output will be `['package', 'package2']`, when it should be `[]`

### Expected behavior

Imports in multiline try blocks should be ignored when determining what packages a modeling file requires. I believe https://github.com/huggingface/transformers/blob/ba7054533fa455e8b2dd35feb077e0c7aae646b3/src/transformers/dynamic_module_utils.py#L126 just needs to be modified to include `flags=re.MULTILINE | re.DOTALL`.
I'd make the change myself, but I can't tell where this codepath is tested (implicitly everywhere?), so will leave to a dev more familiar with `transformers` dev process and tests.<|||||>This is the right fix indeed. I don't think that function is tested yet, but you can add a new test file in `tests/utils/` named `test_dynamic_module_utils` with your failing test if you want to go the extra mile.