
    
3j                         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                   f  ^  \ 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S\S\	\   S
\R                  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__trainable_moduler   r   getattrtyper   _loggerinfo)selfr   r   r   r   r   	loss_name	__class__s          R/home/wildlama/miniconda3/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 #D$9$9 _j _T^ _r   backendmodec                     [         R                  " U R                  4XS.UD6U l        U R                  U l        U R                  $ )z5Compile the classification model before DDP wrapping.)r)   r*   )torchcompiler   
eval_model)r   r)   r*   compile_kwargss       r   r-   ClassificationTask.compileD   s?     !&d.C.C rW rcq r//$$$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   r1   r2   r5   r4   s        r   forwardClassificationTask.forwardP   s4      &&u-~~f- 
 	
r   )r   r.   r   )NNT)N)inductorN)r   
__module____qualname____firstlineno____doc__nnModuler   r   r   r,   r   r   boolr   listr'   strr-   Tensorr   r6   __static_attributes____classcell__)r   s   @r   r
   r
      s   , .2+/ G99G RYY01G U\\*	G
 EKK(G G G$ *.  
	, &"&
%
% 3-
%
 

%
<<
 LL
 
c5<<	 	
 
r   r
   )r<   loggingtypingr   r   r   r   r,   torch.nnr=   taskr   	getLoggerr   r   r
    r   r   <module>rK      s8    #  2 2   


H
%Y
 Y
r   