noamaanMulla-03/transformers-issues huggingface dataset:
Issue working with the Trainer class. ImportError: Using the `Trainer` with `PyTorch` requires `accelerate>=0.20.1`: Please run `pip install transformers[torch]` or `pip install accelerate -U`
Author: Siddharth4725
Pull request: no

### System Info

google colab
transformers version :  (4.33.3)

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

class CustomTrainer(Trainer):
  def compute_loss(self, model, inputs, return_outputs = False):
    labels = inputs.pop("labels")
    outputs = model(**inputs)
    logits = outputs.get("logits")

    loss_fct = torch.nn.BCELoss()
    loss = loss_fct(logits.view(-1, self.model.config.num_labels), labels.view(-1))
    return (loss, outputs) if return_outputs else loss


training_examples = []

for i, row in mapped_df.iterrows():
  training_examples.append(([row['answer_text'], row['question_text']], row['relevance']))

model =   SiameseBERT(bert_model)
tokenizer =  AutoTokenizer.from_pretrained('bert-base-uncased')
dataloader =  torch.utils.data.DataLoader(training_examples, batch_size = 32, collate_fn= lambda batch: tokenizer(batch, padding=True, return_tensors="pt"))
loss_fn = torch.nn.BCELoss()
trainer = CustomTrainer(
    model=model,
    # args=TrainingArguments(output_dir="./results"),
    train_dataset=dataloader,
)



### Expected behavior

I want the trainer object to be created using my own loss funciton and use it to train my model.. However I encounter an error while instantiating my Trainer class CustomTrainer().

Comments:
Hello, what is the error you encountered?

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.
transformers==4.34.1 have error for load chatglm model
Author: Lzhang-hub
Pull request: no

### System Info


Copy-and-paste the text below in your GitHub issue and FILL OUT the two last points.

- `transformers` version: 4.34.1
- Platform: Linux-4.19.96-x86_64-with-glibc2.31
- Python version: 3.10.10
- Huggingface_hub version: 0.17.3
- Safetensors version: 0.4.0
- Accelerate version: 0.23.0
- Accelerate config: 	not found
- 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
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>

### Who can help?

load chatglm model failed: 
```
File "/root/.cache/huggingface/modules/transformers_modules/tokenization_chatglm.py", line 112, in get_vocab
    vocab = {self._convert_id_to_token(i): i for i in range(self.vocab_size)}
  File "/root/.cache/huggingface/modules/transformers_modules/tokenization_chatglm.py", line 108, in vocab_size
    return self.tokenizer.n_words
AttributeError: 'ChatGLMTokenizer' object has no attribute 'tokenizer'. Did you mean: 'tokenize'?
```

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

from transformer import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm2-6b")

### Expected behavior

load model correct

Comments:
Hey! This uses `trust_remote_code = True` and has custom code on the hub! Recommend you to open an issue on this repo! 

transformers==4.33.3 is work well

---- Replied Message ----
| From | ***@***.***> |
| Date | 10/23/2023 19:10 |
| To | huggingface/transformers ***@***.***> |
| Cc | Lzhang-hub ***@***.***>,
Author ***@***.***> |
| Subject | Re: [huggingface/transformers] transformers==4.34.1 have error for load chatglm model (Issue #27015) |

Hey! This uses trust_remote_code = True and has custom code on the hub! Recommend you to open an issue on this repo!

—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
Fix example tests from failing
Author: muellerzr
Pull request: yes

# What does this PR do?

This PR tweaks the inputs to the accelerate tests to align with the ones in the pytorch tests, which was causing test failures. (Plus some fixes in Accelerate main)

## 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?
- [ ] 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?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@ydshieh @amyeroberts 

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

> inputs to the accelerate tests to align with the ones in the pytorch tests

Just wondering where the is target of alignment (i.e. the pytorch tests). Otherwise, looks good to me as I trust you that the update makes sense (due to the change in `accelerate`)!


@ydshieh for how many steps that example script takes. For the torch ones it’s 10, here it’s 2 :)
MusicGen: Add Stereo Model
Author: sanchit-gandhi
Pull request: yes

# What does this PR do?

The original MusicGen model generates mono (1-channel) outputs. It does this by predicting a set of 4 codebooks at each generation step:
```
[codebook_1, codebook_2, codebook_3, codebook_4]
```
After generating, the sequence of predicted codebooks is passed through the EnCodec model to get the final waveform.

This PR adds the MusicGen **stereo** model. It works by predicting **two** sets of codebooks at each step. One set of codebooks corresponds to the left channel, the other set corresponds to the right channel. The sets of codebooks are interleaved as follows:
```
[left_codebook_1, right_codebook_1, left_codebook_2, right_codebook_2, ..., left_codebook_4, right_codebook_4]
```

After generating, the sequence of generated codebooks are partitioned into their left/right parts, and then each sequence passed through EnCodec to get the left/right waveform respectively.

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

Is the format we gave (interleaving) forced by BC? Otherwise storing in two list or tuples would be better IMO (kind of like how audio are stored no?) 
my only "complain" here

The original model is designed to predict them in an interleaved way:
```
[left_codebook_1, right_codebook_1, left_codebook_2, right_codebook_2, ..., left_codebook_4, right_codebook_4]
```
We could change this to predict left first, then right:
```
[left_codebook_1, left_codebook_2, ..., left_codebook_4, right_codebook_1, right_codebook_2, ..., right_codebook_4]
```
Which would require re-shaping the LM head weights, and duplicating the pattern mask along the row dimension. Overall I think the complexity would be similar to the interleaved way we have now.

But predicting two sets of codebooks as two separate tuples would break compatibility with the existing mono musicgen, or otherwise complicate the code since we'll have different inputs / sampling logic depending on whether we're mono / stereo.

Awesome thanks for explaining
Remove unused param from example script tests
Author: muellerzr
Pull request: yes

# What does this PR do?

Removes a very old and unused param in the example script tests (`--fp16`) that wasn't ever really *part* of the example scripts, I think it was just a bad copy/paste when writing the tests potentially. 

Fixes # (issue)

A few tests that were giving notice of weird args/params being passed to it.


## 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?
- [ ] 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?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@amyeroberts 


Comments:
_The documentation is not available anymore as the PR was closed or merged._
Whisper Large v3 Flax
Author: peregilk
Pull request: no

### System Info

Latest. installed from source.

### Who can help?

@sanchit-gandhi 

Num_mel_bins are hardcoded in class [FlaxWhisperPreTrainedModel](https://github.com/huggingface/transformers/blob/b6dbfee0a21d333447b47887dbe2cb87720ebfd0/src/transformers/models/whisper/modeling_flax_whisper.py#L870)

Since num_mel_bins has changed from 80 to 128, this should probably either be read from `num_mel_bins` in `config.json`, or `feature_size` in `preprocessor_config.json`.



### Information

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

One of the issues that blocks using this class for training based on Large v3 in Flax.

### Expected behavior

Input feature size should be set in config file.

Comments:
[Flax Whisper] large-v3 compatibility
Author: sanchit-gandhi
Pull request: yes

# What does this PR do?

Fixes #27363. Whisper large-v3 uses 128 log-mel bins, instead of 80 for previous Whisper checkpoints. This changes the shape of the input tensors to the model. For the JAX trace to work when initialising the weights, we need to set the input shape correctly based on the model dims.

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Missing generation token for zephyr-beta
Author: dt-ahmed-touila
Pull request: no

### System Info

transformers version: 4.34.0
tokenizers version: 0.14.1
Platform: macOS 13.5.1
Python version: 3.8.10
huggingface-hub version: 0.17.3
PyTorch version(GPU?): 2.0.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?: N
Using distributed or parallel set-up in script?: N

### Who can help?

_No response_

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

```python
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("HuggingFaceH4/zephyr-7b-beta")
tokenizer.apply_chat_template([{"role": "user", "content": "What is life?"}], tokenize=False, add_generation_prompt=True)
```

Output: `
\nWhat is life?
\n`

### Expected behavior

`
\nWhat is life?
\n
`

Comments:
cc @Rocketknight1 

cc @lewtun to this one, I think he wrote the chat template for Zephyr-beta!

Wait, no, my mistake! The issue is just that your version of `transformers` is slightly out of date @dt-ahmed-touila, and `add_generation_prompt` was only added in 4.35. Please `pip install --upgrade transformers` to resolve the issue! 

Thank you @Rocketknight1 ! Updating to `transformers-4.35.0` solved this.
Fix tiny model script: not using `from_pt=True`
Author: ydshieh
Pull request: yes

# What does this PR do?

After #27064, the checkpoint is saved with format `safetensors`. If we specify `from_pretrained("...", from_pt=True)` while the checkpoint is in `safetensors` format, we get error like `invalid load key *\xa0* (or *\xd8* etc.)`.

This PR remove the usage of `from_pt=True` and therefore fix 1 issue in the failing CI (that checks the script working). 

### Code snippet

```python
from transformers import BertModel, TFBertModel


ckpt = "hf-internal-testing/tiny-random-BertModel"

bert_pt = BertModel.from_pretrained(ckpt)
bert_pt.save_pretrained("my-bert")

# this works
bert_tf = TFBertModel.from_pretrained("my-bert")

# this fail
bert_tf = TFBertModel.from_pretrained("my-bert", from_pt=True)
print(bert_tf)
```

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Fix `Kosmos-2` device issue
Author: ydshieh
Pull request: yes

# What does this PR do?

Fix device issues in Kosmos-2
Fix #27301

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

Merge this now, but feel free to drop your insights if any @muellerzr 🙏 

Hey @ydshieh, I had to do the same thing for [fuyu](https://github.com/huggingface/transformers/pull/26949#discussion_r1369058114) when I added the `device_map`. There was no way to make sure that those two embeddings are on the same device without specifying a very big module. I guess it is okay for now as the change is minimal but I was thinking about creating in the future a `no_split_layers` arg if it becomes too difficult + ugly to deal with. 

Thank you @SunMarc !
Translate index.md to Turkish
Author: mertyyanik
Pull request: yes

# What does this PR do?

Translated `index.md` to Turkish language.
Part of #27088 

## Who can review?
@stevhliu, @MKhalusova, @merveenoyan 

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker and @younesbelkada
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @gante
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @pacman100

Integrations:

- deepspeed: HF Trainer/Accelerate: @pacman100
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc and @younesbelkada

Documentation: @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
Hi @mertyyanik ! Thank you for working on translating the doc page into Turkish.
From what I see, this is the first time a doc page has been translated into Turkish. As such, you'll need to modify two more files in order to build the docs in a new language - `.github/workflows/build_documentation.yml` and `.github/workflows/build_pr_documentation.yml`.  

Add the two-letter code for your language to the list of languages. You can look up the code [here](https://www.loc.gov/standards/iso639-2/php/code_list.php).
Also pinging @merveenoyan for a review of the Turkish translation :) 

I made the changes. Thanks @MKhalusova and @merveenoyan 

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_27093). All of your documentation changes will be reflected on that endpoint.

Hello, @merveenoyan. I need a review. When it's done, I will proceed to the other sections.

Thank you for your work, we can merge it now!
Update deprecated torch.range in tests/models/ibert/test_modeling_ibert.py
Author: kit1980
Pull request: yes

# What does this PR do?

`torch.range` is deprecated since PyTorch 0.4 and will be removed in a future PyTorch release.
This PR updates it to `torch.arange`.
Fixed with TorchFix https://github.com/pytorch/test-infra/tree/main/tools/torchfix

## 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?
- [ ] 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?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

cc @ydshieh 

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker and @younesbelkada
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @gante
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @pacman100

Integrations:

- deepspeed: HF Trainer/Accelerate: @pacman100
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc and @younesbelkada

Documentation: @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_27355). All of your documentation changes will be reflected on that endpoint.

@ydshieh I've removed the commented out line.
moving example of benchmarking to legacy dir
Author: ji-huazhong
Pull request: yes

# What does this PR do?

Since benchmarking tools was deprecated by  https://github.com/huggingface/transformers/pull/15848, I think it is more appropriate to put the corresponding examples in the legacy directory :-).
WDYT @patrickvonplaten @LysandreJik




Comments:
Agree! Wdyt @ArthurZucker 

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_27337). All of your documentation changes will be reflected on that endpoint.
translate debugging.md to chinese
Author: jiaqiw09
Pull request: yes

# What does this PR do?

Part of  #26803 

## Before submitting
- [x] 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? _not necessary_


## Who can review?
@stevhliu

Comments:
@stevhliu

hi, here is another pr for debugging doc. I think I can finish this section before next week.

Best

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_27374). All of your documentation changes will be reflected on that endpoint.
translate big_models.md and performance.md to chinese
Author: jiaqiw09
Pull request: yes

# What does this PR do?

Part of  #26803 

## Before submitting
- [x] 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? _not necessary_


## Who can review?
@stevhliu

Comments:
@stevhliu

Hi, I will translate `Performance and scalability` part next.

For the possible merge conflict, I will fix it later after another pr merged. 

Best

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_27334). All of your documentation changes will be reflected on that endpoint.

@stevhliu

Hi, I have fixed redirect problem.

Best