[cleanup] Offline mode and cache dir from `huggingface_hub` constants + cleanup in `PushToHubMixin`
Author: Wauplin
Pull request: yes

### Offline mode / env variables changes:
- `def offline_mode` helper directly takes its value from `huggingface_hub.constants` without an intermediate `_offline_mode` variable. It looks like it was only useful for testing purposes. In practice it's much better to rely solely on the hfh's one so that if a user monkeypatch it, it will be globally monkeypatched both in huggingface_hub and transformers (and other libraries)
- related to https://github.com/huggingface/transformers/pull/27564, I've removed some deprecated env variables to rely only on `huggingface_hub.constants.HF_HUB_CACHE`. It is not possible anymore to define a cache specific to `transformers` (which is on-purpose^^)
  - `TRANSFORMERS_CACHE`
  - `PYTORCH_TRANSFORMERS_CACHE`
  - `PYTORCH_PRETRAINED_BERT_CACHE`
- updated the offline tests to make them cleaner (use `unittest.patch`, less logging, use `pytest.raises`, etc.)
- updated docs to mention only `HF_HUB_CACHE` / `HF_HOME` / `XDG_CACHE_HOME`
- removed `transformers.utils.hub.torch_cache_home` (not used anywhere)
- removed `transformers.utils.hub.default_cache_path` (not used anywhere but exposed at root)
- removed `transformers.utils.hub.HUGGINGFACE_CO_EXAMPLES_TELEMETRY` (not used anywhere)
- removed `transformers.utils.hub.HUGGINGFACE_CO_PREFIX` (not used anywhere but exposed at root)
- removed `transformers.utils.hub.HUGGINGFACE_CO_RESOLVE_ENDPOINT` (used in some legacy parts and exposed at root, not used anymore)

Basically, **_"do not parse high-level env variables from `transformers`"_.**

---

### `PushToHubMixin` changes

Also some changes in `PushToHubMixin`:
- removed deprecated `organization` and `repo_url` from `PushToHubMixin._create_repo`
- therefore removed `PushToHubMixin._create_repo` entirely (it became just an alias so not worth it)
- removed deprecated `organization` from `PushToHubMixin`
- removed deprecated `repo_path_or_name` from `PushToHubMixin`
- removed `ignore_metadata_errors` from `PushToMixin`. This parameter was added in [#28405](https://github.com/huggingface/transformers/pull/28405) but more as a copy-paste (see [comment](https://github.com/huggingface/transformers/pull/28405/files#r1447436761)) rather than a deliberated decision. In practice if we ignore errors while loading the model card, we won't be able to push the card back to the Hub. Better to fail early here and not provide the option to fail later. (also removed from `create_and_tag_model_card` helper)
- since `push_to_hub` do not use `**kwargs` anymore, remove it from the method signature
- make arguments in `push_to_hub` keyword-only to avoid confusion + reorder them. Only `repo_id` can be positional since it's the main arg. Same as what is done on `huggingface_hub` side.
- removed `use_temp_dir` argument from `push_to_hub`. We now use a tmp dir in all cases
- removed `working_or_temp_dir` helper (not used anymore)


---

### Open questions!

There are a few more things I would like to cleanup as well, either in this PR or a follow-up one. Not 100% sure though as one might disagree with me^^

- [x] IMO `push_to_hub` should not save to a local dir at all. Currently if the model name part of `repo_id` is also a local folder, then the model is saved in it and then pushed to the Hub, unless `use_temp_dir=True` is passed. This logic is super unintuitive in my opinion (and likely related to when we were pushing from a git repo). It also induce some logic to determine which files have been updated (and push only these ones). All in all quite a lot of complexity for little benefit. For the record, the `PyTorchModelHubMixin` always use a tmp dir
    - => Done in this PR :heavy_check_mark: 
- [ ] do we still want to allow saving with `safe_serialization=False`? The v5 release feels a very good opportunity to definitely get rid of non-safetensors serialization. WDYT ? 
    - => yes but future PR
    - tracked in https://github.com/huggingface/transformers/issues/42556#issue-3685706215
- [x] in `push_to_hub(...)` all parameters are positional, meaning that the order counts, meaning it's harder to remove or add a new one. I would strongly suggest to use `*, ` to explicitly require keyword-arguments. This is what we do in `huggingface_hub` and other places of `transformers`. Let's take advantage of v5 to introduce this breaking change?
    - => Done in this PR :heavy_check_mark: 
- [ ] currently `max_shard_size` defaults to 5GB. [Recommendations are now to use <50GB chunks](https://huggingface.co/docs/hub/storage-limits#recommendations) (the recommendation increased a lot since Xet is now the default). Should we increase the default value to e.g. 48GB? (not 50, to avoid having files slightly larger than 50). 
    - => maybe, depends on I/O performances
    - tracked in https://github.com/huggingface/transformers/issues/42555

I'm willing to take care of all of these changes if approved. Sorry to bring this up so late in the release cycle. For some reasons I thought I had already taken a look at this but doesn't seem to be the case^^ Let me know @huggingface/transformers-core-maintainers 

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42391). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

> Thanks @Wauplin!
> 
> 1. IMO `push_to_hub` should not save to a local dir at all. Currently if the model name part of `repo_id` is also a local folder, then the model is saved in it and then pushed to the Hub, unless `use_temp_dir=True` is passed. This logic is super unintuitive in my opinion (and likely related to when we were pushing from a git repo). It also induce some logic to determine which files have been updated (and push only these ones). All in all quite a lot of complexity for little benefit. For the record, the `PyTorchModelHubMixin` always use a tmp dir
>     - => my suggestion is to entirely remove `use_temp_dir` and always use a tmp dir

Yes, this sounds good to me, cc @SunMarc for the trainer


> 2. do we still want to allow saving with `safe_serialization=False`? The v5 release feels a very good opportunity to definitely get rid of non-safetensors serialization. WDYT ? 

Yes, this could be cool! Maybe a bit of work necessary here, so could be cool to land it for RC1 rather than RC0.

> 3. in `push_to_hub(...)` all parameters are positional, meaning that the order counts, meaning it's harder to remove or add a new one. I would strongly suggest to use `*, ` to explicitly require keyword-arguments. This is what we do in `huggingface_hub` and other places of `transformers`. Let's take advantage of v5 to introduce this breaking change?

No problem for me!

> 4. currently `max_shard_size` defaults to 5GB. [Recommendations are now to use <50GB chunks](https://huggingface.co/docs/hub/storage-limits#recommendations) (the recommendation increased a lot since Xet is now the default). Should we increase the default value to e.g. 48GB? (not 50, to avoid having files slightly larger than 50). 

This is the only one I'm not sure about -> have smaller shards means that it's easier to parallelize load from checkpoints. Will let @ArthurZucker complete as he's been working with this quite a bit lately

Thanks for the quick answers! I'll add 1. and 3. to this PR since it's small-ish and quite related.

For 2. (safe serialization), I'll start a new PR later this week.

For 4., I'd rather not touch it for now. Seems like an interesting topic but lower prio + requires investigation.

> Yes, this sounds good to me, cc @SunMarc for the trainer

Happy to have this, not sure we use `use_temp_dir` at all in trainer as we have our own `push_to_hub`. 

Thanks for your feedback @LysandreJik @ArthurZucker @SunMarc ! I've addressed the remaining open questions so PR should now be in a final state for review :) If I see anything new, I'll do it in a separate PR.

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: conditional_detr, convnext, deformable_detr, dit, dpt, glpn, got_ocr2, groupvit, internvl, llama, maskformer

Agreed with @ArthurZucker here! In general it would indeed be very good to increase the size of the shards to a much larger value, to avoid having hundreds of files on big repos, and it's something that was raised previously. But we need to study carefully the implications on loading time and if it's going to impact us positively/negatively!

I have opened:
- https://github.com/huggingface/transformers/issues/42555
- https://github.com/huggingface/transformers/issues/42556


To keep track of the remaining items discussed in this PR.