unload_textual_inversion(token) leaves the extra tokens of a multi-vector embedding behind, so it can't be loaded again
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
Bắt đầu bằng cách đọc các phương thức tải và gỡ tải textual inversion cùng tra cứu maybe_convert_prompt mà chúng sử dụng; issue không nêu đường dẫn tệp hay bài kiểm thử. Tái hiện với pipeline Stable Diffusion nhỏ và embedding hai vector. Hoàn thành khi gỡ tải token cơ sở cũng xóa các token có hậu tố và các hàng embedding của nó, để có thể tải lại cùng embedding.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
load_textual_inversion registers a multi-vector embedding as <token>, <token>_1, ..., <token>_{n-1}, and maybe_convert_prompt expands <token> into all of them. unload_textual_inversion("<token>") only removes <token> itself. The _1 ... _{n-1} tokens and their embedding rows stay in the tokenizer and text encoder, and loading the same embedding again fails with Multi-vector Token [...] already in tokenizer vocabulary.
Users only pass <token> to load_textual_inversion, so they have no reason to know about the suffixed tokens. #7856 hit this with an SDXL negative embedding and was closed with a workaround (list every suffixed token), but the behaviour is still there on main.
I'd like to send a PR for this: when tokens is given, also remove its <token>_1, <token>_2, ... tokens, using the same lookup maybe_convert_prompt uses. Happy to adjust if you prefer a different approach.
Reproduction
Shown with the tiny test pipeline so it runs in seconds; the loader code is the same for SD1.5 and SDXL embeddings.
import torch
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained("hf-internal-testing/tiny-stable-diffusion-torch", safety_checker=None)
embedding = torch.randn(2, 32) # a 2-vector embedding (this tiny text encoder has hidden size 32)
pipe.load_textual_inversion(embedding, token="<neg>")
pipe.unload_textual_inversion("<neg>")
print([t for t in pipe.tokenizer.get_added_vocab() if t.startswith("<neg>")]) # ['<neg>_1']
pipe.load_textual_inversion(embedding, token="<neg>") # ValueError
Context
I ran into this while testing loading and unloading of multi-vector textual inversion embeddings.
Logs
ValueError: Multi-vector Token ['<neg>', '<neg>_1'] already in tokenizer vocabulary. Please choose a different token name or remove the ['<neg>', '<neg>_1'] and embedding from the tokenizer and text encoder.
System Info
- 🤗 Diffusers version: 0.42.0.dev0 (main @ 84532a058)
- Platform: macOS-26.6.2-arm64-arm-64bit
- Running on Google Colab?: No
- Python version: 3.12.11
- PyTorch version (GPU?): 2.15.0 (False)
- Huggingface_hub version: 2.4.0
- Transformers version: 5.22.2
- Accelerate version: 1.15.0
- PEFT version: 0.21.2
- Safetensors version: 0.8.0
- xFormers version: not installed
- Accelerator: Apple M5 Pro
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No
Who can help?
@sayakpaul
- Ngôn ngữ chính
- Python
- Star
- 34.9k
- Fork
- 7.5k
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 57
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của huggingface/diffusers
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
huggingface/diffusers#15210 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
UniPCMultistepScheduler.set_timesteps(sigmas=...) raises TypeError for a list when use_flow_sigmas=TrueCó thể đã có người làm @marlonferreira1800-hue đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
huggingface/diffusers#15207 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
huggingface/diffusers#15170 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
huggingface/diffusers#15163 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`encode_video` truncates a fractional `fps`, so the video runs longer than its audioCó thể đã có người làm @guptaishaan đã nhận 18 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
huggingface/diffusers#15104 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của huggingface/diffusers
Issue tương tự
-
Document style: tablesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
-
Successor registrant to review: Navient Holdings, Inc. (CIK 2152623), 8-K12B 0001193125-26-436899Đang mởsuccessor-review
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
dgunning/edgartools#1889 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`destroy` sans terminal répond « Aborted. » au lieu de réclamer `--yes` comme `clean` et `reset`Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
stephrobert/dsoxlab#354 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
hardware help wanted testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
mediajunkie/piper-morgan-product#2335 · 1 bình luận ·