
    xi=                     ~    d Z ddlmZmZ ddlmZ e G d d             Ze G d d             Ze G d d	             Zy
)z\
Training Configuration Classes

Contains dataclasses for LoRA and training configurations.
    )	dataclassfield)Listc                   t    e Zd ZU dZdZeed<   dZeed<   dZe	ed<    e
d 	      Zee   ed
<   dZeed<   d Zy)
LoRAConfiga  Configuration for LoRA (Low-Rank Adaptation) training.
    
    Attributes:
        r: LoRA rank (dimension of low-rank matrices)
        alpha: LoRA scaling factor (alpha/r determines the scaling)
        dropout: Dropout probability for LoRA layers
        target_modules: List of module names to apply LoRA to
        bias: Whether to train bias parameters ("none", "all", or "lora_only")
       r   alphag?dropoutc                  
    g dS N)q_projk_projv_projo_proj r       7/mnt/workspace/ACE-Step-1.5/acestep/training/configs.py<lambda>zLoRAConfig.<lambda>        ?r   default_factorytarget_modulesnonebiasc                 v    | j                   | j                  | j                  | j                  | j                  dS )z&Convert to dictionary for PEFT config.)r	   
lora_alphalora_dropoutr   r   )r	   r   r   r   r   selfs    r   to_dictzLoRAConfig.to_dict   s3     ** LL"11II
 	
r   N)__name__
__module____qualname____doc__r	   int__annotations__r   r   floatr   r   r   strr   r"   r   r   r   r   r      sP     AsJE3OGU % 7 !NDI  D#
r   r   c                       e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	e
ed	<   dZe
ed
<   dZe
ed<   dZe
ed<    ed       Zee   ed<   dZe
ed<   dZe
ed<   dZe
ed<   dZe
ed<   d Zy)
LoKRConfigz5Configuration for LoKr (Low-Rank Kronecker) training.@   
linear_dim   linear_alphafactorFdecompose_both
use_tucker
use_scalarweight_decomposec                  
    g dS r   r   r   r   r   r   zLoKRConfig.<lambda>4   r   r   r   r   full_matrixbypass_moders_loraunbalanced_factorizationc                    | j                   | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  dS )z)Convert to dictionary for LyCORIS config.r.   r0   r2   r3   r4   r5   r6   r   r8   r9   r:   r;   r=   r    s    r   r"   zLoKRConfig.to_dict<   sp     // --kk"11//// $ 5 5"11++++||(,(E(E
 	
r   N)r#   r$   r%   r&   r.   r'   r(   r0   r2   r3   boolr4   r5   r6   r   r   r   r*   r8   r9   r:   r;   r"   r   r   r   r,   r,   )   s    ?JL#FC ND JJ"d" % 7 !NDI  KKGT%*d*
r   r,   c                   T   e Zd ZU dZdZeed<   dZeed<   dZ	eed<   dZ
eed	<   d
Zeed<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   d
Zeed<   dZeed <   d!Zeed"<   dZeed#<   d$Zeed%<   dZeed&<   d'Zeed(<   d,d*Zd+ Z y))-TrainingConfigap  Configuration for LoRA training process.
    
    Training uses:
    - Device-aware mixed precision (bf16 on CUDA/XPU, fp16 on MPS, fp32 on CPU)
    - Discrete timesteps from turbo shift=3.0 schedule (8 steps)
    - Randomly samples one of 8 timesteps per training step:
      [1.0, 0.9545, 0.9, 0.8333, 0.75, 0.6429, 0.5, 0.3]
    
    Attributes:
        shift: Timestep shift factor (fixed at 3.0 for turbo model)
        num_inference_steps: Number of inference steps (fixed at 8 for turbo)
        learning_rate: Initial learning rate
        batch_size: Training batch size
        gradient_accumulation_steps: Number of gradient accumulation steps
        max_epochs: Maximum number of training epochs
        save_every_n_epochs: Save checkpoint every N epochs
        warmup_steps: Number of warmup steps for learning rate scheduler
        weight_decay: Weight decay for optimizer
        max_grad_norm: Maximum gradient norm for clipping
        mixed_precision: Preferred precision mode for logging/config tracking
        seed: Random seed for reproducibility
        output_dir: Directory to save checkpoints and logs
    g      @shiftr   num_inference_stepsg-C6?learning_rate   
batch_size   gradient_accumulation_stepsd   
max_epochs
   save_every_n_epochswarmup_stepsg{Gz?weight_decay      ?max_grad_normbf16mixed_precisionFuse_fp8gradient_checkpointing*   seedz./lora_output
output_dirnum_workersT
pin_memory   prefetch_factorpersistent_workers pin_memory_devicelog_every_n_steps        	val_splitNc                 \    d| j                   cxk  rdk  st        d       t        d      y )Nr_   rN   z val_split must be in [0.0, 1.0).)r`   
ValueErrorr    s    r   __post_init__zTrainingConfig.__post_init__   s5    dnn*s*?@@ +?@@ +r   c                 4   i d| j                   d| j                  d| j                  d| j                  d| j                  d| j
                  d| j                  d| j                  d	| j                  d
| j                  d| j                  d| j                  d| j                  d| j                  d| j                  d| j                  d| j                   | j"                  | j$                  | j&                  | j(                  | j*                  dS )zConvert to dictionary.rA   rB   rC   rE   rG   rI   rK   rL   rM   rO   rQ   rR   rS   rU   rV   rW   rX   )rZ   r[   r]   r^   r`   )rA   rB   rC   rE   rG   rI   rK   rL   rM   rO   rQ   rR   rS   rU   rV   rW   rX   rZ   r[   r]   r^   r`   r    s    r   r"   zTrainingConfig.to_dict   s^   
TZZ
!4#;#;
 T//
 $//	

 *4+K+K
 $//
 "4#;#;
 D--
 D--
 T//
 t33
 t||
 %d&A&A
 DII
 $//
  4++!
" $//#
$  $33"&"9"9!%!7!7!%!7!7-
 	
r   )returnN)!r#   r$   r%   r&   rA   r)   r(   rB   r'   rC   rE   rG   rI   rK   rL   rM   rO   rQ   r*   rR   r>   rS   rU   rV   rW   rX   rZ   r[   r]   r^   r`   rc   r"   r   r   r   r@   r@   N   s    0 E5  M5J'((J!!L#L%M5!OS!GT#(D(D#N%J% KJOS##s  s IuA
r   r@   N)	r&   dataclassesr   r   typingr   r   r,   r@   r   r   r   <module>rh      sa    )  
 
 
: !
 !
 !
H S
 S
 S
r   