Skip to content

hf_transformer_utils

Utilities for Huggingface Transformers.

Functions

fastvideo.models.hf_transformer_utils.check_gguf_file

check_gguf_file(model: str | PathLike) -> bool

Check if the file is a GGUF model.

Source code in fastvideo/models/hf_transformer_utils.py
def check_gguf_file(model: str | os.PathLike) -> bool:
    """Check if the file is a GGUF model."""
    model = Path(model)
    if not model.is_file():
        return False
    elif model.suffix == ".gguf":
        return True

    with open(model, "rb") as f:
        header = f.read(4)
    return header == b"GGUF"

fastvideo.models.hf_transformer_utils.get_diffusers_config

get_diffusers_config(model: str) -> dict[str, Any]

Gets a configuration for the given diffusers model.

Parameters:

Name Type Description Default
model str

The model name or path.

required
fastvideo_args

Optional inference arguments to override in the config.

required

Returns:

Type Description
dict[str, Any]

The loaded configuration.

Source code in fastvideo/models/hf_transformer_utils.py
def get_diffusers_config(model: str, ) -> dict[str, Any]:
    """Gets a configuration for the given diffusers model.

    Args:
        model: The model name or path.
        fastvideo_args: Optional inference arguments to override in the config.

    Returns:
        The loaded configuration.
    """
    config_name = "config.json"
    if "scheduler" in model:
        config_name = "scheduler_config.json"
    # Check if the model path exists
    if os.path.exists(model):
        config_file = os.path.join(model, config_name)
        if os.path.exists(config_file):
            try:
                # Load the config directly from the file
                with open(config_file) as f:
                    config_dict: dict[str, Any] = json.load(f)
                if "_diffusers_version" in config_dict:
                    config_dict.pop("_diffusers_version")
                # TODO(will): apply any overrides from inference args
                return config_dict
            except Exception as e:
                raise RuntimeError(
                    f"Failed to load diffusers config from {config_file}: {e}"
                ) from e
        raise RuntimeError(f"Config file not found at {config_file}")
    else:
        raise RuntimeError(f"Diffusers config file not found at {model}")