Reduce warning noise caused by Tensor.new_tensor
Author: st81
Pull request: yes

# What does this PR do?

This PR replaces `Tensor.new_tensor()` calls to suppress warning that users cannot address. This allows users to avoid being confused by warnings they cannot act on, making it easier for them to focus on meaningful warnings.

More specifically, when calling the `EncoderDecoderModel` forward method, users see warning like:

```py
from transformers import EncoderDecoderModel, AutoTokenizer

tok = AutoTokenizer.from_pretrained("bert-base-uncased")
model = EncoderDecoderModel.from_encoder_decoder_pretrained("bert-base-uncased", "bert-base-uncased")
model.config.decoder_start_token_id = tok.cls_token_id
model.config.pad_token_id = tok.pad_token_id

src = tok("hello world", return_tensors="pt")
tgt = tok("hi there", return_tensors="pt").input_ids
labels = tgt.clone()
labels[labels == tok.pad_token_id] = -100

out = model(
    input_ids=src["input_ids"],
    attention_mask=src["attention_mask"],
    labels=labels,
)
```

```sh
/home/shutotakahashi/projects/transformers-uv/transformers/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py:453:
UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.detach().clone() or sourceTensor.detach().clone().requires_grad_(True), rather than tensor.new_tensor(sourceTensor).
  decoder_attention_mask = decoder_input_ids.new_tensor(decoder_input_ids != self.config.pad_token_id)
```

This warning is triggered by the use of `Tensor.new_tensor()` in the internal code and cannot be resolved by users.

The fix is functionally equivalent because `new_tensor()` creates a new tensor with the same dtype as the original tensor. Additionally, I think the fixed version is more semantically clear as it explicitly shows that `decoder_attention_mask` is created through tensor comparison followed by type casting.

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

- text models: @ArthurZucker @Cyrilvallez



Comments:
Looks like the test failed due to a timeout while fetching hub objects.  Maybe a retry would solve the failure?

https://app.circleci.com/pipelines/github/huggingface/transformers/150842/workflows/847c2cbf-f38c-445b-8be9-dda96ffc5fc2/jobs/1986440?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-checks-link&utm_content=summary

```sh
`use_fast` is set to `True` but the tokenizer class does not have a fast version.  Falling back to the slow version.
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 101, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 250, in handle_request
    resp = self._pool.handle_request(req)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py", line 256, in handle_request
    raise exc from None
  File "/usr/local/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py", line 236, in handle_request
    response = connection.handle_request(
  File "/usr/local/lib/python3.10/site-packages/httpcore/_sync/connection.py", line 103, in handle_request
    return self._connection.handle_request(request)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_sync/http11.py", line 136, in handle_request
    raise exc
  File "/usr/local/lib/python3.10/site-packages/httpcore/_sync/http11.py", line 106, in handle_request
    ) = self._receive_response_headers(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_sync/http11.py", line 177, in _receive_response_headers
    event = self._receive_event(timeout=timeout)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_sync/http11.py", line 217, in _receive_event
    data = self._network_stream.read(
  File "/usr/local/lib/python3.10/site-packages/httpcore/_backends/sync.py", line 126, in read
    with map_exceptions(exc_map):
  File "/usr/local/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.10/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.ReadTimeout: The read operation timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/root/project/utils/fetch_hub_objects_for_ci.py", line 196, in <module>
    MistralTokenizer.from_hf_hub(repo_id)
  File "/usr/local/lib/python3.10/site-packages/mistral_common/tokens/tokenizers/mistral.py", line 259, in from_hf_hub
    tokenizer_path = download_tokenizer_from_hf_hub(
  File "/usr/local/lib/python3.10/site-packages/mistral_common/tokens/tokenizers/utils.py", line 132, in download_tokenizer_from_hf_hub
    repo_files = hf_api.list_repo_files(repo_id)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 89, in _inner_fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/hf_api.py", line 2920, in list_repo_files
    return [
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/hf_api.py", line 2920, in <listcomp>
    return [
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/hf_api.py", line 3057, in list_repo_tree
    for path_info in paginate(path=tree_url, headers=headers, params={"recursive": recursive, "expand": expand}):
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_pagination.py", line 36, in paginate
    r = session.get(path, params=params, headers=headers)
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1053, in get
    return self.request(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 825, in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 914, in send
    response = self._send_handling_auth(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 942, in _send_handling_auth
    response = self._send_handling_redirects(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 979, in _send_handling_redirects
    response = self._send_single_request(request)
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1014, in _send_single_request
    response = transport.handle_request(request)
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 249, in handle_request
    with map_httpcore_exceptions():
  File "/usr/local/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 118, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout: The read operation timed out

Exited with code exit status 1
```

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

run-slow: encoder_decoder

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