
    xi=                     ~    S r SSKJrJr  SSKJr  \ " S S5      5       r\ " S S5      5       r\ " S S	5      5       rg
)z\
Training Configuration Classes

Contains dataclasses for LoRA and training configurations.
    )	dataclassfield)Listc                   v    \ rS rSr% SrSr\\S'   Sr\\S'   Sr	\
\S'   \" S	 S
9r\\   \S'   Sr\\S'   S rSrg)
LoRAConfig   al  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                  
    / SQ$ N)q_projk_projv_projo_proj r       O/mnt/workspace/acestep.cpp/tests/../../ACE-Step-1.5/acestep/training/configs.py<lambda>LoRAConfig.<lambda>        ?r   default_factorytarget_modulesnonebiasc                 v    U R                   U R                  U R                  U R                  U R                  S.$ )z&Convert to dictionary for PEFT config.)r
   
lora_alphalora_dropoutr   r   )r
   r   r   r   r   selfs    r   to_dictLoRAConfig.to_dict   s3     ** LL"11II
 	
r   r   N)__name__
__module____qualname____firstlineno____doc__r
   int__annotations__r   r   floatr   r   r   strr   r$   __static_attributes__r   r   r   r   r      sP     AsJE3OGU % 7 !NDI  D#
r   r   c                       \ rS rSr% SrSr\\S'   Sr\\S'   Sr	\\S'   S	r
\\S
'   S	r\\S'   S	r\\S'   S	r\\S'   \" S S9r\\   \S'   S	r\\S'   S	r\\S'   S	r\\S'   S	r\\S'   S rSrg)
LoKRConfig)   z5Configuration for LoKr (Low-Rank Kronecker) training.@   
linear_dim   linear_alphafactorFdecompose_both
use_tucker
use_scalarweight_decomposec                  
    / SQ$ r   r   r   r   r   r   LoKRConfig.<lambda>4   r   r   r   r   full_matrixbypass_moders_loraunbalanced_factorizationc                    U R                   U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  S.$ )z)Convert to dictionary for LyCORIS config.r4   r6   r8   r9   r:   r;   r<   r   r?   r@   rA   rB   rD   r"   s    r   r$   LoKRConfig.to_dict<   sp     // --kk"11//// $ 5 5"11++++||(,(E(E
 	
r   r   N)r&   r'   r(   r)   r*   r4   r+   r,   r6   r8   r9   boolr:   r;   r<   r   r   r   r.   r?   r@   rA   rB   r$   r/   r   r   r   r1   r1   )   s    ?JL#FC ND JJ"d" % 7 !NDI  KKGT%*d*
r   r1   c                   ^   \ rS rSr% SrSr\\S'   Sr\	\S'   Sr
\\S'   S	r\	\S
'   Sr\	\S'   Sr\	\S'   Sr\	\S'   Sr\	\S'   Sr\\S'   Sr\\S'   Sr\\S'   Sr\\S'   Sr\\S'   Sr\	\S'   Sr\\S'   Sr\	\S'   S r\\S!'   S"r\	\S#'   S r\\S$'   S%r\\S&'   Sr\	\S''   S(r\\S)'   S.S+ jr S, r!S-r"g*)/TrainingConfigN   a  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                 L    SU R                   s=::  a  S:  d  O  [        S5      eg )Nrh   rW   z val_split must be in [0.0, 1.0).)ri   
ValueErrorr"   s    r   __post_init__TrainingConfig.__post_init__   s$    dnn*s*?@@ +r   c                 4   0 SU R                   _SU R                  _SU R                  _SU R                  _SU R                  _SU R
                  _SU R                  _SU R                  _S	U R                  _S
U R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                   _U R"                  U R$                  U R&                  U R(                  U R*                  S.E$ )zConvert to dictionary.rJ   rK   rL   rN   rP   rR   rT   rU   rV   rX   rZ   r[   r\   r^   r_   r`   ra   )rc   rd   rf   rg   ri   )rJ   rK   rL   rN   rP   rR   rT   rU   rV   rX   rZ   r[   r\   r^   r_   r`   ra   rc   rd   rf   rg   ri   r"   s    r   r$   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   r   )returnN)#r&   r'   r(   r)   r*   rJ   r-   r,   rK   r+   rL   rN   rP   rR   rT   rU   rV   rX   rZ   r.   r[   rF   r\   r^   r_   r`   ra   rc   rd   rf   rg   ri   rl   r$   r/   r   r   r   rH   rH   N   s    0 E5  M5J'((J!!L#L%M5!OS!GT#(D(D#N%J% KJOS##s  s IuA
r   rH   N)	r*   dataclassesr   r   typingr   r   r1   rH   r   r   r   <module>rs      sa    )  
 
 
: !
 !
 !
H S
 S
 S
r   