
     sg(                     l    d dl Z d dlmZ d dlZd dlmZ  G d de j                        Z G d de      Z	y)    N)Anyc                       e Zd Zej                  dej                  ej                     de	dej                  ej                     fd       Z
y)LlamaDraftModel	input_idskwargsreturnc                    t               N)NotImplementedErrorselfr   r   s      N/var/www/html/venv/lib/python3.12/site-packages/llama_cpp/llama_speculative.py__call__zLlamaDraftModel.__call__
   s     "##    N)__name__
__module____qualname__abcabstractmethodnptNDArraynpintcr   r    r   r   r   r   	   sL    $RWW-$<?$	RWW	$ $r   r   c                       e Zd ZdZddedefdZedej                  e	j                     dedefd       Zdej                  e	j                     dedej                  e	j                     fd	Zy
)LlamaPromptLookupDecodingz>Based on https://github.com/apoorvumang/prompt-lookup-decodingmax_ngram_sizenum_pred_tokensc                      || _         || _        y r
   )r   r   )r   r   r   s      r   __init__z"LlamaPromptLookupDecoding.__init__   s    ,.r   r   c                    | j                   d   }t        t        ||dz
        dd      D ]  }t        j                  j
                  j                  | |f      }| | d  }t        j                  ||k(  d      }t        j                  |      d   }|D ]&  }	|	|z   }
|
|z   }t        ||      }|
|k  s| |
| c c S   t        j                  g t        j                        S )Nr      )axis)dtype)shaperangeminr   libstride_trickssliding_window_viewallnonzeroarrayr   )r   r   r   input_length
ngram_sizewindowsngram_arraymatchesmatch_indicesidx	start_idxend_idxs               r   find_candidate_pred_tokensz4LlamaPromptLookupDecoding.find_candidate_pred_tokens   s     !q)NL14D Eq"M 	8Jff**>>y:-XG $ZKL1K ffW3!<G JJw/2M % 8*,	#o5g|4w&$Yw778	8. xx"''**r   r   r   c                R    | j                  || j                  | j                        S )N)r   r   r   )r8   r   r   r   s      r   r   z"LlamaPromptLookupDecoding.__call__9   s1     .... 00 / 
 	
r   N)   
   )r   r   r   __doc__intr    staticmethodr   r   r   r   r8   r   r   r   r   r   r   r      s    H/s / / +;;rww'++ + +@
RWW-
<?
	RWW	
r   r   )
r   typingr   numpyr   numpy.typingr   ABCr   r   r   r   r   <module>rC      s-    
   $cgg $/
 /
r   