---
name: model_ref
lang: py
domain: ml
version: "1.0.0"
algebraic: product
definition: |
  class ModelRef(BaseModel):
      name: str
      model_type: Literal["sd15","sd20","sdxl","sd3","flux_dev","flux_schnell","flux_kontext","qwen_image","chroma","z_image"]
      quantization: Literal["fp32","fp16","bf16","q8_0","q5_1","q5_0","q4_1","q4_0"] = "fp16"
      path: str | None = None
description: "Referencia a un modelo de generacion de imagenes. Identifica arquitectura, cuantizacion y ruta local opcional. Serializable a JSON canonico para contrato compartido con Go."
tags: [ml, diffusion, model, stable-diffusion, flux, quantization, huggingface]
uses_types: []
file_path: "python/functions/ml/model_ref.py"
---

## Notas

Tipo producto inmutable (`frozen=True` en pydantic). Fallback a `dataclass(frozen=True)` si pydantic no esta instalado.

`model_type` es un tipo suma embebido que cubre las arquitecturas mas comunes:

| Valor         | Arquitectura                        |
|---------------|-------------------------------------|
| sd15          | Stable Diffusion 1.5                |
| sd20          | Stable Diffusion 2.0/2.1            |
| sdxl          | Stable Diffusion XL                 |
| sd3           | Stable Diffusion 3                  |
| flux_dev      | FLUX.1-dev                          |
| flux_schnell  | FLUX.1-schnell                      |
| flux_kontext  | FLUX.1-Kontext                      |
| qwen_image    | Qwen2-VL / Qwen2.5-VL con imagen    |
| chroma        | Chroma (variante flux controlada)   |
| z_image       | Z-Image (pipeline experimental)     |

`quantization` controla el formato del checkpoint: fp32/fp16/bf16 para pesos flotantes, q4_0-q8_0 para formatos GGUF (stable-diffusion.cpp).
