{"record":{"id":"0886c8e886a80a13","repo":"hiyouga/LlamaFactory","slug":"kt-config-requires-use-kt-true","errorCode":null,"errorMessage":"`kt_config` requires `use_kt: true`.","messagePattern":"`kt_config` requires `use_kt: true`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/hparams/model_args.py","lineNumber":683,"sourceCode":"        kt_config = self.get_kt_config_dict(\n            finetuning_args,\n            model_max_length,\n            self._get_advanced_kt_config(training_args),\n        )\n        update_kt_config = getattr(training_args, \"update_kt_config\", None)\n        if not callable(update_kt_config):\n            raise RuntimeError(\n                \"The installed Transformers-KT does not provide `TrainingArguments.update_kt_config()`.\"\n            )\n\n        adapter_dir = self._resolve_kt_adapter_artifact_dir(\"training\")\n        update_kt_config(kt_config, adapter_name_or_path=adapter_dir)\n\n    def configure_kt_loading(self, finetuning_args: Any, model_max_length: int | None) -> None:\n        r\"\"\"Configure KT model loading for inference and evaluation.\"\"\"\n        if not self.use_kt:\n            if self._kt_inference_config is not None:\n                raise ValueError(\"`kt_config` requires `use_kt: true`.\")\n            return\n        if self.infer_backend != EngineName.HF:\n            raise ValueError(\"KTransformers inference requires `infer_backend: huggingface`.\")\n\n        adapter_dir = self._resolve_kt_adapter_artifact_dir(\"inference\")\n\n        try:\n            from transformers.integrations.kt import configure_kt\n        except (ImportError, ModuleNotFoundError) as exc:\n            raise RuntimeError(\"The installed Transformers-KT does not provide `configure_kt()`.\") from exc\n\n        kt_config = self.get_kt_config_dict(\n            finetuning_args,\n            model_max_length,\n            self._normalize_advanced_kt_config(self._kt_inference_config),\n        )\n        self._kt_adapter_artifact_path = adapter_dir\n        self._kt_config_handle = configure_kt(kt_config)","sourceCodeStart":665,"sourceCodeEnd":701,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/hparams/model_args.py#L665-L701","documentation":"Raised by configure_kt_loading when _kt_inference_config is populated but use_kt is false. The inference-side kt_config is captured only during KT-enabled parsing, so finding it without use_kt means the config was partially applied — LLaMA-Factory refuses the inconsistent state instead of silently ignoring KT settings.","triggerScenarios":"An inference/eval entry point (chat, api, eval) builds ModelArguments with kt_config settings applied (e.g. via a path that records the inference config) while the effective use_kt resolves to false, hitting the branch at the top of configure_kt_loading.","commonSituations":"Configs where use_kt was toggled off (or a template merged without it) but a leftover kt_config block still reaches inference argument handling.","solutions":["Set `use_kt: true` in the YAML that also defines `kt_config`.","Or fully remove the `kt_config` block if KTransformers is not intended for this inference run."],"exampleFix":"# before (yaml)\ninfer_backend: huggingface\nkt_config:\n  kt_model_max_length: 8192\n\n# after (yaml)\nuse_kt: true\ninfer_backend: huggingface\nkt_config:\n  kt_model_max_length: 8192","handlingStrategy":"validation","validationCode":"if cfg.get('kt_config') and not cfg.get('use_kt'):\n    raise SystemExit('kt_config requires use_kt: true')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep use_kt and kt_config in the same YAML include so they toggle together."],"tags":["ktransformers","config","llamafactory"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}