{"record":{"id":"ee20eee068922730","repo":"hiyouga/LlamaFactory","slug":"predict-with-generate-cannot-be-set-as-true-exce","errorCode":null,"errorMessage":"`predict_with_generate` cannot be set as True except SFT.","messagePattern":"`predict_with_generate` cannot be set as True except SFT\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/hparams/parser.py","lineNumber":420,"sourceCode":"                \"megatron-bridge is required when USE_MEGATRON_BRIDGE=1. \"\n                \"Please install `megatron-bridge` and its dependencies.\"\n            )\n        model_args, data_args, training_args, finetuning_args, mb_args, generating_args = _parse_train_mbridge_args(\n            args\n        )\n    else:\n        model_args, data_args, training_args, finetuning_args, generating_args = _parse_train_args(args)\n        finetuning_args.use_mca = False\n        finetuning_args.use_megatron_bridge = False\n\n    # Setup logging\n    if training_args.should_log:\n        _set_transformers_logging()\n\n    # Check arguments\n    if finetuning_args.stage != \"sft\":\n        if training_args.predict_with_generate:\n            raise ValueError(\"`predict_with_generate` cannot be set as True except SFT.\")\n\n        if data_args.neat_packing:\n            raise ValueError(\"`neat_packing` cannot be set as True except SFT.\")\n\n        if data_args.train_on_prompt or data_args.mask_history:\n            raise ValueError(\"`train_on_prompt` or `mask_history` cannot be set as True except SFT.\")\n\n    if finetuning_args.stage == \"sft\" and training_args.do_predict and not training_args.predict_with_generate:\n        raise ValueError(\"Please enable `predict_with_generate` to save model predictions.\")\n\n    if finetuning_args.use_megatron_bridge:\n        if finetuning_args.use_mca or finetuning_args.use_hyper_parallel:\n            raise ValueError(\"Megatron Bridge cannot be used together with MCA or HyperParallel.\")\n        if finetuning_args.stage not in [\"pt\", \"sft\"]:\n            raise ValueError(\"Megatron Bridge only supports the `pt` and `sft` stages.\")\n        if finetuning_args.finetuning_type not in [\"full\", \"lora\"]:\n            raise ValueError(\"Megatron Bridge only supports `full` and `lora` finetuning.\")\n        if model_args.quantization_bit is not None:","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/hparams/parser.py#L402-L438","documentation":"predict_with_generate makes the trainer run generation during evaluation to produce text predictions, which is only implemented for the SFT stage (it needs an instruction-tuned decode path with the model's generate()). For stages like pt/rm/ppo/dpo/kto the flag is meaningless, so the parser rejects it when finetuning_args.stage != 'sft'.","triggerScenarios":"A train config with stage: rm (or dpo/ppo/pt/kto) together with predict_with_generate: true, passed to llamafactory-cli train / run_exp(). Typical when copying an SFT eval config and only changing the stage field.","commonSituations":"Reusing a YAML that was written for SFT with do_eval + predict_with_generate, then switching stage to dpo or rm for preference training; webui-generated configs that keep the prediction flag enabled.","solutions":["Set predict_with_generate: false in the training_args block of your config.","If you actually want generation-based evaluation, change stage: sft and use the SFT pipeline.","Remove do_predict/do_eval-with-generation from non-SFT configs entirely."],"exampleFix":"# before\nstage: dpo\npredict_with_generate: true\n\n# after\nstage: dpo\npredict_with_generate: false","handlingStrategy":"validation","validationCode":"stage = cfg.get(\"stage\", \"sft\")\nif stage != \"sft\" and cfg.get(\"predict_with_generate\"):\n    raise SystemExit(f\"predict_with_generate is SFT-only; config stage is {stage}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Start non-SFT configs from a stage-specific template instead of editing a copy of an SFT config.","Write a config preflight that maps each flag to its allowed stages (predict_with_generate/neat_packing/train_on_prompt/mask_history -> sft only)."],"tags":["config","validation","evaluation","stage","sft"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}