Skip to content

CLI parsing error: fit -c run.yaml works but -c run.yaml fit fails #21245

@oooooio

Description

@oooooio

Bug description

When running Lightning CLI with a config file, the position of the subcommand (fit, validate, etc.) affects parsing.

  • ✅ Works:
uv run src/trainer.py fit -c run.yaml
  • ❌ Fails:
uv run src/trainer.py -c run.yaml fit
  • Error
usage: trainer.py [-h] [-c CONFIG] [--print_config[=flags]] {fit,validate,test,predict} ...
error: Validation failed: Key 'model.backbone.init_args.seq_length' is not expected
  • Expected behavior
    Both fit -c run.yaml and -c run.yaml fit should behave identically, or the CLI should raise a clearer error message.

What version are you seeing the problem on?

v2.5

Reproduced in studio

No response

How to reproduce the bug

Error messages and logs

# Error messages and logs here please

Environment

Current environment
#- PyTorch Lightning Version (e.g., 2.5.0):
#- PyTorch Version (e.g., 2.5):
#- Python version (e.g., 3.12):
#- OS (e.g., Linux):
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(`conda`, `pip`, source):

More info

No response

cc @mauvilsa

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions