Numpy is not available
Author: vpapaioannou
Pull request: no
Labels: name: bug

### System Info

MacOs Sequoia 15.0.1, Python 3.10

Running `pip list`
```
Package                   Version
------------------------- --------------
accelerate                1.2.0
aiohappyeyeballs          2.4.4
aiohttp                   3.11.9
aiosignal                 1.3.1
anyio                     4.6.2.post1
appnope                   0.1.4
argon2-cffi               23.1.0
argon2-cffi-bindings      21.2.0
arrow                     1.3.0
asttokens                 3.0.0
async-lru                 2.0.4
async-timeout             5.0.1
attrs                     24.2.0
babel                     2.16.0
beautifulsoup4            4.12.3
bleach                    6.2.0
certifi                   2024.8.30
cffi                      1.17.1
charset-normalizer        3.4.0
comm                      0.2.2
datasets                  3.1.0
debugpy                   1.8.9
decorator                 5.1.1
defusedxml                0.7.1
dill                      0.3.8
evaluate                  0.4.3
exceptiongroup            1.2.2
executing                 2.1.0
fastjsonschema            2.21.1
filelock                  3.16.1
fqdn                      1.5.1
frozenlist                1.5.0
fsspec                    2024.9.0
h11                       0.14.0
httpcore                  1.0.7
httpx                     0.28.0
huggingface-hub           0.26.3
idna                      3.10
ipykernel                 6.29.5
ipython                   8.30.0
ipywidgets                8.1.5
isoduration               20.11.0
jedi                      0.19.2
Jinja2                    3.1.4
json5                     0.10.0
jsonpointer               3.0.0
jsonschema                4.23.0
jsonschema-specifications 2024.10.1
jupyter                   1.1.1
jupyter_client            8.6.3
jupyter-console           6.6.3
jupyter_core              5.7.2
jupyter-events            0.10.0
jupyter-lsp               2.2.5
jupyter_server            2.14.2
jupyter_server_terminals  0.5.3
jupyterlab                4.3.2
jupyterlab_pygments       0.3.0
jupyterlab_server         2.27.3
jupyterlab_widgets        3.0.13
MarkupSafe                3.0.2
matplotlib-inline         0.1.7
mistune                   3.0.2
mpmath                    1.3.0
multidict                 6.1.0
multiprocess              0.70.16
nbclient                  0.10.1
nbconvert                 7.16.4
nbformat                  5.10.4
nest-asyncio              1.6.0
networkx                  3.4.2
notebook                  7.3.0
notebook_shim             0.2.4
numpy                     2.1.3
overrides                 7.7.0
packaging                 24.2
pandas                    2.2.3
pandocfilters             1.5.1
parso                     0.8.4
pexpect                   4.9.0
pillow                    11.0.0
pip                       24.2
platformdirs              4.3.6
prometheus_client         0.21.1
prompt_toolkit            3.0.48
propcache                 0.2.1
protobuf                  5.29.0
psutil                    6.1.0
ptyprocess                0.7.0
pure_eval                 0.2.3
pyarrow                   18.1.0
pycparser                 2.22
Pygments                  2.18.0
python-dateutil           2.9.0.post0
python-json-logger        2.0.7
pytz                      2024.2
PyYAML                    6.0.2
pyzmq                     26.2.0
referencing               0.35.1
regex                     2024.11.6
requests                  2.32.3
rfc3339-validator         0.1.4
rfc3986-validator         0.1.1
rpds-py                   0.22.3
safetensors               0.4.5
Send2Trash                1.8.3
sentencepiece             0.2.0
setuptools                75.1.0
six                       1.16.0
sniffio                   1.3.1
soupsieve                 2.6
stack-data                0.6.3
sympy                     1.13.3
terminado                 0.18.1
tinycss2                  1.4.0
tokenizers                0.20.3
tomli                     2.2.1
torch                     2.2.2
torchvision               0.17.2
tornado                   6.4.2
tqdm                      4.67.1
traitlets                 5.14.3
transformers              4.46.3
types-python-dateutil     2.9.0.20241003
typing_extensions         4.12.2
tzdata                    2024.2
uri-template              1.3.0
urllib3                   2.2.3
wcwidth                   0.2.13
webcolors                 24.11.1
webencodings              0.5.1
websocket-client          1.8.0
wheel                     0.44.0
widgetsnbextension        4.0.13
xxhash                    3.5.0
yarl                      1.18.3
```

### Who can help?

_No response_

### Information

- [ ] 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

From here, https://huggingface.co/learn/nlp-course/chapter3/3#evaluation, I ran this code,

```
predictions = trainer.predict(tokenized_datasets["validation"])
print(predictions.predictions.shape, predictions.label_ids.shape)
```

and I got this error,
```
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[10], line 1
----> 1 predictions = trainer.predict(tokenized_datasets["validation"])
      2 print(predictions.predictions.shape, predictions.label_ids.shape)

File ~/anaconda3/envs/py10hugface/lib/python3.10/site-packages/transformers/trainer.py:4053, in Trainer.predict(self, test_dataset, ignore_keys, metric_key_prefix)
   4050 start_time = time.time()
   4052 eval_loop = self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
-> 4053 output = eval_loop(
   4054     test_dataloader, description="Prediction", ignore_keys=ignore_keys, metric_key_prefix=metric_key_prefix
   4055 )
   4056 total_batch_size = self.args.eval_batch_size * self.args.world_size
   4057 if f"{metric_key_prefix}_jit_compilation_time" in output.metrics:

File ~/anaconda3/envs/py10hugface/lib/python3.10/site-packages/transformers/trainer.py:4235, in Trainer.evaluation_loop(self, dataloader, description, prediction_loss_only, ignore_keys, metric_key_prefix)
   4232     delattr(self, "_past")
   4234 # Gather all remaining tensors and put them back on the CPU
-> 4235 all_losses = all_losses.get_arrays()
   4236 all_preds = all_preds.get_arrays()
   4237 all_labels = all_labels.get_arrays()

File ~/anaconda3/envs/py10hugface/lib/python3.10/site-packages/transformers/trainer_pt_utils.py:346, in EvalLoopContainer.get_arrays(self)
    344 def get_arrays(self):
    345     """Returns the numpified and moved to CPU stored objects."""
--> 346     self.to_cpu_and_numpy()
    347     return self.arrays

File ~/anaconda3/envs/py10hugface/lib/python3.10/site-packages/transformers/trainer_pt_utils.py:333, in EvalLoopContainer.to_cpu_and_numpy(self)
    330 if self.tensors is None:
    331     return
--> 333 new_arrays = nested_numpify(self.tensors)
    334 if self.arrays is None:
    335     self.arrays = new_arrays

File ~/anaconda3/envs/py10hugface/lib/python3.10/site-packages/transformers/trainer_pt_utils.py:180, in nested_numpify(tensors)
    175 if t.dtype == torch.bfloat16:
    176     # As of Numpy 1.21.4, NumPy does not support bfloat16 (see
    177     # https://github.com/numpy/numpy/blob/a47ecdea856986cd60eabbd53265c2ca5916ad5d/doc/source/user/basics.types.rst ).
    178     # Until Numpy adds bfloat16, we must convert float32.
    179     t = t.to(torch.float32)
--> 180 return t.numpy()

RuntimeError: Numpy is not available
```

### Expected behavior

To see the same output as in the class i.e., `(408, 2) (408,)`

Comments:
Closing as duplicate/related to #35220