hiyouga/LlamaFactory · critical · RuntimeError

The installed Transformers-KT does not provide `TrainingArgu

Error message

The installed Transformers-KT does not provide `TrainingArguments.update_kt_config()`.

What it means

Raised by apply_kt_config when the installed transformers(-kt) build does not expose a callable TrainingArguments.update_kt_config. LLaMA-Factory's thin KT integration delegates the final config push to that Transformers-side hook, so a stock or outdated transformers install makes the contract unfulfillable.

Source

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

                raise ValueError("`adapter_folder` must stay inside the KT adapter directory.")
        if not os.path.isdir(adapter_dir):
            raise ValueError(f"KTransformers {operation} requires a local adapter directory.")
        return adapter_dir

    def apply_kt_config(self, finetuning_args: Any, training_args: Any, model_max_length: int | None) -> None:
        r"""Apply LLaMA-Factory KT args to transformers/accelerate KT integration points."""
        if not self.use_kt:
            return

        self.configure_kt_checkpointing(training_args)
        kt_config = self.get_kt_config_dict(
            finetuning_args,
            model_max_length,
            self._get_advanced_kt_config(training_args),
        )
        update_kt_config = getattr(training_args, "update_kt_config", None)
        if not callable(update_kt_config):
            raise RuntimeError(
                "The installed Transformers-KT does not provide `TrainingArguments.update_kt_config()`."
            )

        adapter_dir = self._resolve_kt_adapter_artifact_dir("training")
        update_kt_config(kt_config, adapter_name_or_path=adapter_dir)

    def configure_kt_loading(self, finetuning_args: Any, model_max_length: int | None) -> None:
        r"""Configure KT model loading for inference and evaluation."""
        if not self.use_kt:
            if self._kt_inference_config is not None:
                raise ValueError("`kt_config` requires `use_kt: true`.")
            return
        if self.infer_backend != EngineName.HF:
            raise ValueError("KTransformers inference requires `infer_backend: huggingface`.")

        adapter_dir = self._resolve_kt_adapter_artifact_dir("inference")

        try:

View on GitHub (pinned to f28afaf635)

Solutions

  1. Install/upgrade the KT-enabled Transformers fork: `pip install -U transformers-kt` (as required by _check_extra_dependencies).
  2. Verify the hook: `python -c "from transformers import TrainingArguments; print(callable(getattr(TrainingArguments, 'update_kt_config', None)))"`.
  3. Check for a shadowing stock transformers earlier on sys.path (`pip show transformers transformers-kt`).

Example fix

# before (bash)
pip install llamafactory  # stock transformers retained
llamafactory-cli train kt.yaml  # RuntimeError

# after (bash)
pip install -U transformers-kt accelerate-kt kt-kernel
llamafactory-cli train kt.yaml
Defensive patterns

Strategy: validation

Validate before calling

from transformers import TrainingArguments
if not callable(getattr(TrainingArguments, 'update_kt_config', None)):
    raise SystemExit('install transformers-kt: pip install -U transformers-kt')

Try / catch

try:
    model_args.apply_kt_config(ft_args, tr_args, cutoff_len)
except RuntimeError as e:
    if 'update_kt_config' in str(e):
        raise SystemExit('KT stack missing; pip install -U transformers-kt accelerate-kt kt-kernel') from e
    raise

Prevention

When it happens

Trigger: use_kt: true with a plain `transformers` package (no KT fork) installed, or a transformers-kt version predating update_kt_config; getattr on training_args returns None and the RuntimeError fires at startup.

Common situations: Environments where LLaMA-Factory was upgraded to the KT-supporting version but the transformers-kt dependency was pinned, skipped, or shadowed by a stock transformers in the venv.

Related errors


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