+
    ƒ°ñj¬  ã                   ó  € R t ^ RIt^ RIt^ RIt^ RIHt RtRtRt ! R R]P                  P                  P                  4      t ! R R	]P                  P                  P                  4      t ! R
 R]P                  4      tRR ltR# )a›  Mage-Flow text encoder: Qwen3-VL-4B, last hidden state (2560-dim).

Mage-Flow conditions on the final hidden state of Qwen3-VL-4B with the leading
system + user-opening template tokens stripped (reference start_idx 34 for t2i,
64 for edit). The t2i template is identical to Qwen-Image's; the edit template
uses the same system prompt as Qwen-Image-Edit with "Image N: " reference
prefixes and no <think> block.
N)Úsd1_clipz+<|vision_start|><|image_pad|><|vision_end|>z×<|im_start|>system
Describe the image by detailing the color, shape, size, texture, quantity, text, spatial relationships of the objects and background:<|im_end|>
<|im_start|>user
{}<|im_end|>
<|im_start|>assistant
a‚  <|im_start|>system
Describe the key features of the input image (color, shape, size, texture, objects, background), then explain how the user's text instruction should alter or modify the image. Generate a new image that meets the user's requirements while maintaining consistency with the original input where appropriate.<|im_end|>
<|im_start|>user
{}<|im_end|>
<|im_start|>assistant
c                   óR   a a€ ] tR t^t oR/ 3V 3R lltRR. R3V 3R lltRtVtV ;t# )ÚMageFlowTokenizerNc                óV   <€ \         SV `  WR R7       \        V n        \        V n        R# )Ú
qwen3vl_4b)Úembedding_directoryÚtokenizer_dataÚ
model_typeN)ÚsuperÚ__init__ÚMAGE_T2I_TEMPLATEÚllama_templateÚMAGE_EDIT_TEMPLATEÚllama_template_images)Úselfr   r   Ú	__class__s   &&&€ÚAC:\Ai_Coding\apps\studio\ComfyUI\comfy\text_encoders\mage_flow.pyr   ÚMageFlowTokenizer.__init__   s'   ø€ Ü‰ÑÐ-@ÐlxÐÔyÜ/ˆÔÜ%7ˆÖ"ó    Fc                óÐ  <€ VP                  R R4      pVeD   \        V4      ^ 8X  d4   \        VP                  ^ ,          4       Uu. uF  q‡Wˆ^,            NK  	  ppVfl   \        V4      ^ 8”  dP   RP	                  R \        \        V4      4       4       4      p	V P
                  P                  RV	R,           ^4      pMV P                  p\        S
V `$  ! V3RVRVRVRV/VB # u upi )	ÚimageNÚ c              3   ó\   "  € T F"  pR P                  V^,           \        4      x € K$  	  R# 5i)zImage {}: {}N)ÚformatÚMAGE_VISION_BLOCK)Ú.0Újs   & r   Ú	<genexpr>Ú:MageFlowTokenizer.tokenize_with_weights.<locals>.<genexpr>$   s(   é € Ð mÑZlÐUV ×!6Ñ!6°q¸1µuÔ>O×!PÐ!PÓZlùs   ‚*,z{}Úreturn_word_idsr   ÚimagesÚprevent_empty_text)
ÚgetÚlenÚrangeÚshapeÚjoinr   Úreplacer   r
   Útokenize_with_weights)r   Útextr   r   r    r!   Úkwargsr   ÚiÚprefixr   s   &&&&&&,   €r   r(   Ú'MageFlowTokenizer.tokenize_with_weights   sþ   ø€ Ø—
‘
˜7 DÓ)ˆØÒ¤ V£°Ô!1Ü.3°E·K±KÀµNÔ.CÓDÑ.C¨˜A !�e“nÑ.CˆFÐDØÒ!Ü�6‹{˜QŒàŸ™Ñ mÔZ_Ô`cÐdjÓ`kÔZlÓ mÓm�Ø!%×!;Ñ!;×!CÑ!CÀDÈ&ÐSWÍ-ÐYZÓ![‘à!%×!4Ñ!4�Ü‰wÒ,¨Tñ  sÀ?ð  sÐcqð  sð  {Að  sð  Vhð  sð  lrñ  sð  	sùò Es   ÁC#)r   r   )	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   r(   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r   Ú__classdict__s   @@r   r   r      s*   ù‡ € Ø+/À÷ 8ð
 ;@ÐPTÐ]_Ðty÷ s÷ sr   r   c                   ó@   a a€ ] tR t^+t oRRR/ R3V 3R lltRtVtV ;t# )ÚMageFlowQwen3VLClipModelÚcpuNTr   c                ó:   <€ \         SV `  WW4VR 7       RV n        R# ))ÚdeviceÚdtypeÚattention_maskÚmodel_optionsr	   TN)r
   r   Úlayer_norm_hidden_state)r   r;   r<   r=   r>   r	   r   s   &&&&&&€r   r   Ú!MageFlowQwen3VLClipModel.__init__,   s'   ø€ Ü‰Ñ ÀNð  }GÐô  	Hà'+ˆÖ$r   )r?   ©r.   r/   r0   r1   r   r2   r3   r4   r5   s   @@r   r8   r8   +   s   ù‡ € Ø#¨4ÀÐTVÐco÷ ,÷ ,r   r8   c                   óL   a a€ ] tR t^2t oRR/ 3V 3R lltRV 3R lltRtVtV ;t# )ÚMageFlowTEModelr9   Nc                ó2   <€ R  p\         SV `  WRWCR7       R# )c                  ó    € \        R/ V BR R/B # )r	   r   © )r8   )Úkws   ,r   Ú<lambda>Ú*MageFlowTEModel.__init__.<locals>.<lambda>4   s   € Ô":Ñ"Y¸RÑ"YÈLÓ"Yr   r   )r;   r<   ÚnameÚ
clip_modelr>   N)r
   r   )r   r;   r<   r>   rK   r   s   &&&& €r   r   ÚMageFlowTEModel.__init__3   s   ø€ ÙYˆ
Ü‰Ñ ¸,ÐS]ÐÖ{r   c                óø  <€ \         SV `  V4      w  r4pVR ,          ^ ,          p^ pVR8X  dÙ   \        V4       Fk  w  r‰V	^ ,          p
\        P                  ! V
4      '       d   K,  \        V
\        P                  4      '       g   KN  V
R8X  g   KW  V^8  g   K`  TpV^,          pKm  	  VP                  ^,          V^,           8”  d@   Wb^,           ,          ^ ,          R8X  d%   Wb^,           ,          ^ ,          ^Æ8X  d
   V^,          pVRVR13,          pRV9   d`   VR,          RVR13,          VR&   VR,          P                  4       \        P                  ! VR,          4      8X  d   VP                  R4       W4V3# )r   i\P ih  :NNNNr=   éÿÿÿÿ)r
   Úencode_token_weightsÚ	enumerateÚtorchÚ	is_tensorÚ
isinstanceÚnumbersÚIntegralr%   ÚsumÚnumelÚpop)r   Útoken_weight_pairsÚtemplate_endÚoutÚpooledÚextraÚ	tok_pairsÚcount_im_startr+   ÚvÚelemr   s   &&&        €r   rO   Ú$MageFlowTEModel.encode_token_weights7   sL  ø€ ä"™WÑ9Ð:LÓMÑˆ�UØ& |Õ4°QÕ7ˆ	ØˆØ˜2ÔÜ! )Ö,‘�Ø˜•t�Ü—’ t×,Ô,Ü! $¬×(8Ñ(8×9Ô9Ø 6ž>¨n¸qÖ.@Ø+,˜LØ*¨aÕ/šNñ -ð �y‰y˜�|˜|¨aÕ/Ô0Ø¨AÕ-Õ.¨qÕ1°SÔ8Ø °Õ!1Õ2°1Õ5¸Ô<Ø$¨Õ)˜à�!�\‘]Ð"Õ#ˆà˜uÔ$Ø&+Ð,<Õ&=¸aÀÁÐ>NÕ&OˆEÐ"Ñ#ØÐ%Õ&×*Ñ*Ó,´·²¸EÐBRÕ<SÓ0TÔTØ—	‘	Ð*Ô+à˜EÐ!Ð!r   rF   )rN   )	r.   r/   r0   r1   r   rO   r2   r3   r4   r5   s   @@r   rC   rC   2   s   ù‡ € Ø#¨4¸r÷ |÷"÷ "r   rC   c                 ó0   a a€  ! V V3R  lR\         4      pV# )c                   óB   <a a€ ] tR t^Ut oRR/ 3V VV3R lltRtVtV ;t# )Úte.<locals>.MageFlowTEModel_r9   Nc                óh   <€ Se   SpSe   VP                  4       pSVR&   \        SV `	  WVR7       R # )NÚquantization_metadata)r;   r<   r>   )Úcopyr
   r   )r   r;   r<   r>   r   Údtype_llamaÚllama_quantization_metadatas   &&&&€€€r   r   Ú%te.<locals>.MageFlowTEModel_.__init__V   s?   ø€ ØÒ&Ø#�Ø*Ò6Ø -× 2Ñ 2Ó 4�Ø9T�Ð5Ñ6Ü‰GÑ FÀ}ÐÖUr   rF   rA   )r   r6   ri   rj   s   @@€€r   ÚMageFlowTEModel_re   U   s   ú‡ € Ø"'¨tÀ2÷ 	V÷ 	Vñ 	Vr   rl   )rC   )ri   rj   rl   s   ff r   Úterm   T   s   ù€ ÷Vð Vœ?ô Vð Ðr   )NN)Ú__doc__rT   rQ   Úcomfy.text_encoders.qwen3vlÚcomfyr   r   r   r   Útext_encodersÚqwen3vlÚQwen3VLTokenizerr   ÚQwen3VLClipModelr8   ÚSD1ClipModelrC   rm   rF   r   r   Ú<module>rv      s†   ðñó ã ã "Ý àAÐ ð sÐ ð _Ð ôs˜×+Ñ+×3Ñ3×DÑDô sô(,˜u×2Ñ2×:Ñ:×KÑKô ,ô"�h×+Ñ+ô "öD	r   