o
    zi                     @   s\   d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ G dd deZdS )	    )AnyDictListTuple)override)ModelSummary)_RICH_AVAILABLE)get_human_readable_countc                       sv   e Zd ZdZddededdf fddZeed	e	e
ee	e f  d
edededeeef deddfddZ  ZS )RichModelSummaryaE  Generates a summary of all layers in a :class:`~pytorch_lightning.core.LightningModule` with `rich text
    formatting <https://github.com/Textualize/rich>`_.

    Install it with pip:

    .. code-block:: bash

        pip install rich

    .. code-block:: python

        from pytorch_lightning import Trainer
        from pytorch_lightning.callbacks import RichModelSummary

        trainer = Trainer(callbacks=RichModelSummary())

    You could also enable ``RichModelSummary`` using the :class:`~pytorch_lightning.callbacks.RichProgressBar`

    .. code-block:: python

        from pytorch_lightning import Trainer
        from pytorch_lightning.callbacks import RichProgressBar

        trainer = Trainer(callbacks=RichProgressBar())

    Args:
        max_depth: The maximum depth of layer nesting that the summary will include. A value of 0 turns the
            layer summary off.
        **summarize_kwargs: Additional arguments to pass to the `summarize` method.

    Raises:
        ModuleNotFoundError:
            If required `rich` package is not installed on the device.

       	max_depthsummarize_kwargsreturnNc                    s$   t stdt j|fi | d S )Nz``RichModelSummary` requires `rich` to be installed. Install it by running `pip install -U rich`.)r   ModuleNotFoundErrorsuper__init__)selfr   r   	__class__ b/home/ubuntu/.local/lib/python3.10/site-packages/pytorch_lightning/callbacks/rich_model_summary.pyr   <   s
   zRichModelSummary.__init__summary_datatotal_parameterstrainable_parameters
model_sizetotal_training_modesc                 K   s  ddl m} ddlm} | }|dd}	||	d}
|
jddd	 |
jd
ddd |
d |
jddd |
d tt|  d }dD ]}||v rR|
j|ddd qDttdd | D  }|D ]}|
j|  q`|	|
 g }||| ||fD ]}|
dtt|d qw|jdd}|  |  |d|d   |d|d   |d|d   |d |d!   |d"|d#   |d$|d%   |	| d S )&Nr   )get_console)Tableheader_stylezbold magenta)r    dim)styleNameleftT)justifyno_wrapTypeParamsright)r$   Mode)zIn sizesz	Out sizeswhite)r$   r!   c                 s   s    | ]}|d  V  qdS )r   Nr   ).0arrr   r   r   	<genexpr>`   s    z-RichModelSummary.summarize.<locals>.<genexpr>z{:<{}}
   )expandz[bold]Trainable params[/]: z[bold]Non-trainable params[/]: r   z[bold]Total params[/]:    z1[bold]Total estimated model params size (MB)[/]:    z [bold]Modules in train mode[/]: trainz[bold]Modules in eval mode[/]: eval)richr   
rich.tabler   get
add_columnlistzipadd_rowprintappendformatr	   intgrid)r   r   r   r   r   r   r   r   consoler   tablecolumn_namescolumn_namerowsrow
parametersparamr?   r   r   r   	summarizeC   s@   




zRichModelSummary.summarize)r   )__name__
__module____qualname____doc__r>   r   r   staticmethodr   r   r   strfloatr   rH   __classcell__r   r   r   r   r
      s(    $
r
   N)typingr   r   r   r   typing_extensionsr   pytorch_lightning.callbacksr   2pytorch_lightning.callbacks.progress.rich_progressr   )pytorch_lightning.utilities.model_summaryr	   r
   r   r   r   r   <module>   s   