{"record":{"id":"16cfbd1657d73835","repo":"hiyouga/LlamaFactory","slug":"unknown-task-finetuning-args-stage","errorCode":null,"errorMessage":"Unknown task: {finetuning_args.stage}.","messagePattern":"Unknown task: (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/train/tuner.py","lineNumber":151,"sourceCode":"        elif finetuning_args.stage == \"dpo\":\n            from .mca import run_dpo as run_dpo_mca\n\n            run_dpo_mca(model_args, data_args, training_args, finetuning_args, callbacks)\n\n    elif finetuning_args.stage == \"pt\":\n        run_pt(model_args, data_args, training_args, finetuning_args, callbacks)\n    elif finetuning_args.stage == \"sft\":\n        run_sft(model_args, data_args, training_args, finetuning_args, generating_args, callbacks)\n    elif finetuning_args.stage == \"rm\":\n        run_rm(model_args, data_args, training_args, finetuning_args, callbacks)\n    elif finetuning_args.stage == \"ppo\":\n        run_ppo(model_args, data_args, training_args, finetuning_args, generating_args, callbacks)\n    elif finetuning_args.stage == \"dpo\":\n        run_dpo(model_args, data_args, training_args, finetuning_args, callbacks)\n    elif finetuning_args.stage == \"kto\":\n        run_kto(model_args, data_args, training_args, finetuning_args, callbacks)\n    else:\n        raise ValueError(f\"Unknown task: {finetuning_args.stage}.\")\n\n    if is_ray_available() and ray.is_initialized():\n        return  # if ray is initialized it will destroy the process group on return\n\n    try:\n        if dist.is_initialized():\n            dist.destroy_process_group()\n    except Exception as e:\n        logger.warning(f\"Failed to destroy process group: {e}.\")\n\n\ndef run_exp(args: Optional[dict[str, Any]] = None, callbacks: Optional[list[\"TrainerCallback\"]] = None) -> None:\n    args = read_args(args)\n    if \"-h\" in args or \"--help\" in args:\n        get_train_args(args)\n\n    ray_args = get_ray_args(args)\n    callbacks = callbacks or []","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/train/tuner.py#L133-L169","documentation":"At the end of `_training_function` (src/llamafactory/train/tuner.py:151) the stage string is dispatched over exactly six values: pt, sft, rm, ppo, dpo, kto. Anything else raises ValueError naming the offending stage. This almost always means the YAML `stage:` key was misspelled or the args dict was built incorrectly.","triggerScenarios":"A training YAML with `stage: SFT` (uppercase), `stage: pretrain`, `stage: rm_training`, or a typo like `stage: sfy`; or calling run_exp with a hand-built dict lacking a valid stage.","commonSituations":"Copy-paste edits of example configs; users renaming stages from other frameworks (e.g. 'instruction_tuning'); programmatic config generation.","solutions":["Set `stage:` to one of: pt, sft, rm, ppo, dpo, kto (lowercase) in the YAML.","If generating configs programmatically, validate the stage against that enum before invoking run_exp.","Check for YAML indentation errors that make `stage` parse as part of another key."],"exampleFix":"# before (yaml)\nstage: SFT\n\n# after\nstage: sft","handlingStrategy":"type-guard","validationCode":"VALID_STAGES = {\"pt\", \"sft\", \"rm\", \"ppo\", \"dpo\", \"kto\"}\nassert stage in VALID_STAGES, f\"stage must be one of {VALID_STAGES}\"","typeGuard":"def is_valid_stage(stage: str) -> bool:\n    return stage in {\"pt\", \"sft\", \"rm\", \"ppo\", \"dpo\", \"kto\"}","tryCatchPattern":null,"preventionTips":["Validate the stage enum in config-generation scripts.","Use schema validation (pydantic/jsonschema) on YAML configs before launch."],"tags":["config","stage","dispatch","typo"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}