o
    TÃiö  ã                   @   s`   d dl Z ddlmZ ddlmZmZ de jdedede jfd	d
„Zdedededefdd„Z	dS )é    Né   )ÚShardingType)Úshard_paramÚget_shard_endpointsÚparamÚ
shard_rankÚ
num_shardsÚreturnc                 C   s   t | tj||ƒS )aN  
    Utility method for sharding an embedding parameter.

    Args:
        param (torch.Tensor): The parameter to shard. Should be of shape [vocab_size, model_dim]
        shard_rank (int): Which shard of the partitioned tensor to return.
        num_shards (int): The total number of shards the parameter is distributed across.
    )r   r   ÚINNER_DIMENSION)r   r   r   © r   ús/home/ubuntu/.local/lib/python3.10/site-packages/deepspeed/inference/v2/model_implementations/sharding/embedding.pyÚshard_embedding_param   s   	r   Úembedding_sizec                 C   s   t | ||ƒ\}}|| S )aI  
    Utility method for getting the size of the embedding dimension of a sharded embedding.

    Args:
        embedding_size (int): The size of the embedding.
        shard_rank (int): Which shard of the partitioned tensor to return.
        num_shards (int): The total number of shards the parameter is distributed across.
    )r   )r   r   r   Ú	start_idxÚend_idxr   r   r   Úsharded_embedding_dim   s   	r   )
ÚtorchÚtypesr   Úutilsr   r   ÚTensorÚintr   r   r   r   r   r   Ú<module>   s
   