Files
fn_registry/python/functions/ml/diffusers_load_pipeline.md
T
egutierrez e3c8979e8d chore: auto-commit (95 archivos)
- cmd/fn/doctor.go
- cmd/fn/main.go
- cpp/apps/primitives_gallery/playground/tables/CMakeLists.txt
- cpp/apps/primitives_gallery/playground/tables/data_table.cpp
- cpp/apps/primitives_gallery/playground/tables/data_table_logic.cpp
- cpp/apps/primitives_gallery/playground/tables/data_table_logic.h
- cpp/apps/primitives_gallery/playground/tables/self_test.cpp
- cpp/apps/primitives_gallery/playground/tables/tql.cpp
- cpp/apps/primitives_gallery/playground/tables/viz.cpp
- cpp/apps/primitives_gallery/playground/tables/viz.h
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 00:50:34 +02:00

2.2 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
diffusers_load_pipeline function py ml 1.0.0 impure def diffusers_load_pipeline(model: ModelRef, device: str = 'auto', dtype: str = 'fp16') -> Any Carga un pipeline diffusers (AutoPipelineForText2Image) con cache global por (model_key, dtype, device). Segunda llamada con mismos parametros retorna el objeto cacheado sin recargar disco.
diffusers
ml
image-generation
pipeline
cache
torch
torch_device_select_py_ml
model_ref_py_ml
false error_go_core
torch
diffusers
name desc
model Referencia al modelo. model.path si disponible (ruta local), model.name si no (HuggingFace Hub o nombre corto).
name desc
device Preferencia de device: 'auto' (CUDA>MPS>CPU), 'cuda', 'cuda:N', 'mps', 'cpu'. Default 'auto'.
name desc
dtype Precision del modelo: 'fp16' (torch.float16 + variant=fp16), 'bf16' (bfloat16), 'fp32' (float32). Default 'fp16'.
Pipeline diffusers cargado y movido al device. Callable via pipe(prompt=..., ...). Cacheado en _PIPELINE_CACHE. true
carga pipeline y retorna callable
segunda carga usa cache (< 100ms)
python/functions/ml/tests/test_diffusers_backend.py python/functions/ml/diffusers_load_pipeline.py

Ejemplo

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

model = ModelRef(
    name="sd-turbo",
    model_type="sd15",
    quantization="fp16",
    path="/home/lucas/vaults/imagegen_models/diffusers/sd-turbo",
)
pipe = diffusers_load_pipeline(model, device="cuda", dtype="fp16")
# Segunda llamada: cache hit, < 100ms
pipe2 = diffusers_load_pipeline(model, device="cuda", dtype="fp16")
assert pipe is pipe2

Notas

Cache global _PIPELINE_CACHE indexado por (model_key, dtype, resolved_device). model_key es model.path si no es None, sino model.name.

Para liberar memoria: usar diffusers_unload(pipe=None) que llama _clear_pipeline_cache().

Imports lazy de torch y diffusers dentro de la funcion — ImportError descriptivo si no instalados.