hiyouga/LlamaFactory · error · ValueError

Put KTransformers settings in the LLaMA-Factory training YAM

Error message

Put KTransformers settings in the LLaMA-Factory training YAML `kt_config`; remove `kt_config` from the Accelerate config.

What it means

Raised by _get_advanced_kt_config (model_args.py:571) when kt_config is absent from the LlamaFactory training YAML but present under accelerator_config.kt_config in the Accelerate config file. LlamaFactory wants a single source of truth for KTransformers settings, so defining them only in the Accelerate launcher config is rejected with instructions on where to put them.

Source

Thrown at src/llamafactory/hparams/model_args.py:571

    def _normalize_advanced_kt_config(self, raw_config: Any) -> dict[str, Any]:
        if raw_config is None:
            return {}
        if not isinstance(raw_config, dict):
            raise TypeError("LLaMA-Factory `kt_config` must be a flat mapping.")

        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:

View on GitHub (pinned to f28afaf635)

Solutions

  1. Move the kt_config block from the Accelerate config into the LlamaFactory training YAML under a top-level kt_config key
  2. Delete accelerator_config.kt_config from the Accelerate YAML
  3. Re-run; if both files now define identical kt_config it is accepted (see error 158 for the not-equal case)

Example fix

# before (accelerate_config.yaml)
accelerator_config:
  kt_config:
    gen_config: {temperature: 0.7}

# after (train.yaml)
kt_config:
  gen_config:
    temperature: 0.7
# accelerate config: kt_config block removed
Defensive patterns

Strategy: validation

Validate before calling

acc = yaml.safe_load(open('accelerate_config.yaml'))
assert 'kt_config' not in (acc.get('accelerator_config') or {}), 'move kt_config to the LF training YAML'

Type guard

def accelerate_has_kt_config(acc_cfg: dict) -> bool:
    return 'kt_config' in (acc_cfg.get('accelerator_config') or {})

Prevention

When it happens

Trigger: Running accelerate launch with an Accelerate YAML that includes a kt_config: {...} block under accelerator_config, while the training YAML has no kt_config; following an older tutorial that put KT settings in the Accelerate file.

Common situations: Migrating setups from when Accelerate-side kt_config was tolerated; team shared Accelerate configs accumulating feature blocks; users pasting the KT block into the wrong YAML.

Related errors


AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14). Data as JSON: /api/errors/4187d47adabb6a12. Report an issue: GitHub.