hiyouga/LlamaFactory · error · ValueError

Please upgrade `transformers` to 4.34.0

Error message

Please upgrade `transformers` to 4.34.0

What it means

During config patching, LlamaFactory inspects config.architectures and rejects checkpoints whose architecture list contains InternVLChatModel (patcher.py:404). The original OpenGVLab InternVL releases ship a custom InternVLChatModel implementation that is incompatible with LlamaFactory's transformers-based training/inference path, so it demands a checkpoint converted to the HF-native InternVLForCausalLM format.

Source

Thrown at scripts/convert_ckpt/llamafy_qwen.py:33

import json
import os
from collections import OrderedDict
from typing import Any

import fire
import torch
from huggingface_hub import split_torch_state_dict_into_shards
from safetensors import safe_open
from safetensors.torch import save_file
from tqdm import tqdm
from transformers.modeling_utils import SAFE_WEIGHTS_INDEX_NAME, SAFE_WEIGHTS_NAME, WEIGHTS_INDEX_NAME, WEIGHTS_NAME
from transformers.utils import check_min_version


try:
    check_min_version("4.34.0")
except Exception:
    raise ValueError("Please upgrade `transformers` to 4.34.0")


CONFIG_NAME = "config.json"


def save_weight(input_dir: str, output_dir: str, shard_size: str, save_safetensors: bool) -> str:
    qwen_state_dict: dict[str, torch.Tensor] = OrderedDict()
    for filepath in tqdm(os.listdir(input_dir), desc="Load weights"):
        if os.path.isfile(os.path.join(input_dir, filepath)) and filepath.endswith(".safetensors"):
            with safe_open(os.path.join(input_dir, filepath), framework="pt", device="cpu") as f:
                for key in f.keys():
                    qwen_state_dict[key] = f.get_tensor(key)

    llama_state_dict: dict[str, torch.Tensor] = OrderedDict()
    torch_dtype = None
    for key, value in tqdm(qwen_state_dict.items(), desc="Convert format"):
        if torch_dtype is None:
            torch_dtype = value.dtype

View on GitHub (pinned to f28afaf635)

Solutions

  1. Use an HF-converted checkpoint, e.g. model_name_or_path: OpenGVLab/InternVL3-8B-hf (any *-hf InternVL repo)
  2. If you must keep the original weights, convert the checkpoint to HF format (transformers conversion scripts) before training

Example fix

# before
model_name_or_path: OpenGVLab/InternVL3-8B  # legacy InternVLChatModel format

# after
model_name_or_path: OpenGVLab/InternVL3-8B-hf
Defensive patterns

Strategy: validation

Validate before calling

from transformers import AutoConfig
cfg = AutoConfig.from_pretrained(model_path, trust_remote_code=False)
arch = getattr(cfg, 'architectures', []) or []
assert 'InternVLChatModel' not in arch, 'Use an HF-format InternVL checkpoint, e.g. OpenGVLab/InternVL3-8B-hf'

Type guard

def is_hf_internvl(model_name_or_path: str) -> bool:
    cfg = AutoConfig.from_pretrained(model_name_or_path, trust_remote_code=False)
    archs = getattr(cfg, 'architectures', None) or []
    return 'InternVLChatModel' not in archs and any('InternVL' in a for a in archs)

Try / catch

try:
    run_sft(train_args)
except ValueError as e:
    if 'InternVL' in str(e):
        raise SystemExit('Switch to an -hf InternVL checkpoint (OpenGVLab/InternVL3-8B-hf)') from e
    raise

Prevention

When it happens

Trigger: model_name_or_path points at a raw OpenGVLab release such as OpenGVLab/InternVL3-8B or a local copy of it; AutoConfig reports architectures containing 'InternVLChatModel' and _check_audio_module / config patching raises ValueError before any weights load.

Common situations: Downloading the original model card checkpoint instead of the '-hf' variant; fine-tuning a third-party InternVL finetune that was published in the legacy format; pointing at an old local InternVL2/InternVL checkpoint directory.

Related errors


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