o
    پi                     @   sB   d dl Z d dlZd dlmZ d dlmZmZ G dd dejZdS )    N)	BertModelBertTokenizerc                       s2   e Zd ZdZd fdd	Zejd	ddZ  ZS )
HunyuanClipz
    Hunyuan clip code copied from https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py
    hunyuan's clip used BertModel and BertTokenizer, so we copy it.
    M   c                    s@   t    || _ttj|d| _t	tj|d| _
d S )N	tokenizerclip_text_encoder)super__init__
max_lengthr   from_pretrainedospathjoinr   r   text_encoder)self	model_dirr
   	__class__ f/home/ubuntu/.local/lib/python3.10/site-packages/sglang/multimodal_gen/runtime/models/encoders/bert.pyr	      s   

zHunyuanClip.__init__Tc                 C   s`   t | j j| _| j|d| jdddd}| j|j| j|r&|j| jnd d}|j	|j
fS )Nr
   Tpt)paddingr
   
truncationreturn_attention_maskreturn_tensors)attention_mask)nextr   
parametersdevicer   r
   	input_idstor   last_hidden_statepooler_output)r   prompts	with_masktext_inputsprompt_embedsr   r   r   forward   s   zHunyuanClip.forward)r   )T)	__name__
__module____qualname____doc__r	   torchno_gradr'   __classcell__r   r   r   r   r      s
    r   )	r   r,   torch.nnnntransformersr   r   Moduler   r   r   r   r   <module>   s
   