
    7|h                     n    d dl Z d dlmZmZ d dlmZ d dlmZ  e j                  e	      Z
 G d de      Zy)    N)AnyOptional)LLM)IpexLLMc                       e Zd ZdZe	 ddddddedee   dee   ded	ee   d
e	de
fd       Ze	 ddddedee   dee   d
e	de
f
d       Zedefd       Zy)BigdlLLMzWrapper around the BigdlLLM model

    Example:
        .. code-block:: python

            from langchain_community.llms import BigdlLLM
            llm = BigdlLLM.from_model_id(model_id="THUDM/chatglm-6b")
    NT)tokenizer_idload_in_4bitload_in_low_bitmodel_idmodel_kwargsr	   r
   r   kwargsreturnc                >   t         j                  d       	 ddlm}m} ddlm}	m}
 |t         j                  d       |st        d      |xs i }|xs |}	  |	j                  |fi |}	  |j                  |fdd	i|}d
|v r)|j                         D ci c]  \  }}|d
k7  s|| }}} | d||||d|S # t        $ r t        d      w xY w# t        $ r  |
j                  |fi |}Y w xY w# t        $ r  |j                  |fdd	i|}Y w xY wc c}}w )a5  
        Construct object from model_id

        Args:
            model_id: Path for the huggingface repo id to be downloaded or
                      the huggingface checkpoint folder.
            tokenizer_id: Path for the huggingface repo id to be downloaded or
                      the huggingface checkpoint folder which contains the tokenizer.
            model_kwargs: Keyword arguments to pass to the model and tokenizer.
            kwargs: Extra arguments to pass to the model and tokenizer.

        Returns:
            An object of BigdlLLM.
        4BigdlLLM was deprecated. Please use IpexLLM instead.r   	AutoModelAutoModelForCausalLMAutoTokenizerLlamaTokenizerpCould not import bigdl-llm or transformers. Please install it with `pip install --pre --upgrade bigdl-llm[all]`.z`load_in_low_bit` option is not supported in BigdlLLM and 
                is ignored. For more data types support with `load_in_low_bit`, 
                use IpexLLM instead.zBigdlLLM only supports loading in 4-bit mode, i.e. load_in_4bit = True. Please install it with `pip install --pre --upgrade bigdl-llm[all]`.r
   Ttrust_remote_coder   model	tokenizerr    )loggerwarningbigdl.llm.transformersr   r   transformersr   r   ImportError
ValueErrorfrom_pretrained	Exceptionitems)clsr   r   r	   r
   r   r   r   r   r   r   _model_kwargs_tokenizer_idr   r   kvs                    a/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/llms/bigdl_llm.pyfrom_model_idzBigdlLLM.from_model_id   s   2 	MN	 C &NN( W  %*$0	W555mU}UI	8(88'+/<E -/!.!4!4!6A!?R:R1M   
&	

 
 	
U  	W 	2  	W666}VVI	W  	-I--'+/<E	s;   B; C ,C5 D&D;CC21C25DD)r	   c                   t         j                  d       	 ddlm}m} ddlm}m} |xs i }	|xs |}
	  |j                  |
fi |	}	  |j                  |fi |	}d|	v r)|	j                         D ci c]  \  }}|dk7  s|| }	}} | d||||	d|S # t        $ r t        d      w xY w# t        $ r  |j                  |
fi |	}Y w xY w# t        $ r  |j                  |fi |	}Y w xY wc c}}w )	a  
        Construct low_bit object from model_id

        Args:

            model_id: Path for the bigdl-llm transformers low-bit model folder.
            tokenizer_id: Path for the huggingface repo id or local model folder
                      which contains the tokenizer.
            model_kwargs: Keyword arguments to pass to the model and tokenizer.
            kwargs: Extra arguments to pass to the model and tokenizer.

        Returns:
            An object of BigdlLLM.
        r   r   r   r   r   r   r   r   )r   r   r    r   r   r!   r   r   r"   r$   r%   load_low_bitr&   )r'   r   r   r	   r   r   r   r   r   r(   r)   r   r   r*   r+   s                  r,   from_model_id_low_bitzBigdlLLM.from_model_id_low_biti   sS   0 	MN	 C %*$0	W555mU}UI	F5(55hP-PE -/!.!4!4!6A!?R:R1M   
&	

 
 	
1  	W 	  	W666}VVI	W
  	F*I**8E}EE	Fs:   B B- C 2C1 C1B*-CCC.-C.c                      y)Nz	bigdl-llmr   )selfs    r,   	_llm_typezBigdlLLM._llm_type   s        )N)__name__
__module____qualname____doc__classmethodstrr   dictboolr   r   r-   r0   propertyr3   r   r4   r,   r   r      s     (,Q

 '+!)-Q
Q
 tnQ

 smQ
 Q
 "#Q
 Q
 
Q
 Q
f  (,>

 '+>
>
 tn>

 sm>
 >
 
>
 >
@ 3  r4   r   )loggingtypingr   r   #langchain_core.language_models.llmsr   !langchain_community.llms.ipex_llmr   	getLoggerr5   r   r   r   r4   r,   <module>rC      s1       3 5			8	$aw ar4   