Skip to content

Fix TypeError in LongCatImageEditPipeline truncation warning#13526

Open
Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Ricardo-M-L:fix-longcat-image-edit-token-warning-typeerror
Open

Fix TypeError in LongCatImageEditPipeline truncation warning#13526
Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Ricardo-M-L:fix-longcat-image-edit-token-warning-typeerror

Conversation

@Ricardo-M-L
Copy link
Copy Markdown
Contributor

What this PR does

LongCatImageEditPipeline._encode_prompt calls len() twice on an int when building its truncation warning message:

https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/longcat_image/pipeline_longcat_image_edit.py#L284-L289

if len(all_tokens) > self.tokenizer_max_length:
    logger.warning(
        "Your input was truncated because \`max_sequence_length\` is set to "
        f" {self.tokenizer_max_length} input token nums : {len(len(all_tokens))}"
    )
    all_tokens = all_tokens[: self.tokenizer_max_length]

len(all_tokens) already returns an int, so the outer len() raises TypeError: object of type 'int' has no len() — inside the f-string formatting — every time the branch fires.

Why this is a real bug

The warning only executes when len(all_tokens) > self.tokenizer_max_length (default 512). That is the exact scenario the warning is supposed to inform the user about. Instead of informing them, the pipeline crashes with a TypeError during prompt encoding.

Minimal repro:

pipe = LongCatImageEditPipeline.from_pretrained(...)
pipe(prompt="a very long prompt ..." * 200, image=image)
# TypeError: object of type 'int' has no len()

The sibling LongCatImagePipeline._encode_prompt has the correct form at line 291 — this is a local typo in the edit pipeline only.

Fix

Drop the extraneous len() call to match the sibling pipeline:

-                f" {self.tokenizer_max_length} input token nums : {len(len(all_tokens))}"
+                f" {self.tokenizer_max_length} input token nums : {len(all_tokens)}"

Before submitting

  • Did you read the contributor guideline?
  • Was this discussed/approved via a Github issue or the forum? N/A — single-character typo fix.
  • Did you make sure to update the documentation with your changes? N/A.
  • Did you write any new necessary tests? N/A — fixes a log-message crash; no behavior change.

Who can review?

@yiyixuxu @sayakpaul

`_encode_prompt` in `LongCatImageEditPipeline` calls `len()` twice on
`all_tokens` when logging the truncation warning:

    f" {self.tokenizer_max_length} input token nums : {len(len(all_tokens))}"

`len(all_tokens)` already returns an `int`, so the outer `len()` raises
`TypeError: object of type 'int' has no len()`. The failure triggers
exactly in the only branch this warning exists for (prompts longer
than `tokenizer_max_length`, default 512), turning the intended
informational warning into a hard crash.

The sibling `LongCatImagePipeline._encode_prompt` has the correct
`{len(all_tokens)}` at line 291, so this is a typo local to the edit
pipeline. Minimal fix: drop the extra `len()` call.

Reproduces with any prompt whose tokenization exceeds 512 tokens:

    pipe = LongCatImageEditPipeline.from_pretrained(...)
    pipe(prompt="a very long prompt ..." * 200, image=...)
    # TypeError: object of type 'int' has no len()
@github-actions github-actions Bot added pipelines size/S PR with diff < 50 LOC labels Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pipelines size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant