
    *`is                     `    d Z ddlZddlmZ ej        dej        dej        defd            ZdS )z'MLX kernel for applying token bitmasks.    Nbitmasklogits
vocab_sizec                 ,   t          j        d t          j        t	          d          dggdz   D             |j                  }|                     t           j                  } |dd|f         ||                              d          dd|f         z   S )	a  Apply a token bitmask to logits using MLX for Metal GPUs.

    Args:
        bitmask: A tensor of shape (batch_size, (vocab_size + 31) // 32) containing
            the bitmask. Each bit in the bitmask determines whether the corresponding
            token is allowed (1) or not (0).
        logits: A tensor of shape (batch_size, vocab_size) containing the logits.

    Returns:
        The logits with -inf for tokens that are not allowed.
    c                 $    g | ]}|d d d         S )N ).0ls     |/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/xgrammar/kernels/apply_token_bitmask_mlx.py
<listcomp>z+apply_token_bitmask_mlx.<locals>.<listcomp>   s"    GGGQ44R4GGG    z-infr      )dtype.N)	mxarray	itertoolsproductfloatr   viewuint8flatten)r   r   r   bitmaps       r   apply_token_bitmask_mlxr      s     XGG)+uV}}a.@-AA-EFGGGv|  F ll28$$G#{
{"#fWo&=&=b&A&A#{
{BR&SSSr   )	__doc__r   mlx.corecorer   compiler   intr   r	   r   r   <module>r!      sw    - -           TRX Trx TS T T T T T Tr   