noamaanMulla-03/transformers-issues huggingface dataset:
Move usage of deprecated logging.warn to logging.warning
Author: PeterJCLaw
Pull request: yes

The former spelling is deprecated and has been discouraged for a while. The latter spelling seems to be more common in this project anyway, so this change ought to be safe.

Does this project have testing for things like warnings? Or a developer style guide we could add a note to? (Is this worth it?)

Fixes https://github.com/huggingface/transformers/issues/25283

cc @amyeroberts as you commented on the issue.

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Give more memory in test_disk_offload
Author: sgugger
Pull request: yes

# What does this PR do?

Give more memory available in `disk_offload_test` by using the second split (0.7) instead of the first (0.5). I haven't tried all of them, but it seems to fix all the ones I tried. We will know more at the next GPU CI run.

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Generate: get generation mode as an enum
Author: gante
Pull request: yes

# What does this PR do?

Currently, generate gets several `is_XXX_mode` flags, to determine the generation mode. This was cool when there were a handful of generation modes, but now it means we have many variables. This PR replaces that part of the logic by a single variable -- an enum.

In a future PR, I will use the enum to efficiently perform generate kwarg validation and throw informative warnings/exceptions -- for instance, all beam methods (with "beam" in the name) share a large set of restrictions!

Related PR: #24575 

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Agent trying to load remote tools when being offline
Author: Romainlg29
Pull request: no

### System Info

Transformers 4.31
Python 3.11.4
Windows 10

### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Code:

```
import os
os.environ['TRANSFORMERS_OFFLINE'] = '1'

from transformers import LocalAgent, AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-7b-instruct", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-7b-instruct")

agent = LocalAgent(model=model, tokenizer=tokenizer) # Error here

agent.run("my query");
```

Error:

```
Max retries exceeded with url: /api/spaces?author=huggingface-tools
```

### Expected behavior

To not access the remote tools.

Comments:
Hi @Romainlg29 

Could you provide a complete code snippet instead of definitions like `model = ...`. Thanks in advance!

> Hi @Romainlg29
> 
> Could you provide a complete code snippet instead of definitions like `model = ...`. Thanks in advance!

Hi,

It's the following.

```
import os
os.environ['TRANSFORMERS_OFFLINE'] = '1'

from transformers import LocalAgent, AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained("tiiuae/falcon-7b-instruct", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-7b-instruct")

agent = LocalAgent(model=model, tokenizer=tokenizer) # Error here

agent.run("my query");
```

cc our agent @sgugger 😆 

Agents do not work in offline mode since the prompts are fetched online and we have some tools defined on the Hub only.

If not too much work, probably not to try to connect if `os.environ['TRANSFORMERS_OFFLINE'] = '1'` and raise an error directly with a more specific message?

> Agents do not work in offline mode since the prompts are fetched online and we have some tools defined on the Hub only.

Can't we have an offline mode for the agent, where we only load our tools through additional_tools and using a custom prompt ?

@Romainlg29 You can load your tools via `additional_tools`, but the default tools are still loaded. We could add some guards around that in the future to not try to load tools from the Hub in offline mode, but it is not supported now.

Drafted a PR to add this, could you try the PR linked above? I believe it should work in offline mode as long as you have all the necessary models in the cache, and either pass custom prompts or also have the prompts in the cache. It will ignore remote tools.

> Drafted a PR to add this, could you try the PR linked above? I believe it should work in offline mode as long as you have all the necessary models in the cache, and either pass custom prompts or also have the prompts in the cache. It will ignore remote tools.

Ok, I'm going on that.
Add offline mode for agents
Author: sgugger
Pull request: yes

# What does this PR do?

This PR adds a check in the remote tools setup to bypass it when Transformers is in offline mode.
Fixes #25223

Comments:
_The documentation is not available anymore as the PR was closed or merged._

I'm getting an error:

```
ValueError: image-transformation is not implemented on the Hub.
```

It's coming from ```_setup_default_tools``` called from the ```__init__```.

It's because of the for loop that check ```HUGGINGFACE_DEFAULT_TOOLS_FROM_HUB```.

Thanks for the check! Could you try again with the updated branch?

It's working great!
Thank you!
Make `bark` could have tiny model
Author: ydshieh
Pull request: yes

# What does this PR do?

Make `bark` could have tiny model. This is mainly for #24952

cc @ylacombe

Comments:
_The documentation is not available anymore as the PR was closed or merged._

> Hi @ydshieh, many thanks for your help in that matter! Looks great to me, I will implement some actual tests ASAP

I think you already tests in your PR. I will try to merger your PR with my own, see how those tests go and let you know.

> > Hi @ydshieh, many thanks for your help in that matter! Looks great to me, I will implement some actual tests ASAP
> 
> I think you already tests in your PR. I will try to merger your PR with my own, see how those tests go and let you know.

Oh, you mean the `TODO` I put in this PR. Nice, thanks in advance

Going to merge. But `bark` is kind special and the tiny model for it still has some issue.
Document check copies
Author: sgugger
Pull request: yes

# What does this PR do?

This PR document a little bit better how or `Copied from` framework works, adds comments in the actual scripts and rework a bit the test to be better.

In passing I added a feature requested which was to make sure `make fix-copies` took the function definition or the superclass into account: currently it ignore the whole first line, but if we change the signature of a function / the superclass of a class which is copied from, that modification is not propagated (cc @Rocketknight1 who last requested it)

As you can see from the diff, that feature was direly needed... I had to add `BartPreTrainedModel` (right spelling to be consistent with other models) or break multiple copies, and you can see a lot of signatures or copied from statement being fixed.

Comments:
_The documentation is not available anymore as the PR was closed or merged._

Little late but great fix and the diff is really nice too!
[Whisper] Better error message for outdated generation config
Author: sanchit-gandhi
Pull request: yes

# What does this PR do?

Gives a better error message in the case that a user tries using an outdated generation config with the new generation arguments `language` and `task` (as described in https://github.com/huggingface/transformers/issues/25084#issuecomment-1653722724).


Comments:
_The documentation is not available anymore as the PR was closed or merged._
Image-Classification Dataloader Missing Image Key
Author: umarkhalidAI
Pull request: no

### System Info



- `transformers` version: 4.31.0.dev0
- Platform: Linux-5.15.0-1029-azure-x86_64-with-glibc2.31
- Python version: 3.10.10
- Huggingface_hub version: 0.15.1
- Safetensors version: 0.3.1
- PyTorch version (GPU?): 2.0.1+cu117 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
-

### Who can help?

@amyeroberts 
I tried to run the official example of image classification as:  python run_image_classification.py --output_dir output --dataset_name cifar10 --do_train --overwrite_output_dir
![image](https://github.com/huggingface/transformers/assets/46391971/ab2e7a19-b024-4dc7-91c2-a79833492037)


### 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

I just try to run the official image- classification examples. 

### Expected behavior


I was expecting the code to find the image key.

Comments:
This dataset seems to have `img` as key in the dataset.

If you just want to try the script, the official example in the README is

```python
python run_image_classification.py \
    --dataset_name beans \
    --output_dir ./beans_outputs/ \
    --remove_unused_columns False \
    --do_train \
    --do_eval \
    --push_to_hub \
    --push_to_hub_model_id vit-base-beans \
    --learning_rate 2e-5 \
    --num_train_epochs 5 \
    --per_device_train_batch_size 8 \
    --per_device_eval_batch_size 8 \
    --logging_strategy steps \
    --logging_steps 10 \
    --evaluation_strategy epoch \
    --save_strategy epoch \
    --load_best_model_at_end True \
    --save_total_limit 3 \
    --seed 1337
```

> This dataset seems to have `img` as key in the dataset.

That's not the case. In the trained, _remove_unused_columns remove "image" keys


What I am saying is the original dataset has the `img` key, but the script expects `image` key. That is why there is an error. 

If you really want to try `cifar10`, the quick way is to replace `"image"` to `"img"`.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.
CI 🚀 even more
Author: ydshieh
Pull request: yes

# What does this PR do?

A follow up of #25274:

- To reduce `torch_job` reaches `95%` RAM --> with this PR, it reaches only `82%`.
  - Also smaller RAM usage for: `tf_job`: `60%` | `flax_job`: `86%`
- Avoid the non-modeling files being tested redundantly
  - we save the timing for ~ 2 x 8 = 16 min.    

Now, all the jobs of the full suite CI runs < 10 minutes (except the new job `non_modeling_job`, but it takes ~2 min to restore the cache!)

<img width="206" alt="Screenshot 2023-08-03 081339" src="https://github.com/huggingface/transformers/assets/2521628/07a8b1b5-7521-4d8c-8d7e-11b176c427c4">


Comments:
Well, request a review too quickly, sorry, but just a few tiny thing to fix ...

_The documentation is not available anymore as the PR was closed or merged._

OK, fair point. At least a (closed) PR is in the history for reference if we ever need it in  the future. Thanks!

(we will need to keep an eye on the `torch_job` if something strange happens - mostly hanging in a full run: likely an OOM and some workers are killed.)

We can then go back to 6 workers instead of 8 if it happens.
use `pytest_num_workers=8` for `torch_job` and `tf_job`
Author: ydshieh
Pull request: yes

# What does this PR do?

We set `pytest_num_workers` to `3` for `torch_job` and `6` for `tf_job` to avoid OOM. With the recent efforts of reducing model size in CI, we can actually set `pytest_num_workers=8`.

The full suite: all 3 jobs (PT/TF/Flax) 12-15 minutes
(on the latest nightly CI without all PRs merged today: PT: 37 min | TF: 25 min | Flax: 20 min)

The `torch_job` reach 95% of RAM (peak), and `tf_job` is at 80% of RAM. The `torch_job` with `n8` is a bit dangerous, but I think I have a way to further improvement in follow PR(s).




Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25273). All of your documentation changes will be reflected on that endpoint.
loss reduction for `Llama2ForCausalLM.forward`
Author: ain-soph
Pull request: no

### Feature request

In `forward` method, it outputs `loss` when `labels` are provided. But the `loss` shape is always `(1,)` because `reduction='mean'` in CrossEntropy. I wonder if I could pass `reduction='none'` and get a `(batch_size,)` shaped loss tensor.

https://github.com/huggingface/transformers/blob/641adca55832ed9c5648f54dcd8926d67d3511db/src/transformers/models/llama/modeling_llama.py#L837

### Motivation

I'm using this loss for reward-based learning.

### Your contribution

I could make a PR if needed.

Comments:
Hi @ain-soph 

This is not supported. But you can choose `not to pass labels` to the `model forward`, but compute the loss in you own code 🤗 .

@ydshieh Thanks for your reply. Yeah, so my current workaround is to copy the implementation of `LlamaForCausalLM.forward` and calculate in my own, and it works.

Feel free close the issue if maintainers think it's not appropriate to pass `reduction` argument to `forward`.

Glad it works!
Transformers not working with the new Jax 0.4.14 due to API deprecation
Author: SystemPanic
Pull request: no

### System Info

- `transformers` version: 4.31.0
- Platform: Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
- Python version: 3.10.6
- Huggingface_hub version: 0.14.1
- Safetensors version: 0.3.1
- Accelerate version: 0.21.0
- Accelerate config:    not found
- PyTorch version (GPU?): 2.0.0+cu117 (True)
- Tensorflow version (GPU?): 2.11.0 (True)
- Flax version (CPU?/GPU?/TPU?): 0.7.0 (gpu)
- Jax version: 0.4.14
- JaxLib version: 0.4.14
- Using GPU in script?: Yes
- Using distributed or parallel set-up in script?: No

### Who can help?

@ArthurZucker @younesbelkada @sanchit-gandhi

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

For example, loading a Bart model from Flax using msgpack_restore (modeling_flax_bart.py) raises `AttributeError: module 'jax.numpy' has no attribute 'DeviceArray'`



### Expected behavior

Load the state dict correctly

Comments:
Hi @SystemPanic 

`transformers` currently only support `jax<=0.4.13` and `jaxlib<=0.4.13`. You can see that in

https://github.com/huggingface/transformers/blob/400e76ef11d94a12c255fe1a598966e1d6021511/setup.py#L127-L128
Remove jnp.DeviceArray since it is deprecated.
Author: mariecwhite
Pull request: yes

The latest version of JAX deprecates jax.numpy.DeviceArray. When using this version with Transformers, we get this error when instantiating FlaxBertModel: `module 'jax.numpy' has no attribute 'DeviceArray'`

Comments:
cc @sanchit-gandhi 

@sanchit-gandhi This pull request should be prioritised since the affected Flax models are currently not usable at all.

@mariecwhite Thanks for opening this PR! Running `make style` and pushing the changes will resolve the code quality CI checks

Hey @mariecwhite - it seems there is an issue with your CircleCI permissions, meaning the tests won't run!
Could you try refreshing your permissions as shown [here](https://support.circleci.com/hc/en-us/articles/360048210711-How-to-Refresh-User-Permissions-)? Let me know if you encounter any issues!

_The documentation is not available anymore as the PR was closed or merged._

> Hey @mariecwhite - it seems there is an issue with your CircleCI permissions, meaning the tests won't run! Could you try refreshing your permissions as shown [here](https://support.circleci.com/hc/en-us/articles/360048210711-How-to-Refresh-User-Permissions-)? Let me know if you encounter any issues!

I just updated my CircleCI permissions and rebased.

CircleCI is still failing for me. Since this is a priority, I'm happy to let https://github.com/huggingface/transformers/pull/25275 get merged instead of this.

Forced circleCI to run by also pushing the same branch on the main fork of Transformers. Should solve the tests issues (at least if there are no further commits needed 😅 )
Can't access ViTImageProcessor on transformers==4.25.1
Author: navinelahi
Pull request: no

### System Info

ImportError: cannot import name 'ViTImageProcessor' from 'transformers' (/opt/conda/lib/python3.7/site-packages/transformers/__init__.py)

Am I using the wrong version? Should I downgrade? Where can I get the release history in general? I often find discrepancies like this for usage documentation in the website and it's often related to versioning.

### Who can help?

@sgugger @stevhliu 

### Information

- [X] The official example scripts
- [X] 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

!pip install transformers==4.25.1
from transformers import ViTImageProcessor, BertTokenizer, VisionEncoderDecoderModel


### Expected behavior

It should work.

Comments:
Hi,

Release history is here: https://github.com/huggingface/transformers/releases.

I just tried it out on Google Colab, it works fine for me. This might be an issue with your environment. Could you uninstall and install Transformers again?



This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

Hello, just do: **pip install transformers --upgrade**
then problem fixed

Note that if you are running backlevel Python (e.g. 3.6) `pip install transformers --upgrade` will only get you as far as transformers 4.18
Issue while training Donut model for parsing with custom decoder and tokenizer
Author: akashlp27
Pull request: no

Hey all, I was trying to train donut model for parsing, which contains Arabic(only) information, in order to achieve this i had collected `Arabic corpus` from various sources and then trained,
1. `Mbart Tokenizer` for arabic corpus.
2. `Mbart decoder` with the same dataset.

Initially the model was training well meaning the loss was decreasing gradually but, during Validation, all my dataset tokens are predicting as `<UNK>` tokens. Because of this the `Normed ED` value is above `0.9` but still the loss is decreasing. 

Is there anything I am missing out , any inputs will help a lot. @gwkrsrch , @Vadkoz ,@NielsRogge
Thanks regards.

Comments:
Hi @akashlp27 

As per our [issues guidelines](https://github.com/huggingface/transformers/blob/main/ISSUES.md), we reserve GitHub issues for bugs in the repository and/or feature requests. For any other matters, we'd like to invite you to use our [forum](https://discuss.huggingface.co/) 🤗

However, you might want to take a look
https://github.com/huggingface/transformers/issues/18190#issuecomment-1273482690
https://github.com/huggingface/transformers/issues/18190#issuecomment-1216584872
(Not sure though)

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.
sentencepiece\sentencepiece\src\sentencepiece_processor.cc(1102) [model_proto->ParseFromArray(serialized.data(), serialized.size())]
Author: showpiecep
Pull request: no

### System Info

- `transformers` version: 4.24.0
- Platform: Windows-10-10.0.19041-SP0
- Python version: 3.9.2
- Huggingface_hub version: 0.10.1
- PyTorch version (GPU?): 1.13.0+cpu (False)
- 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?

@patrickvonplaten
@sgugger

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

from transformers import T5Tokenizer
tokenizer = T5Tokenizer(vocab_file='vocab_ruturk.spm') 

Traceback (most recent call last):
  File "app.py", line 3, in <module>
    tokenizer = T5Tokenizer(vocab_file='vocab.ruturk.spm')
  File "env\lib\site-packages\transformers\models\t5\tokenization_t5.py", line 157, in __init__
    self.sp_model.Load(vocab_file)
  File "env\lib\site-packages\sentencepiece\__init__.py", line 910, in Load
    return self.LoadFromFile(model_file)
  File "env\lib\site-packages\sentencepiece\__init__.py", line 311, in LoadFromFile
    return _sentencepiece.SentencePieceProcessor_LoadFromFile(self, arg)
RuntimeError: Internal: a\sentencepiece\sentencepiece\src\sentencepiece_processor.cc(1102) [model_proto->ParseFromArray(serialized.data(), serialized.size())]

### Expected behavior

No errors

Comments:
It looks like you are using the tokenizer with a broken sentencepiece vocab. In any case, we would need a reproducer with a file we have access to to be able to investigate.

Ran into the same issue. How did you solve it?

> Ran into the same issue. How did you solve it?

The whole problem was the vocab. I just took a different one.

Whats wrong with vocab? how to change it correct?

> Whats wrong with vocab? how to change it correct?

make sure your vocab files(*.bin files) have been downloaded fully.in my case, I didn't install git-lfs. git clone repo from huggingface is failed for these files. download these files or use git-lfs.
force_download for pipelines
Author: morrisalp
Pull request: no

### Feature request

Add `force_download=True/False` argument to the pipeline API to allow for re-downloading a model and ignoring local cache.

### Motivation

[PreTrainedModel](https://huggingface.co/docs/transformers/main_classes/model#transformers.PreTrainedModel) has the very useful argument `force_download` argument for ignoring local cache and downloading a model.
However, this does not work with the pipeline API:

```
from transformers import pipeline
pipe = pipeline("text2text-generation", model='t5-small', force_download=True)
pipe('test')
```
yields error: `ValueError: The following `model_kwargs` are not used by the model: ['force_download'] (note: typos in the generate arguments will also show up in this list)`

This is an issue since I am working with a pipeline using a model that is updating and would like to easily re-download it as needed.

### Your contribution

could add this to docs if implemented

Comments:
cc @Narsil for information. You can already pass this in the `model_kwargs` @morrisalp , I don't think it's worth surfacing it more than this.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.