Updated `ruff` to the latest version
Author: Sai-Suraj-27
Pull request: yes

# What does this PR do?
Updated `ruff` to the [latest version](https://github.com/astral-sh/ruff/releases) and fixed the required code according to the latest version.

After updating ruff to the latest version, I ran `make style`, `make quality`, and the following `ruff` rule was failing at few places:
[E721](https://docs.astral.sh/ruff/rules/type-comparison/) (use **is** and **is not** for type comparisons, or **isinstance()** for isinstance checks). So, i fixed them.

Fixes # (issue)


## 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?
@ArthurZucker @amyeroberts 

Comments:
We will have to modify the workflow file around this part

```
  push:
    branches:
      - build_ci_docker_image*
```
in order to trigger the build.

Look `ruff` release history, almost every week there is a release. I am not sure we want to update (so frequently) our `ruff` pin and the corresponding code changes to keep update with it.



> We will have to modify the workflow file around this part
> 
> ```
>   push:
>     branches:
>       - build_ci_docker_image*
> ```
> 
> in order to trigger the build.
> 
> Look `ruff` release history, almost every week there is a release. I am not sure we want to update (so frequently) our `ruff` pin and the corresponding code changes to keep update with it.

Thanks for the review @ydshieh. Yes, ruff is making new releases almost every week. But at the moment we are 8 versions behind the latest release so I thought of making a PR to update it. I think we can update it once every few (2-3) months as required. Also, thanks for the review @ArthurZucker I just updated the PR with this latest [commit](https://github.com/huggingface/transformers/commit/d1a1bcf56aeb8593b9cc613b21422e6311875599) and now, all the `ci tests` are passing. So, I'm not exactly sure what was wrong previously that made few tests fail but after this latest commit they are passing.

Hi @Sai-Suraj-27 Yes, every 2-3 month is reasonable.

This PR itself is still running against `ruff==0.4.4` however, and we still have to build the new images and run CI against the new images first before we merge. 

(that only our team can do)

@ArthurZucker 

CI is green with the new images

https://app.circleci.com/pipelines/github/huggingface/transformers/97697/workflows/3e9c46ec-919b-4941-bf65-73780438ad5e


Once you approved, I will push the images and merge the PR.

> Hi @Sai-Suraj-27 Yes, every 2-3 month is reasonable.
> 
> This PR itself is still running against `ruff==0.4.4` however, and we still have to build the new images and run CI against the new images first before we merge.
> 
> (that only our team can do)


> @ArthurZucker
> 
> CI is green with the new images
> 
> https://app.circleci.com/pipelines/github/huggingface/transformers/97697/workflows/3e9c46ec-919b-4941-bf65-73780438ad5e
> 
> Once you approved, I will push the images and merge the PR.

Hi, @ydshieh. Thanks for the clear explanation and thank you for working on building the new images 👍.

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