Ë
    éÓ^j¬  ã                   ó‚   — d Z ddlZddlmZmZmZmZ ddlZddlm	Z	 ddl
mZ  ej                  e«      Z G d„ de«      Zy)zClassification training task.é    N)ÚCallableÚDictÚOptionalÚUnioné   )ÚTrainingTaskc                   óN  ‡ — e Zd ZdZ	 	 	 ddej
                  deej
                  ef   dee	j                     dee	j                     def
ˆ fd„Z	 ddee   d	d fd
„Z	 	 ddedee   d	ej
                  fd„Zde	j$                  de	j$                  d	eee	j$                  f   fd„Zˆ xZS )ÚClassificationTaska?  Standard supervised classification task.

    Simple task that performs a forward pass through the model and computes
    the classification loss.

    Args:
        model: The model to train
        criterion: Loss function (e.g., CrossEntropyLoss)
        device: Device for task tensors/buffers
        dtype: Dtype for task tensors/buffers
        verbose: Enable info logging

    Example:
        >>> task = ClassificationTask(model, nn.CrossEntropyLoss(), device=torch.device('cuda'))
        >>> result = task(input, target)
        >>> result['loss'].backward()
    ÚmodelÚ	criterionÚdeviceÚdtypeÚverbosec                 óØ   •— t         ‰| �  |||¬«       || _        || _        | j                  r=t        |dd «      xs t        |«      j                  }t        j                  d|› �«       y y )N)r   r   r   Ú__name__zClassificationTask: criterion=)
ÚsuperÚ__init__Útrainable_moduler   r   ÚgetattrÚtyper   Ú_loggerÚinfo)Úselfr   r   r   r   r   Ú	loss_nameÚ	__class__s          €úc/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/timm/task/classification.pyr   zClassificationTask.__init__    se   ø€ ô 	‰Ñ ¨e¸WÐÔEØ %ˆÔØ"ˆŒà�<Š<Ü 	¨:°tÓ<ÒXÄÀYÃ×@XÑ@XˆIÜ�L‰LÐ9¸)¸ÐEÕFð ó    Ú
device_idsÚreturnc                 óF   — ddl m}  || j                  fd|i|¤Ž| _        | S )aK  Prepare task for distributed training.

        Wraps the model in DistributedDataParallel (DDP).

        Args:
            device_ids: List of device IDs for DDP (e.g., [local_rank])
            **ddp_kwargs: Additional arguments passed to DistributedDataParallel

        Returns:
            self (for method chaining)
        r   )ÚDistributedDataParallelr   )Útorch.nn.parallelr!   r   )r   r   Ú
ddp_kwargsÚDDPs       r   Úprepare_distributedz&ClassificationTask.prepare_distributed0   s+   € õ  	EÙ # D×$9Ñ$9Ñ _ÀjÐ _ÐT^Ñ _ˆÔØˆr   ÚbackendÚmodec                 óŒ   — t        j                  | j                  f||dœ|¤Ž| _        | j                  | _        | j                  S )z5Compile the classification model before DDP wrapping.)r&   r'   )ÚtorchÚcompiler   Ú
eval_model)r   r&   r'   Úcompile_kwargss       r   r*   zClassificationTask.compileD   sB   € ô !&§¡¨d×.CÑ.CÐ rÈWÐ[_Ñ rÐcqÑ rˆÔà×/Ñ/ˆŒØ×$Ñ$Ð$r   ÚinputÚtargetc                 óR   — | j                  |«      }| j                  ||«      }||dœS )a2  Forward pass through model and compute classification loss.

        Args:
            input: Input tensor [B, C, H, W]
            target: Target labels [B]

        Returns:
            Dictionary containing:
                - 'loss': Classification loss
                - 'output': Model logits
        )ÚlossÚoutput)r   r   )r   r-   r.   r1   r0   s        r   ÚforwardzClassificationTask.forwardP   s6   € ð  ×&Ñ& uÓ-ˆØ�~‰~˜f fÓ-ˆð Øñ
ð 	
r   )NNT)N)ÚinductorN)r   Ú
__module__Ú__qualname__Ú__doc__ÚnnÚModuler   r   r   r)   r   r   Úboolr   Úlistr%   Ústrr*   ÚTensorr   r2   Ú__classcell__)r   s   @r   r
   r
      sú   ø„ ñð, .2Ø+/Ø ñGà—9‘9ðGð ˜RŸY™Y¨Ð0Ñ1ðGð ˜UŸ\™\Ñ*ð	Gð
 ˜EŸK™KÑ(ðGð õGð$ *.ñà  ™ðð 
ó	ð, &Ø"&ñ
%àð
%ð ˜3‘-ð
%ð
 
�‰ó
%ð
à—<‘<ð
ð —L‘Lð
ð 
ˆc�5—<‘<ÐÑ	 ÷	
r   r
   )r6   ÚloggingÚtypingr   r   r   r   r)   Útorch.nnr7   Útaskr   Ú	getLoggerr   r   r
   © r   r   ú<module>rD      s:   ðÙ #Û ß 2Ó 2ã Ý å à
ˆ'×
Ñ
˜HÓ
%€ôY
˜õ Y
r   