Skip to content

LECO: verify_training_args() crashes on missing sample_every_n_epochs/sample_every_n_steps #2402

Description

@bmaltais

Summary

train_leco.py and sdxl_train_leco.py's setup_parser() never register --sample_every_n_epochs / --sample_every_n_steps, but verify_training_args() in library/args.py unconditionally accesses args.sample_every_n_epochs and args.sample_every_n_steps:

if args.sample_every_n_epochs is not None and args.sample_every_n_epochs <= 0:
    ...
if args.sample_every_n_steps is not None and args.sample_every_n_steps <= 0:
    ...

Since these two scripts don't call whatever add_*_arguments() helper registers those sample-related flags, argparse.Namespace never gets a sample_every_n_epochs / sample_every_n_steps attribute, and this line raises AttributeError — before training starts.

Steps to reproduce

Run either script with a minimal valid LECO config:

accelerate launch train_leco.py \
  --pretrained_model_name_or_path="model.safetensors" \
  --prompts_file="prompts.toml" \
  --output_dir="output" \
  --output_name="test"

main() calls args_util.verify_training_args(args), which hits:

AttributeError: 'Namespace' object has no attribute 'sample_every_n_epochs'

(Same issue in sdxl_train_leco.py.)

Suggested fix

Either:

  1. Register --sample_every_n_epochs and --sample_every_n_steps in LECO's setup_parser() with default=None (even if unused, so verify_training_args()'s generic checks don't fail), or
  2. Guard the two checks in verify_training_args() with getattr(args, "sample_every_n_epochs", None) / getattr(args, "sample_every_n_steps", None) instead of direct attribute access, consistent with how getattr(args, "train_inpainting", False) is already handled a few lines above in the same function.

Option 2 is more robust against future scripts that similarly opt out of the sample-image machinery.

Context

Found while adding LECO GUI support in kohya_ss (bmaltais/kohya_ss#3539). Not a GUI-side bug — this is purely in the training script / arg verification, hence filing here rather than downstream.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions