{"record":{"id":"2b616857a01072ab","repo":"hiyouga/LlamaFactory","slug":"quantized-models-are-not-supported-with-megatron-b","errorCode":null,"errorMessage":"Quantized models are not supported with Megatron Bridge.","messagePattern":"Quantized models are not supported with Megatron Bridge\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/hparams/parser.py","lineNumber":439,"sourceCode":"\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:\n            raise ValueError(\"Quantized models are not supported with Megatron Bridge.\")\n        if training_args.deepspeed is not None:\n            raise ValueError(\"Megatron Bridge is incompatible with DeepSpeed.\")\n        if mb_args is None:\n            raise ValueError(\"Megatron Bridge arguments are missing. Please set USE_MEGATRON_BRIDGE=1.\")\n        _validate_megatron_bridge_parallel_args(mb_args, training_args.world_size)\n        finetuning_args.megatron_bridge_args = mb_args\n\n    if finetuning_args.stage in [\"rm\", \"ppo\"] and training_args.load_best_model_at_end:\n        raise ValueError(\"RM and PPO stages do not support `load_best_model_at_end`.\")\n\n    if finetuning_args.stage == \"ppo\":\n        if not training_args.do_train:\n            raise ValueError(\"PPO training does not support evaluation, use the SFT stage to evaluate models.\")\n\n        if model_args.shift_attn:\n            raise ValueError(\"PPO training is incompatible with S^2-Attn.\")\n\n        if finetuning_args.reward_model_type == \"lora\" and model_args.use_kt:","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/hparams/parser.py#L421-L457","documentation":"Megatron Bridge loads and shards full-precision weights into its own distributed format; quantized (bitsandbytes/GPTQ-style) checkpoints are incompatible with that path. The parser rejects any config where model_args.quantization_bit is not None while use_megatron_bridge is true.","triggerScenarios":"USE_MEGATRON_BRIDGE=1 plus quantization_bit: 4 (or 8) in the model_args block of the training config.","commonSituations":"Memory-saving QLoRA configs reused when switching to Megatron Bridge for multi-GPU throughput; users assuming quantization carries over between backends.","solutions":["Remove quantization_bit (or set it to null) for Megatron Bridge runs; rely on TP/PP sharding for memory.","If you must train quantized, drop Megatron Bridge (unset USE_MEGATRON_BRIDGE) and use the standard QLoRA path.","For deployment-size reduction, quantize after training during export instead."],"exampleFix":"# before\nexport USE_MEGATRON_BRIDGE=1\nquantization_bit: 4\n\n# after\nexport USE_MEGATRON_BRIDGE=1\nquantization_bit:  # removed / null","handlingStrategy":"validation","validationCode":"import os\n\nif os.environ.get(\"USE_MEGATRON_BRIDGE\") == \"1\" and cfg.get(\"quantization_bit\") is not None:\n    raise SystemExit(\"Remove quantization_bit for Megatron Bridge runs\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip the quantization block when porting QLoRA configs to Megatron; use TP/PP for memory savings.","Quantize at export time, not train time, in bridge workflows."],"tags":["megatron","quantization","config","validation"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}