HF_ENDPOINT value affected in hub.py cached_file
Author: fenglui
Pull request: yes

# What does this PR do?

use os.environ.get("HF_ENDPOINT", HUGGINGFACE_CO_RESOLVE_ENDPOINT) value as endpoint param, so HF_ENDPOINT value will affected when download files using cached_file method

Fixes # (issue)


## Before submitting
- [ ] os.environ["HF_ENDPOINT"]="https://hf-mirror.com" may not affected


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

Comments:
@fenglui What is this PR supposed to fix? Can you show a snippet of code that doesn't work as expected? I'm asking before `hf_hub_download` is already supposed to read the `HF_ENDPOINT` environment variable (see [here](https://github.com/huggingface/huggingface_hub/blob/84d1b31901088e8261131f68323c0bee6b2e2f58/src/huggingface_hub/constants.py#L57)).

> @fenglui What is this PR supposed to fix? Can you show a snippet of code that doesn't work as expected? I'm asking before `hf_hub_download` is already supposed to read the `HF_ENDPOINT` environment variable (see [here](https://github.com/huggingface/huggingface_hub/blob/84d1b31901088e8261131f68323c0bee6b2e2f58/src/huggingface_hub/constants.py#L57)).

Because projects like LLaMA-Factory eg. use cached_file method as a standardalone function to download and load a model
```python
from transformers.utils import cached_file

mapping = cached_file(
    path_or_repo_id = os.path.join(self.eval_args.task_dir, self.eval_args.task),
    filename="mapping.json",
    cache_dir=self.model_args.cache_dir,
    **kwargs
)
```

see "https://github.com/hiyouga/LLaMA-Factory/blob/db6cb2d0e78c1a9cab57f5067dd669ffd82ab20f/src/llmtuner/eval/evaluator.py#L13" 

when user start the 3rd project with bash command “HF_ENDPOINT=https://hf-mirror.com python src/train_web.py --flash_attn”
the user defined var HF_ENDPOINT is still the origin default value.

Reproducing the issue do this：

modify transformers/transformers/utils/hub.py
add the output 

```python
user_agent = http_user_agent(user_agent)
    try:
        # Load from URL or cache if already cached
        # add lines
        print(F"HUGGINGFACE_CO_RESOLVE_ENDPOINT is {HUGGINGFACE_CO_RESOLVE_ENDPOINT}")
        endpoint = os.environ.get("HF_ENDPOINT", HUGGINGFACE_CO_RESOLVE_ENDPOINT)
        print(F"endpoint is {endpoint }")
		
        resolved_file = hf_hub_download(
```

lauch the test project use cached_file method

```bash
git clone --depth 1 git@github.com:hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
conda create -n llama_factory python=3.10
conda activate llama_factory
cd LLaMA-Factory
pip install -r requirements.txt
CUDA_VISIBLE_DEVICES=0  HF_ENDPOINT=https://hf-mirror.com python src/train_web.py
```
and with the ui, load a new model you don't have

with this pr, I think  can fix that. And now with your newly commit, this issue has gone.


> @fenglui What is this PR supposed to fix? Can you show a snippet of code that doesn't work as expected? I'm asking before `hf_hub_download` is already supposed to read the `HF_ENDPOINT` environment variable (see [here](https://github.com/huggingface/huggingface_hub/blob/84d1b31901088e8261131f68323c0bee6b2e2f58/src/huggingface_hub/constants.py#L57)).

a snippet of code saved as test.py

```python
        
from transformers.utils import cached_file

kwargs = {}

mapping = cached_file(
    path_or_repo_id = "Qwen/Qwen-1_8B-Chat",
    filename="mapping.json",
    cache_dir="/root/ML/",
    **kwargs
)

print(mapping)
```

modify transformers/transformers/utils/hub.py
add the output 

```python
user_agent = http_user_agent(user_agent)
    try:
        # Load from URL or cache if already cached
        # add lines
        print(F"HUGGINGFACE_CO_RESOLVE_ENDPOINT is {HUGGINGFACE_CO_RESOLVE_ENDPOINT}") # add break point 
        print(F"endpoint is {endpoint }")
		
        resolved_file = hf_hub_download(
```
bash "HF_ENDPOINT=https://hf-mirror.com python test.py" and debug run the test.py