transformers/utils/generic.py contains function deprecated in latest PyTorch
Author: rationalism
Pull request: no

### System Info

- `transformers` version: 4.35.2
- Platform: Linux-5.19.0-50-generic-x86_64-with-glibc2.35
- Python version: 3.10.13
- Huggingface_hub version: 0.17.3
- Safetensors version: 0.3.1
- Accelerate version: 0.24.1
- Accelerate config: 	- compute_environment: LOCAL_MACHINE
	- distributed_type: NO
	- mixed_precision: bf16
	- use_cpu: False
	- debug: False
	- num_processes: 1
	- machine_rank: 0
	- num_machines: 1
	- gpu_ids: 0
	- rdzv_backend: static
	- same_network: True
	- main_training_function: main
	- downcast_bf16: no
	- tpu_use_cluster: False
	- tpu_use_sudo: False
	- tpu_env: []
	- dynamo_config: {'dynamo_backend': 'INDUCTOR'}
- PyTorch version (GPU?): 2.2.0.dev20231123+cu121 (True)
- 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?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>


### Who can help?

_No response_

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Run any Transformers code (eg. I just ran `transformers-cli env`) with the latest version of PyTorch (2.2.0.dev20231123+cu121).

### Expected behavior

It should run without warnings. Instead, this warning appears due to a function call having been deprecated. Monkey-patching "_register_pytree_node" with "register_pytree_node" fixes the bug.

/home/alyssa/anaconda3/envs/lm_fun/lib/python3.10/site-packages/transformers/utils/generic.py:441: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.
  _torch_pytree._register_pytree_node(


Comments:
Hey! Thanks for opening this 🤗 
Would be down to update this but we need to make sure we support other versions of `torch` (you are using the latest). 
Would you like to open a PR and makes sure this works on previous versions as well? 

+1

+1

same issue 

#27803 fixes this! Make sure to use the `main` branch

same issue

The issue was fixed. we cannot help you if you don't share a reproducer and make sure that you are using the version that included the PR in the release. 

> The issue was fixed. we cannot help you if you don't share a reproducer and make sure that you are using the version that included the PR in the release.

How can we check what's the minimum version that includes this PR? Thanks.

https://github.com/huggingface/transformers/commit/e6dcf8abd6f65bb4b6dfc1831b20d9ba49ce00e2 here you can check that it is in the latest release for example

Is there a way to just quiet this particular warning ?

Update to the latest transformers release. It's not really generated by `transformers` it's external 

pip install --upgrade transformers

> pip install --upgrade transformers

You are awesome.

> pip install --upgrade transformers

Thank you. It works for me.

> pip install --upgrade transformers

Work for me too

It didn't work for me

It didn't work for me