o
    Ti
                     @   s\   d dl mZ d dlZdZejejejejejej	ej
ejejejd
ZG dd dejZdS )    )DictN_ds_core_param_key)
ztorch.float32ztorch.float64ztorch.float16ztorch.bfloat16ztorch.int64ztorch.int32ztorch.int16z
torch.int8ztorch.uint8z
torch.boolc                       sr   e Zd ZdZe fddZ fddZedej	dd fdd	Z
edd
dZedeeej	f fddZ  ZS )InferenceParameterz
    An extension of the torch.Tensor class to support our inference focused features. One important
    thing to note here is that an InferenceParam can be used a torch.Tensor, but outputs of
    torch.Tensor operations will not be InferenceParams.
    c                    s8   t  j| |g|R i |}t|drt|d|j |S )N
_aux_attrs)super__new__hasattrsetattr	aux_attrs)clstensorargskwargs
new_tensor	__class__ ^/home/ubuntu/.local/lib/python3.10/site-packages/deepspeed/inference/v2/inference_parameter.pyr   !   s   
zInferenceParameter.__new__c                    s   t  j|i |}t| drt|d| j z't|d }|j D ]\}}|j|i |}t||| ||j|< q"W |S    Y |S )Nr   r   )r   tor   r	   r
   torchdeviceitems)selfr   r   r   _nameattrnew_attrr   r   r   r   (   s   
zInferenceParameter.to
core_paramreturnc                 K   sl   t |}t|d| | D ]%\}}t||rtd| dt|tjs-td| dt||| q|S )z1
        Create the inference parameter.
        r   z
Attribute z already exists on param.z must be a tensor.)r   r	   r   r   
ValueError
isinstancer   Tensor)r   r   r   param	attr_namer   r   r   r   
initialize7   s   
zInferenceParameter.initializec                 K   s.   t |vrtdt  dtj|t  fi |S )zW
        All kwargs must be torch.Tensors and must include the core parameter.
        z&Must provide core parameter, with key .)
CORE_PARAMr   r   r$   )r   r   r   r   r   initialize_rawJ   s   z!InferenceParameter.initialize_rawc                 C   s   | j S )z5
        Dictionary of auxiliary attributes.
        )r   )r   r   r   r   r
   T   s   zInferenceParameter.aux_attrs)r   r   )__name__
__module____qualname____doc__staticmethodr   r   classmethodr   r!   r$   r'   propertyr   strr
   __classcell__r   r   r   r   r      s    	"r   )typingr   r   r&   float32float64float16bfloat16int64int32int16int8uint8boolSTR_TO_DTYPEr!   r   r   r   r   r   <module>   s   