Skip to content

fix: raise clear error when non-LLM model is used with TextGenerate node#13291

Open
octo-patch wants to merge 1 commit intoComfy-Org:masterfrom
octo-patch:fix/issue-13286-clip-text-model-generate-error
Open

fix: raise clear error when non-LLM model is used with TextGenerate node#13291
octo-patch wants to merge 1 commit intoComfy-Org:masterfrom
octo-patch:fix/issue-13286-clip-text-model-generate-error

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #13286

Problem

When a user connects a CLIP text encoder model (e.g. CLIPTextModel) to the TextGenerate node instead of a language model (LLM), the node fails with a cryptic AttributeError: 'CLIPTextModel' object has no attribute 'generate'. This happens because standard CLIP models only support text encoding (for embeddings), not text generation.

Solution

Added an explicit check in CLIP.generate() to verify that the underlying cond_stage_model has a generate method before attempting to call it. If the model doesn't support generation, a RuntimeError is raised with a clear, actionable error message informing the user that they need to use a language model (LLM) like Qwen, LLaMA, or Gemma.

if not hasattr(self.cond_stage_model, 'generate'):
    raise RuntimeError(
        f"The loaded model ({type(self.cond_stage_model).__name__}) does not support text generation. "
        "The TextGenerate node requires a language model (LLM) such as Qwen, LLaMA, or Gemma, "
        "not a CLIP text encoder. Please load the correct model type."
    )

Testing

  • Verified that the check correctly identifies models without a generate method
  • The error message clearly indicates the model type that was loaded and what type is required

…ode (fixes Comfy-Org#13286)

When a user connects a CLIP text encoder (e.g. CLIPTextModel) to the
TextGenerate node instead of a language model (LLM), the previous
behavior was an unhelpful AttributeError. Now a RuntimeError is raised
with a clear explanation of what model type is required.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: efa4400c-3135-4216-90c5-de497a63fa19

📥 Commits

Reviewing files that changed from the base of the PR and between 13917b3 and 76fe91c.

📒 Files selected for processing (1)
  • comfy/sd.py

📝 Walkthrough

Walkthrough

The change adds a capability check to the CLIP.generate() method. Before attempting to invoke the generate method on the loaded cond_stage_model, the code now verifies that the method exists. If the cond_stage_model does not implement the generate method, a RuntimeError is raised with a descriptive error message indicating that the model type is unsupported for the TextGenerate node. This check executes prior to resetting clip options and calling the model's generate method.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a check to raise a clear error when a non-LLM model is used with the TextGenerate node.
Description check ✅ Passed The description comprehensively explains the problem, solution, and testing approach, directly relating to the changeset in comfy/sd.py.
Linked Issues check ✅ Passed The PR addresses issue #13286 by implementing the exact solution needed: adding a capability check in CLIP.generate() to raise a clear RuntimeError when a non-generation-capable model is used.
Out of Scope Changes check ✅ Passed The changes are narrowly scoped to adding a single validation check in CLIP.generate(), directly addressing the linked issue without introducing unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'CLIPTextModel' object has no attribute 'generate'

1 participant