Skip to content

refactor: attention backend registry#256

Open
akaitsuki-ii wants to merge 1 commit into
v1from
dev/registry
Open

refactor: attention backend registry#256
akaitsuki-ii wants to merge 1 commit into
v1from
dev/registry

Conversation

@akaitsuki-ii

Copy link
Copy Markdown
Contributor

No description provided.

@akaitsuki-ii akaitsuki-ii requested a review from molepi40 June 9, 2026 13:19

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the attention backend and pipeline registries by consolidating them into a unified registry module (diffsynth_engine/registry.py) and transitioning AttentionType to a string-based enum. It also replaces the hardcoded ring attention compatibility list with a dynamic supports_ring_attention capability check on the backend classes. The reviewer's feedback suggests improving error messages when attn_type is None by dynamically retrieving the resolved backend name, and making the backend selection case-insensitive by converting attn_type to lowercase in the registry.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +38 to +40
attn_backend = get_attn_backend(attn_type)
if not attn_backend.supports_head_size(head_size):
raise ValueError(f"Attention backend {attn_type!r} does not support head size {head_size}.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If attn_type is None (the default), the error message will display None instead of the actual resolved backend name (e.g., 'sdpa'). Using attn_backend.get_type() ensures the correct backend name is shown in the error message.

Suggested change
attn_backend = get_attn_backend(attn_type)
if not attn_backend.supports_head_size(head_size):
raise ValueError(f"Attention backend {attn_type!r} does not support head size {head_size}.")
attn_backend = get_attn_backend(attn_type)
if not attn_backend.supports_head_size(head_size):
raise ValueError(f"Attention backend {attn_backend.get_type()!r} does not support head size {head_size}.")

Comment on lines +105 to +107
attn_backend = get_attn_backend(attn_type)
if not attn_backend.supports_head_size(head_size):
raise ValueError(f"Attention backend {attn_type!r} does not support head size {head_size}.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If attn_type is None (the default), the error message will display None instead of the actual resolved backend name (e.g., 'sdpa'). Using attn_backend.get_type() ensures the correct backend name is shown in the error message.

Suggested change
attn_backend = get_attn_backend(attn_type)
if not attn_backend.supports_head_size(head_size):
raise ValueError(f"Attention backend {attn_type!r} does not support head size {head_size}.")
attn_backend = get_attn_backend(attn_type)
if not attn_backend.supports_head_size(head_size):
raise ValueError(f"Attention backend {attn_backend.get_type()!r} does not support head size {head_size}.")

Comment on lines +115 to +117
if attn_type is None:
attn_type = "sdpa"
if attn_type not in ATTENTION_BACKEND_REGISTRY:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To make the attention backend selection case-insensitive and more robust against mixed-case string inputs (e.g., 'SDPA' or 'FA2'), we should convert attn_type to lowercase when it is not None.

Suggested change
if attn_type is None:
attn_type = "sdpa"
if attn_type not in ATTENTION_BACKEND_REGISTRY:
if attn_type is None:
attn_type = "sdpa"
else:
attn_type = attn_type.lower()
if attn_type not in ATTENTION_BACKEND_REGISTRY:

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.

1 participant