
    RЦi
                         S r SSKrSSKJrJrJrJr  SSKrSSKJ	r	  SSK
Jr  \R                  " \5      r " S S\5      rg)zClassification training task.    N)CallableDictOptionalUnion   )TrainingTaskc                   .  ^  \ rS rSrSr   SS\R                  S\\R                  \4   S\	\
R                     S\	\
R                     S\4
U 4S jjjr SS	\	\   S
S 4S jjrS\
R"                  S\
R"                  S
\\\
R"                  4   4S jrSrU =r$ )ClassificationTask   a  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U ]  X4US9  Xl        X l        U R                  (       aB  [        USS 5      =(       d    [        U5      R                  n[        R                  SU 35        g g )N)r   r   r   __name__zClassificationTask: criterion=)
super__init__r   r   r   getattrtyper   _loggerinfo)selfr   r   r   r   r   	loss_name	__class__s          W/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/timm/task/classification.pyr   ClassificationTask.__init__    s^     	WE
"<<	:t<XY@X@XILL9)EF     
device_idsreturnc                 F    SSK Jn  U" U R                  4SU0UD6U l        U $ )a  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_distributed&ClassificationTask.prepare_distributed0   s'      	EI
IjI
r   inputtargetc                 P    U R                  U5      nU R                  X25      nUUS.$ )zForward 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)   r,   r+   s        r   forwardClassificationTask.forwardD   s2      E"~~f- 
 	
r   )r   r   )NNT)N)r   
__module____qualname____firstlineno____doc__nnModuler   r   r   torchr   r   boolr   listr&   Tensorr   strr-   __static_attributes____classcell__)r   s   @r   r
   r
      s    , .2+/ G99G RYY01G U\\*	G
 EKK(G G G$ *.  
	(
<<
 LL
 
c5<<	 	
 
r   r
   )r2   loggingtypingr   r   r   r   r5   torch.nnr3   taskr   	getLoggerr   r   r
    r   r   <module>rB      s8    #  2 2   


H
%M
 M
r   