hiyouga/LlamaFactory · error · ValueError
LLaMA-Factory YAML and Accelerate config cannot define diffe
Error message
LLaMA-Factory YAML and Accelerate config cannot define different KT settings.
What it means
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.
Source
Thrown at src/llamafactory/hparams/model_args.py:577
config = dict(raw_config)
conflicts = sorted(set(config) & self._KT_DERIVED_KEYS)
if conflicts:
raise ValueError(f"These `kt_config` values are derived from LLaMA-Factory arguments: {conflicts}.")
return config
def _get_advanced_kt_config(self, training_args: Any) -> dict[str, Any]:
raw_config = getattr(training_args, "kt_config", None)
accelerator_config = self._get_accelerator_kt_config(training_args)
if raw_config is None:
if accelerator_config is not None:
raise ValueError(
"Put KTransformers settings in the LLaMA-Factory training YAML `kt_config`; "
"remove `kt_config` from the Accelerate config."
)
return {}
if accelerator_config is not None and accelerator_config != raw_config:
raise ValueError("LLaMA-Factory YAML and Accelerate config cannot define different KT settings.")
return self._normalize_advanced_kt_config(raw_config)
def configure_kt_checkpointing(self, training_args: Any) -> None:
r"""Keep LLaMA-Factory as the single gradient-checkpointing entry point."""
if self.use_unsloth or self.use_unsloth_gc:
raise ValueError("KTransformers cannot be combined with Unsloth checkpoint wrapping.")
if getattr(training_args, "gradient_checkpointing", False):
raise ValueError(
"KTransformers uses LLaMA-Factory's `disable_gradient_checkpointing`; "
"remove `gradient_checkpointing: true`."
)
if getattr(training_args, "gradient_checkpointing_kwargs", None) is not None:
raise ValueError("KTransformers supplies its checkpoint context; remove `gradient_checkpointing_kwargs`.")
fsdp_config = getattr(training_args, "fsdp_config", None)
if isinstance(fsdp_config, dict) and fsdp_config.get("activation_checkpointing"):
raise ValueError("Disable FSDP activation checkpointing when using KTransformers.")
if os.environ.get("FSDP_ACTIVATION_CHECKPOINTING", "false").lower() in {"1", "true", "yes"}:View on GitHub (pinned to f28afaf635)
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
Example fix
# before
# accelerate.yaml: kt_config: {gen_config: {temperature: 0.9}}
# train.yaml: kt_config: {gen_config: {temperature: 0.7}}
# after
# accelerate.yaml: (kt_config removed)
# train.yaml:
kt_config:
gen_config:
temperature: 0.7 Defensive patterns
Strategy: validation
Validate before calling
lf_kt = cfg.get('kt_config')
acc_kt = (yaml.safe_load(open('accelerate_config.yaml')).get('accelerator_config') or {}).get('kt_config')
assert not (acc_kt is not None and lf_kt is not None and acc_kt != lf_kt), 'kt_config defined twice and differs' Type guard
def kt_sources_agree(lf: dict | None, acc: dict | None) -> bool:
return lf is None or acc is None or lf == acc Prevention
- Maintain kt_config in exactly one file (the training YAML)
- If you must keep both, generate one from the other in CI
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- Put KTransformers settings in the LLaMA-Factory training YAM
- These `kt_config` values are derived from LLaMA-Factory argu
- `kt_cpu_activation` must be `retain` or `recompute`.
- `kt_cpu_activation` is only valid when `use_kt: true`.
- `kt_cpu_activation: recompute` requires GPU gradient checkpo
AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14).
Data as JSON: /api/errors/21ff2af0ded7d1f5.
Report an issue: GitHub.