o
    i	                     @   sR   d dl Z d dlZd dlZdedefddZdefddZdejj	defd	d
Z
dS )    Nnumberreturnc                 C   s   | dksJ g d}t | dkrtt| d nd}t t|d }t|t|}d|d  }| d|  } |d }| dd||  S )	ab  Return human_readable_count

    Originated from:
    https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pytorch_lightning/core/memory.py

    Abbreviates an integer number with K, M, B, T for thousands, millions,
    billions and trillions, respectively.
    Examples:
        >>> get_human_readable_count(123)
        '123  '
        >>> get_human_readable_count(1234)  # (one thousand)
        '1 K'
        >>> get_human_readable_count(2e6)   # (two million)
        '2 M'
        >>> get_human_readable_count(3e9)   # (three billion)
        '3 B'
        >>> get_human_readable_count(4e12)  # (four trillion)
        '4 T'
        >>> get_human_readable_count(5e15)  # (more than trillion)
        '5,000 T'
    Args:
        number: a positive integer number
    Return:
        A string formatted according to the pattern described above.
    r   ) KMBT      
   z.2fr   )intnpfloorlog10ceilminlen)r   labels
num_digits
num_groupsshiftindex r   U/home/ubuntu/.local/lib/python3.10/site-packages/espnet2/torch_utils/model_summary.pyget_human_readable_count   s   $r   c                 C   s   t t| dd  d S )N   )r   str)dtyper   r   r   to_bytes+   s   r    modelc                 C   s   d}|t | 7 }tdd |  D }tdd |  D }d|d | }t|}t|}|d7 }|d| jj d	7 }|d
| d	7 }|d| d| d7 }ttdd |  D }|d| d	7 }t	t
|  j}|d| 7 }|S )NzModel structure:
c                 s   s    | ]}|  V  qd S N)numel.0pr   r   r   	<genexpr>3   s    z model_summary.<locals>.<genexpr>c                 s   s    | ]
}|j r| V  qd S r"   )requires_gradr#   r$   r   r   r   r'   4   s    z{:.1f}g      Y@z

Model summary:
z    Class Name: 
z&    Total Number of model parameters: z$    Number of trainable parameters: z (z%)
c                 s   s(    | ]}|j r| t|j V  qd S r"   )r(   r#   r    r   r$   r   r   r   r'   ?   s    
z
    Size: z
    Type: )r   sum
parametersformatr   	__class____name__humanfriendlyformat_sizenextiterr   )r!   message
tot_params
num_paramspercent_trainable	num_bytesr   r   r   r   model_summary0   s,   r8   )r/   numpyr   torchr   r   r   r    nnModuler8   r   r   r   r   <module>   s    %