Files
fn_registry/python/functions/ml/sdcpp_python_load.md
T
egutierrez 8284afcba5 feat(ml): auto-commit con 14 cambios
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 01:22:02 +02:00

2.5 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports params output tested tests test_file_path file_path
sdcpp_python_load function py ml 1.0.0 impure def sdcpp_python_load(model: ModelRef, n_threads: int = -1, wtype: str = 'default', rng_type: str = 'cuda') -> Any Carga un StableDiffusion via stable-diffusion-cpp-python con cache global por (model_key, wtype, n_threads). Segunda llamada con mismos params retorna instancia cacheada sin recargar disco.
ml
stable-diffusion
sdcpp
inference
backend
cache
load
model_ref_py_ml
false error_go_core
stable_diffusion_cpp
name desc
model Referencia al modelo. model.path se usa si presente; si no, model.name como ruta local o HuggingFace hub.
name desc
n_threads Numero de hilos CPU para inferencia. -1 usa todos los disponibles.
name desc
wtype Tipo de pesos en memoria: 'default' | 'f32' | 'f16' | 'q8_0' | 'q5_1' | 'q5_0' | 'q4_1' | 'q4_0'. 'default' respeta el tipo original del checkpoint.
name desc
rng_type Generador de aleatorios: 'std_default' | 'cuda'. 'cuda' produce resultados compatibles con la implementacion CUDA incluso en CPU.
Instancia StableDiffusion (stable_diffusion_cpp.StableDiffusion) lista para llamar a generate_image(). true
load retorna objeto StableDiffusion
segunda llamada retorna instancia cacheada
python/functions/ml/tests/test_sdcpp_python_backend.py python/functions/ml/sdcpp_python_load.py

Ejemplo

import sys
sys.path.insert(0, "python/functions/ml")
from model_ref import ModelRef
from sdcpp_python_load import sdcpp_python_load

model = ModelRef(
    name="sd-turbo",
    model_type="sd15",
    quantization="fp16",
    path="/home/lucas/vaults/imagegen_models/diffusers/sd-turbo/sd_turbo.safetensors",
)
sd = sdcpp_python_load(model, n_threads=-1, wtype="default")
# sd listo para sd.generate_image(...)

Notas

  • El cache evita recargas de disco en bucles de generacion con el mismo modelo.
  • wtype="default" respeta el tipo de cuantizacion del checkpoint; util para safetensors mixtos.
  • rng_type="cuda" produce seeds compatibles con la implementacion GPU aunque se corra en CPU.
  • Para limpiar el cache en tests: sdcpp_python_load._clear_sd_cache().
  • Compilacion sin CUDA: CMAKE_ARGS="-DSD_CUDA=OFF" pip install stable-diffusion-cpp-python.
  • El binding 0.4.7 usa generate_image() (no txt_to_img que era la API de versiones anteriores).