o
    _۷is                     @   s<   d Z ddlZddlmZ ejdejdejdefddZdS )z'MLX kernel for applying token bitmasks.    Nbitmasklogits
vocab_sizec                 C   sd   t jdd tjtddggd  D |jd}| t j} |dd|f ||  d	dd|f  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                 S   s   g | ]	}|d d d qS )N ).0lr   r   ^/home/ubuntu/vllm_env/lib/python3.10/site-packages/xgrammar/kernels/apply_token_bitmask_mlx.py
<listcomp>   s    z+apply_token_bitmask_mlx.<locals>.<listcomp>z-infr      )dtype.N)	mxarray	itertoolsproductfloatr   viewuint8flatten)r   r   r   bitmapr   r   r	   apply_token_bitmask_mlx   s
   $*r   )	__doc__r   mlx.corecorer   compiler   intr   r   r   r   r	   <module>   s
     