47fac22230
- .claude/CLAUDE.md - .claude/commands/subagentes.md - .claude/rules/INDEX.md - .mcp.json - bash/functions/cybersecurity/analyze_dns.md - bash/functions/cybersecurity/audit_http_headers.md - bash/functions/cybersecurity/audit_ssh_config.md - bash/functions/cybersecurity/check_firewall.md - bash/functions/cybersecurity/detect_suspicious_users.md - bash/functions/cybersecurity/encrypt_file.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
50 lines
1.7 KiB
Markdown
50 lines
1.7 KiB
Markdown
---
|
|
name: diffusers_unload
|
|
kind: function
|
|
lang: py
|
|
domain: ml
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "def diffusers_unload(pipe: Any | None = None) -> None"
|
|
description: "Libera la memoria de un pipeline diffusers. Si pipe=None limpia el cache global de diffusers_load_pipeline. Siempre llama gc.collect() y torch.cuda.empty_cache()."
|
|
tags: [diffusers, ml, memory, cleanup, vram, cache, pendiente-usar]
|
|
uses_functions: []
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: [torch, gc]
|
|
params:
|
|
- name: pipe
|
|
desc: "Pipeline a liberar con del. Si None, limpia el cache global _PIPELINE_CACHE de diffusers_load_pipeline (descarga todos los pipelines cacheados)."
|
|
output: "None. Efecto secundario: del pipe si pasado, cache limpiado si None, gc.collect() y torch.cuda.empty_cache() siempre."
|
|
tested: true
|
|
tests:
|
|
- "unload None limpia cache cuda si disponible"
|
|
test_file_path: "python/functions/ml/tests/test_diffusers_backend.py"
|
|
file_path: "python/functions/ml/diffusers_unload.py"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```python
|
|
from diffusers_unload import diffusers_unload
|
|
|
|
# Liberar un pipeline especifico
|
|
diffusers_unload(pipe)
|
|
|
|
# Limpiar TODO el cache (descarga todos los modelos en memoria)
|
|
diffusers_unload()
|
|
```
|
|
|
|
## Notas
|
|
|
|
`del pipe` no garantiza liberacion inmediata si hay otras referencias al objeto.
|
|
Llamar `diffusers_unload(pipe)` + borrar la referencia local (`pipe = None`)
|
|
para asegurar que el GC pueda recolectar.
|
|
|
|
`torch.cuda.empty_cache()` solo libera cache del allocator de PyTorch, no
|
|
memoria que otros procesos ocupen. Para liberacion total, el proceso debe terminar.
|
|
|
|
Import lazy de torch — si no esta instalado, omite empty_cache silenciosamente.
|