Repository: EvolvingLMMs-Lab/lmms-eval
Issue: VILA import error
Root cause: External Dependency Breakage

Catch import error ASAP with https://github.com/EvolvingLMMs-Lab/lmms-eval/pull/650#issue-3014538339

Error:

`Failed to import VILA from vila: VILA is not installed. Please install VILA to use this model. Error: cannot import name 'field_serializer' from 'pydantic'`

To reproduce the error:
1. Install VILA:
```python
def install_vila(in_folder: str = "third-party"):
    """
    Clone VILA into `in_folder`, append missing constants, and install.
    """
    append_block = """\
    # --------
    # NOTE: This is from the original LLaVA codebase:
    # https://github.com/haotian-liu/LLaVA/blob/main/llava/constants.py
    # --------
    IGNORE_INDEX = -100
    IMAGE_TOKEN_INDEX = -200
    DEFAULT_IMAGE_TOKEN = "<image>"
    DEFAULT_IMAGE_PATCH_TOKEN = "<im_patch>"
    DEFAULT_IM_START_TOKEN = "<im_start>"
    DEFAULT_IM_END_TOKEN = "<im_end>"
    # --------
    """

    repo_dir = os.path.join(in_folder, "VILA")
    target_file = os.path.join(repo_dir, "llava", "constants.py")

    # 1. Clone if needed
    if not os.path.isdir(repo_dir):
        subprocess.run(
            f"git clone https://github.com/NVlabs/VILA.git {repo_dir}",
            check=True,
            shell=True,
        )
    else:
        print(f"{repo_dir} already exists, skipping clone")

    # 2. Append constants if missing
    if os.path.isfile(target_file):
        with open(target_file, "r") as f:
            content = f.read()
        if "DEFAULT_IM_END_TOKEN" not in content:
            with open(target_file, "a") as f:
                f.write("\n" + append_block)
            print(f"Added constants to {target_file}")
        else:
            print(f"{target_file} already contains the constants")
    else:
        print(f"{target_file} not found, skipping append")

    # 3. Install the package
    subprocess.run("pip install uv && uv pip install .", cwd=repo_dir, check=True, shell=True)
    subprocess.run(
        "uv pip install s2wrapper@git+https://github.com/bfshi/scaling_on_scales",
        check=True,
        shell=True,
    )

```
2. CLI cmd:
```bash
CUDA_VISIBLE_DEVICES=0,1 python3 -m accelerate.commands.launch \
  --num_processes=2 \
  --mixed_precision=fp16 \
  -m lmms_eval \
  --model vila \
  --model_args pretrained=Efficient-Large-Model/VILA1.5-40b \
  --tasks mme \
  --batch_size 1 \
  --limit 10 \
  --log_samples \
  --output_path logs \
  --verbosity=DEBUG
```

Solved by:
```python
import subprocess

APPEND_BLOCK = """\
# --------
# NOTE: This is from the original LLaVA codebase:
# https://github.com/haotian-liu/LLaVA/blob/main/llava/constants.py
# --------
IGNORE_INDEX = -100
IMAGE_TOKEN_INDEX = -200
DEFAULT_IMAGE_TOKEN = "<image>"
DEFAULT_IMAGE_PATCH_TOKEN = "<im_patch>"
DEFAULT_IM_START_TOKEN = "<im_start>"
DEFAULT_IM_END_TOKEN = "<im_end>"
# --------
"""


def install_vila(in_folder: str = "third-party"):
    """
    Clone VILA into `in_folder`, append missing constants, and install.
    """

    repo_dir = os.path.join(in_folder, "VILA")
    target_file = os.path.join(repo_dir, "llava", "constants.py")

    # 1. Clone if needed
    if not os.path.isdir(repo_dir):
        subprocess.run(
            f"git clone https://github.com/NVlabs/VILA.git {repo_dir}",
            check=True,
            shell=True,
        )
    else:
        print(f"{repo_dir} already exists, skipping clone")

    # 2. Append constants if missing
    if os.path.isfile(target_file):
        with open(target_file, "r") as f:
            content = f.read()
        if "DEFAULT_IM_END_TOKEN" not in content:
            with open(target_file, "a") as f:
                f.write("\n" + APPEND_BLOCK)
            print(f"Added constants to {target_file}")
        else:
            print(f"{target_file} already contains the constants")
    else:
        print(f"{target_file} not found, skipping append")

    # 3. Install the package
    subprocess.run(
        "pip install uv && uv pip install .", cwd=repo_dir, check=True, shell=True
    )
    subprocess.run(
        "uv pip install s2wrapper@git+https://github.com/bfshi/scaling_on_scales",
        check=True,
        shell=True,
    )
    subprocess.run("uv pip install pydantic==2.11.3", check=True, shell=True)

# Install VILA and solve package conflicts
install_vila()
```