ComfyUI-Apt_UnitPromptWeight
A powerful ComfyUI node for precise control of prompt weights
Profil du package
- Statut
- Vérifié
- Éditeur
- @cardenluo
- Source
- GitHub
- Étoiles
- 8
LIREMOI
Unit Prompt Weight
A powerful ComfyUI node for precise control of prompt weights, supporting multiple processing modes and visual weight allocation.
Core Working Principle
Weight Parsing Algorithm
The Unit Prompt Weight node employs an advanced Semantic Weight Dynamic Allocation Algorithm, which achieves precise control of prompt weights through a multi-stage processing flow:
-
Regular Expression Pattern Matching: Uses an optimized regular expression
\[([^\]]+)@([0-9.]+)\]for semantic-weight pair identification, which can accurately capture nested structures and edge cases. -
Text Segmentation Processing: Adopts Adaptive Segment Segmentation strategy, which can intelligently identify structured information in prompts. The algorithm first identifies core semantic units with weight markers (such as
[[email protected]]) through regular expressions, then processes unmarked parts as context units with default weight (1.0). This method ensures accurate capture of user semantic intent even in complex prompt structures, while preserving natural language coherence. The segmentation process also includes text cleaning steps to automatically remove excess punctuation and whitespace characters, optimizing subsequent encoding efficiency. -
Weight Vector Normalization: Executes L1-Norm Normalization, a key technique for maintaining numerical stability in high-dimensional feature spaces. The algorithm first calculates the absolute sum of all weight values, then divides each weight by this sum to ensure the normalized weight vector satisfies the unit L1 norm constraint. This normalization method is particularly suitable for prompt weight adjustment scenarios as it maintains the relative proportional relationships of weights while preventing numerical overflow or gradient vanishing problems. When all weights are detected to be equal, the algorithm automatically switches to uniform distribution mode, simplifying the calculation process.
-
Independent Feature Encoding: Performs CLIP Context-Aware Encoding on each semantic segment, which fully leverages the powerful semantic understanding capabilities of the CLIP model. Each segment is individually input into CLIP's text encoder to generate 768-dimensional high-dimensional feature representations. The encoding process preserves the complete contextual information of each semantic unit, ensuring that combined concepts like "girl with umbrella" are correctly understood as a whole rather than a simple bag-of-words model. For encoding failures, the algorithm implements graceful degradation processing to ensure the robustness of the entire process.
-
Weighted Feature Fusion: Applies Linear Weighted Fusion strategy, an advanced technique for achieving precise semantic weight control in feature space. The algorithm first performs alignment processing on feature vectors of different lengths (especially in qwen-image mode), then executes convex combination operations based on normalized weight vectors. This fusion method ensures that the final conditional embedding can accurately reflect the user's weight intentions while maintaining the geometric properties of the feature space. The fusion process also implements balance control between the overall prompt and individual weighted segments, providing additional adjustment freedom through the main_prompt_ratio parameter.
Feature Fusion Mechanism
The node implements two key feature fusion mechanisms:
- Individual Feature Fusion: Fuses features of each segment with different weights according to weight proportions
- Overall and Individual Balance: Controls the balance between the overall prompt and individual weighted segments through the
main_prompt_ratioparameter
Features
- **P
Nœuds dans ce pack
Nœud 1
Nœuds dans ce pack
Nœud 1- Unit_PromptWeight
Sources
3 sources
Sources
3 sourcesVérifié 10 oct.
Vérifié 10 oct.
Extraits de sources
1 extrait
Extraits de sources
1 extraitSource context: Repo cardenluo/ComfyUI-Apt_UnitPromptWeight
