{"record":{"id":"79a8ab25312d741f","repo":"hiyouga/LlamaFactory","slug":"kt-model-max-length-must-be-a-positive-integer","errorCode":null,"errorMessage":"`kt_model_max_length` must be a positive integer.","messagePattern":"`kt_model_max_length` must be a positive integer\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/hparams/model_args.py","lineNumber":620,"sourceCode":"        training_args.gradient_checkpointing_kwargs = None\n\n    def get_kt_config_dict(\n        self,\n        finetuning_args: Any,\n        model_max_length: int | None,\n        advanced_config: dict[str, Any] | None = None,\n    ) -> dict[str, Any]:\n        r\"\"\"Map LLaMA-Factory-owned training values to the public KT configuration.\"\"\"\n        if getattr(finetuning_args, \"finetuning_type\", None) != \"lora\":\n            raise ValueError(\"KTransformers thin integration currently supports LoRA finetuning only.\")\n\n        kt_config = dict(advanced_config or {})\n        configured_capacity = kt_config.pop(\"kt_model_max_length\", None)\n        if configured_capacity is not None:\n            try:\n                configured_capacity = int(configured_capacity)\n            except (TypeError, ValueError) as exc:\n                raise ValueError(\"`kt_model_max_length` must be a positive integer.\") from exc\n            if configured_capacity <= 0:\n                raise ValueError(\"`kt_model_max_length` must be a positive integer.\")\n\n        kt_config.update(\n            {\n                \"kt_lora_rank\": getattr(finetuning_args, \"lora_rank\", None),\n                \"kt_lora_alpha\": getattr(finetuning_args, \"lora_alpha\", None),\n                \"kt_lora_dropout\": getattr(finetuning_args, \"lora_dropout\", None),\n                \"kt_weight_path\": self.kt_weight_path,\n                \"kt_non_expert_weight_path\": self.kt_non_expert_weight_path,\n                \"kt_expert_checkpoint_path\": self.kt_expert_checkpoint_path,\n                \"kt_model_max_length\": max(model_max_length or 0, configured_capacity or 0) or None,\n                \"kt_use_lora_experts\": self.kt_use_lora_experts,\n                \"kt_lora_expert_num\": self.kt_lora_expert_num,\n                \"kt_lora_expert_intermediate_size\": self.kt_lora_expert_intermediate_size,\n                \"kt_activation_policy\": self.get_kt_activation_policy(),\n                \"kt_train_mode\": \"lora\",\n                \"kt_full_weight_grad\": False,","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/hparams/model_args.py#L602-L638","documentation":"Raised by get_kt_config_dict when the user-supplied kt_config.kt_model_max_length cannot be converted to int (TypeError/ValueError, e.g. a string like 'long' or a nested dict). kt_model_max_length is the token-capacity hint KT uses to size CPU expert buffers, so it must be a clean positive integer.","triggerScenarios":"Passing kt_config: {kt_model_max_length: abc} or a float-string/non-numeric value in the YAML; int() conversion inside the try block raises and is re-raised as this ValueError.","commonSituations":"YAML typos, unquoted placeholder values, or copy-pasting 'kt_model_max_length: 8k'-style shorthand from notes into the config.","solutions":["Set `kt_model_max_length` to a plain positive integer, e.g. 8192, inside `kt_config`.","Remove the key entirely to let LLaMA-Factory derive capacity from `cutoff_len` and batch size."],"exampleFix":"# before (yaml)\nkt_config:\n  kt_model_max_length: 8k\n\n# after (yaml)\nkt_config:\n  kt_model_max_length: 8192","handlingStrategy":"validation","validationCode":"v = (cfg.get('kt_config') or {}).get('kt_model_max_length')\nif v is not None and (not isinstance(v, int) or isinstance(v, bool) or v <= 0):\n    raise SystemExit('kt_model_max_length must be a positive integer')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep numeric YAML values unquoted and unprefixed.","Prefer omitting derived capacity keys unless KT requires a specific buffer size."],"tags":["ktransformers","config","validation","llamafactory"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}