repo
stringclasses
1 value
number
int64
1
25.3k
state
stringclasses
2 values
title
stringlengths
1
487
body
stringlengths
0
234k
โŒ€
created_at
stringlengths
19
19
closed_at
stringlengths
19
19
comments
stringlengths
0
293k
transformers
25,306
open
"Dynamic" Issue in LlamaDynamicNTKScalingRotaryEmbedding - Long context inference will impact short context inference.
### System Info - `transformers` version: 4.32.0.dev0 - Platform: Linux-5.15.109+-x86_64-with-glibc2.35 - Python version: 3.10.12 - Huggingface_hub version: 0.16.4 - Safetensors version: 0.3.1 - Accelerate version: 0.22.0.dev0 - Accelerate config: not found - PyTorch version (GPU?): 2.0.1+cu118 (True) - Tensorflow version (GPU?): 2.12.0 (True) - Flax version (CPU?/GPU?/TPU?): 0.7.0 (gpu) - Jax version: 0.4.13 - JaxLib version: 0.4.13 - Using GPU in script?: No - Using distributed or parallel set-up in script?: No ### 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, ...) - [X] My own task or dataset (give details below) ### Reproduction Please see my colab code: https://colab.research.google.com/drive/1SnQQxW7WMHgSOvAwF_HIlIDrAuXZ4IKp?usp=sharing I asked the same prompt twice, with a long-context prompt inserted in between. However, this intermediate long-context inference resulted in different answers for the same question before and after it. ### Expected behavior Since the input length of the tested prompts is within the maximum input token capacity the model can handle, the significance of "Dynamic" lies in ensuring that the embeddings for the inputs before and after remain the same, and consequently, the output results should also be the same. I reviewed the code of the class "[LlamaDynamicNTKScalingRotaryEmbedding](https://github.com/huggingface/transformers/blob/main/src/transformers/models/llama/modeling_llama.py#L147C8-L147C8)" and I think that due to caching, when the model infers a long context, the cached values of `cos_cached` and `sin_cached` are updated to adapt to the longer context. This causes the issue when the model infers a shorter context again.
08-04-2023 00:31:00
08-04-2023 00:31:00
transformers
25,305
open
Unable to change default cache folders despite setting environment variables
### System Info Collecting environment information... PyTorch version: 2.0.1+cu117 Is debug build: False CUDA used to build PyTorch: 11.7 ROCM used to build PyTorch: N/A OS: Ubuntu 22.04.2 LTS (x86_64) GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 Clang version: Could not collect CMake version: Could not collect Libc version: glibc-2.35 Python version: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (64-bit runtime) Python platform: Linux-5.15.0-71-generic-x86_64-with-glibc2.35 Is CUDA available: True CUDA runtime version: 11.8.89 CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA GeForce RTX 2080 Ti GPU 1: NVIDIA GeForce RTX 2080 Ti GPU 2: NVIDIA GeForce RTX 2080 Ti GPU 3: NVIDIA GeForce RTX 2080 Ti GPU 4: NVIDIA GeForce RTX 2080 Ti GPU 5: NVIDIA GeForce RTX 2080 Ti GPU 6: NVIDIA GeForce RTX 2080 Ti GPU 7: NVIDIA GeForce RTX 2080 Ti Nvidia driver version: 530.30.02 cuDNN version: Probably one of the following: /usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.3 /usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.3 /usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.3 /usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.3 /usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.3 /usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.3 /usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.3 HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 46 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 80 On-line CPU(s) list: 0-79 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) Gold 6230 CPU @ 2.10GHz CPU family: 6 Model: 85 Thread(s) per core: 2 Core(s) per socket: 20 Socket(s): 2 Stepping: 7 CPU max MHz: 3900.0000 CPU min MHz: 800.0000 BogoMIPS: 4200.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts pku ospke avx512_vnni md_clear flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 1.3 MiB (40 instances) L1i cache: 1.3 MiB (40 instances) L2 cache: 40 MiB (40 instances) L3 cache: 55 MiB (2 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0-19,40-59 NUMA node1 CPU(s): 20-39,60-79 Vulnerability Itlb multihit: KVM: Mitigation: VMX disabled Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Retbleed: Mitigation; Enhanced IBRS Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Mitigation; TSX disabled Versions of relevant libraries: [pip3] mypy-extensions==1.0.0 [pip3] numpy==1.24.3 [pip3] torch==2.0.1 [pip3] torchvision==0.15.2 [pip3] triton==2.0.0 [conda] Could not collect ### 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 1- Set the following environment variables: ``` import os os.environ['XDG_CACHE_HOME'] = '/MyFolder/.cache' os.environ['HF_HOME'] = '/MyFolder/.cache/huggingface' os.environ['HF_DATASETS_CACHE'] = '/MyFolder/.cache/datasets' os.environ['TRANSFORMERS_CACHE'] = '/MyFolder/.cache/models' os.environ['HUGGINGFACE_HUB_CACHE'] = '/MyFolder/.cache/hub' ``` 2- Try to download a model. In my case, I do this: ``` model = "google/flan-t5-small" tokenizer = AutoTokenizer.from_pretrained(model) pipeline = transformers.pipeline( "text2text-generation", model=model, tokenizer=tokenizer, torch_dtype=torch.bfloat16, trust_remote_code=True, device_map="auto", ) ``` ### Expected behavior Expected behavior The caches should be saved to the custom directories specified in the environment variables. Actual behavior The caches continue to be saved to the default locations and do not use the custom directories.
08-03-2023 23:42:20
08-03-2023 23:42:20
transformers
25,304
open
Tokenizer failing to encode chatml correctly
### System Info - `transformers` version: 4.31.0 - Platform: Linux-5.14.0-284.18.1.el9_2.x86_64-x86_64-with-glibc2.34 - Python version: 3.10.12 - Huggingface_hub version: 0.16.4 - Safetensors version: 0.3.1 - Accelerate version: 0.21.0 - Accelerate config: not found - PyTorch version (GPU?): 2.0.1+cu118 (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?: Yes - Using distributed or parallel set-up in script?: No Note: also tested and broken on: - 641adca - 4.30.2 - 4.30.1 - 4.30.0 - 4.29.2 - 4.29.1 - 4.29.0 - 4.28.1 - 4.28.0 - 4.27.4 ### Who can help? @ArthurZucker @younesbelkada ### 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 I'm attempting to finetune Llama2 with a ChatML format. No matter how I approach it, it seems to be failing to encode/decode correctly. I see multiple issues and PRs that are related, but this specific format seems to be hitting all of them with none of the workarounds being effective. A repro is available here: https://gist.github.com/ozreact/a4b565cd2c7fac65d6cb76c78dbdf9e2 #24565 recommends setting `legacy=false`, and further says that this only addresses a subset of issues with the slow tokenizer only. It also mentions that `decode` isn't fixed, so validating that the encoding step is working is fiddly. This format, when newlines are used, is also impacted by #21120. #25073 also breaks this. #25176 recommends setting `legacy=True` to fix an invalid unk token that effectively over-writes a final token in a partial ChatML response, but this conflicts with attempting to fix the issues in #24565. ### Expected behavior ChatML instruction format should 'just work', tokenize correctly, and decode correctly.
08-03-2023 23:13:33
08-03-2023 23:13:33
transformers
25,303
open
loss reduction for `Llama2ForCausalLM.forward`
### 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.
08-03-2023 21:29:20
08-03-2023 21:29:20
transformers
25,302
closed
Fix typo: Roberta -> RoBERTa
# What does this PR do? Small typo in docs: "Roberta" should have the correct capitalization "RoBERTa". Fixes #25301 ## 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? 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. Documentation: @sgugger, @stevhliu and @MKhalusova
08-03-2023 20:04:27
08-03-2023 20:04:27
_The documentation is not available anymore as the PR was closed or merged._
transformers
25,301
closed
Minor typo referencing RoBERTa
"Roberta" should use the correct capitalization: "RoBERTa" https://github.com/huggingface/transformers/blob/d27e4c18fe2970abcb9a48dcb8a824e48083b15f/docs/source/en/tokenizer_summary.md?plain=1#L144 Should be a simple fix.
08-03-2023 19:58:21
08-03-2023 19:58:21
transformers
25,300
open
Add zero-shot classification task for BLIP-2
### Feature request I would like to add the support for the zero-shot classification task using BLIP2, computing text-image similarities with the normalized embeddings, that would be accessed from BLIP2 feature extractor. The idea is to enable calling the zero-shot classification pipeline using BLIP2, by implementing the `get_image_feature`and `get_text_features`methods. I would love more guidance, if possible, on the criteria for accepting the PR. ### Motivation This is related to the following the discussion on this issue on the hub, and the comment left by @NielsRogge here https://huggingface.co/Salesforce/blip2-opt-2.7b/discussions/3#64cbe5e487ec96aa473a1f54 . ### Your contribution I would like to submit a PR to contribute for this feature.
08-03-2023 19:53:46
08-03-2023 19:53:46
transformers
25,299
open
cannot import name 'Module' from '_pytest.doctest'
### System Info transformers 4.32.0.dev0 torch 2.1.0.dev20230523+cu117 Error: Traceback (most recent call last): File "/workspace/transformers/examples/pytorch/language-modeling/run_clm.py", line 52, in <module> Traceback (most recent call last): File "/workspace/transformers/examples/pytorch/language-modeling/run_clm.py", line 52, in <module> from transformers.testing_utils import CaptureLogger File "/opt/conda/envs/ptca/lib/python3.8/site-packages/transformers-4.32.0.dev0-py3.8.egg/transformers/testing_utils.py", line 111, in <module> from transformers.testing_utils import CaptureLogger File "/opt/conda/envs/ptca/lib/python3.8/site-packages/transformers-4.32.0.dev0-py3.8.egg/transformers/testing_utils.py", line 111, in <module> from _pytest.doctest import ( ImportError: cannot import name 'Module' from '_pytest.doctest' (/opt/conda/envs/ptca/lib/python3.8/site-packages/_pytest/doctest.py) from _pytest.doctest import ( ### Who can help? @sgugger ### 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 -m torch.distributed.launch --nproc_per_node=8 --use-env /workspace/transformers/examples/pytorch/language-modeling/run_clm.py --model_name_or_path xlnet-base-cased --dataset_name wikitext --dataset_config_name wikitext-2-raw-v1 --label_smoothing 0.1 --do_train --output_dir /dev/shm --overwrite_output_dir --max_steps 200 --logging_steps 20 --per_device_train_batch_size 8 --fp16 ### Expected behavior example runs without error
08-03-2023 19:05:56
08-03-2023 19:05:56
You might need a `pip install --upgrade pytest`.
transformers
25,298
open
[Whisper] Better error message for outdated generation config
# 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).
08-03-2023 17:57:18
08-03-2023 17:57:18
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25298). All of your documentation changes will be reflected on that endpoint.
transformers
25,297
open
MaskFormer, Mask2Former - replace einsum for tracing
# What does this PR do? Maskformer cannot currently be traced because of einsum operations. This PR replaces the einsum operations with standard matmuls. With this PR, the following now runs: ```python import torch from transformers import Mask2FormerForUniversalSegmentation device = torch.device("cuda") model = Mask2FormerForUniversalSegmentation.from_pretrained( "facebook/mask2former-swin-tiny-coco-instance", torchscript=True ).eval().to(device) dummy_input = torch.randn((1,3,640,640)).to(device) traced_model = torch.jit.trace(model, dummy_input) with torch.no_grad(): out = traced_model(torch.randn((2,3,640,640)).to(device)) out = traced_model(torch.randn((2,3,640,640)).to(device)) ``` Partially fixes #25261 - enables tracing but does not resolve the issue of different results between traced and non-traced model on GPU ## 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?
08-03-2023 17:48:58
08-03-2023 17:48:58
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25297). All of your documentation changes will be reflected on that endpoint.
transformers
25,296
open
BertForSequenceClassification does not support 'device_map':"auto" yet
### System Info I have trained a model and am now trying to load and quantise it but getting the error: BertForSequenceClassification does not support 'device_map':"auto" yet Code for loading is simply: ` model = AutoModelForSequenceClassification.from_pretrained(model_dir, device_map='auto', load_in_8bit=True)` Help would be greatly appreciated! Thanks, Lee ### Who can help? _No response_ ### 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 model = AutoModelForSequenceClassification.from_pretrained(model_dir, device_map='auto', load_in_8bit=True) ### Expected behavior The model would load and be usable.
08-03-2023 17:00:09
08-03-2023 17:00:09
transformers
25,295
closed
[small] llama2.md typo
# What does this PR do? `groupe` -> `grouped` <!-- 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 --> ## 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? 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. <!-- 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: @sgugger Integrations: - deepspeed: HF Trainer/Accelerate: @pacman100 - ray/raytune: @richardliaw, @amogkam Documentation: @sgugger, @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: @sgugger - TensorFlow: @Rocketknight1 -->
08-03-2023 16:51:06
08-03-2023 16:51:06
_The documentation is not available anymore as the PR was closed or merged._
transformers
25,294
open
Generate: remove Marian hack
# What does this PR do? WIP, let's see first if all tests pass
08-03-2023 16:48:40
08-03-2023 16:48:40
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25294). All of your documentation changes will be reflected on that endpoint.
transformers
25,293
open
MassFormer
### Model description We propose adding a new model, MassFormer, to predict tandem mass spectra accurately. MassFormer uses a graph transformer architecture to model long-distance relationships between atoms in the molecule. The transformer module is initialized with parameters obtained through a chemical pre-training task, then fine-tuned on spectral data. MassFormer outperforms competing approaches for spectrum prediction on multiple datasets and is able to recover prior knowledge about the effect of collision energy on the spectrum. We demonstrate that the model can identify relationships between fragment peaks by employing gradient-based attribution methods. To further highlight MassFormerโ€™s utility, we show that it can match or exceed existing prediction-based methods on two spectrum identification tasks. Our code is the first open-source implementation of a deep-learning MS/MS spectrum predictor and may encourage future research in this area. ### Open source status - [X] The model implementation is available - [X] The model weights are available ### Provide useful links for the implementation This model will be implemented according to the paper by @adamoyoung as listed below. Reference: Young, A., Wang, B. and Rรถst, H., 2021. MassFormer: Tandem mass spectrum prediction with graph transformers. arXiv preprint arXiv:2111.04824.
08-03-2023 16:41:42
08-03-2023 16:41:42
transformers
25,292
open
Generate: get generation mode as a string
# 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 -- a string containing the name of the generation mode. In a future PR, I will use the string 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
08-03-2023 16:33:36
08-03-2023 16:33:36
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25292). All of your documentation changes will be reflected on that endpoint.
transformers
25,291
open
Document check copies
# 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.
08-03-2023 15:59:52
08-03-2023 15:59:52
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25291). All of your documentation changes will be reflected on that endpoint.
transformers
25,290
open
Make `bark` could have tiny model
# What does this PR do? Make `bark` could have tiny model. This is mainly for #24952 cc @ylacombe
08-03-2023 15:35:40
08-03-2023 15:35:40
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25290). All of your documentation changes will be reflected on that endpoint.
transformers
25,289
open
Quantized models + PEFT + multi-gpu setup failing during training
### System Info - `transformers` version: 4.31.0 - Platform: Linux-5.10.178-162.673.amzn2.x86_64-x86_64-with-glibc2.26 - Python version: 3.10.8 - Huggingface_hub version: 0.16.4 - Safetensors version: 0.3.1 - Accelerate version: 0.21.0 ### Who can help? @younesbelkada ### 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 To repoduce: (Note, this is related to https://github.com/huggingface/accelerate/pull/1523) ``` accelerator = Accelerator() model_id = "t5-base" # Load tokenizer of FLAN-t5-XL tokenizer = AutoTokenizer.from_pretrained(model_id, cache_dir = 'model_cache') dataset = get_data() tokenized_dataset = dataset.map(lambda sample: preprocess_function(sample, tokenizer), batched=True, remove_columns=["source", "target"]) # print(dist.get_rank()) model = AutoModelForSeq2SeqLM.from_pretrained( model_id, load_in_8bit=True, device_map='auto', cache_dir='model_cache') # Define LoRA Config lora_config = LoraConfig( r=16, lora_alpha=32, lora_dropout=0.05, bias="none", task_type=TaskType.SEQ_2_SEQ_LM ) # prepare int-8 model for training model = prepare_model_for_int8_training(model) # add LoRA adaptor model = get_peft_model(model, lora_config) model = accelerator.prepare(model) label_pad_token_id = -100 data_collator = DataCollatorForSeq2Seq( tokenizer, label_pad_token_id=label_pad_token_id, pad_to_multiple_of=None, padding=False ) # Define training args training_args = TrainingArguments( per_device_train_batch_size=1, learning_rate=1e-3, num_train_epochs=10, logging_strategy='steps', logging_steps=5, weight_decay=0, output_dir = 'weights', seed=22 ) # Create Trainer instance trainer = Trainer( model=model, args=training_args, train_dataset=tokenized_dataset['train'].select(range(10)), data_collator=data_collator, ) train_result = trainer.train() ``` `tokenized_dataset` can be an arbitrary dataset. The problem arises when running `python -m torch.distributed.launch --nproc_per_node=4 multi-gpu.py`. Note that it works fine if just using `python multi-gpu.py` (since only 1 GPU is used here). I am running with four T4s. ### Expected behavior Error message: ``` Traceback (most recent call last): File "/home/ec2-user/SageMaker/training/scripts/multi-gpu.py", line 131, in <module> main() File "/home/ec2-user/SageMaker/training/scripts/multi-gpu.py", line 125, in main train_result = trainer.train() File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/transformers/trainer.py", line 1539, in train return inner_training_loop( File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/transformers/trainer.py", line 1656, in _inner_training_loop model, self.optimizer = self.accelerator.prepare(self.model, self.optimizer) File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/accelerate/accelerator.py", line 1202, in prepare result = tuple( File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/accelerate/accelerator.py", line 1203, in <genexpr> self._prepare_one(obj, first_pass=True, device_placement=d) for obj, d in zip(args, device_placement) File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/accelerate/accelerator.py", line 1030, in _prepare_one return self.prepare_model(obj, device_placement=device_placement) File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/accelerate/accelerator.py", line 1270, in prepare_model raise ValueError( ValueError: You can't train a model that has been loaded in 8-bit precision on multiple devices in any distributed mode. In order to use 8-bit models that have been loaded across multiple GPUs the solution is to use Naive Pipeline Parallelism. Therefore you should not specify that you are under any distributed regime in your accelerate config. ``` Some notes: - this works if I remove 8 bit training - I have tried this with and without `accelerator.prepare(model)` and this makes no difference (although when I remove 8bit training but keep this line, I get another error. When I remove the line, it trains fine). Any help appreciated!
08-03-2023 15:17:46
08-03-2023 15:17:46
@younesbelkada maybe you can have a look at it?
transformers
25,288
closed
device_map="auto" -> uninitialized parameters
### System Info - `transformers` version: 4.31.0 - Platform: Windows-10-10.0.19045-SP0 - Python version: 3.11.4 - Huggingface_hub version: 0.16.4 - Safetensors version: 0.3.1 - Accelerate version: 0.21.0 - Accelerate config: not found - PyTorch version (GPU?): 2.0.1+cu118 (True) ### Who can help? @ArthurZucker @younesbelkada Maybe also @sgugger because this is a general use-case about PyTorch models ### 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 I am encountering an issue that worries me slightly. When I load a model with `device_map`, everything goes fine - no warnings. ```python from transformers import AutoModelForSeq2SeqLM model = AutoModelForSeq2SeqLM.from_pretrained("BramVanroy/flan-t5-small-amr-en") ``` Howver, when I do use the device_map, I get the warning that some weights are not initialized ```python from transformers import AutoModelForSeq2SeqLM model = AutoModelForSeq2SeqLM.from_pretrained("BramVanroy/flan-t5-small-amr-en", device_map="auto") ``` Result: > Some weights of T5ForConditionalGeneration were not initialized from the model checkpoint at BramVanroy/flan-t5-small-amr-en and are newly initialized: ['decoder.embed_tokens.weight', 'encoder.embed_tokens.weight'] > You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference. However, I am wondering whether this isn't a false positive because the model performance seems the same with/without. My model repo contains both safetensors and the PyTorch *.bin, if that has something to do with it? ### Expected behavior Either a warning in both or no warning in either.
08-03-2023 13:54:40
08-03-2023 13:54:40
I think this should have been fixed by #25101 Could you try again with a source install? (Yes it is a false positive, just tied weights where the copies are not present in the state dict.)<|||||>Awesome, that works. Was afraid that I was messing something up with converting to safetensors. Glad that that is not the case. Thanks for the prompt response! @sgugger
transformers
25,287
open
Transformers Agent suggesting it should use text_generator although it is not provided.
### System Info I am running a version of [your notebook on Transformers Agent](https://colab.research.google.com/drive/1c7MHD-T1forUPGcC_jlwsIptOzpG3hSj), where I have added a cell where I ask the StarCoder agent to generate a sentence for me. I am using StarCoder, as you can see: ``` #@title Agent init agent_name = "StarCoder (HF Token)" #@param ["StarCoder (HF Token)", "OpenAssistant (HF Token)", "OpenAI (API Key)"] import getpass if agent_name == "StarCoder (HF Token)": from transformers.tools import HfAgent agent = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoder") print("StarCoder is initialized ๐Ÿ’ช") elif agent_name == "OpenAssistant (HF Token)": from transformers.tools import HfAgent agent = HfAgent(url_endpoint="https://api-inference.huggingface.co/models/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5") print("OpenAssistant is initialized ๐Ÿ’ช") if agent_name == "OpenAI (API Key)": from transformers.tools import OpenAiAgent pswd = getpass.getpass('OpenAI API key:') agent = OpenAiAgent(model="text-davinci-003", api_key=pswd) print("OpenAI is initialized ๐Ÿ’ช") ``` ### Who can help? @ArthurZucker and @younesbelkada ### 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 Based on the notebook mentioned, I have added a cell where I prompt the following: ``` agent.run("Write a sentence of the form 'A_ V_ at P_', where A_ should be replaced by the name of an animal, V_ should be replaced by a verb, and P_ should be replaced by the name of a place. Examples for valid sentences are 'Dog eating at macdonalds', 'Horse jumping at a gym', 'Duck fishing at a supermarket'. ") ``` As you see in the printout below, it suggests it will use the tool 'text_generation', but then stops because it does not have access to it. ``` ==Explanation from the agent== I will use the following tools: `text_classifier` to classify the sentence, then `text_generator` to generate the sentence. ==Code generated by the agent== sentence = text_generator(prompt="A_ V_ at P_") print(f"The sentence is {sentence}.") sentence_class = text_classifier(sentence) print(f"The sentence class is {sentence_class}.") ==Result== Evaluation of the code stopped at line 0 before the end because of the following error: It is not permitted to evaluate other functions than the provided tools (tried to execute text_generator). ``` ### Expected behavior Either, the agent should not even consider using "text_generation" as a tool, or it should have access to this tool as default.
08-03-2023 13:08:51
08-03-2023 13:08:51
I'm not too sure why you are reporting a bug. The agent is an LLM which sometimes hallucinate content (in this case, a tool that does not exist). If your prompt does not work, you should try refining it. You should also try using another model and see if it performs better.
transformers
25,286
closed
[JAX] Bump min version
# What does this PR do? Bumps the minimum version of JAX to [0.4.1](https://jax.readthedocs.io/en/latest/changelog.html#jax-0-4-1-dec-13-2022), the earliest version where the new `jax.Array` API is introduced, replacing the deprecated `jax.numpy.DeviceArray` API. This allows compatibility with the latest JAX version [0.4.14](https://jax.readthedocs.io/en/latest/changelog.html#jax-0-4-14-july-27-2023), where `jax.numpy.DeviceArray` is removed entirely. Related: #24875
08-03-2023 12:53:27
08-03-2023 12:53:27
_The documentation is not available anymore as the PR was closed or merged._
transformers
25,284
open
Fix Llama's attention map handling for left padding which causes numerical instability and performance drops
Hi this PR is trying to address the performance drop and potential numerical instability caused by vanilla left padding in Llama. Here is the explanation: 1. If we initialize the tokenizer with left padding and call model.generate without passing in corresponding attention_mask, the code will run, but for the instances who are left padded, its unpadded tokens will "see" the padded tokens. This will cause performance drop a lot ! At least in my case, my performance of llama2 in socialQA drops from 55% to around 20% if I use left padded batch inference instead of one by one generate. 2. If instead, I passed in the attention_map generated by the left_padding tokenizer to model.generate function, the model will throw an error when doing sampling because some values in the hidden states are inf or nan. This numerical instability suddenly appeared because train-test mismatch: **By examining the locations of these infs/nans, I found them only shows up in the position of those padded token and are caused by the attention_map.** 3. The reason why attention map are causing the numerical instability is because the current way of generating attention mask did not considered the left padded situation and it will cause the left padded tokens to have a fully masked attention tensor ! While the model was never trained with any token that can not see any(including itself) token, the model thus generates anomaly values and creates nan/inf. So this PR is trying to fix two bugs I observed: 1. The attention_mask created for left_padded values will contain -inf value due to the operation "expanded_attn_mask + combined_attention_mask". Consider the attention_map that looks like this ([[1, 1, 1, 1, 1], [0, 0, 0, 1, 1]]). The combined_attention_mask created by line 585 will look like this (under float16) ``` tensor([[[[ 0., -65504., -65504., -65504., -65504.], [ 0., 0., -65504., -65504., -65504.], [ 0., 0., 0., -65504., -65504.], [ 0., 0., 0., 0., -65504.], [ 0., 0., 0., 0., 0.]]], [[[ 0., -65504., -65504., -65504., -65504.], [ 0., 0., -65504., -65504., -65504.], [ 0., 0., 0., -65504., -65504.], [ 0., 0., 0., 0., -65504.], [ 0., 0., 0., 0., 0.]]]], device='cuda:0', dtype=torch.float16) ``` and the expanded_attn_mask created will look like this ``` tensor([[[[ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.]]], [[[-65504., -65504., -65504., 0., 0.], [-65504., -65504., -65504., 0., 0.], [-65504., -65504., -65504., 0., 0.], [-65504., -65504., -65504., 0., 0.], [-65504., -65504., -65504., 0., 0.]]]], device='cuda:0', dtype=torch.float16) ``` And in line 598 these two variables are added together. I believe it will be now clear why left padding causes the attention_map itself contains -inf values and why some tokens has a fully masked attn tensor. 3. My solution then is straightforward, I clamped the variables so it does not overflow, and I forces the left padded values to at least attend to itself. Though the hidden states of the left padded values will not be used by the unpadded tokens due to the attention map, making it cleaned of inf/nan will not break the generation process. 4. I tested in my local cases and I did not observe any performance drop or nan errors during sampling. Though I am not sure if my patches will break any other use cases.
08-03-2023 12:02:01
08-03-2023 12:02:01
cc @ArthurZucker
transformers
25,283
open
Use of logging.warn is deprecated in favour of logging.warning
There are a few places where `transformers` uses the deprecated `warn` method on a logger, while most of the library uses `warning`. While this works for now, it will presumably be removed at some point (calling it emits a `DeprecationWarning`) and it means that strict test runners (such as `pytest`) complain about some codepaths. As far as I can tell, all versions of Python supported by `transformers` support the new spelling (`warning` has been around for a _long_ time) so the upgrade should be simple. I'd be happy to have a go at a PR for this.
08-03-2023 11:38:29
08-03-2023 11:38:29
@PeterJCLaw Indeed! Happy to review a PR :)
transformers
25,282
open
Timm models Safetensor weights give 'NoneType' object has no attribute 'get', weight re-initialization and wrong num_labels
### System Info My env information: ``` - `transformers` version: 4.31.0 - Platform: Linux-5.15.0-78-generic-x86_64-with-glibc2.31 - Python version: 3.9.17 - Huggingface_hub version: 0.16.4 - Safetensors version: 0.3.1 - Accelerate version: 0.20.3 - 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? _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, ...) - [ ] My own task or dataset (give details below) ### Reproduction For a GSOC project under [Openvino Toolkit](https://summerofcode.withgoogle.com/archive/2022/organizations/openvino-toolkit), I have working with Timm models through Transformers. As we know most of the timm models(on HF Hub) are trained or fine-tuned on some variation of Imagenet dataset, and thus are effectively Image classification models. If I attempt to load Timm models using `AutoModelForImageClassification`, ``` import torch from transformers import AutoModelForImageClassification model_id = "timm/vit_tiny_r_s16_p8_224.augreg_in21k" hf_model = AutoModelForImageClassification.from_pretrained( model_id) out = hf_model(pixel_values = torch.zeros((5, 3, hf_model.config.image_size, hf_model.config.image_size))) print(out.logits.shape) ``` I get this Error: ``` Traceback (most recent call last): File "/home/sawradip/Desktop/practice_code/practice_gsoc/optimum-intel/../demo.py", line 10, in <module> hf_model = AutoModelForImageClassification.from_pretrained( model_id, File "/home/sawradip/miniconda3/envs/gsoc_env/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py", line 493, in from_pretrained return model_class.from_pretrained( File "/home/sawradip/miniconda3/envs/gsoc_env/lib/python3.9/site-packages/transformers/modeling_utils.py", line 2629, in from_pretrained state_dict = load_state_dict(resolved_archive_file) File "/home/sawradip/miniconda3/envs/gsoc_env/lib/python3.9/site-packages/transformers/modeling_utils.py", line 449, in load_state_dict if metadata.get("format") not in ["pt", "tf", "flax"]: AttributeError: 'NoneType' object has no attribute 'get' ``` I find that this issue doesn't occur if I force transformers to use pytorch weights, and avoid `.safetensors`. ``` import torch from transformers import AutoModelForImageClassification model_id = "timm/vit_tiny_r_s16_p8_224.augreg_in21k" hf_model = AutoModelForImageClassification.from_pretrained( model_id, use_safetensors = False ) out = hf_model(pixel_values = torch.zeros((5, 3, hf_model.config.image_size, hf_model.config.image_size))) print(out.logits.shape) ``` But I still get this warnings in the output, that a lot of weights were not initialized successfully. ``` Some weights of ViTForImageClassification were not initialized from the model checkpoint at timm/vit_tiny_r_s16_p8_224.augreg_in21k and are newly initialized: ['encoder.layer.0.layernorm_before.bias', 'encoder.layer.11.attention.attention.query.weight', 'encoder.layer.1.attention.attention.query.weight', 'encoder.layer.11.attention.output.dense.bias', 'encoder.layer.4.attention.output.dense.bias', 'encoder.layer.4.layernorm_before.bias', 'encoder.layer.10.attention.attention.query.weight', 'encoder.layer.6.attention.attention.key.weight', 'encoder.layer.4.output.dense.bias', 'encoder.layer.0.attention.attention.key.bias', 'encoder.layer.2.layernorm_after.weight', 'encoder.layer.7.attention.output.dense.bias', 'encoder.layer.7.output.dense.weight', 'encoder.layer.10.layernorm_after.bias', 'layernorm.bias', 'encoder.layer.0.attention.attention.key.weight', 'encoder.layer.1.attention.attention.value.bias', 'encoder.layer.4.output.dense.weight', 'embeddings.patch_embeddings.projection.weight', 'encoder.layer.6.attention.output.dense.weight', 'encoder.layer.1.layernorm_after.weight', 'encoder.layer.2.attention.attention.query.weight', 'encoder.layer.3.attention.attention.key.bias', 'encoder.layer.11.layernorm_after.bias', 'encoder.layer.4.attention.output.dense.weight', 'encoder.layer.2.layernorm_before.weight', 'encoder.layer.4.attention.attention.query.bias', 'encoder.layer.6.layernorm_after.weight', 'encoder.layer.4.intermediate.dense.bias', 'encoder.layer.7.layernorm_before.weight', 'encoder.layer.8.attention.attention.value.bias', 'encoder.layer.6.attention.attention.query.weight', 'encoder.layer.8.attention.output.dense.weight', 'encoder.layer.10.layernorm_before.weight', 'encoder.layer.1.intermediate.dense.bias', 'encoder.layer.9.attention.attention.key.weight', 'encoder.layer.6.layernorm_after.bias', 'classifier.bias', 'encoder.layer.1.layernorm_before.bias', 'encoder.layer.6.attention.output.dense.bias', 'encoder.layer.8.intermediate.dense.weight', 'encoder.layer.2.attention.output.dense.bias', 'encoder.layer.10.attention.output.dense.bias', 'encoder.layer.10.attention.attention.query.bias', 'encoder.layer.3.layernorm_before.bias', 'encoder.layer.3.intermediate.dense.weight', 'encoder.layer.5.attention.attention.value.bias', 'encoder.layer.6.attention.attention.value.weight', 'encoder.layer.0.layernorm_after.weight', 'encoder.layer.10.intermediate.dense.bias', 'encoder.layer.0.output.dense.bias', 'encoder.layer.0.attention.output.dense.bias', 'encoder.layer.7.layernorm_after.weight', 'encoder.layer.8.output.dense.bias', 'layernorm.weight', 'encoder.layer.0.output.dense.weight', 'encoder.layer.11.attention.attention.key.weight', 'encoder.layer.2.attention.attention.query.bias', 'encoder.layer.11.attention.attention.value.weight', 'encoder.layer.3.layernorm_after.bias', 'classifier.weight', 'encoder.layer.4.attention.attention.value.weight', 'encoder.layer.8.layernorm_after.weight', 'encoder.layer.9.attention.attention.query.weight', 'encoder.layer.0.intermediate.dense.bias', 'encoder.layer.8.output.dense.weight', 'encoder.layer.1.attention.attention.value.weight', 'encoder.layer.6.output.dense.weight', 'encoder.layer.6.output.dense.bias', 'encoder.layer.5.attention.attention.query.bias', 'encoder.layer.6.attention.attention.key.bias', 'encoder.layer.9.layernorm_before.bias', 'encoder.layer.7.attention.attention.query.weight', 'encoder.layer.5.output.dense.bias', 'encoder.layer.8.layernorm_after.bias', 'encoder.layer.2.attention.attention.key.weight', 'encoder.layer.5.layernorm_after.bias', 'encoder.layer.10.attention.output.dense.weight', 'encoder.layer.7.layernorm_after.bias', 'encoder.layer.5.intermediate.dense.weight', 'encoder.layer.9.attention.attention.value.bias', 'encoder.layer.3.output.dense.weight', 'encoder.layer.2.attention.attention.value.bias', 'encoder.layer.5.attention.attention.key.weight', 'encoder.layer.6.intermediate.dense.bias', 'encoder.layer.6.attention.attention.query.bias', 'encoder.layer.9.output.dense.weight', 'encoder.layer.0.attention.attention.value.weight', 'encoder.layer.3.attention.attention.value.bias', 'encoder.layer.2.layernorm_before.bias', 'encoder.layer.2.output.dense.weight', 'encoder.layer.1.output.dense.weight', 'encoder.layer.4.intermediate.dense.weight', 'encoder.layer.5.attention.attention.value.weight', 'encoder.layer.9.intermediate.dense.weight', 'encoder.layer.8.attention.attention.key.weight', 'encoder.layer.3.attention.attention.value.weight', 'encoder.layer.11.intermediate.dense.weight', 'encoder.layer.7.attention.attention.key.weight', 'encoder.layer.0.attention.attention.value.bias', 'encoder.layer.2.attention.attention.value.weight', 'encoder.layer.5.layernorm_before.bias', 'encoder.layer.0.intermediate.dense.weight', 'encoder.layer.5.intermediate.dense.bias', 'encoder.layer.2.intermediate.dense.bias', 'encoder.layer.5.layernorm_before.weight', 'encoder.layer.1.attention.output.dense.weight', 'encoder.layer.7.attention.attention.value.weight', 'encoder.layer.6.layernorm_before.weight', 'encoder.layer.3.attention.attention.key.weight', 'encoder.layer.11.attention.attention.query.bias', 'encoder.layer.5.attention.output.dense.bias', 'encoder.layer.6.layernorm_before.bias', 'encoder.layer.3.attention.output.dense.weight', 'encoder.layer.11.attention.output.dense.weight', 'encoder.layer.9.attention.output.dense.bias', 'encoder.layer.10.attention.attention.value.weight', 'encoder.layer.7.attention.attention.key.bias', 'encoder.layer.10.attention.attention.value.bias', 'encoder.layer.3.attention.output.dense.bias', 'encoder.layer.4.attention.attention.value.bias', 'encoder.layer.0.attention.output.dense.weight', 'encoder.layer.5.attention.output.dense.weight', 'encoder.layer.2.attention.attention.key.bias', 'encoder.layer.3.intermediate.dense.bias', 'encoder.layer.5.output.dense.weight', 'encoder.layer.8.attention.attention.query.weight', 'encoder.layer.3.attention.attention.query.bias', 'encoder.layer.1.attention.attention.key.weight', 'encoder.layer.4.layernorm_after.weight', 'encoder.layer.7.intermediate.dense.bias', 'encoder.layer.7.attention.attention.value.bias', 'encoder.layer.3.layernorm_before.weight', 'encoder.layer.11.attention.attention.key.bias', 'encoder.layer.10.output.dense.bias', 'encoder.layer.8.intermediate.dense.bias', 'encoder.layer.9.intermediate.dense.bias', 'encoder.layer.11.output.dense.weight', 'encoder.layer.1.attention.output.dense.bias', 'encoder.layer.3.output.dense.bias', 'encoder.layer.4.attention.attention.key.weight', 'encoder.layer.10.attention.attention.key.weight', 'encoder.layer.4.layernorm_before.weight', 'encoder.layer.9.attention.attention.value.weight', 'encoder.layer.5.attention.attention.query.weight', 'encoder.layer.2.output.dense.bias', 'encoder.layer.0.attention.attention.query.weight', 'encoder.layer.10.intermediate.dense.weight', 'encoder.layer.8.attention.attention.value.weight', 'encoder.layer.4.attention.attention.key.bias', 'encoder.layer.4.layernorm_after.bias', 'encoder.layer.6.intermediate.dense.weight', 'encoder.layer.7.intermediate.dense.weight', 'encoder.layer.9.attention.output.dense.weight', 'encoder.layer.11.output.dense.bias', 'encoder.layer.0.layernorm_after.bias', 'encoder.layer.9.attention.attention.query.bias', 'encoder.layer.11.attention.attention.value.bias', 'encoder.layer.8.attention.attention.key.bias', 'encoder.layer.2.attention.output.dense.weight', 'encoder.layer.9.layernorm_after.bias', 'encoder.layer.11.layernorm_after.weight', 'encoder.layer.6.attention.attention.value.bias', 'encoder.layer.2.layernorm_after.bias', 'encoder.layer.9.layernorm_after.weight', 'encoder.layer.1.attention.attention.key.bias', 'encoder.layer.10.output.dense.weight', 'encoder.layer.7.attention.attention.query.bias', 'embeddings.cls_token', 'encoder.layer.2.intermediate.dense.weight', 'encoder.layer.11.layernorm_before.weight', 'encoder.layer.0.attention.attention.query.bias', 'encoder.layer.1.layernorm_after.bias', 'encoder.layer.3.attention.attention.query.weight', 'encoder.layer.1.output.dense.bias', 'encoder.layer.10.layernorm_after.weight', 'encoder.layer.5.layernorm_after.weight', 'encoder.layer.1.layernorm_before.weight', 'encoder.layer.0.layernorm_before.weight', 'encoder.layer.5.attention.attention.key.bias', 'encoder.layer.8.layernorm_before.weight', 'encoder.layer.3.layernorm_after.weight', 'encoder.layer.10.layernorm_before.bias', 'embeddings.position_embeddings', 'encoder.layer.11.intermediate.dense.bias', 'encoder.layer.7.layernorm_before.bias', 'encoder.layer.1.attention.attention.query.bias', 'encoder.layer.10.attention.attention.key.bias', 'encoder.layer.7.attention.output.dense.weight', 'encoder.layer.9.layernorm_before.weight', 'encoder.layer.1.intermediate.dense.weight', 'encoder.layer.4.attention.attention.query.weight', 'encoder.layer.8.attention.attention.query.bias', 'encoder.layer.7.output.dense.bias', 'encoder.layer.8.layernorm_before.bias', 'encoder.layer.9.output.dense.bias', 'encoder.layer.8.attention.output.dense.bias', 'embeddings.patch_embeddings.projection.bias', 'encoder.layer.11.layernorm_before.bias', 'encoder.layer.9.attention.attention.key.bias'] ``` Meaning this models directly can not be used for classification on imagenet. But I still get a output the shape,(number of output classes: 2) which is not the expected number of class for this model ``` torch.Size([5, 2]) ``` Whereas the model name `timm/vit_tiny_r_s16_p8_224.augreg_in21k` indicates that, the weights were fine-tuned for `imagenet-21k`, meaning classes 21843. This happens because the attached model `config` files for all timm models in the hub, contains the number of output classes in `num_classes` parameter. Whereas `AutoConfig` expects the `num_labels` parameter from the config file, and not finding such an parameter, it assigns the default value 2, as can be seen [here](https://github.com/huggingface/transformers/blob/2bd7a27a671fd1d98059124024f580f8f5c0f3b5/src/transformers/configuration_utils.py#L331). So we can see in the model, ``` print(hf_model.config.num_classes) -> 21843 print(hf_model.config.num_labels) ->2 ``` ### I know there are a number of issues, but it is not possible to reproduce the later ones without fixing the previous one. So creating separate issues for each one would be more cumbersome for the reader. Let me summarize the points I am making: 1. Can not load timm models through `AutoModelForImageClassification` due to loading from `safetensors` weight. 2. If we mention explicitly`use_safetensors = False` , then the pytorch weights are loaded but Huge numbers of weights are initialized randomly.So the models won't be useful out of the box. 3. For all models, number of output classes are 2, and unlike timm's `create_model`, there is no option for specifying `num_classes` by users without modifying the config file. Is this behaviour expected? @amyeroberts @rwightman ### Expected behavior Expected behavior is , This mentioned code block will output: ``` torch.Size([5, 21843]) ```
08-03-2023 09:20:08
08-03-2023 09:20:08
@sawradip `timm` weights on the hub work in timm, unless I'm missing something (some automatic conversion was added that I'm not aware) I don't think there is any expectation you can load them in `transformers`? I feel the pytorch native weights is a bug that it doesn't crash and it's probably not loading any keys... ![Screenshot from 2023-08-03 15-20-06](https://github.com/huggingface/transformers/assets/5702664/c0c4d7ae-c0ea-45aa-9465-2c81a4a2a4c1)
transformers
25,281
closed
Docs: Update list of `report_to` logging integrations in docstring
# What does this PR do? ## Pull Request overview * Add missing `dagshub`, `codecarbon` and `flyte` integrations to `TrainingArguments` docstring. * Update `report_to` type hint to allow strings. ## Details I also converted the ordering back to alphabetical. I considered using a typing `Literal` as the type hint to help users via their IDE, but I haven't implemented it here as to not clash with the existing style. ## Before submitting - [x] This PR fixes a typo or improves the docs ## Who can review? @sgugger - Tom Aarsen
08-03-2023 08:52:32
08-03-2023 08:52:32
_The documentation is not available anymore as the PR was closed or merged._
transformers
25,280
open
How to download files from HF spaces
### System Info google colab ### Who can help? @sanchit-gandhi @rock ### 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 i tried: ``` from huggingface_hub import hf_hub_download,hf_hub_url # model_path = hf_hub_download(repo_id="xinyu1205/recognize-anything", filename="tag2text_swin_14m.pth", local_dir = "/content") ``` but throws an error repo not present ### Expected behavior download the file
08-03-2023 07:02:03
08-03-2023 07:02:03
Hi @andysingal, There is a typo in the repo_id. The correct command is: ``` model_path = hf_hub_download(repo_id="xinyu1205/recognize_anything_model", filename="tag2text_swin_14m.pth", local_dir = "/content") ``` If you receive an error that a repo doesn't exist, the best thing to do is check directly on the hub for the repo and file name. <|||||>The file exists in the space On Thu, Aug 3, 2023 at 15:41 amyeroberts ***@***.***> wrote: > Hi @andysingal <https://github.com/andysingal>, > > There is a typo in the repo_id. The correct command is: > > model_path = hf_hub_download(repo_id="xinyu1205/recognize_anything_model", filename="tag2text_swin_14m.pth", local_dir = "/content") > > If you receive an error that a repo doesn't exist, the best thing to do is > check directly on the hub for the repo and file name. > > โ€” > Reply to this email directly, view it on GitHub > <https://github.com/huggingface/transformers/issues/25280#issuecomment-1663711815>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AE4LJNPJ7VV53GDNHXAUTCLXTN2N7ANCNFSM6AAAAAA3CJWHSU> > . > You are receiving this because you were mentioned.Message ID: > ***@***.***> > <|||||>If downloading from the space, then you should specify the repo type in the `hf_hub_download` command ``` model_path = hf_hub_download(repo_id="xinyu1205/recognize-anything", filename="tag2text_swin_14m.pth", local_dir = "/content", repo_type="space") ```
transformers
25,279
closed
CI ๐Ÿš€ even more
# 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">
08-03-2023 06:03:20
08-03-2023 06:03:20
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.
transformers
25,278
open
Llama tokenizer add_prefix_space
Hi @sgugger This PR enables llama tokenizer supporting `add_prefix_space`. Would you please help me review it? Thanks!
08-03-2023 03:36:00
08-03-2023 03:36:00
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25278). All of your documentation changes will be reflected on that endpoint.<|||||>Hi @sgugger , I have the same request here. My problem is as follows: "\nObservation" is a substring of "!\nObservation", but in the encoded version by the `LlamaTokenizerFast` tokenizer, it is not the case anymore. This can be solved if we enable passing the `add_prefix_space` parameter to the tokenizer. Here is my code: ```python from transformers import AutoTokenizer model_name = 'lmsys/vicuna-13b-v1.3' tokenizer = AutoTokenizer.from_pretrained(model_name, add_special_tokens=False, padding=True, use_fast=True) print(tokenizer) for stop_word in ['\nObservation', '!\nObservation']: print(f'++++++++++{stop_word}+++++++++++++') tokens = tokenizer.tokenize(stop_word, add_special_tokens=False) print(tokens) ids = tokenizer.convert_tokens_to_ids(tokens) print(ids) ``` And here is the output: ```bash You are using the default legacy behaviour of the <class 'transformers.models.llama.tokenization_llama.LlamaTokenizer'>. This means that tokens that come after special tokens will not be properly handled. We recommend you to read the related pull request available at https://github.com/huggingface/transformers/pull/24565, and set the legacy attribute accordingly. LlamaTokenizerFast(name_or_path='lmsys/vicuna-13b-v1.3', vocab_size=32000, model_max_length=2048, is_fast=True, padding_side='right', truncation_side='right', special_tokens={'bos_token': AddedToken("<s>", rstrip=False, lstrip=False, single_word=False, normalized=True), 'eos_token': AddedToken("</s>", rstrip=False, lstrip=False, single_word=False, normalized=True), 'unk_token': AddedToken("<unk>", rstrip=False, lstrip=False, single_word=False, normalized=True), 'pad_token': '<unk>'}, clean_up_tokenization_spaces=False) ++++++++++ Observation+++++++++++++ ['โ–', '<0x0A>', 'Ob', 'serv', 'ation'] [29871, 13, 6039, 2140, 362] ++++++++++! Observation+++++++++++++ ['โ–!', '<0x0A>', 'Ob', 'serv', 'ation'] [1738, 13, 6039, 2140, 362] ``` As you can see, [29871, 13, 6039, 2140, 362] is not a subset of [1738, 13, 6039, 2140, 362] anymore. This is because the LlamaTokenizerFast always adds a prefix space before a word. <|||||>cc @ArthurZucker
transformers
25,277
open
Unable to quantize Meta's new AudioCraft MusicGen model
### System Info - Windows 11 64bit - Python 3.10.12 - Torch v2.0.1+cu117 - Transformers v4.31.0 - audiocraft v0.0.2 - bitsandbytes v0.41.0 ### 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 Hi, I'm attempting to quantize Meta's new MusicGen model with bitsandbytes (through the Transformers library) and I've run into a bug with the `deepcopy` function. I'm not familiar with PyTorch's deepcopy function or why this error may be occurring, but I am able to side-step it with a hack and get a bit further until I reach another error, this time with the Transformers library. The first error: ```python >>> from transformers import AutoProcessor, MusicgenForConditionalGeneration bin C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\bitsandbytes\libbitsandbytes_cuda117.dll >>> processor = AutoProcessor.from_pretrained("facebook/musicgen-small", load_in_8bit=True) >>> model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small", load_in_8bit=True) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\transformers\models\musicgen\modeling_musicgen.py", line 1599, in from_pretrained return super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\transformers\modeling_utils.py", line 2719, in from_pretrained modules_to_not_convert = get_keys_to_not_convert(model) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\transformers\utils\bitsandbytes.py", line 257, in get_keys_to_not_convert tied_model = deepcopy(model) # this has 0 cost since it is done inside `init_empty_weights` context manager` File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 271, in _reconstruct state = deepcopy(state, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 146, in deepcopy y = copier(x, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 297, in _reconstruct value = deepcopy(value, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 271, in _reconstruct state = deepcopy(state, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 146, in deepcopy y = copier(x, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 297, in _reconstruct value = deepcopy(value, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 271, in _reconstruct state = deepcopy(state, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 146, in deepcopy y = copier(x, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 297, in _reconstruct value = deepcopy(value, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 271, in _reconstruct state = deepcopy(state, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 146, in deepcopy y = copier(x, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 297, in _reconstruct value = deepcopy(value, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 271, in _reconstruct state = deepcopy(state, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 146, in deepcopy y = copier(x, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 297, in _reconstruct value = deepcopy(value, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 271, in _reconstruct state = deepcopy(state, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 146, in deepcopy y = copier(x, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\copy.py", line 153, in deepcopy y = copier(memo) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\torch\_tensor.py", line 86, in __deepcopy__ raise RuntimeError( RuntimeError: Only Tensors created explicitly by the user (graph leaves) support the deepcopy protocol at the moment ``` The hack: ```python torch.save(model, "temp.pt") tied_model = torch.load("temp.pt") ``` The second error after using the hack: ```python >>> from transformers import AutoProcessor, MusicgenForConditionalGeneration bin C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\bitsandbytes\libbitsandbytes_cuda117.dll >>> processor = AutoProcessor.from_pretrained("facebook/musicgen-small", load_in_8bit=True) >>> model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small", load_in_8bit=True) >>> inputs = processor(text=["80s pop track with bassy drums and synth"], padding=True, return_tensors="pt") >>> audio_values = model.generate(**inputs, do_sample=True, guidance_scale=3, max_new_tokens=256) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\transformers\models\musicgen\modeling_musicgen.py", line 2430, in generate outputs = self.sample( File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\transformers\generation\utils.py", line 2642, in sample outputs = self( File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\accelerate\hooks.py", line 165, in new_forward output = old_forward(*args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\transformers\models\musicgen\modeling_musicgen.py", line 1916, in forward decoder_outputs = self.decoder( File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\accelerate\hooks.py", line 165, in new_forward output = old_forward(*args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\transformers\models\musicgen\modeling_musicgen.py", line 1029, in forward outputs = self.model( File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\accelerate\hooks.py", line 165, in new_forward output = old_forward(*args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\transformers\models\musicgen\modeling_musicgen.py", line 938, in forward decoder_outputs = self.decoder( File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\accelerate\hooks.py", line 165, in new_forward output = old_forward(*args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\transformers\models\musicgen\modeling_musicgen.py", line 848, in forward layer_outputs = decoder_layer( File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\accelerate\hooks.py", line 165, in new_forward output = old_forward(*args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\transformers\models\musicgen\modeling_musicgen.py", line 394, in forward hidden_states = self.self_attn_layer_norm(hidden_states) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\accelerate\hooks.py", line 165, in new_forward output = old_forward(*args, **kwargs) File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\torch\nn\modules\normalization.py", line 190, in forward return F.layer_norm( File "C:\Users\fkdlam\anaconda3\envs\audiocraft\lib\site-packages\torch\nn\functional.py", line 2515, in layer_norm return torch.layer_norm(input, normalized_shape, weight, bias, eps, torch.backends.cudnn.enabled) RuntimeError: expected scalar type Float but found Half ``` This is the same code provided in [an example](https://huggingface.co/docs/transformers/main/en/model_doc/musicgen#textconditional-generation) for generating music in the Transformers documentation, except I've added the `load_in_8bit` flag. I'm not sure how to fix this one though. I've created [an issue](https://github.com/TimDettmers/bitsandbytes/issues/669) in the bitsandbytes repository too. ### Expected behavior Being able to run the MusicGen quantized model with bitsandbytes and obtain audio data output.
08-03-2023 00:18:53
08-03-2023 00:18:53
I figured out a fix by adding the line ```python inputs_embeds = inputs_embeds.to(torch.float16) ``` right after line 776, but I noticed commit https://github.com/huggingface/transformers/commit/03f98f96836477f6f5b86957d3ce98778cad5d94 which also fixes this bug. So the second bug is fixed if you're using a version of transformers since that commit a week ago. Now we are down to two problems: the original `deepcopy` bug and the fact that for some reason the quantized MusicGen model runs over 2x as slow as the non-quantized one. Not sure why that is because quantized models should be faster. I can't do anything about it so I'm at a dead end here.<|||||>Also, non-quantized, normal musicgen-large is about 2x slower on Transformers than Meta's own code. Interestingly musicgen-small is a bit faster than Meta's own code. About 10% faster.<|||||>cc @younesbelkada @sanchit-gandhi <|||||>For benchmarking `transformers` vs `audiocraft` - could you ensure that the `transformers` model is put in half (fp16) precision? By default, we always load in fp32 precision on CPU, whereas `audiocraft` always loads the model in fp16 precision on the GPU. Running the `transformers` model in fp16 half precision should give a considerable speed-up vs fp32 full precision: ```python model = MusicGenForConditionalGeneration.from_pretrained("facebook/musicgen-large", torch_dtype=torch.float16) ``` We can make this faster still by adding Flash Attention with a Better Transformers integration! This should give a further 10-15% speed-up<|||||>Regarding the quantisation, I was **not** able to load the model using bitsandbytes==0.40.0 using the following code snippet: ```python from transformers import MusicgenForConditionalGeneration model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small", load_in_8bit=True) ``` <details> <summary> Traceback </summary> ```python --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) Cell In[6], line 1 ----> 1 model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small", load_in_8bit=True) File ~/transformers/src/transformers/models/musicgen/modeling_musicgen.py:1595, in MusicgenForConditionalGeneration.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs) 1589 logger.warning( 1590 "Fast initialization is currently not supported for MusicgenForConditionalGeneration. " 1591 "Falling back to slow initialization..." 1592 ) 1593 kwargs["_fast_init"] = False -> 1595 return super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs) File ~/transformers/src/transformers/modeling_utils.py:2744, in PreTrainedModel.from_pretrained(cls, pretrained_model_name_or_path, config, cache_dir, ignore_mismatched_sizes, force_download, local_files_only, token, revision, use_safetensors, *model_args, **kwargs) 2742 # We keep some modules such as the lm_head in their original dtype for numerical stability reasons 2743 if llm_int8_skip_modules is None: -> 2744 modules_to_not_convert = get_keys_to_not_convert(model) 2745 else: 2746 modules_to_not_convert = llm_int8_skip_modules File ~/transformers/src/transformers/utils/bitsandbytes.py:257, in get_keys_to_not_convert(model) 245 r""" 246 An utility function to get the key of the module to keep in full precision if any For example for CausalLM modules 247 we may want to keep the lm_head in full precision for numerical stability reasons. For other architectures, we want (...) 253 Input model 254 """ 255 # Create a copy of the model and tie the weights, then 256 # check if it contains tied weights --> 257 tied_model = deepcopy(model) # this has 0 cost since it is done inside `init_empty_weights` context manager` 258 tied_model.tie_weights() 260 tied_params = find_tied_parameters(tied_model) File /usr/lib/python3.10/copy.py:172, in deepcopy(x, memo, _nil) 170 y = x 171 else: --> 172 y = _reconstruct(x, memo, *rv) 174 # If is its own copy, don't memoize. 175 if y is not x: File /usr/lib/python3.10/copy.py:271, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy) 269 if state is not None: 270 if deep: --> 271 state = deepcopy(state, memo) 272 if hasattr(y, '__setstate__'): 273 y.__setstate__(state) File /usr/lib/python3.10/copy.py:146, in deepcopy(x, memo, _nil) 144 copier = _deepcopy_dispatch.get(cls) 145 if copier is not None: --> 146 y = copier(x, memo) 147 else: 148 if issubclass(cls, type): File /usr/lib/python3.10/copy.py:231, in _deepcopy_dict(x, memo, deepcopy) 229 memo[id(x)] = y 230 for key, value in x.items(): --> 231 y[deepcopy(key, memo)] = deepcopy(value, memo) 232 return y File /usr/lib/python3.10/copy.py:172, in deepcopy(x, memo, _nil) 170 y = x 171 else: --> 172 y = _reconstruct(x, memo, *rv) 174 # If is its own copy, don't memoize. 175 if y is not x: File /usr/lib/python3.10/copy.py:297, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy) 295 for key, value in dictiter: 296 key = deepcopy(key, memo) --> 297 value = deepcopy(value, memo) 298 y[key] = value 299 else: [... skipping similar frames: deepcopy at line 172 (1 times)] File /usr/lib/python3.10/copy.py:271, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy) 269 if state is not None: 270 if deep: --> 271 state = deepcopy(state, memo) 272 if hasattr(y, '__setstate__'): 273 y.__setstate__(state) File /usr/lib/python3.10/copy.py:146, in deepcopy(x, memo, _nil) 144 copier = _deepcopy_dispatch.get(cls) 145 if copier is not None: --> 146 y = copier(x, memo) 147 else: 148 if issubclass(cls, type): File /usr/lib/python3.10/copy.py:231, in _deepcopy_dict(x, memo, deepcopy) 229 memo[id(x)] = y 230 for key, value in x.items(): --> 231 y[deepcopy(key, memo)] = deepcopy(value, memo) 232 return y [... skipping similar frames: deepcopy at line 172 (1 times)] File /usr/lib/python3.10/copy.py:297, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy) 295 for key, value in dictiter: 296 key = deepcopy(key, memo) --> 297 value = deepcopy(value, memo) 298 y[key] = value 299 else: [... skipping similar frames: deepcopy at line 172 (6 times), _deepcopy_dict at line 231 (3 times), _reconstruct at line 271 (3 times), deepcopy at line 146 (3 times), _reconstruct at line 297 (2 times)] File /usr/lib/python3.10/copy.py:297, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy) 295 for key, value in dictiter: 296 key = deepcopy(key, memo) --> 297 value = deepcopy(value, memo) 298 y[key] = value 299 else: File /usr/lib/python3.10/copy.py:172, in deepcopy(x, memo, _nil) 170 y = x 171 else: --> 172 y = _reconstruct(x, memo, *rv) 174 # If is its own copy, don't memoize. 175 if y is not x: File /usr/lib/python3.10/copy.py:271, in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy) 269 if state is not None: 270 if deep: --> 271 state = deepcopy(state, memo) 272 if hasattr(y, '__setstate__'): 273 y.__setstate__(state) File /usr/lib/python3.10/copy.py:146, in deepcopy(x, memo, _nil) 144 copier = _deepcopy_dispatch.get(cls) 145 if copier is not None: --> 146 y = copier(x, memo) 147 else: 148 if issubclass(cls, type): File /usr/lib/python3.10/copy.py:231, in _deepcopy_dict(x, memo, deepcopy) 229 memo[id(x)] = y 230 for key, value in x.items(): --> 231 y[deepcopy(key, memo)] = deepcopy(value, memo) 232 return y File /usr/lib/python3.10/copy.py:153, in deepcopy(x, memo, _nil) 151 copier = getattr(x, "__deepcopy__", None) 152 if copier is not None: --> 153 y = copier(memo) 154 else: 155 reductor = dispatch_table.get(cls) File ~/hf/lib/python3.10/site-packages/torch/_tensor.py:86, in Tensor.__deepcopy__(self, memo) 84 return handle_torch_function(Tensor.__deepcopy__, (self,), self, memo) 85 if not self.is_leaf: ---> 86 raise RuntimeError( 87 "Only Tensors created explicitly by the user " 88 "(graph leaves) support the deepcopy protocol at the moment" 89 ) 90 if id(self) in memo: 91 return memo[id(self)] RuntimeError: Only Tensors created explicitly by the user (graph leaves) support the deepcopy protocol at the moment ``` </details> However, I was with: ```python from transformers import MusicgenForConditionalGeneration import torch with torch.no_grad(): model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small", load_in_8bit=True) ``` I can take a deeper look into why the bnb conversion is failing unless @younesbelkada has an idea from this behaviour! Note that if you care about inference speed, your best bet is to stick with fp16 inference here: ```python from transformers import MusicgenForConditionalGeneration model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small", torch_dtype=torch.float16) ```
transformers
25,276
open
vectorize PrefixConstrainedLogitsProcessor
# 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 #25217 (in part). ## 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. - [ ] 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. @gante
08-02-2023 20:56:57
08-02-2023 20:56:57
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25276). All of your documentation changes will be reflected on that endpoint.<|||||>There's a silly shape thing happening here which I'll try to debug ASAP (unless others are interested). Unfortunately testing locally is not working since I'm on Silicon and some dependencies for dev aren't available โ˜น๏ธ but this looks close. I'll want to think hard about the vectorization of the function (which is slightly different and hopefully not breaking).<|||||>@erip thank you for jumping into the issue ๐Ÿ’ช LMK when it is ready for review (assuming it yields speedups)<|||||>I believe it'll yield some improvements since there will be much less CPU<->GPU with masking ops. Whether they're significant will be hard to measure. My big concern is that the semantics of the prefix fn will change slightly (reflected in the test); whether this is acceptable is unclear.<|||||>Worst case scenario, a flag could be set at init time (of the logits processor), if the function supports vectorization<|||||>cc @gante I think this is ready for review. Nothing too controversial here, but I can add a fallback to original behavior in case the fn doesn't support vectorization. I'd like to test the speedup eventually, but I think this won't incur regressions at the very least.
transformers
25,275
open
Replace jnp.DeviceArray with jax.Array in FLAX models
## What does this PR do? Recent JAX versions have dropped support for jax.numpy.DeviceArray. Many FLAX models refer to jax.numpy.DeviceArray which causes a crash. This PR replaces all references to jax.numpy.DeviceArray with jax.Array. <!-- 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. --> ## 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 @sanchit-gandhi <!-- 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: @sgugger Integrations: - deepspeed: HF Trainer/Accelerate: @pacman100 - ray/raytune: @richardliaw, @amogkam Documentation: @sgugger, @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: @sgugger - TensorFlow: @Rocketknight1 -->
08-02-2023 20:03:56
08-02-2023 20:03:56
Thanks for the fix @akhilgoe - believe this is a duplicate of #24875?<|||||> > Thanks for the fix @akhilgoe - believe this is a duplicate of #24875? Yes correct! <|||||>If it's okay with you can we give @mariecwhite the opportunity to finish their PR since they've worked on it since last week? (should be merged asap, just requires CircleCI authentication) Very much appreciate you opening this PR to fix the deprecation though!<|||||>I'm still running into CircleCI issues with https://github.com/huggingface/transformers/pull/24875. Feel free to merge this PR instead.<|||||>Hey guys...Thanks for the update! I don't have a preference, We can use either of the 2 PRs.
transformers
25,274
closed
CI with `pytest_num_workers=8` for torch/tf jobs
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 improve things in follow PR(s).
08-02-2023 19:21:30
08-02-2023 19:21:30
_The documentation is not available anymore as the PR was closed or merged._
transformers
25,273
closed
use `pytest_num_workers=8` for `torch_job` and `tf_job`
# 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).
08-02-2023 19:17:59
08-02-2023 19:17:59
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.
transformers
25,272
closed
Question about generate method for AutoModelForCausalLM
Hi, I am trying to use the git model from the pretrained to pass to captum API for calculation of the attribution score. ` ### Initialize the attribution algorithm from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("microsoft/git-base") ig = IntegratedGradients(model) ` However, in order for the IG algorithm to work, the "model" should be the forward function of the model. I need to understand how the output of the model ` outputs = model(input_ids=training_batch["input_ids"], attention_mask=training_batch["attention_mask"], pixel_values=training_batch["pixel_values"], labels=training_batch["input_ids"]) ` corresponds with output of the generate method `generated_ids = model.generate(pixel_values=pixel_values, max_length=80)` ?
08-02-2023 17:08:26
08-02-2023 17:08:26
Hi, thanks for raising an issue! This is a question best placed in our [forums](https://discuss.huggingface.co/). We try to reserve the github issues for feature requests and bug reports.
transformers
25,271
open
EncoderDecoder does not automatically create decoder_attention_mask to match decoder_input_ids
### System Info ``` - `transformers` version: 4.31.0 - Platform: Linux-4.15.0-192-generic-x86_64-with-glibc2.27 - Python version: 3.11.4 - Huggingface_hub version: 0.16.4 - Safetensors version: 0.3.1 - Accelerate version: 0.21.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?: yes - Using distributed or parallel set-up in script?: no ``` ### Who can help? @ArthurZucker @NielsRogge ### 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 I'm using a pretrained BERT model to make a bert2bert model using an EncoderDecoderModel. According to the [documentation](https://huggingface.co/docs/transformers/model_doc/encoder-decoder#transformers.EncoderDecoderModel.forward.decoder_input_ids) and a deprecation warning in the [source code](https://github.com/huggingface/transformers/blob/bef02fd6b9cde975c51607fb936050ef706ff6d8/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py#L42-L47), it says that you no longer need to pass in `decoder_input_ids` as they'll be automatically generated using `labels`. In the docs specifically, [it also goes on to say](https://huggingface.co/docs/transformers/model_doc/encoder-decoder#transformers.EncoderDecoderModel.forward.decoder_attention_mask) that the default behavior of `decoder_attention_mask` is to automatically generate it based on padded tokens in `decoder_input_ids`, so you don't need to pass the decoder attention mask either, as expected. However, when trying to just pass `input_ids + attention_mask` for the encoder and `labels`, I get a warning that says something to the effect of "we strongly recommend passing an attention mask". If I explicitly pass `input_ids, attention_mask, decoder_input_ids, decoder_attention_mask, and labels`, the warning goes away. Looking at the implementation of creating the `decoder_input_ids` from `labels`, it does indeed seem to skip the generation of `decoder_attention_mask` and simply passes through the value from the arguments, in this case `None`: https://github.com/huggingface/transformers/blob/e42587f596181396e1c4b63660abf0c736b10dae/src/transformers/models/encoder_decoder/modeling_encoder_decoder.py#L619-L637 You can recreate the warning in the notebook that Patrick made for the blog (https://colab.research.google.com/github/patrickvonplaten/notebooks/blob/master/Leveraging_Pre_trained_Checkpoints_for_Encoder_Decoder_Models.ipynb#scrollTo=yoN2q0hZUbXN&line=11&uniqifier=1). Specifically, in the `process_data_to_model_inputs` function, you can just comment out the lines which explicitly set `decoder_input_ids` and `decoder_attention_mask`. ### Expected behavior I'd expect that if you can just pass `labels` to the forward call of EncoderDecoder and it will create `decoder_input_ids`, it would also create `decoder_attention_mask`. The fix is probably a few lines: ```python if (labels is not None) and (decoder_input_ids is None and decoder_inputs_embeds is None): decoder_input_ids = shift_tokens_right( labels, self.config.pad_token_id, self.config.decoder_start_token_id ) if decoder_attention_mask is not None: raise Exception # some error for passing 1/2 of decoder input_id/attn_mask? decoder_attention_mask = torch.where(decoder_input_ids == self.config.pad_token_id, 0, 1) ```
08-02-2023 14:59:12
08-02-2023 14:59:12
somewhat related, it seems like in the notebook, the `decoder_input_ids` nor the `labels` are shifted; Patrick claims it's because: > `"labels"` are shifted automatically to the left for language modeling training. but I don't see any evidence of this in the implementation. Was this behavior changed at some point? The notebook seems like it might be out of date? My current solution to the original `decoder_attention_mask` issue is to manually pass in `decoder_input_ids` shifted 1 to the right with matching `decoder_attention_mask`, while `labels` remains unchanged.<|||||>cc @ArthurZucker @younesbelkada
transformers
25,270
open
Device errors when loading in 8 bit
### System Info Copy-and-paste the text below in your GitHub issue and FILL OUT the two last points. - `transformers` version: 4.31.0 - Platform: Linux-5.10.178-162.673.amzn2.x86_64-x86_64-with-glibc2.26 - Python version: 3.10.10 - Huggingface_hub version: 0.16.4 - Safetensors version: 0.3.1 - Accelerate version: 0.21.0 - Accelerate config: not found - PyTorch version (GPU?): 2.0.0 (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?: Yes (4 GPUs) - Using distributed or parallel set-up in script?: ### Who can help? @younesbelkada @sgugger @mue ### 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 This error occurs when trying to split a quantised `t5-large` model (or any t5 model for that matter) across 4 GPUs using a custom device map (which works when it is not quantised)! Steps to reproduce: 1. ``` from transformers import AutoTokenizer, DataCollatorWithPadding, TrainingArguments, Trainer, AutoModelForCausalLM, AutoModelForSeq2SeqLM from peft import get_peft_config, get_peft_model, PromptTuningInit, PromptTuningConfig, TaskType, PeftType from torch.utils.data import TensorDataset, DataLoader,Dataset from accelerate import dispatch_model, infer_auto_device_map, init_empty_weights from accelerate.utils import get_balanced_memory model_name = "t5-large" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForSeq2SeqLM.from_pretrained(model_name, cache_dir = 'models', load_in_8bit=True) ``` 2. ``` max_memory = get_balanced_memory( model, max_memory=None, no_split_module_classes=["T5Block"], dtype='float16', low_zero=False, ) ``` max_memory: `{0: 263982848, 1: 263982848, 2: 263982848, 3: 13860929536, 'cpu': 189321494528}` 3. ``` device_map = infer_auto_device_map( model, max_memory=max_memory, no_split_module_classes=["T5Block"], dtype='float16' ) ``` I won't show the entire device_map, just the important part: ``` {'shared': 0, 'decoder.embed_tokens': 0, 'encoder.embed_tokens': 0, 'lm_head': 0, 'encoder.block.0': 0, 'encoder.block.1': 0, 'encoder.block.2': 0, 'encoder.block.3': 0, 'encoder.block.4': 0, 'encoder.block.5': 0, 'encoder.block.6': 0, 'encoder.block.7': 0, 'encoder.block.8': 0, 'encoder.block.9': 0, 'encoder.block.10': 1, 'encoder.block.11': 1, 'encoder.block.12': 1, ``` 4. ``` model = dispatch_model(model, device_map=device_map) for i in model.named_parameters(): print(f"{i[0]} -> {i[1].device}") ``` Again, just the pertinent part: ``` encoder.block.10.layer.0.SelfAttention.q.weight -> cuda:0 encoder.block.10.layer.0.SelfAttention.k.weight -> cuda:0 encoder.block.10.layer.0.SelfAttention.v.weight -> cuda:0 encoder.block.10.layer.0.SelfAttention.o.weight -> cuda:0 encoder.block.10.layer.0.layer_norm.weight -> cuda:0 encoder.block.10.layer.1.DenseReluDense.wi.weight -> cuda:0 encoder.block.10.layer.1.DenseReluDense.wo.weight -> cuda:0 encoder.block.10.layer.1.layer_norm.weight -> cuda:0 encoder.block.11.layer.0.SelfAttention.q.weight -> cuda:1 encoder.block.11.layer.0.SelfAttention.k.weight -> cuda:1 encoder.block.11.layer.0.SelfAttention.v.weight -> cuda:1 encoder.block.11.layer.0.SelfAttention.o.weight -> cuda:1 encoder.block.11.layer.0.layer_norm.weight -> cuda:1 encoder.block.11.layer.1.DenseReluDense.wi.weight -> cuda:1 encoder.block.11.layer.1.DenseReluDense.wo.weight -> cuda:1 encoder.block.11.layer.1.layer_norm.weight -> cuda:1 ``` 5. ``` batch = tokenizer("Hello World", return_tensors="pt") model(**batch, decoder_input_ids = batch['input_ids']) ``` ### Expected behavior Error: ``` File ~/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages/transformers/models/t5/modeling_t5.py:260, in T5LayerNorm.forward(self, hidden_states) 257 if self.weight.dtype in [torch.float16, torch.bfloat16]: 258 hidden_states = hidden_states.to(self.weight.dtype) --> 260 return self.weight * hidden_states RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:1 and cuda:0! ``` Note that repeating this with `load_in_8bit = False` works normally. Thanks!
08-02-2023 13:39:56
08-02-2023 13:39:56
You cannot re-dispatch a model that was loaded in 8bit. You need to pass along your `max_memory` or `device_map` to the call to `from_pretrained`.
transformers
25,269
open
run_clm_no_trainer.py example - problem with most recent checkpoint loading
The example has code for finding the latest checkpoint, but accelerator.load_state isn't called. https://github.com/huggingface/transformers/blob/1baeed5bdf3c58b723a6125632567f97bdf322c6/examples/pytorch/language-modeling/run_clm_no_trainer.py#L561C15-L561C15
08-02-2023 13:39:33
08-02-2023 13:39:33
Hi @TomerRonen34, thanks for raising this issue! Can you make sure to follow the issue template and include: * A reproducible code snippet * Details of the expected and observed behaviour including the full traceback if it exists * Information about the running environment: run `transformers-cli env` in the terminal and copy-paste the output
transformers
25,268
closed
recommend DeepSpeed's Argument Parsing documentation
# What does this PR do? Clarify how to properly set the arguments passed by `deepspeed` when running in CLI. For example the following errors might be raised when running something like `deepspeed --num_gpus=2 fine-tune.py google/flan-t5-xxl` due to args passed by `deepspeed`: ``` usage: fine-tune.py [-h] model_id fine-tune.py: error: unrecognized arguments: --local_rank=0 --deepspeed llms/flan-t5-fp16-z3.json usage: fine-tune.py [-h] model_id fine-tune.py: error: unrecognized arguments: --local_rank=1 --deepspeed llms/flan-t5-fp16-z3.json ``` ## Before submitting - [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case). ## 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. @stas00 @sgugger
08-02-2023 13:32:15
08-02-2023 13:32:15
cc @pacman100 <|||||>_The documentation is not available anymore as the PR was closed or merged._
transformers
25,267
closed
[MMS] Fix mms
# 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 #25260. The problem is that the model state_dict is retrieved before the weights are tied which in the case of MMS/Wav2Vec2 means before the state dict is rewritten to the correct expected structure since MMS/Wav2Vec2 loads adapter weights when modeling_utils calls `tie_weights`. I'm not 100% sure if the moving `model.tie_weights()` up here a couple of lines is ok, but it's necessary to fix MMS. I'm pretty sure it's fine because `tie_weights` should not fundamentally change the state_dict architectures for models != MMS. I'm not able to fully pinpoint the reason for how this bug came to be, but as stated in #25260 loading MMS worked on the PR and without having `accelerate` installed it also worked on the main. There were a couple of PRs that touched similar logic around at the same time or a bit later/sooner which might have caused the issue. - https://github.com/huggingface/transformers/pull/24200 - https://github.com/huggingface/transformers/pull/24505 - https://github.com/huggingface/transformers/pull/24310 I might have accidentally also not synced my PR branch with "main" before merging so that between starting to work on it and merging a different logic creeped in. ## 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? 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. <!-- 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: @sgugger Integrations: - deepspeed: HF Trainer/Accelerate: @pacman100 - ray/raytune: @richardliaw, @amogkam Documentation: @sgugger, @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: @sgugger - TensorFlow: @Rocketknight1 -->
08-02-2023 13:26:07
08-02-2023 13:26:07
_The documentation is not available anymore as the PR was closed or merged._<|||||>@ydshieh ok to merge or should we run some more tests?<|||||>The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25267). All of your documentation changes will be reflected on that endpoint.
transformers
25,266
closed
CI with layers=2
# What does this PR do? Running a (sub) set of 24315 tests (given by test fetcher) - only tests in `test_modeling_xxx.py`. (for a full run like nightly run, it doesn't seem change anything about running time - need more investigation) Running time: - num_layers = mixed (2, 3, 4, 5, 6) - currently `main` - torch: 16m - tf: : 8m - flax: 11m30 - num_layers = 2 - torch: 12m30 - tf: 8m (not sure nothing change) - flax: 8m30
08-02-2023 13:08:37
08-02-2023 13:08:37
_The documentation is not available anymore as the PR was closed or merged._
transformers
25,265
open
[`Docs` / `BetterTransformer` ] Added more details about flash attention + SDPA
# What does this PR do? as discussed offline with @LysandreJik This PR clarifies to users how it is possible to use Flash Attention as a backend for most used models in transformers. As we have a seen some questions from users asking whether it is possible to integrate flash attention into HF models, whereas you can already benefit from it when using `model.to_bettertransformer()`, leveraging the `BetterTransformer` API from ๐Ÿค— optimum. The informations are based from the [official documentation of `torch.nn.functional.scaled_dot_product`](https://pytorch.org/docs/master/generated/torch.nn.functional.scaled_dot_product_attention.html?highlight=scaled_dot_product_attention#torch.nn.functional.scaled_dot_product_attention) In the near future, we could also have a small blogpost explaining this as well To do list / To clarify list: - Clarify that it is possible to do that for training as well (I did not added much on the training section) - Maybe add a few lines in overview of performance and scalability to emphasize this? Let me know if I missed anything else cc @fxmarty @MKhalusova @stevhliu
08-02-2023 12:59:23
08-02-2023 12:59:23
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25265). All of your documentation changes will be reflected on that endpoint.<|||||>Thanks a lot for the extensive review @stevhliu ! ๐ŸŽ‰
transformers
25,264
open
[Question] How to load AutoFeatureExtractor on GPU?
Hi, I am following this guide to learn how to do audio classification with wav2vec2: https://huggingface.co/docs/transformers/main/tasks/audio_classification I intend to extract features of my data with the following codes ``` feature_extractor = AutoFeatureExtractor.from_pretrained("/workspace/models/wav2vec2-large-robust") def preprocess_function(examples): audio_arrays = [x["array"] for x in tqdm(examples["audio"])] inputs = feature_extractor( audio_arrays, sampling_rate=feature_extractor.sampling_rate, max_length=16000, truncation=True ) return inputs encoded_audio_dataset_train = audio_dataset_train.map(preprocess_function, remove_columns="audio", batched=True) ``` But it seems the extractor is loaded to CPU instead of GPU, and I didn't find in documentation how to set the device for loading feature extractor. I assume the feature extraction is done by the wav2vec2 model itself right? If so how to do this on GPU? Or is it mentioned in any documentation that I didn't notice? This is my first time to use transformers library in audio processing so please forgive my clumsiness. Any help is much appreciated.
08-02-2023 12:26:20
08-02-2023 12:26:20
Hi @treya-lin, thanks for raising an issue! This is a question best placed in our [forums](https://discuss.huggingface.co/). We try to reserve the github issues for feature requests and bug reports. You can move arrays prepared by the feature extractor to the GPU using the `to` method on its outputs: ``` def preprocess_function(examples): audio_arrays = [x["array"] for x in tqdm(examples["audio"])] inputs = feature_extractor( audio_arrays, sampling_rate=feature_extractor.sampling_rate, max_length=16000, truncation=True ).to("cuda") return inputs ```
transformers
25,263
closed
Remove `pytest_options={"rA": None}` in CI
# What does this PR do? This option causes the (TF/Flax) jobs to spend 6-8 minutes (for a full set run) to prepare something for reporting after the actual tests are finished. Taking [this TF job (nightly run)](https://app.circleci.com/pipelines/github/huggingface/transformers/69562/workflows/8fd9db08-9730-4d57-90b5-660c8a48a55c/jobs/872686/steps) for example, we can see the situation in the following screenshot <img width="1044" alt="Screenshot 2023-08-02 132209" src="https://github.com/huggingface/transformers/assets/2521628/67e6bc89-d0d3-4d6a-9090-f3e1042be639"> Note that the torch job doesn't have this option, as it is removed ~ 3 years ago by Stas in #7995. Also, we still have all the reports we need in the artifact tab. (I don't remember the details about `-rA` though - Stas is the expert of this)
08-02-2023 11:36:03
08-02-2023 11:36:03
_The documentation is not available anymore as the PR was closed or merged._<|||||> > For reference, I think `-rA` generates a [detailed summary report for all groups](https://docs.pytest.org/en/6.2.x/usage.html#detailed-summary-report). Oh yes, my memory mixed the `--make-reports` and `-rA` things. Thanks! <|||||>> As it was removed for the torch job a long time ago, I'm happy for it to be removed here :) If you were not happy, we will have to spend more๐Ÿค‘ on CircleCI credits ๐Ÿ’ธ ๐Ÿ˜† (and for nothing)
transformers
25,262
open
model.push_to_hub not working for gtr-large while loading with 8-bit using bnb
### System Info Issue :- I want to load gtr-large model in 8-bits using bitsandbytes and save it for future usage model = T5ForConditionalGeneration.from_pretrained('sentence-transformers/gtr-t5-large',load_in_8bit=True) model.push_to_hub("snigdhachandan/gtr_large_8bit") Error :- Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/glide/anaconda/envs/llm/lib/python3.11/site-packages/transformers/utils/hub.py", line 814, in push_to_hub self.save_pretrained(work_dir, max_shard_size=max_shard_size, safe_serialization=safe_serialization) File "/glide/anaconda/envs/llm/lib/python3.11/site-packages/transformers/modeling_utils.py", line 1820, in save_pretrained shards, index = shard_checkpoint(state_dict, max_shard_size=max_shard_size, weights_name=weights_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/glide/anaconda/envs/llm/lib/python3.11/site-packages/transformers/modeling_utils.py", line 318, in shard_checkpoint storage_id = id_tensor_storage(weight) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/glide/anaconda/envs/llm/lib/python3.11/site-packages/transformers/pytorch_utils.py", line 290, in id_tensor_storage return tensor.device, storage_ptr(tensor), storage_size(tensor) ^^^^^^^^^^^^^ AttributeError: 'str' object has no attribute 'device' Transformers Version :- 4.30.2 Torch Version :- 2.0.1+cu117 ### 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 model = T5ForConditionalGeneration.from_pretrained('sentence-transformers/gtr-t5-large',load_in_8bit=True) model.push_to_hub("snigdhachandan/gtr_large_8bit") ### Expected behavior It should have been push to Huggingface Hub
08-02-2023 11:18:38
08-02-2023 11:18:38
Hi @nss-programmer, thanks for raising this issue. There's been quite a few updates between bitsandbytes and transformers recently. Could you update your local transformers version to the most recent release `pip install --upgrade transformers` and try again? If that doesn't work, then could you try from source `pip install git+https://github.com/huggingface/transformers` and let us know if either of these work? This way, we can figure out if the issue has already been resolved. Could you also share more information about the running environment )run `transformers-cli env` in the terminal and copy-paste the output) specifically, the bitsandbytes and huggingface_hub versions installed? cc @younesbelkada <|||||>Thanks for the ping! The issue you are describing is really close to what I have described in https://github.com/huggingface/transformers/pull/24416 I believe installing the lib from source as @amyeroberts mentioned should resolve it!
transformers
25,261
open
Mask2Former broadcasting issue when running inference on model traced with GPU device
### System Info ``` - System information: x86_64 GNU/Linux - Ubuntu version: 18.04 - Python version: 3.8.12 - CUDA version: 11.1 - PyTorch version: 2.0.1 - transformers version: 4.31.0 ``` ### Who can help? @amyeroberts @sgugger @muellerzr ### 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 ``` import torch from transformers import Mask2FormerForUniversalSegmentation device = torch.device("cuda") model = Mask2FormerForUniversalSegmentation.from_pretrained( "facebook/mask2former-swin-tiny-coco-instance", torchscript=True ).eval().to(device) dummy_input = torch.randn((1,3,640,640)).to(device) traced_model = torch.jit.trace(model, dummy_input) with torch.no_grad(): out = traced_model(torch.randn((2,3,640,640)).to(device)) out = traced_model(torch.randn((2,3,640,640)).to(device)) ``` The above code generates the following error when calling the **second** forward of `traced_model` (last line): ``` Traceback (most recent call last): File "mask2former_trace.py", line 14, in <module> out = traced_model(torch.randn((2,3,640,640)).to(device)) File "~/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(*args, **kwargs) RuntimeError: The following operation failed in the TorchScript interpreter. Traceback of TorchScript (most recent call last): ~/python3.8/site-packages/torch/functional.py(378): einsum ~/python3.8/site-packages/transformers/models/mask2former/modeling_mask2former.py(2015): forward ~/python3.8/site-packages/torch/nn/modules/module.py(1488): _slow_forward ~/python3.8/site-packages/torch/nn/modules/module.py(1501): _call_impl ~/python3.8/site-packages/transformers/models/mask2former/modeling_mask2former.py(1852): forward ~/python3.8/site-packages/torch/nn/modules/module.py(1488): _slow_forward ~/python3.8/site-packages/torch/nn/modules/module.py(1501): _call_impl ~/python3.8/site-packages/transformers/models/mask2former/modeling_mask2former.py(2080): forward ~/python3.8/site-packages/torch/nn/modules/module.py(1488): _slow_forward ~/python3.8/site-packages/torch/nn/modules/module.py(1501): _call_impl ~/python3.8/site-packages/transformers/models/mask2former/modeling_mask2former.py(2271): forward ~/python3.8/site-packages/torch/nn/modules/module.py(1488): _slow_forward ~/python3.8/site-packages/torch/nn/modules/module.py(1501): _call_impl ~/python3.8/site-packages/transformers/models/mask2former/modeling_mask2former.py(2496): forward ~/python3.8/site-packages/torch/nn/modules/module.py(1488): _slow_forward ~/python3.8/site-packages/torch/nn/modules/module.py(1501): _call_impl ~/python3.8/site-packages/torch/jit/_trace.py(1056): trace_module ~/python3.8/site-packages/torch/jit/_trace.py(794): trace mask2former_trace.py(10): <module> RuntimeError: einsum(): subscript b has size 2 for operand 1 which does not broadcast with previously seen size 400 ``` If I trace the model with batch size 2, i.e. `dummy_input = torch.randn((2,3,640,640)).to(device)`, the same error arises at the **first** forward call of `traced_model` The issue seems to be [here](https://github.com/huggingface/transformers/blob/e42587f596181396e1c4b63660abf0c736b10dae/src/transformers/models/mask2former/modeling_mask2former.py#L2015) ### Expected behavior When tracing on CPU, i.e. in the code above: ``` device = torch.device("cpu") ``` everything works fine. I would expect similar behaviour when tracing on GPU device. **Additional notes**: I already tried tracing the model on CPU device, then moving `traced_model` (as well as the input tensors) to GPU, and running inference, but I got the following error: ``` RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! ``` I know this is a known issue: https://github.com/huggingface/transformers/issues/5664 https://github.com/huggingface/transformers/issues/22038 so I guess there should be some tensors in Mask2Former created at forward time with the same device as the input, and torchscript does not change that device when running on GPU. This is the reason why I need to trace the model on GPU.
08-02-2023 11:06:50
08-02-2023 11:06:50
Hi @matteot11, thanks for reporting this and for providing such a detailed and clean issue report โค๏ธ Looking into it ๐Ÿ” <|||||>@matteot11 I'm going to open up a PR soon to resolve this and remove the einsum operations. In the meantime, if you need to be able to run a compiled model now, it will run on torch nightly (with a bunch of tracer warnings). <|||||>Hi @amyeroberts, thanks for your fast reply. With torch nightly I am able to correctly forward the `traced_model` multiple times (even if it was exported using `torch==2.0.1`). Thanks for the hint! I don't know if this is expected, but when running the model traced on GPU, the following assert sometimes fails: ``` device = torch.device("cuda") dummy_input = torch.randn((2,3,640,640)).to(device) assert torch.isclose(model(dummy_input)[0], traced_model(dummy_input)[0]).all() ``` This does not happen when exporting the model to the CPU. Waiting for your PR!
transformers
25,260
closed
โš ๏ธ [Wav2Vec2-MMS] `pipeline` and `from_pretrained` fail to load the Wav2Vec2 MMS checkpoints
### System Info - `transformers` version: 4.31.0 - Platform: Linux-5.15.109+-x86_64-with-glibc2.35 - Python version: 3.10.12 - Huggingface_hub version: 0.16.4 - Safetensors version: 0.3.1 - Accelerate version: not installed - Accelerate config: not found - PyTorch version (GPU?): 2.0.1+cu118 (False) - Tensorflow version (GPU?): 2.12.0 (False) - Flax version (CPU?/GPU?/TPU?): 0.7.0 (cpu) - Jax version: 0.4.13 - JaxLib version: 0.4.13 - Using GPU in script?: `No` - Using distributed or parallel set-up in script?: `No` ### Who can help? @sanchit-gandhi @patrickvonplaten ### 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 Put together a quick colab to run the model as mentioned in [our documentation](https://huggingface.co/docs/transformers/model_doc/mms#loading) - [colab notebook](https://github.com/Vaibhavs10/scratchpad/blob/main/wav2vec2_mms_repro.ipynb) code snippets: `Pipeline` ```python from transformers import pipeline model_id = "facebook/mms-1b-all" target_lang = "fra" pipe = pipeline(model=model_id, model_kwargs={"target_lang": target_lang, "ignore_mismatched_sizes": True}) ``` Error (full traceback in the [colab notebook](https://github.com/Vaibhavs10/scratchpad/blob/main/wav2vec2_mms_repro.ipynb)): ``` RuntimeError: Error(s) in loading state_dict for Wav2Vec2ForCTC: size mismatch for lm_head.weight: copying a param with shape torch.Size([154, 1280]) from checkpoint, the shape in current model is torch.Size([314, 1280]). size mismatch for lm_head.bias: copying a param with shape torch.Size([154]) from checkpoint, the shape in current model is torch.Size([314]). You may consider adding `ignore_mismatched_sizes=True` in the model `from_pretrained` method. ``` `Processor` + `Model` ```python from transformers import Wav2Vec2ForCTC, AutoProcessor model_id = "facebook/mms-1b-all" target_lang = "fra" processor = AutoProcessor.from_pretrained(model_id, target_lang=target_lang) model = Wav2Vec2ForCTC.from_pretrained(model_id, target_lang=target_lang, ignore_mismatched_sizes=True) ``` Error (full traceback in the [colab notebook](https://github.com/Vaibhavs10/scratchpad/blob/main/wav2vec2_mms_repro.ipynb)): ``` RuntimeError: Error(s) in loading state_dict for Wav2Vec2ForCTC: size mismatch for lm_head.weight: copying a param with shape torch.Size([154, 1280]) from checkpoint, the shape in current model is torch.Size([314, 1280]). size mismatch for lm_head.bias: copying a param with shape torch.Size([154]) from checkpoint, the shape in current model is torch.Size([314]). You may consider adding `ignore_mismatched_sizes=True` in the model `from_pretrained` method. ``` Similar issues reported by @xenova here: https://github.com/huggingface/transformers/issues/24223#issuecomment-1661174505 ### Expected behavior The expected behaviour would be that dispite the mismatch the model weights are loaded and the mismatch is rectified via `load_adapter` for pipeline (as mentioned here:https://github.com/huggingface/transformers/issues/24223#issuecomment-1595856093)
08-02-2023 10:22:16
08-02-2023 10:22:16
cc @patrickvonplaten <|||||>It looks like it's related to some recent changes and accelerate. If you checkout this commit: https://github.com/huggingface/transformers/commit/b0513b013b10939a2b47ab94933c2cca909716a2 and uninstall accelerate the code snippet works fine for me.<|||||>IIRC, fast loading with accelerate never worked with Wav2Vec2 before because Wav2Vec2 has a weird weight norm parameter, so load adapter was not tested with it. It seems like there were a couple of recent changes though with accelerate and loading with might be related. I'm sadly not going to have the time to dive deeper here I think. @amyeroberts or @sanchit-gandhi could you try to take this one maybe?<|||||>Also: cc: @muellerzr for accelerate!<|||||>#25267 should fix it, but it'd be good to get a review from @sgugger and @ydshieh here.
transformers
25,259
closed
Update rescale tests - cast to float after rescaling to reflect #25229
# What does this PR do? In #25229 - the casting to float was moved back to after rescaling. This wasn't reflected in the specific rescaling tests for EfficientNet and ViVit, resulting in failing tests. This PR resolves this. ## 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?
08-02-2023 10:01:18
08-02-2023 10:01:18
_The documentation is not available anymore as the PR was closed or merged._
transformers
25,258
open
Why I cannot assign new parameter to the whisper pretrained config?
### System Info - `transformers` version: 4.31.0 - Platform: Linux-5.4.0-155-generic-x86_64-with-glibc2.31 - Python version: 3.10.11 - Huggingface_hub version: 0.16.4 - Safetensors version: 0.3.1 - Accelerate version: not installed - Accelerate config: not found - PyTorch version (GPU?): 2.0.1+cu118 (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? _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 Why can I not assign a new parameter to the whisper pretrained config? Note that the parameter "final_dropout" is not in a config of the "openai/whisper-small". I used the code piece as following: ``` from transformers import AutoConfig, WhisperModel config = AutoConfig.from_pretrained("openai/whisper-small", final_dropout=0.1) config.final_dropout ``` The error is shown below: ``` AttributeError: 'WhisperConfig' object has no attribute 'final_dropout' ``` ### Expected behavior config.final_dropout=0.1 Any guidance would be appreciated. Tien-Hong
08-02-2023 09:29:35
08-02-2023 09:29:35
Hi @teinhonglo, thanks for raising this issue! The reason for not being able to assign through the `from_pretrained` call is a safety check. Unknown kwargs are not applied: their application is ambigious - should they control the `from_pretrained` behaviour or be set as a config attribute? You can see which kwargs weren't set using `return_unused_kwargs` argument c.f. [here](https://huggingface.co/docs/transformers/v4.31.0/en/main_classes/configuration#transformers.PretrainedConfig.from_pretrained.return_unused_kwargs) and [here](https://huggingface.co/docs/transformers/v4.31.0/en/main_classes/configuration#transformers.PretrainedConfig.from_pretrained.kwargs) in the docs. After loading in the config, you can set attributes e.g.: ``` from transformers import AutoConfig, WhisperModel config = AutoConfig.from_pretrained("openai/whisper-small") config.final_dropout = 0.1 ```
transformers
25,257
open
how to print out the data loaded by each epoch during trainer.train() training?
### Feature request please tell to me, how to print out the data loaded by each epoch during trainer.train() training? ### Motivation how to print out the data loaded by each epoch during trainer.train() training? ### Your contribution how to print out the data loaded by each epoch during trainer.train() training?
08-02-2023 09:13:55
08-02-2023 09:13:55
Hi @ahong007007, thanks for raising an issue! This is a question best placed in our [forums](https://discuss.huggingface.co/). We try to reserve the github issues for feature requests and bug reports.
transformers
25,256
open
Use 'transformers.BertModel.from_pretrained', The code is blocked
![52ae2d1edf2fa3044e6932d42c558f1](https://github.com/huggingface/transformers/assets/86940083/180c1033-375a-46b8-af7e-cda344e1e5ff) this is py-spy result: ![image](https://github.com/huggingface/transformers/assets/86940083/5d5aa094-fa16-452d-ab39-8700fa4d8d1e)
08-02-2023 08:56:36
08-02-2023 08:56:36
Hi, are you running the script/command in some particular setting? Looks like it's in a multiprocessing setting? Could you provide a self-complete code snippet instead of just uploading screenshot? Thanks in advance.<|||||>if not use pyrocketmq is ok. but use pyrocketmq not ok. the code is: ``` import jpype.imports jpype.startJVM(classpath=['D:\\soft\\rocketmq-all-4.3.2-bin-release\\lib\\*', ]) from pyrocketmq import * # import json # from pyrocketmq.common.message import Message # from pyrocketmq.client.producer import Producer, SendStatus # pr = Producer('test_producer') # pr.setNamesrvAddr('10.2.10.6:9876') # pr.start() # body = json.dumps({'name':'Alice', 'age':1}).encode('utf-8') # msg = Message(topic='test_topic', body=body, tags='girl') # # send, tcp-like, return sendStatus # sr = pr.send(msg) # assert(sr.sendStatus == SendStatus.SEND_OK) # pr.shutdown() from multiprocessing import Pool import json import time from typing import List from pyrocketmq.client.consumer.listener import ConsumeConcurrentlyContext, ConsumeConcurrentlyStatus, MessageListenerConcurrently from pyrocketmq.client.consumer.consumer import MessageSelector, PushConsumer from pyrocketmq.common.common import ConsumeFromWhere from pyrocketmq.common.message import MessageExt def from_pretrained(): print('--from_pretrained1--') transformers.BertModel.from_pretrained('/opt/model-service/volume/resource/bert_base') print('--from_pretrained2--') return True # subclass MessageListenerConcurrently to write your own consume action class MyMessageListenerConcurrently(MessageListenerConcurrently): def _consumeMessage(self, msgs:List[MessageExt], context:ConsumeConcurrentlyContext) -> ConsumeConcurrentlyStatus: print('Concurrently', context.ackIndex) for msg in msgs: print(msg.body) print('--_main--') pool = Pool(processes=2) bert_res_future = pool.apply_async(func=from_pretrained) res = bert_res_future.get() print(res) return ConsumeConcurrentlyStatus.CONSUME_SUCCESS cs = PushConsumer('test_push_consumer') cs.setNamesrvAddr('10.2.10.6:9876') selector = MessageSelector.byTag('model') ml = MyMessageListenerConcurrently() cs.registerMessageListener(ml) cs.subscribe('test_topic', selector) cs.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET) cs.start() ``` The code below is problematic, the code above is not ``` import transformers def from_pretrained(): print('--from_pretrained1--') transformers.BertModel.from_pretrained('/opt/model-service/volume/resource/bert_base') print('--from_pretrained2--') return True if __name__ == '__main__': from multiprocessing import Pool print('--_main--') pool = Pool(processes=2) bert_res_future = pool.apply_async(func=from_pretrained) res=bert_res_future.get() print(res) ``` <|||||>Thanks for clarification @yangh0597, appreciated. This is more `pyrocketmq` issue (or the way it works) rather than `transformers`. In general, when doing such multiprocessing thing or inter-communication stuff between processes, we should not pass large objects (inputs, models) etc., but rather creating the necessary objects in the target process(es). It's on the users to take care what would be necessary steps to avoid the blocking. We wouldn't be able to help with the details, especially it involves 3rd party library `pyrocketmq`. But I hope the above comment give you some hint(s) to figure out a working solution.<|||||>thakns very much
transformers
25,255
open
fix bad URL to Llama 2
# What does this PR do? ## Before submitting - [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
08-02-2023 08:43:23
08-02-2023 08:43:23
@fangli80 Running`make fix-copies` and pushing the changes will resolve the failing quality CI checks
transformers
25,254
open
Add FlaxCLIPTextModelWithProjection
# What does this PR do? `FlaxCLIPTextModelWithProjection` is necessary to support the Flax port of Stable Diffusion XL: https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/blob/fb6d705fb518524cabc79c77f13a0e7921bcab3a/text_encoder_2/config.json#L3 I can add some tests, if necessary, after this approach is validated. ## 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. - [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? ## Who can review? @patrickvonplaten @patil-suraj @sanchit-gandhi @younesbelkada
08-02-2023 08:25:27
08-02-2023 08:25:27
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25254). All of your documentation changes will be reflected on that endpoint.<|||||>Should we maybe for now just add it in a subfolder of sdxl in diffusers here: https://github.com/huggingface/diffusers/tree/main/src/diffusers/pipelines/stable_diffusion_xl instead of having to rely on `transformers` here? I'm not 100% convinced this model is really needed for core transformers usage. Would also not force the user to have to install transformers from main :-) <|||||>> Should we maybe for now just add it in a subfolder of sdxl in diffusers here: https://github.com/huggingface/diffusers/tree/main/src/diffusers/pipelines/stable_diffusion_xl instead of having to rely on `transformers` here? I'm not 100% convinced this model is really needed for core transformers usage. The [PyTorch version of the same model was added 9 months ago](https://github.com/huggingface/transformers/blob/bd90cda9a6bb4723515c17df1192e53abc8e36e3/src/transformers/models/clip/modeling_clip.py#L1198), so I assumed it was ok. But sure, we can do that. In that case, how do we deal with it? - Change the library to `diffusers` here: https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/blob/main/model_index.json#L15. Unless I'm mistaken, then we'd need to distribute the flax weights separately, or use a branch. - Create a hack in diffusers to map the library. > > Would also not force the user to have to install transformers from main :-) Yes, of course, this was meant as the long-term solution. <|||||>Ah yeah good point JAX & PyTorch share the same config - this will become complicated indeed then. Ok let's try to get it merged here. CLIP is important enough to be merged to `transformers` indeed
transformers
25,253
open
RWKV-WORLD-4
### Model description BlinkDL/rwkv-4-world is a repo present on Huggingface i want the model's tokenizer and the model to be added to the Transformers Lib. ### Open source status - [X] The model implementation is available - [X] The model weights are available ### Provide useful links for the implementation _No response_
08-02-2023 07:39:58
08-02-2023 07:39:58
Hi @CosmoLM, thanks for opening this model request! The RWKV-4 model already exists in transformers -- [PR](https://github.com/huggingface/transformers/pull/22797), [docs](https://huggingface.co/docs/transformers/v4.31.0/en/model_doc/rwkv#rwkv-attention-and-the-recurrent-formulas). To enable loading the model through `Rwkv.from_pretrained`, the checkpoints would need to be converted and model configs push to the hub using [the conversion script.](https://github.com/huggingface/transformers/blob/8021c684ec3023295513be36bdc30e27e6f28cfc/src/transformers/models/rwkv/convert_rwkv_checkpoint_to_hf.py#L4) I'd suggest opening a discussion on the hub to see if the repo owners would be interested in doing this. <|||||>The RWKV-pile models are available but not the RWKV-world models because its tokenizer is not in the json format it is in txt format. On Wed, 2 Aug, 2023, 4:24 pm amyeroberts, ***@***.***> wrote: > Hi @CosmoLM <https://github.com/CosmoLM>, thanks for opening this model > request! > > The RWKV-4 model already exists in transformers -- PR > <https://github.com/huggingface/transformers/pull/22797>, docs > <https://huggingface.co/docs/transformers/v4.31.0/en/model_doc/rwkv#rwkv-attention-and-the-recurrent-formulas>. > To enable loading the model through Rwkv.from_pretrained, the checkpoints > would need to be converted and model configs push to the hub using the > conversion script. > <https://github.com/huggingface/transformers/blob/8021c684ec3023295513be36bdc30e27e6f28cfc/src/transformers/models/rwkv/convert_rwkv_checkpoint_to_hf.py#L4> > > I'd suggest opening a discussion on the hub to see if the repo owners > would be interested in doing this. > > โ€” > Reply to this email directly, view it on GitHub > <https://github.com/huggingface/transformers/issues/25253#issuecomment-1661993346>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/BA7FALGYW7ERQ3LODEA6NADXTIWVPANCNFSM6AAAAAA3A3B6CY> > . > You are receiving this because you were mentioned.Message ID: > ***@***.***> >
transformers
25,252
open
run_mae.py can not be used directly on own dir
### System Info ref: https://github.com/huggingface/transformers/tree/main/examples/pytorch/image-pretraining python run_mae.py \ --model_type vit_mae \ --dataset_name nateraw/image-folder \ --train_dir <path-to-train-root> \ --output_dir ./outputs/ \ --remove_unused_columns False \ --label_names pixel_values \ --do_train \ --do_eval My params: --model_name_or_path /home/ana/data4/models/vit-mae-base --dataset_name nateraw/image-folder --train_dir /home/ana/data4/datasets/rvl_cdip/data/pretrain_images/train/ --validation_dir /home/ana/data4/datasets/rvl_cdip/data/pretrain_images/eval/ --output_dir /home/ana/data4/output_models/rvl_mae_pretrain_demo_10k_100 --remove_unused_columns False --label_names pixel_values --mask_ratio 0.75 --norm_pix_loss --base_learning_rate 1.5e-4 --lr_scheduler_type cosine --weight_decay 0.05 --num_train_epochs 800 --warmup_ratio 0.05 --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 5 --seed 1337 --do_train --do_eval output: Traceback (most recent call last): File "/home/ana/data4/projects/hf_mae/run_mae.py", line 397, in <module> main() File "/home/ana/data4/projects/hf_mae/run_mae.py", line 222, in main ds = load_dataset( File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/load.py", line 1773, in load_dataset builder_instance = load_dataset_builder( File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/load.py", line 1528, in load_dataset_builder builder_instance: DatasetBuilder = builder_cls( File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/builder.py", line 329, in __init__ data_files = DataFilesDict.from_local_or_remote( File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/data_files.py", line 783, in from_local_or_remote DataFilesList.from_local_or_remote( File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/data_files.py", line 751, in from_local_or_remote data_files = resolve_patterns_locally_or_by_urls(base_path, patterns, allowed_extensions) File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/data_files.py", line 349, in resolve_patterns_locally_or_by_urls for path in _resolve_single_pattern_locally(base_path, pattern, allowed_extensions): File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/data_files.py", line 293, in _resolve_single_pattern_locally raise FileNotFoundError(error_msg) FileNotFoundError: Unable to find '/home/ana/data4/datasets/rvl_cdip/data/pretrain_images/train/' at / ### Who can help? _No response_ ### 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 build a dir like: dataset/ train/ 1.jpg 2.jpg eval/ 1.jpg 2.jpg run: python run_mae.py \ --model_name_or_path /home/ana/data4/models/vit-mae-base --dataset_name nateraw/image-folder --train_dir /home/ana/data4/datasets/rvl_cdip/data/pretrain_images/train/ --validation_dir /home/ana/data4/datasets/rvl_cdip/data/pretrain_images/eval/ --output_dir /home/ana/data4/output_models/rvl_mae_pretrain_demo_10k_100 --remove_unused_columns False --label_names pixel_values --mask_ratio 0.75 --norm_pix_loss --base_learning_rate 1.5e-4 --lr_scheduler_type cosine --weight_decay 0.05 --num_train_epochs 800 --warmup_ratio 0.05 --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 5 --seed 1337 --do_train --do_eval ### Expected behavior output: Traceback (most recent call last): File "/home/ana/data4/projects/hf_mae/run_mae.py", line 397, in <module> main() File "/home/ana/data4/projects/hf_mae/run_mae.py", line 222, in main ds = load_dataset( File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/load.py", line 1773, in load_dataset builder_instance = load_dataset_builder( File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/load.py", line 1528, in load_dataset_builder builder_instance: DatasetBuilder = builder_cls( File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/builder.py", line 329, in __init__ data_files = DataFilesDict.from_local_or_remote( File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/data_files.py", line 783, in from_local_or_remote DataFilesList.from_local_or_remote( File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/data_files.py", line 751, in from_local_or_remote data_files = resolve_patterns_locally_or_by_urls(base_path, patterns, allowed_extensions) File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/data_files.py", line 349, in resolve_patterns_locally_or_by_urls for path in _resolve_single_pattern_locally(base_path, pattern, allowed_extensions): File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/data_files.py", line 293, in _resolve_single_pattern_locally raise FileNotFoundError(error_msg) FileNotFoundError: Unable to find '/home/ana/data4/datasets/rvl_cdip/data/pretrain_images/train/' at /
08-02-2023 07:30:25
08-02-2023 07:30:25
The error > FileNotFoundError: Unable to find '/home/ana/data4/datasets/rvl_cdip/data/pretrain_images/train/' at / shows you don't have local datasets (or there is some issue to locate it). Could you verify this on your own side? Thanks.<|||||>Hi @CheungZeeCn, thanks for raising this issue! So that we can best help you, could you: * make sure code snippets and errors are properly formatted - placed between pairs of three backticks e.g. ` ``` code here ``` `. * Add information about the running environment: run `transformers-cli env` in the terminal and copy-paste the output As @ydshieh mentions, it looks like the issue is coming from the paths being passed in for `train_dir` and `validation_dir`. They should be the names of folders containing the train and validation datasets relative to `dataset_name`. Based on the paths, the arguments should be: ``` --dataset_name /home/ana/data4/datasets/rvl_cdip/data/pretrain_images --train_dir train --validation_dir eval ```<|||||>@ydshieh @amyeroberts thank's for your replies, ``` --dataset_name /home/ana/data4/datasets/rvl_cdip/data/pretrain_images --train_dir train --validation_dir eval ``` can not solve my problem. That's how I fix it: step1: download dataset python file from: https://huggingface.co/datasets/nateraw/imagefolder/tree/main/ than put it in my local diretory: /home/ana/data4/datasets/rvl_cdip/data/pretrain_images step2: use the following params: ``` --dataset_name \ /home/ana/data4/datasets/rvl_cdip/data/pretrain_images \ --train_dir \ "/home/ana/data4/datasets/rvl_cdip/data/pretrain_images/train/*" \ --validation_dir \ "/home/ana/data4/datasets/rvl_cdip/data/pretrain_images/eval/*" ``` It's not the same as the doc.<|||||>Hi @CheungZeeCn Glad that you managed to make it work. Just to make sure, what is works it with `--dataset_name nateraw/image-folder ` like the following ```bash --dataset_name nateraw/image-folder --train_dir \ "/home/ana/data4/datasets/rvl_cdip/data/pretrain_images/train/*" \ --validation_dir \ "/home/ana/data4/datasets/rvl_cdip/data/pretrain_images/eval/*" ``` or the one with `/home/ana/data4/datasets/rvl_cdip/data/pretrain_images \ --train_dir \`? Thanks in advance!<|||||>Hi, @ydshieh That's how my local dataset directory looks like: ``` (torch2) ana@pts-m1:~/data4/datasets/rvl_cdip/data/pretrain_images$ pwd /home/ana/data4/datasets/rvl_cdip/data/pretrain_images (torch2) ana@pts-m1:~/data4/datasets/rvl_cdip/data/pretrain_images$ ls eval imagefolder.py train (torch2) ana@pts-m1:~/data4/datasets/rvl_cdip/data/pretrain_images$ ls eval |head -10 0000298044.jpg 0000553824.jpg 0012197285.jpg 0060128913.jpg ``` and the imagefolder.py is the same as this one https://huggingface.co/datasets/nateraw/imagefolder/blob/main/imagefolder.py using the following is OK: ``` export WANDB_DISABLED=true python run_mae.py \ --model_name_or_path \ /home/ana/data4/models/vit-mae-base \ --dataset_name \ /home/ana/data4/datasets/rvl_cdip/data/pretrain_images \ --train_dir \ "/home/ana/data4/datasets/rvl_cdip/data/pretrain_images/train/*" \ --validation_dir \ "/home/ana/data4/datasets/rvl_cdip/data/pretrain_images/eval/*" \ --output_dir \ /home/ana/data4/output_models/rvl_mae_pretrain_demo_10k_100 \ --remove_unused_columns \ False \ --label_names \ pixel_values \ --mask_ratio \ 0.5 \ --base_learning_rate \ 1.5e-4 \ --lr_scheduler_type \ cosine \ --weight_decay \ 0.05 \ --num_train_epochs \ 800 \ --warmup_ratio \ 0.05 \ --per_device_train_batch_size \ 32 \ --gradient_accumulation_steps \ 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 \ 5 \ --seed \ 1337 \ --do_train \ --do_eval \ --overwrite_output_dir ``` However, if I tried this: ``` python run_mae.py --model_name_or_path /home/ana/data4/models/vit-mae-base --dataset_name nateraw/image-folder --train_dir "/home/ana/data4/datasets/rvl_cdip/data/pretrain_images/train/*" --validation_dir "/home/ana/data4/datasets/rvl_cdip/data/pretrain_images/eval/*" --output_dir /home/ana/data4/output_models/rvl_mae_pretrain_demo_10k_100_tmp --remove_unused_columns False --label_names pixel_values --mask_ratio 0.5 --base_learning_rate 1.5e-4 --lr_scheduler_type cosine --weight_decay 0.05 --num_train_epochs 800 --warmup_ratio 0.05 --per_device_train_batch_size 32 --gradient_accumulation_steps 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 5 --seed 1337 --do_train --do_eval ``` the output is: ``` Traceback (most recent call last): File "/home/ana/data4/projects/hf_mae/run_mae.py", line 397, in <module> main() File "/home/ana/data4/projects/hf_mae/run_mae.py", line 222, in main ds = load_dataset( File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/load.py", line 1773, in load_dataset builder_instance = load_dataset_builder( File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/load.py", line 1528, in load_dataset_builder builder_instance: DatasetBuilder = builder_cls( File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/site-packages/datasets/builder.py", line 350, in __init__ info.update(self._info()) File "/home/ana/.cache/huggingface/modules/datasets_modules/datasets/nateraw--image-folder/a2b5eb21064d8bd9b44c3b3fc91ae8205c3002a441852e1b02da78e8025c332e/image-folder.py", line 30, in _info classes = sorted([x.name.lower() for x in Path(folder).glob('*/**')]) File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/pathlib.py", line 1041, in __new__ self = cls._from_parts(args, init=False) File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/pathlib.py", line 682, in _from_parts drv, root, parts = self._parse_args(args) File "/home/ana/data1/anaconda3/envs/torch2/lib/python3.8/pathlib.py", line 666, in _parse_args a = os.fspath(a) TypeError: expected str, bytes or os.PathLike object, not DataFilesList ``` <|||||>Thanks a lot, we will take a look and update the doc if necessary!
transformers
25,251
open
Defining top_k within pipeline changes output from list to nested list
### System Info ``` - `transformers` version: 4.30.2 - Platform: Linux-5.14.0-162.22.2.el9_1.x86_64-x86_64-with-glibc2.34 - Python version: 3.9.17 - Huggingface_hub version: 0.16.4 - Safetensors version: 0.3.1 - PyTorch version (GPU?): 1.11.0+cu102 (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?: no - Using distributed or parallel set-up in script?: no ``` ### Who can help? @Narsil @sgugger ### Reproduction Was trying to output all scores for a single-label classification problem. Initially tried to use `return_all_scores` as written in the docs for TextClassificationPipeline, which returned this error: ```UserWarning: return_all_scores is now deprecated, if want a similar funcionality use top_k=None instead of return_all_scores=True or top_k=1 instead of return_all_scores=False.``` Switched to top_k, but some of my code broke in strange ways. Eventually realized that it was because calling pipeline without top_k returns a list containing a dictionary, but calling it with top_k returns a list containing a list containing a dictionary, regardless of what value top_k is set to. Without top_k=1: `from transformers import pipeline` `classifier = pipeline("sentiment-analysis", model="ProsusAI/finbert")` `classifier("Inflation Remains Risk Confronting Financial Markets")` Resulting output: `[{'label': 'negative', 'score': 0.8932788372039795}]` With top_k=1: `from transformers import pipeline` `classifier = pipeline("sentiment-analysis", model="ProsusAI/finbert", top_k=1)` `classifier("Inflation Remains Risk Confronting Financial Markets")` Resulting output: `[[{'label': 'negative', 'score': 0.8932788372039795}]]` With top_k=None: `from transformers import pipeline` `classifier = pipeline("sentiment-analysis", model="ProsusAI/finbert", top_k=None)` `classifier("Inflation Remains Risk Confronting Financial Markets")` Resulting output: `[[{'label': 'negative', 'score': 0.8932788372039795},` `{'label': 'neutral', 'score': 0.07486031949520111},` `{'label': 'positive', 'score': 0.03186087682843208}]]` This issue does not occur if top_k is set within `__call__`: `from transformers import pipeline` `classifier = pipeline("sentiment-analysis", model="ProsusAI/finbert")` `classifier("Inflation Remains Risk Confronting Financial Markets", top_k=None)` Resulting output: `[{'label': 'negative', 'score': 0.8932788372039795},` `{'label': 'neutral', 'score': 0.07486031949520111},` `{'label': 'positive', 'score': 0.03186087682843208}]` ### Expected behavior Behavior should be consistent regardless of whether top_k has been set within pipeline, set within `__call__`, or not set at all. Also, [the documentation for TextClassificationPipeline](https://huggingface.co/docs/transformers/main_classes/pipelines#transformers.TextClassificationPipeline) says that top_k is a parameter under `__call__`, but does not explain that top_k is also a parameter under pipeline.
08-02-2023 05:12:29
08-02-2023 05:12:29
Hi @Harjas123 thank you for reporting! Our team will take a look.<|||||>also cc @Narsil <|||||>I agree that this is inconsistent but I don't think there is much to do about it now since this has been the case for the past three years, and making any change would break a lot of users code.<|||||>I understand. Would it at least be possible to add a mention of this somewhere in the docs?<|||||>Harmonizing outputs of pipelines is definitely in my mind for V5 if/when it happens :)
transformers
25,250
open
Ko perf train gpu one
<!-- PR์˜ ์ œ๋ชฉ์€ "๐ŸŒ [i18n-KO] Translated `<your_file>.md` to Korean" ์œผ๋กœ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค! --> # What does this PR do? Translated the `<your_file>.md` file of the documentation to Korean. Thank you in advance for your review. Part of https://github.com/huggingface/transformers/issues/20179 ## Before reviewing - [ ] Check for missing / redundant translations (๋ฒˆ์—ญ ๋ˆ„๋ฝ/์ค‘๋ณต ๊ฒ€์‚ฌ) - [ ] Grammar Check (๋งž์ถค๋ฒ• ๊ฒ€์‚ฌ) - [ ] Review or Add new terms to glossary (์šฉ์–ด ํ™•์ธ ๋ฐ ์ถ”๊ฐ€) - [ ] Check Inline TOC (e.g. `[[lowercased-header]]`) - [ ] Check live-preview for gotchas (live-preview๋กœ ์ •์ƒ์ž‘๋™ ํ™•์ธ) ## Who can review? (Initial) <!-- 1. ์œ„ ์ฒดํฌ๊ฐ€ ๋ชจ๋‘ ์™„๋ฃŒ๋œ ๋’ค์—, ์ด ์•„๋ž˜์— ๋ฆฌ๋ทฐ๋ฅผ ์š”์ฒญํ•  ํŒ€์›๋“ค์„ ๋ฉ˜์…˜ํ•ด์ฃผ์„ธ์š”! --> <!-- May you please review this PR? @keonju2 @harheem @junejae @wonhyeongseo ... --> ## 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? - [ ] 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? (Final) <!-- 2. ํŒ€์›๋“ค๊ณผ ๋ฆฌ๋ทฐ๊ฐ€ ๋๋‚œ ํ›„์—๋งŒ ํ—ˆ๊น…ํŽ˜์ด์Šค ์ง์›๋“ค์—๊ฒŒ ๋ฆฌ๋ทฐ ์š”์ฒญํ•˜๋Š” ์•„๋ž˜ ์ฃผ์„์„ ๋…ธ์ถœํ•ด์ฃผ์„ธ์š”! -->
08-02-2023 03:43:28
08-02-2023 03:43:28
transformers
25,249
closed
Bump cryptography from 41.0.2 to 41.0.3 in /examples/research_projects/decision_transformer
Bumps [cryptography](https://github.com/pyca/cryptography) from 41.0.2 to 41.0.3. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst">cryptography's changelog</a>.</em></p> <blockquote> <p>41.0.3 - 2023-08-01</p> <pre><code> * Fixed performance regression loading DH public keys. * Fixed a memory leak when using :class:`~cryptography.hazmat.primitives.ciphers.aead.ChaCha20Poly1305`. * Updated Windows, macOS, and Linux wheels to be compiled with OpenSSL 3.1.2. <p>.. _v41-0-2: </code></pre></p> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/pyca/cryptography/commit/b22271cf3c3dd8dc8978f8f4b00b5c7060b6538d"><code>b22271c</code></a> bump for 41.0.3 (<a href="https://redirect.github.com/pyca/cryptography/issues/9330">#9330</a>)</li> <li><a href="https://github.com/pyca/cryptography/commit/774a4a16cbd22a89fdb4195ade9e4fcee27a7afa"><code>774a4a1</code></a> Only check DH key validity when loading a private key. (<a href="https://redirect.github.com/pyca/cryptography/issues/9071">#9071</a>) (<a href="https://redirect.github.com/pyca/cryptography/issues/9319">#9319</a>)</li> <li><a href="https://github.com/pyca/cryptography/commit/bfa4d95f0f356f2d535efd5c775e0fb3efe90ef2"><code>bfa4d95</code></a> changelog for 41.0.3 (<a href="https://redirect.github.com/pyca/cryptography/issues/9320">#9320</a>)</li> <li><a href="https://github.com/pyca/cryptography/commit/0da7165aa73c0a4865b0a4d9e019db3c16eea55a"><code>0da7165</code></a> backport fix the memory leak in fixedpool (<a href="https://redirect.github.com/pyca/cryptography/issues/9272">#9272</a>) (<a href="https://redirect.github.com/pyca/cryptography/issues/9309">#9309</a>)</li> <li>See full diff in <a href="https://github.com/pyca/cryptography/compare/41.0.2...41.0.3">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=cryptography&package-manager=pip&previous-version=41.0.2&new-version=41.0.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/huggingface/transformers/network/alerts). </details>
08-02-2023 02:22:03
08-02-2023 02:22:03
_The documentation is not available anymore as the PR was closed or merged._<|||||>OK, I won't notify you again about this release, but will get in touch when a new version is available. If you'd rather skip all updates until the next major or minor version, let me know by commenting `@dependabot ignore this major version` or `@dependabot ignore this minor version`. If you change your mind, just re-open this PR and I'll resolve any conflicts on it.<|||||>@dependabot ignore this major version<|||||>OK, I won't notify you about version 41.x.x again, unless you re-open this PR.
transformers
25,248
open
Allow `trust_remote_code` in example scripts
# 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 --> Update example scripts to use `trust_remote_code`. This PR is similar to https://github.com/huggingface/transformers/pull/25167 but for adding the `trust_remote_code` arg instead of updating the `token` arg. I am not sure if this feature is welcome so I have only modified pytorch `run_glue.py` for now. I will modify the other files (every file that was modified in https://github.com/huggingface/transformers/pull/25167) if the change is welcome and after you all are happy with the help string ## 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? @ydshieh @sgugger <!-- 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: @sgugger Integrations: - deepspeed: HF Trainer/Accelerate: @pacman100 - ray/raytune: @richardliaw, @amogkam Documentation: @sgugger, @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: @sgugger - TensorFlow: @Rocketknight1 -->
08-01-2023 20:31:51
08-01-2023 20:31:51
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25248). All of your documentation changes will be reflected on that endpoint.<|||||>Will do flax and tf tomorrow. I have a few questions though: 1. @ydshieh, this script is still using `use_auth_token`. Is this intended? https://github.com/huggingface/transformers/blob/main/examples/pytorch/image-pretraining/run_mim_no_trainer.py#L450 2. This script doesnt use `token` or `use_auth_token` for the tokenizer https://github.com/huggingface/transformers/blob/main/examples/pytorch/contrastive-image-text/run_clip.py#L333-L340 3. The Permutation Language Modeling [script](https://github.com/huggingface/transformers/blob/main/examples/pytorch/language-modeling/run_plm.py) only uses Auto for config and tokenizer, the model is hardcoded to XLNet. So there are 2 options: a. Not put `trust_remote_code` in this script -- only the transformers XLNet will be supported. b. Change the XLNet lines to use Auto, though Im not sure which Auto to use here. <|||||> > 1. @ydshieh, this script is still using `use_auth_token`. Is this intended? No, it's a miss from my side. Nice catch and thanks! > 2. This script doesnt use `token` or `use_auth_token` for the tokenizer > https://github.com/huggingface/transformers/blob/main/examples/pytorch/contrastive-image-text/run_clip.py#L333-L340 It's probably already been this even before my `token` PRs. I will update them too :-) > 3. The Permutation Language Modeling [script](https://github.com/huggingface/transformers/blob/main/examples/pytorch/language-modeling/run_plm.py) only uses Auto for config and tokenizer, the model is hardcoded to XLNet. So there are 2 options: > a. Not put `trust_remote_code` in this script -- only the transformers XLNet will be supported. Let's just keep `a` . Looking forward your PR completed ๐Ÿš€ <|||||>Couple more places not using `token` or `use_auth_token` - Tensorflow examples - run_clip: Tokenizer - run_clm: Config, Tokenizer, Model - run_mlm: Config, Tokenizer, Model - run_ner: Config, Tokenizer, Model Most of the no_trainer scripts don't have `token` or `use_auth_token` in the args. Do we want to add them?
transformers
25,247
open
Enable use of best epoch in Trial, with early stopping, during hyperparameter search
### Feature request When running a `Trainer.hyperparameter_search`, each trial's value is calculated from the last epoch's chosen metric. However, especially when using early stopping and `load_best_model_at_end`, it would be useful to use the best model instead. This could be a parameter of `Trainer.hyperparameter_search` or a an overridable function getting the best value, or some callback. ### Motivation Often, we use early stopping and take the best model from a particular run because it's possible for models to start overfitting and dropping off after a certain number of epochs. This phenomenon can also appear during hyper parameter search and, as such, we'd like to be able to use the best epoch's value to compare trials. Without this we may get results that are not fully representative. ### Your contribution Happy to help testing or in other ways I can. Not sure where to start but if there is a clear place to do it I'd be open to help.
08-01-2023 19:36:07
08-01-2023 19:36:07
cc @sgugger <|||||>Yes this is not currently supported. Could be nice to add, but this is not high-priority on our side, so it would have to be a contribution :-) Happy to review a PR!
transformers
25,246
closed
Fix return_dict_in_generate bug in InstructBlip generate function
# What does this PR do? Previously, the postprocessing conducted on generated sequences in InstructBlip's generate function assumed these sequences were tensors (i.e. that `return_dict_in_generate == False`). This PR updates the InstructBlip generate function to check whether the result of the call to the wrapped language model `generate()` is a tensor: if it's not, we attempt to postprocess the sequence attribute of the returned results object rather than the object itself. <!-- 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. --> ## Before submitting - [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case). - (Not quite a typo, but a very small bugfix...) - [ ] 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. - Vision model bug: @amyeroberts <!-- 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: @sgugger Integrations: - deepspeed: HF Trainer/Accelerate: @pacman100 - ray/raytune: @richardliaw, @amogkam Documentation: @sgugger, @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: @sgugger - TensorFlow: @Rocketknight1 -->
08-01-2023 18:28:04
08-01-2023 18:28:04
_The documentation is not available anymore as the PR was closed or merged._
transformers
25,245
open
BLIP-2 request: If it's even possible, can you please provide an official example script of how to get the text(caption) features and image features into the same vector space (e.g. for cross-modal retrieval/search using BLIP-2 models, similar to what we can already do with CLIP.) Thanks in advance.
### System Info linux, python 3.8+, pytorch '1.13.0+cu116' ### Who can help? @sgugger ### 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 N/A ### Expected behavior N/A
08-01-2023 18:21:07
08-01-2023 18:21:07
Hi @wingz1, thanks for raising an issue! This is a question best placed in our [forums](https://discuss.huggingface.co/). We try to reserve the github issues for feature requests and bug reports. There are code examples of how to use [BLIP](https://huggingface.co/docs/transformers/v4.31.0/en/model_doc/blip#transformers.BlipModel.forward.example) and [BLIP-2](https://huggingface.co/docs/transformers/v4.31.0/en/model_doc/blip-2#transformers.Blip2Model) in the docs. Both have a similar API to CLIP and have the same methods e.g. `get_text_features`, `get_image_features` implemented and return similar outputs. <|||||>Thanks, I figured that -- I will check the forums! Indeed those methods do exist in BLIP-2, but those outputs don't share the same dimensionality or mean the same thing as the equivalent commands in CLIP due to the how the model is set up.<|||||>Not really a useful answer, but from the following lines in the modeling file, you can go `language_projection` to get the same dimension. But it's super questionable regarding if this is `the same space` with the meaningful text/image features. (and yes, further question on this topic should be on the forum) > self.language_projection = nn.Linear(config.qformer_config.hidden_size, config.text_config.hidden_size) > ilanguage_model_inputs = self.language_projection(query_output) > inputs_embeds = self.language_model.get_input_embeddings()(input_ids) > inputs_embeds = torch.cat([language_model_inputs, inputs_embeds], dim=1)<|||||>Hi I think multimodal embeddings is something lacking in the current implementation, where we can't extract embeddings obtained by passing both text and image to the QFormer, infact the Qformer in HF doesn't even take text `input_ids` as input [here](https://github.com/huggingface/transformers/blob/66c240f3c950612fa05b2e14c85d4b86c88e473e/src/transformers/models/blip_2/modeling_blip_2.py#L1081 ) Whereas the original Qformer implementation did take text inputs as input_id [here](https://github.com/salesforce/LAVIS/blob/91c8e6863b4b02d7d75167e7d18037ef3a96c54b/lavis/models/blip2_models/Qformer.py#L804) , along with the image and this can be used to extract multimodal embeddings as done in the `extract_features` fn [here](https://github.com/salesforce/LAVIS/blob/f982acc73288408bceda2d35471a8fcf55aa04ca/lavis/models/blip2_models/blip2_qformer.py#L387)
transformers
25,244
open
VQA task guide
This PR adds a new Visual Question Answering task guide to the transformers docs: fine-tuning ViLT, based on @NielsRogge 's [notebook](https://github.com/NielsRogge/Transformers-Tutorials/blob/master/ViLT/Fine_tuning_ViLT_for_VQA.ipynb)
08-01-2023 17:57:58
08-01-2023 17:57:58
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_25244). All of your documentation changes will be reflected on that endpoint.
transformers
25,243
closed
RetNet model support
### Model description RetNet / Retentive Networks is a new model *archetype* released by microsoft; the research paper is [here](https://arxiv.org/pdf/2307.08621.pdf). As of now, there is *one* model for retnet; [made by me](https://huggingface.co/parsee-mizuhashi/retnet-tiny-wikitext-undertrained); which is undertrained (`loss=8`!) and I am trying to make a second model on a larger arch. ### Open source status - [X] The model implementation is available - [X] The model weights are available ### Provide useful links for the implementation [commit that has retnet training](https://github.com/microsoft/torchscale/commit/bf65397b26469ac9c24d83a9b779b285c1ec640b) @donglixp was the main author for commit and cited on the paper all code is licensed under MIT, including model weights
08-01-2023 17:35:07
08-01-2023 17:35:07
cc @ArthurZucker @younesbelkada <|||||>p.s. if google offered any bigger TPU's for TRC; i could train retnet-3b (the point at which retnet is better than regular transformers), but as of now; theres retnet_base (small) and retnet_medium (ill upload it when it gets good)<|||||>I am wondering if the original authors released the trained models?<|||||>as far as i know, no official pretrained models were released by microsoft; but the training code is on the torchscale repo, so thats how i am training the models<|||||>Cool model! But as long as we don't have official/ very good pretraining checkpoints, not really anything we can do! <|||||>ah, understood, i'll try to get a good checkpoint; but for now, i assume i can close this and reopen when it finishes training<|||||>oops

Dataset Card for "hf-repo-issues"

More Information needed

Downloads last month
0
Edit dataset card