o
    "j                     @   sJ   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ G dd dZdS )    N)static)corec                   @   s>   e Zd Zdd Zdd ZddgfddZd	d
 ZdddZdS )	CostModelc                 C   s   d S )N )selfr   r   ]/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/cost_model/cost_model.py__init__   s   zCostModel.__init__c                 C   s   t   t }t }tj||d* t jjdd dgdd}t jj|d}t |}t j	j
dd| W d    n1 s@w   Y  td	|  ||fS )
N)main_programstartup_programX   float32)nameshapedtype
   g{Gz?)Zlearning_ratezmain program is: )paddleZenable_staticr   ZProgramZprogram_guarddatannfcmeanZ	optimizerZSGDZminimizeprint)r   r	   r
   r   ZhiddenZlossr   r   r   build_program   s   


zCostModel.build_programgputimec                 C   sp   t d}tjjddd}t j|}|| t j	 }|
  |j|d|ig d t }	|	|}
d S )Nr   )r   r   )sizer   r   )feedZ
fetch_list)r   Z
set_devicenprandomZastyper   ZExecutorrunZprofilerZProfilerstartr   r   ZProfileMeasure)r   r
   r	   ZdeviceZfetch_cost_listZplacexexepZ
cost_modelZ	cost_datar   r   r   profile_measure0   s   


zCostModel.profile_measurec                 C   sT   t jt jtd}t|d}t|}W d    n1 s w   Y  || _|S )Nzstatic_op_benchmark.jsonr)	ospathjoindirname__file__openjsonload_static_cost_data)r   Zstatic_cost_data_pathZload_f	load_dictr   r   r   static_cost_dataC   s   zCostModel.static_cost_dataTr   c                 C   sf   |d u rt di }| jD ]#}|d |kr0||d v r0|r$|d |d< n|d |d< |d |d< q|S )Nz?op_name should not be empty when you want to get static op timeopconfigZpaddle_gpu_timeZop_timeZpaddle_gpu_time_backward)
ValueErrorr.   )r   Zop_nameforwardr   Zop_costZop_datar   r   r   get_static_op_timeM   s   
zCostModel.get_static_op_timeN)Tr   )__name__
__module____qualname__r   r   r$   r0   r5   r   r   r   r   r      s    

r   )	r,   r&   numpyr   r   r   Zpaddle.baser   r   r   r   r   r   <module>   s   