{"record":{"id":"0a9ebfc1fba378a2","repo":"hiyouga/LlamaFactory","slug":"dpo-trainer-currently-only-supports-cp-size-1","errorCode":null,"errorMessage":"DPO trainer currently only supports cp_size == 1.","messagePattern":"DPO trainer currently only supports cp_size == 1\\.","errorType":"validation","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/v1/trainers/dpo_trainer.py","lineNumber":98,"sourceCode":"    sample_keys = sorted(sample.keys())\n    raise ValueError(\n        \"DPO training requires pair-format samples containing chosen/rejected responses. \"\n        f\"First sample from dataset '{dataset_name}' has keys: {sample_keys}. \"\n        \"Please use pair data (e.g. a dataset with chosen_messages/rejected_messages).\"\n    )\n\n\nclass DPOTrainer(BaseTrainer):\n    def __init__(\n        self,\n        args: TrainingArguments,\n        model: HFModel,\n        renderer,\n        train_dataset,\n        callbacks=None,\n    ) -> None:\n        if args.cp_size > 1:\n            raise NotImplementedError(\"DPO trainer currently only supports cp_size == 1.\")\n\n        self.pref_loss = args.pref_loss\n        self.pref_beta = args.pref_beta\n        self.pref_ftx = args.pref_ftx\n        self.simpo_gamma = args.simpo_gamma\n        self.ld_alpha = args.ld_alpha\n        self.dpo_label_smoothing = args.dpo_label_smoothing\n\n        # ref_model must be created AFTER super().__init__() because FSDP2 with\n        # init_on_meta materialises the model during _shard_model().  We defer\n        # creation to _init_ref_model() below.\n        self.ref_model = None\n\n        super().__init__(args, model, renderer, train_dataset, callbacks)\n\n        if self.pref_loss == \"sigmoid\":\n            self._init_ref_model()\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/v1/trainers/dpo_trainer.py#L80-L116","documentation":"NotImplementedError from DPOTrainer.__init__ (dpo_trainer.py:98) when args.cp_size > 1. Context parallelism is not yet implemented for the v1 DPO trainer; the check runs before super().__init__ so it fails fast, before model sharding or dataloader creation.","triggerScenarios":"Launching DPO training with cp_size set to a value greater than 1 in the v1 training arguments (e.g. to fit long sequences across GPUs).","commonSituations":"Users with very long preference sequences try to reuse a cp_size>1 SFT config for DPO; or a shared yaml defaults cp_size > 1 and is reused for a DPO run.","solutions":["Set cp_size: 1 in the training config for DPO runs.","To fit long sequences, reduce them via cutoff_len, or increase per-GPU memory techniques (activation checkpointing, zero-stage) instead of CP.","If CP is a hard requirement, fall back to the v0 DPO implementation or implement CP support in the v1 trainer."],"exampleFix":"# before\ntraining_args:\n  cp_size: 2\n\n# after\ntraining_args:\n  cp_size: 1","handlingStrategy":"validation","validationCode":"if args.cp_size > 1:\n    raise SystemExit(\"v1 DPOTrainer does not support cp_size > 1; set cp_size=1 or use v0\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin cp_size: 1 in DPO config templates.","Document unsupported dimensions per stage in team runbooks."],"tags":["dpo","distributed","context-parallelism","not-implemented"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}