o
    8wi                     @   s   d Z ddlZddlmZmZ ddlmZ ddlZddl	m
Z
 ddlmZmZ ddlmZ ddlmZ eeZG d	d
 d
e
ZdS )a  
Model Summary
=============

Generates a summary of all layers in a :class:`~pytorch_lightning.core.LightningModule`.

The string representation of this summary prints a table with columns containing
the name, type and number of parameters for each layer.

    N)AnyUnion)override)Callback)DeepSpeedSummary	summarize)ModelSummary)_format_summary_tablec                   @   s   e Zd ZdZddededdfddZedddZd	d
ddde	e
ef fddZ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dS )r   a  Generates a summary of all layers in a :class:`~pytorch_lightning.core.LightningModule`.

    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.

    Example::

        >>> from pytorch_lightning import Trainer
        >>> from pytorch_lightning.callbacks import ModelSummary
        >>> trainer = Trainer(callbacks=[ModelSummary(max_depth=1)])

       	max_depthsummarize_kwargsreturnNc                 K   s   || _ || _d S N)
_max_depth_summarize_kwargs)selfr   r    r   f/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/pytorch_lightning/callbacks/model_summary.py__init__7   s   
zModelSummary.__init__trainer
pl.Trainer	pl_modulepl.LightningModulec           	      C   s`   | j sd S | ||}| }|j}|j}|j}|j}|jr.| j|||||fi | j	 d S d S r   )
r   _summary_get_summary_datatotal_parameterstrainable_parameters
model_sizetotal_training_modesis_global_zeror   r   )	r   r   r   model_summarysummary_datar   r   r   r   r   r   r   on_fit_start;   s&   
zModelSummary.on_fit_startc                 C   s<   ddl m} t|j|r|jjrt|| jdS t|| jdS )Nr   )DeepSpeedStrategy)r   )&pytorch_lightning.strategies.deepspeedr#   
isinstancestrategyzero_stage_3r   r   r   )r   r   r   r#   r   r   r   r   Q   s   zModelSummary._summaryr!   r   r   r   r   c                 K   s(   t ||||g| R  }td|  d S )N
)r	   loginfo)r!   r   r   r   r   r   summary_tabler   r   r   r   X   s   	zModelSummary.summarize)r
   )r   r   r   r   r   N)__name__
__module____qualname____doc__intr   r   r   r"   r   r   Summaryr   staticmethodlisttuplestrfloatdictr   r   r   r   r   r   '   s,    
r   )r/   loggingtypingr   r   typing_extensionsr   pytorch_lightningpl$pytorch_lightning.callbacks.callbackr   )pytorch_lightning.utilities.model_summaryr   r   r   r1   7pytorch_lightning.utilities.model_summary.model_summaryr	   	getLoggerr,   r)   r   r   r   r   <module>   s   
