Multi-vector textual inversion uses only the first vector when the token has uppercase letters (transformers v5)
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 75/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Domínio
- backend, machine-learning
Direção de pesquisa
Comece lendo _maybe_convert_prompt e os testes relacionados a maybe_convert_prompt. Reproduza o problema com um token de textual inversion com vários vetores que contenha letras maiúsculas e, em seguida, verifique como o token registrado é identificado e substituído. O objetivo é alcançado quando os prompts que usam o token com letras maiúsculas são expandidos para o token base e todos os vetores numerados; verifique isso com um teste de regressão tanto para o registro com uma combinação de letras maiúsculas e minúsculas quanto para o texto do prompt.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Describe the bug
With transformers v5, a multi-vector textual inversion embedding only contributes its first vector when its token contains uppercase letters. This happens both when the token is loaded that way (token="EasyNegative") and when it is written that way in the prompt (Neg for a token loaded as neg). No error or warning is raised.
maybe_convert_prompt should expand the token to <token> <token>_1 ... <token>_n before tokenizing. In v5, CLIPTokenizer matches added tokens case-insensitively and tokenize() returns them lowercased. But _maybe_convert_prompt looks the result up in tokenizer.added_tokens_encoder and replaces it in the prompt case-sensitively, so nothing gets expanded. With transformers 4.57.1, tokenize() returned the token as registered and the expansion worked.
Proposed fix: in _maybe_convert_prompt, find the registered token through its lowercased form and replace it case-insensitively. Happy to open a PR with a test if this approach works for you.
Reproduction
import torch
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained("hf-internal-testing/tiny-sd-pipe", safety_checker=None)
dim = pipe.text_encoder.config.hidden_size
pipe.load_textual_inversion(torch.randn(3, dim), token="MyToken") # adds MyToken, MyToken_1, MyToken_2
pipe.load_textual_inversion(torch.randn(3, dim), token="neg") # adds neg, neg_1, neg_2
for text in ["MyToken", "neg", "Neg"]:
prompt = pipe.maybe_convert_prompt(text, pipe.tokenizer) # what the pipeline passes to the tokenizer
print(f"{text!r:10} -> {pipe.tokenizer.tokenize(prompt)}")
Output on main:
'MyToken' -> ['mytoken']
'neg' -> ['neg', 'neg_1', 'neg_2']
'Neg' -> ['neg']
Expected: all three vectors in every case, e.g. 'MyToken' -> ['mytoken', 'mytoken_1', 'mytoken_2'].
Context
This affects embeddings made for A1111, which are referred to by their capitalized file name in prompts. For example, EasyNegative has 8 vectors. With the SD 1.5 tokenizer and the token loaded as EasyNegative, the prompt EasyNegative, blurry is expanded to 8 tokens with transformers 4.57.1 and stays a single token with 5.22.2.
Logs
No error or warning is raised.
System Info
- 🤗 Diffusers version: 0.44.0.dev0 (main, 1dabc292d)
- 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
- Linguagem predominante
- Python
- Estrelas
- 34.9k
- Forks
- 7.5k
- Merge médio
- 3d 16h
- PRs com merge (30d)
- 65
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de huggingface/diffusers
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
huggingface/diffusers#15363 ·
Mantenedores costumam responder em até 1 dia
-
`ZImageImg2ImgPipeline` / `ZImageInpaintPipeline`: explicit height/width different from the input image raises RuntimeErrorTalvez já em andamento @chessing234 assumiu hoje. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
huggingface/diffusers#15337 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
TCDScheduler advances the generator on the final step of a strength-truncated custom scheduleTalvez já em andamento @SIDDARTHAREDDY8 assumiu há 5 dias. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
huggingface/diffusers#15288 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
unload_textual_inversion(token) leaves the extra tokens of a multi-vector embedding behind, so it can't be loaded againTalvez já em andamento @sohailshk assumiu há 11 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
huggingface/diffusers#15211 · 3 comentários ·
Mantenedores costumam responder em até 1 dia
-
set_ip_adapter_scale(float) raises "Cannot assign 1 scale_configs to 2 IP-Adapter" when several IP-Adapters are loadedTalvez já em andamento @sohailshk assumiu há 11 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
huggingface/diffusers#15210 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Todas as issues de huggingface/diffusers
Issues semelhantes
-
[dbt] exported dataset keys reference physical columnsTalvez já em andamento @WilliamKelley assumiu hoje. Abertaneeds-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
apache/ossie-converters#251 ·
Mantenedores costumam responder em até 2 dias
-
cli difficulty: easy enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
desec-io/desec-stack#1312 ·
Mantenedores costumam responder em até 14 dias
-
needs-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
aws/aws-durable-execution-sdk-python#977 ·
Mantenedores costumam responder em até 1 dia
-
needs-triage
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
flashinfer-ai/flashinfer#9803 ·
Mantenedores costumam responder em até 1 dia