{"record":{"id":"21ff2af0ded7d1f5","repo":"hiyouga/LlamaFactory","slug":"llama-factory-yaml-and-accelerate-config-cannot-de","errorCode":null,"errorMessage":"LLaMA-Factory YAML and Accelerate config cannot define different KT settings.","messagePattern":"LLaMA-Factory YAML and Accelerate config cannot define different KT settings\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/hparams/model_args.py","lineNumber":577,"sourceCode":"\n        config = dict(raw_config)\n        conflicts = sorted(set(config) & self._KT_DERIVED_KEYS)\n        if conflicts:\n            raise ValueError(f\"These `kt_config` values are derived from LLaMA-Factory arguments: {conflicts}.\")\n        return config\n\n    def _get_advanced_kt_config(self, training_args: Any) -> dict[str, Any]:\n        raw_config = getattr(training_args, \"kt_config\", None)\n        accelerator_config = self._get_accelerator_kt_config(training_args)\n        if raw_config is None:\n            if accelerator_config is not None:\n                raise ValueError(\n                    \"Put KTransformers settings in the LLaMA-Factory training YAML `kt_config`; \"\n                    \"remove `kt_config` from the Accelerate config.\"\n                )\n            return {}\n        if accelerator_config is not None and accelerator_config != raw_config:\n            raise ValueError(\"LLaMA-Factory YAML and Accelerate config cannot define different KT settings.\")\n        return self._normalize_advanced_kt_config(raw_config)\n\n    def configure_kt_checkpointing(self, training_args: Any) -> None:\n        r\"\"\"Keep LLaMA-Factory as the single gradient-checkpointing entry point.\"\"\"\n        if self.use_unsloth or self.use_unsloth_gc:\n            raise ValueError(\"KTransformers cannot be combined with Unsloth checkpoint wrapping.\")\n        if getattr(training_args, \"gradient_checkpointing\", False):\n            raise ValueError(\n                \"KTransformers uses LLaMA-Factory's `disable_gradient_checkpointing`; \"\n                \"remove `gradient_checkpointing: true`.\"\n            )\n        if getattr(training_args, \"gradient_checkpointing_kwargs\", None) is not None:\n            raise ValueError(\"KTransformers supplies its checkpoint context; remove `gradient_checkpointing_kwargs`.\")\n\n        fsdp_config = getattr(training_args, \"fsdp_config\", None)\n        if isinstance(fsdp_config, dict) and fsdp_config.get(\"activation_checkpointing\"):\n            raise ValueError(\"Disable FSDP activation checkpointing when using KTransformers.\")\n        if os.environ.get(\"FSDP_ACTIVATION_CHECKPOINTING\", \"false\").lower() in {\"1\", \"true\", \"yes\"}:","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/hparams/model_args.py#L559-L595","documentation":"Raised by _get_advanced_kt_config (model_args.py:577) when kt_config is defined in BOTH the LLaMA-Factory training YAML and the Accelerate config's accelerator_config.kt_config, and the two mappings are not equal. Divergent duplicates would make the effective KT settings depend on merge order, so LlamaFactory refuses to guess.","triggerScenarios":"Editing kt_config in the training YAML but not updating the copy in the Accelerate file (or vice versa); a shared Accelerate base config pinned to an older KT block combined with an updated experiment YAML.","commonSituations":"Two-file setups drifting apart after iterative tuning; CI templates that regenerate one file; JSON vs YAML quoting differences making apparently-equal values unequal (e.g. string 'true' vs bool true).","solutions":["Delete kt_config from the Accelerate config and keep only the training-YAML copy (preferred)","Or make the two mappings byte-for-byte equivalent in parsed value (mind types and quoting)","Add a pre-launch lint that fails if both files contain kt_config"],"exampleFix":"# before\n# accelerate.yaml: kt_config: {gen_config: {temperature: 0.9}}\n# train.yaml:    kt_config: {gen_config: {temperature: 0.7}}\n\n# after\n# accelerate.yaml: (kt_config removed)\n# train.yaml:\nkt_config:\n  gen_config:\n    temperature: 0.7","handlingStrategy":"validation","validationCode":"lf_kt = cfg.get('kt_config')\nacc_kt = (yaml.safe_load(open('accelerate_config.yaml')).get('accelerator_config') or {}).get('kt_config')\nassert not (acc_kt is not None and lf_kt is not None and acc_kt != lf_kt), 'kt_config defined twice and differs'","typeGuard":"def kt_sources_agree(lf: dict | None, acc: dict | None) -> bool:\n    return lf is None or acc is None or lf == acc","tryCatchPattern":null,"preventionTips":["Maintain kt_config in exactly one file (the training YAML)","If you must keep both, generate one from the other in CI"],"tags":["ktransformers","accelerate","config-conflict"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}