Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

1.8 KB
Raw Blame
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

"""Pure torch-free per-family steady footprint (transformer * factor + companions) for info endpoint."""

from __future__ import annotations

from typing import Any

from .diffusion_auto_policy import _FAMILY_BF16_GB, _QUANT_STEADY_FACTOR, policy_steady_factor
from .diffusion_families import _FAMILIES
from .diffusion_nvfp4_flag import nvfp4_blocked


def _round1(value: float) -> float:
    return round(value, 1)


def _family_base_repos() -> dict[str, str]:
    return {fam.name.strip().lower(): fam.base_repo for fam in _FAMILIES}


def family_inference_infos() -> list[dict[str, Any]]:
    """Per-family estimated resident GB under bf16 and each quant scheme, scaling only the transformer."""
    infos: list[dict[str, Any]] = []
    bases = _family_base_repos()
    for name, (transformer_gb, text_encoders_gb, vae_gb) in _FAMILY_BF16_GB.items():
        companions_gb = text_encoders_gb + vae_gb
        estimated = {"bf16": _round1(transformer_gb + companions_gb)}
        policy_factor = policy_steady_factor(name, bases.get(name.strip().lower()))
        for scheme, factor in _QUANT_STEADY_FACTOR.items():
            if nvfp4_blocked(scheme):
                continue
            if scheme == "nvfp4" and policy_factor is not None:
                factor = policy_factor
            estimated[scheme] = _round1(transformer_gb * factor + companions_gb)
        infos.append(
            {
                "family": name,
                "transformer_bf16_gb": _round1(transformer_gb),
                "text_encoders_bf16_gb": _round1(text_encoders_gb),
                "vae_bf16_gb": _round1(vae_gb),
                "estimated_resident_gb": estimated,
            }
        )
    return infos