noamaanMulla-03/transformers-issues huggingface dataset:
start from 1.12, torch_ccl is renamed as oneccl_bindings_for_pytorch …
Author: sywangyi
Pull request: yes

…and should import it before use

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>

# What does this PR do?

when run the transformer with torch 1.12 and we should pip install one ccl (version 1.12) as well to enable DDP finetune in cpu.
python -m pip install oneccl_bind_pt==1.12.0 -f https://developer.intel.com/ipex-whl-stable
from 1.12.0 the module name will be changed to oneccl_bindings_for_pytorch. and should be imported before use. or else
error will happen.

Fixes # (issue)
as described above.

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      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?


Library:

- trainer: @sgugger


Comments:
@yao-matrix @liangan1 please review

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

@sgugger document has been uploaded

Hi, @sgugger ,this fix is aligned with what we do in the accelerate PR, without the correct module import, the DDP could not work with CCL backend

@sgugger  thanks for the careful review. doc is updated based one your comment
oob performance improvement for cpu DDP
Author: sywangyi
Pull request: yes

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>

# What does this PR do?

oob performance improvement for cpu DDP, currently if no OMP_NUM_THREADS/MKL_NUM_THREADS is set, num_cpu_threads_per_process is set to 1. very slow performance.


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      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?

- trainer: @sgugger


Comments:
@yao-matrix @sgugger @liangan1 please help review it

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

Hey @sywangyi, thanks for your PR! Sylvain is currently off for a few weeks, we'll merge this PR once he's back.

Thanks for your contribution!
update the train_batch_size in case HPO changes batch_size_per_device
Author: sywangyi
Pull request: yes

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes # (issue)
get incorrect "total optimization steps" in HPO. since train_batch_size is not updated accordingly

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      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?

- trainer: @sgugger 

Comments:
 @sgugger @yao-matrix please help review it. the bug in finding when HPO is enabled in example. "Total optimization steps" is incorrect since train_batch_size is not updated accordingly. add the update of this parameter in trainer.train

_The documentation is not available anymore as the PR was closed or merged._
update doc for perf_train_cpu_many, add intel mpi introduction
Author: sywangyi
Pull request: yes

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>

# What does this PR do?

update doc for perf_train_cpu_many, add intel mpi introduction

Fixes # (issue)


## Before submitting
- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      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?

Documentation: @sgugger


Comments:
@sgugger please help review, thanks very much

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

Failure is unrelated to this PR (would disappear with a rebase) so merging. Thanks again!
add DDP HPO support for optuna
Author: sywangyi
Pull request: yes

only main_process will have HPO, and pass argument to other process

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes: optuna HPO does not support DDP



## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      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?

Library:
- trainer: @sgugger

Comments:
@yao-matrix @sgugger please have a review

_The documentation is not available anymore as the PR was closed or merged._
Update `ImageToTextPipelineTests.test_small_model_tf`
Author: ydshieh
Pull request: yes

# What does this PR do?

After PR #19732, I uploaded the correctly converted TF model to the Hub repo [hf-internal-testing/tiny-random-vit-gpt2](https://huggingface.co/hf-internal-testing/tiny-random-vit-gpt2/tree/main)

This PR updates the expected values accordingly, which is the same values as for `test_small_model_pt`.

Comments:
Thank you so much for this @ydshieh !!

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

Thanks!
`truncation='do_not_truncate'` is not working equivalently to `truncation=False`
Author: urialon
Pull request: no

Hi,
`truncation='do_not_truncate'` is not working equivalently to `truncation=False`.
When using `truncation=False` and providing `max_length`, it defaults to `'longest_first'` truncation strategy.
Whether this default behavior is natural or not, isn't `False` supposed to be identical to `'do_not_truncate'`?

This leads to a situation when the user explicitly specifies `truncation=False` but the text **is tokenized**.

This manual: https://huggingface.co/docs/transformers/pad_truncation and this doc https://huggingface.co/docs/transformers/main_classes/tokenizer
say that:
>`False` or `'do_not_truncate'`: no truncation is applied. This is the default behavior.

Which means that they are supposed to be equivalent (regardless of what they do, they should behave the same).

I suggest that `False` should just mean "no truncation", regardless of `max_length` was supplied or not.

Here is a short example:

```python
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("facebook/bart-base")
sent = 'The quick brown fox jumps over the lazy dog'

len(tokenizer.encode(sent, max_length=5, truncation='do_not_truncate'))
```
prints: `11`

```python
len(tokenizer.encode(sent, max_length=5, truncation=False))
```
prints: `5`

Thanks,
Uri

Comments:
Hi,
This issue belongs in `transformers` afaik. All the logic should be handled there as `truncation=False` does not mean anything for this library (IIRC).

If you can reproduce the bug just using `tokenizers` and not `transformers` then it's probably that the bug in this library.

Thanks, closing and re-creating in the `transformers` format
Make public versions of private tensor utils
Author: sgugger
Pull request: yes

# What does this PR do?

This PR makes public versions of `_is_torch`, `_is_tensorflow`, `_is_numpy` and `_is_jax` that are safe to use even when those frameworks are not installed, as I need them for some future PRs. The same functions have also been written independtenly by @amyeroberts in image_utils, this PR puts them in the generic utils and remove the use of the private ones.

Comments:
Fix CTRL `test_torchscrip_xxx` CI by updating `_create_and_check_torchscript`
Author: ydshieh
Pull request: yes

# What does this PR do?

Fix CTRL `test_torchscrip_xxx` CI by updating `_create_and_check_torchscript`. Before calling `torch.jit.trace`, we run the prepared inputs first.

### More context

The PR #19681 puts `pos_encoding` attribute to the correct device for CTRL model, but this could be only done safely in the `forward` method.

However, our current `torchscript` tests don't run the model with the prepared inputs before calling `torch.jit.trace`. And so we get the following error for `CTRL` after PR #19678:
```bash
(line 535)  torch.jit._trace.TracingCheckError: Tracing failed sanity checks!
...
...
Comparison exception: 	The values for attribute 'device' do not match: cpu != cuda:0.
``` 
See [CI report](https://github.com/huggingface/transformers/actions/runs/3286486761/jobs/5414682626)



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

Running all tests (per model separately, as in our CI) of `test_torchscript_xxx`, all pass
Fix nightly test setup
Author: sgugger
Pull request: yes

# What does this PR do?

The nightly tests were not properly triggered because I made a typo in the variable name to set 🤦‍♂️ . This is fixed since yesterday., but now there is a failure in the setup (see [here](https://app.circleci.com/jobs/github/huggingface/transformers/597479?utm_campaign=workflow-failed&utm_medium=email&utm_source=notification)) because I forgot to checkout the repo.

Comments:
_The documentation is not available anymore as the PR was closed or merged._
`"transformers_version"` is not enforced
Author: urialon
Pull request: no

### System Info

- `transformers` version: 4.21.1
- Platform: macOS-10.16-x86_64-i386-64bit
- Python version: 3.9.7
- Huggingface_hub version: 0.8.1
- PyTorch version (GPU?): 1.9.1 (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?: Yes+no
- Using distributed or parallel set-up in script?: no

### Who can help?

This is a general problem with loading pretrained models in the library, not any specific model:
@sgugger @stevhliu @patrickvonplaten


### 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

```python
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("NinedayWang/PolyCoder-2.7B")
model = AutoModelForCausalLM.from_pretrained("NinedayWang/PolyCoder-2.7B")
```

### Expected behavior

The model's `config.json` specifies that this model requires version `4.23.1` here:
https://huggingface.co/NinedayWang/PolyCoder-2.7B/blob/main/config.json#L21

but if the user is trying to load this model with an older version (`4.21.1`), it still incorrectly and silently does load.

So, I would expect an error instead of a successful loading, because with an old version of `transformers`, this model produces incorrect predictions.
I prefer not being able to load the checkpoint if I don't have the required version of the library.

In other words, why do we have the `"transformers_version"` field in the `config.json`, if it is not enforced?
Thanks!


Comments:
It is just informative (and saved automatically, not selected by the user), so it is by no way a minimal version required for the model.

thanks!

Don't we want a way to enforce that a certain checkpoint will be loaded only by a specific version?
Currently users may download checkpoints, load them successfully, but just get bad predictions

DO you have an explicit example of that? We maintain very strict backward/forward compatibility in the model code.

Yes,
This model `NinedayWang/PolyCoder-2.7B` must be loaded with version `>=4.23.0`,
because it depends on this PR: https://github.com/huggingface/transformers/pull/18695



Ah, yet another argument for not adding config arguments like those. Thanks for pointing that out.

Thanks a lot!
Old import clause in seq2seq trainer
Author: zhaowei-wang-nlp
Pull request: no
Labels: name: bug

### System Info

transformers==4.21.3
pytorch==1.10.1+cu111


### Who can help?

@sgugger

### Information

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

When I tried to import Seq2SeqTrainer, there is an bug of import:
"from transformers import Seq2SeqTrainer
File "<frozen importlib._bootstrap>", line 1039, in _handle_fromlist
File "/opt/conda/lib/python3.8/site-packages/transformers/utils/import_utils.py", line 992, in __getattr__
module = self._get_module(self._class_to_module[name])
File "/opt/conda/lib/python3.8/site-packages/transformers/utils/import_utils.py", line 1004, in _get_module
raise RuntimeError(
RuntimeError: Failed to import transformers.trainer_seq2seq because of the following error (look up to see its traceback):
cannot import name 'container_abcs' from 'torch._six' (/opt/conda/lib/python3.8/site-packages/torch/_six.py)"
When I google it. I found 'container_abcs' doesn't exist now from torch 1.9.
https://stackoverflow.com/questions/70193443/colab-notebook-cannot-import-name-container-abcs-from-torch-six

### Expected behavior

no import errors.

Comments:
The problem comes when trying to import `torch`, according to the traceback you posted, so you should raise the issue there :-)

> 
There are solutions: people in the following issue changed the import clause by themself. However, in my condition, this import clause is written in the package "transformer," and I can change it.
https://github.com/pytorch/pytorch/issues/51959

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.
Fix image segmentation pipeline errors, resolve backward compatibility issues
Author: alaradirik
Pull request: yes

# What does this PR do?
- Replaces hard-coded mask score binarization threshold used in `post_process_panoptic_segmentation` and `post_process_instance_segmentation` method of DETR and MaskFormer feature extractors with the `mask_threshold` argument
- Adds copied from statements to MaskFormer post processing helper functions
- Reintroduces the mask_threshold argument to the `ImageSegmentationPipeline` (resolves backward compatibility issues)
- Renames `ImageSegmentationPipeline` task argument to subtask to avoid conflicts, defaults to None
- If `ImageSegmentationPipeline` subtask is unset, tries performing panoptic segmentation first, followed by instance and semantic segmentation
- Fixes broken `ImageSegmentationPipeline` tests

Reintroducing the `mask_threshold` argument and setting it to 0 fixes the test errors and ensures at least one mask is returned for any input and model.

## 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#start-contributing-pull-requests),
      Pull Request section?
- [X ] 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.
- [X ] 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?


Comments:
_The documentation is not available anymore as the PR was closed or merged._
Small typo in documentation of TokenClassificationPipeline
Author: pchr8
Pull request: no

### System Info

https://github.com/huggingface/transformers/blob/v4.23.1/src/transformers/pipelines/token_classification.py#L176


### Who can help?

_No response_

### Information

- [ ] 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

Open the documentation https://huggingface.co/docs/transformers/main_classes/pipelines#transformers.TokenClassificationPipeline.__call__

> word (str) — The token/word classified. This is obtained by decoding the selected tokens. If you want to have the exact string in the original sentence, use start and stop.

### Expected behavior

I'm quite sure it should be "`start` and `end`"


Comments:
Use None to detect if truncation was unset
Author: sgugger
Pull request: yes

# What does this PR do?

This PR changes the default of the `truncation` argument to `None` so that we can detect the difference between:
- truncation was not set
- truncation was set to `False`.

As pointed out in #19790, relying on `False` to test if the argument is unset yields unexpected behaviors.

Fixes #19790

Comments:
Fix error/typo in docstring of TokenClassificationPipeline
Author: pchr8
Pull request: yes

Fixes #19797

## Before submitting
- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      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?



Comments:
_The documentation is not available anymore as the PR was closed or merged._
Generate: contrastive search test updates
Author: gante
Pull request: yes

# What does this PR do?

The newly introduced tests had a bunch of minor issues, including models too big for CI, formatting problems, or slightly incorrect strings (the hardcoded strings were generated for inputs that were changed before the final commit). This PR addresses these issues.

All new (slow) tests passing locally now.

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