Can't pickle local object when running official benchmark
Author: ryanrudes
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.11.3
- Platform: macOS-12.5-arm64-arm-64bit
- Python version: 3.8.13
- PyTorch version (GPU?): 1.12.0.post2 (False)
- Tensorflow version (GPU?): 2.9.2 (True)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

### Who can help?

@LysandreJik

### Information

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

### Tasks

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

### Reproduction

```python
from transformers import PyTorchBenchmark, PyTorchBenchmarkArguments

args = PyTorchBenchmarkArguments(models=["bert-base-uncased"], batch_sizes=[8], sequence_lengths=[8, 32, 128, 512])
benchmark = PyTorchBenchmark(args)

results = benchmark.run()
print(results)
```
```
1 / 3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ryanrudes/miniforge3/envs/torch-gpu/lib/python3.8/site-packages/transformers/benchmark/benchmark_utils.py", line 707, in run
    memory, inference_summary = self.inference_memory(model_name, batch_size, sequence_length)
  File "/Users/ryanrudes/miniforge3/envs/torch-gpu/lib/python3.8/site-packages/transformers/benchmark/benchmark_utils.py", line 676, in inference_memory
    return separate_process_wrapper_fn(self._inference_memory, self.args.do_multi_processing)(*args, **kwargs)
  File "/Users/ryanrudes/miniforge3/envs/torch-gpu/lib/python3.8/site-packages/transformers/benchmark/benchmark_utils.py", line 101, in multi_process_func
    p.start()
  File "/Users/ryanrudes/miniforge3/envs/torch-gpu/lib/python3.8/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Users/ryanrudes/miniforge3/envs/torch-gpu/lib/python3.8/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/Users/ryanrudes/miniforge3/envs/torch-gpu/lib/python3.8/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/Users/ryanrudes/miniforge3/envs/torch-gpu/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Users/ryanrudes/miniforge3/envs/torch-gpu/lib/python3.8/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Users/ryanrudes/miniforge3/envs/torch-gpu/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/Users/ryanrudes/miniforge3/envs/torch-gpu/lib/python3.8/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'separate_process_wrapper_fn.<locals>.multi_process_func.<locals>.wrapper_func'
```

### Expected behavior

```
====================       INFERENCE - SPEED - RESULT       ====================
--------------------------------------------------------------------------------
Model Name             Batch Size     Seq Length     Time in s                  
--------------------------------------------------------------------------------
bert-base-uncased          8               8             0.006     
bert-base-uncased          8               32            0.006     
bert-base-uncased          8              128            0.018     
bert-base-uncased          8              512            0.088     
--------------------------------------------------------------------------------

====================      INFERENCE - MEMORY - RESULT       ====================
--------------------------------------------------------------------------------
Model Name             Batch Size     Seq Length    Memory in MB 
--------------------------------------------------------------------------------
bert-base-uncased          8               8             1227
bert-base-uncased          8               32            1281
bert-base-uncased          8              128            1307
bert-base-uncased          8              512            1539
--------------------------------------------------------------------------------

====================        ENVIRONMENT INFORMATION         ====================
...
```

Comments:
Hey @ryanrudes, we're in the process of deprecating and removing benchmarks from the library, so we unfortunately won't be able to help you out on this one.

Understood