Skip to content

NFT训练问题 #176

Description

@PlutoQyl

「项目背景」输入服饰+人脸,输出TryOn结果
「训练config文件」

# Environment Configuration
launcher: "accelerate"  # Options: accelerate
config_file: config/deepspeed/deepspeed_zero2.yaml  # Path to distributed config file (optional)
num_processes: 16  # Number of processes to launch (overrides config file)
main_process_port: 29500
mixed_precision: "bf16"  # Options: no, fp16, bf16

# Data Configuration
data:
  datasets:
    - name: tryon_synthetic_20k  # Unique identifier (used in metrics, caching, reward routing)
      dataset_dir: "/mnt/bn/image-data-lf/yunlong/data/TryOn/TryOn_Synthetic_NanoPro/version/0513_cqc20k"  # Path to dataset folder
      train:  # Training participation config
        weight: 1  # Mixing weight (integer); ratio with other sources determines batch allocation
        max_dataset_size: 4096  # Cap on number of training samples for this source
      eval: {}  # Eval participation (inherits shared `eval:` section settings)
  preprocessing_batch_size: 8  # Batch size for preprocessing
  enable_preprocess: true  # 启动离线预处理
  dataloader_num_workers: 16  # Number of workers for DataLoader
  force_reprocess: false  # Force reprocessing of the dataset
  cache_dir: "~/.cache/flow_factory/datasets" # Cache directory for preprocessed datasets
  sampler_type: "auto"  # Options: auto, distributed_k_repeat, group_contiguous

# Model Configuration
model:
  finetune_type: 'lora' # Options: full, lora
  lora_rank : 64
  lora_alpha : 128
  target_modules: "default" # Options: all, default, or list of module names like ["to_k", "to_q", "to_v", "to_out.0"]
  model_name_or_path: "/mnt/bn/image-data-lf/yunlong/models/FLUX.2-klein-base-9B-RL"  # Options: black-forest-labs/FLUX.2-klein-base-4B, black-forest-labs/FLUX.2-klein-base-9B
  model_type: "flux2-klein-tryon"
  resume_path: null # Path to load previous checkpoint/lora adapter
  resume_type: null # Options: lora, full, state. Null to auto-detect based on `finetune_type`

log:
  run_name: "flux2_lora_16gpus_nft_0604_nocfg_kl"  # Run name (auto: {model_type}_{finetune_type}_{trainer_type}_{timestamp})
  project: "Flow-Factory-Custom"  # Project name for logging
  logging_backend: "wandb"  # Options: wandb, swanlab, none
  save_dir: "/mnt/bn/image-data-lf/yunlong/Flow-Factory/train/NFT/"  # Directory to save model checkpoints and logs
  save_freq: 20  # Save frequency in epochs (0 to disable)
  save_model_only: true  # Save only the model weights (not optimizer, scheduler, etc.)

# Training Configuration
train:
  # Trainer settings
  trainer_type: 'nft'
  advantage_aggregation: 'gdpo' # Options: 'sum', 'gdpo'
  nft_beta: 0.1
  # `Old` Policy settings
  off_policy: true # Whether to use ema parameters for sampling off-policy data.
  ema_decay_schedule: "piecewise_linear"  # Decay schedule for EMA. Options: ['constant', 'power', 'linear', 'piecewise_linear', 'cosine', 'warmup_cosine']
  flat_steps: 0
  ramp_rate: 0.001
  ema_decay: 0.5  # EMA decay rate (0 to disable)
  ema_update_interval: 1  # EMA update interval (in epochs)
  ema_device: "cuda"  # Device to store EMA model (options: cpu, cuda)
  # Training Timestep distribution
  num_train_timesteps: 2 # Set null to all steps
  time_sampling_strategy: discrete # Options: uniform, logit_normal, discrete, discrete_with_init, discrete_wo_init
  time_shift: 3.0
  timestep_range: 0.5 # Select fraction of timesteps to train on
  # KL div
  kl_type: 'v-based'
  kl_beta: 1e-3 # KL divergence beta - 0 to disable and save memory. Set ~1e-2 for 'x-based' and ~1e-3 for 'v-based'.
  ref_param_device: 'cuda' # Options: cpu, cuda
  # Clipping
  adv_clip_range: 5.0  # Advantage clipping range

  # Sampling Settings
  resolution: [1168, 880]  # 训练时FM采样生成的分辨率。Can be int or [height, width]
  condition_image_size: 1024  # 训练时FM输入编辑图像的分辨率。Can be int or [height, width],注意实际用的时候是计算max_area
  max_sequence_length: 1024  # 文本 Prompt 编码的最大截断长度 (默认512)
  num_inference_steps: 8  # 训练时采样的时间步,对应的Flow-GRPO的Denoising Reduction。Number of timesteps
  guidance_scale: 1.0  # Guidance scale for sampling

  # Batch and sampling
  per_device_batch_size: 1  # Batch size per device. For image-to-image task, this will always fallback to 1.
  group_size: 16  # Group size for GRPO sampling
  global_std: false  # Use global std for advantage normalization
  unique_sample_num_per_epoch: 48  # Unique samples per group
  gradient_step_per_epoch: 1  # Gradient steps per epoch
  gradient_accumulation_steps: auto  # Options: auto, or positive integer. When set, `gradient_step_per_epoch` is ignored.
  
  # Optimization
  learning_rate: 1.0e-4  # Initial learning rate
  adam_weight_decay: 1.0e-4  # AdamW weight decay
  adam_betas: [0.9, 0.999]  # AdamW betas
  adam_epsilon: 1.0e-8  # AdamW epsilon
  max_grad_norm: 1.0  # Max gradient norm for clipping
  
  # Gradient Checkpointing
  enable_gradient_checkpointing: true  # Enable gradient checkpointing to save memory with extra compute
  # offload_samples_to_cpu: CPU-offload sample tensor fields between sample() and optimize() to reduce GPU peak memory.
  # Pros (true): saves N x per_batch_size GPU memory in sample()/optimize() (often GB-scale); no correctness or convergence impact.
  # Cons (true): adds ~100ms/epoch H2D in reward path; tiny per-batch H2D in optimize (<5ms each).
  # Recommended (true) for higher resolutions, larger batch sizes, or any sample()/optimize() OOM. Default false works for current example settings.
  offload_samples_to_cpu: false

  # Seed
  seed: 0 # Random seed

# Scheduler Configuration
scheduler:
  dynamics_type: "ODE"  # Options: Flow-SDE, Dance-SDE, CPS, ODE

# Evaluation settings
eval:
  resolution: [1168, 880]  # Evaluation resolution
  condition_image_size: 1024
  max_sequence_length: 1024  # 文本 Prompt 编码的最大截断长度 (默认512)
  per_device_batch_size: 1  # Eval batch size
  guidance_scale: 1.0  # Guidance scale for sampling
  num_inference_steps: 28  # Number of eval timesteps
  eval_freq: 20  # Eval frequency in epochs (0 to disable)
  seed: 0  # Eval seed (defaults to training seed)

# Reward Model Configuration
rewards:
  - name: "face_consistency"
    reward_model: "facezhichuangreward"
    weight: 1.0
    batch_size: 16
    timeout: 10.0
    max_area: 1048576 # 1024 * 1024
    person_image_index: 1 # TryOn 任务中,condition_images[1] 通常是人像图
    max_concurrent: 16 # RPC 并发请求限制
    async_reward: true # 开启异步并发打分,隐藏网络延迟

「补充说明」其中奖励函数是人脸相似度
「训练曲线」

Image

「问题」

  1. 已经开启了KL损失,但是奖励还是指数级上升?同时观察可视化case发现是hacking了(人脸直接copypaste了)。请问如何在NFT中继续调整参数,可否提供一些训练的调参思路
  2. 可否帮忙检查下是否是由于NFT参数设置错误导致的问题?

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionDiscussion about experiment configs, phenomena and etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions