chore: sync from fn-registry agent

This commit is contained in:
fn-registry agent
2026-05-13 00:50:31 +02:00
commit 7d5d4fb394
17 changed files with 5241 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
# JUPYTER HABILITADO EN ESTE ANALISIS
## Reglas OBLIGATORIAS para Claude
### 1. CODIGO INMUTABLE — NUNCA MODIFICAR CELDAS EXISTENTES
- **PROHIBIDO** usar NotebookEdit para reemplazar celdas existentes
- **SIEMPRE** anadir celdas NUEVAS al final del notebook
- Si hay un error en una celda, crear celda nueva con la correccion
- El historial de trabajo debe quedar intacto para trazabilidad
### 2. PROGRAMACION FUNCIONAL OBLIGATORIA
- **Funciones puras**: sin efectos secundarios, mismo input -> mismo output
- **Inmutabilidad**: nunca mutar datos, crear copias transformadas
- **Composicion**: funciones pequenas que se combinan
- Preferir: `map`, `filter`, `reduce`, list comprehensions
- Evitar: loops con mutacion, `global`, modificar argumentos in-place
### 3. SIEMPRE usar MCP jupyter para ejecutar codigo Python
- Las ejecuciones se ven en tiempo real en Jupyter Lab del usuario
- Compartimos variables y estado del kernel
- **NUNCA usar bash para ejecutar Python en este analisis**
### 4. Verificar Jupyter activo ANTES de ejecutar
- Si no esta activo: pedir al usuario que ejecute `./run-jupyter-lab.sh`
### 5. Gestion de notebooks
- Notebooks en la carpeta `notebooks/` o subcarpetas
- Si un notebook tiene >50 celdas, crear uno nuevo
- Nombrar descriptivamente: `01_exploracion.ipynb`, `02_limpieza.ipynb`
### 6. Gestion de Python
- **SIEMPRE usar `uv`** para gestionar dependencias
- Anadir paquetes con `uv add nombre_paquete`
### 7. Acceso al fn_registry
- `FN_REGISTRY_ROOT` apunta a la raiz del registry
- Para importar funciones Python: `sys.path.insert(0, os.path.join(os.environ["FN_REGISTRY_ROOT"], "python", "functions"))`
- Para consultar registry.db: `sqlite3` o `import sqlite3` con la ruta `$FN_REGISTRY_ROOT/registry.db`
Binary file not shown.
@@ -0,0 +1,100 @@
"""
fn_registry kernel startup
Autoconfigura acceso al registry en cada notebook.
Generado por write_jupyter_registry_kernel (fn_registry).
"""
import os
import sys
import sqlite3
from pathlib import Path
# ── FN_REGISTRY_ROOT ────────────────────────────────────────
# Prioridad: env var > path hardcoded > descubrimiento automatico
def _discover_registry_root():
if os.environ.get("FN_REGISTRY_ROOT"):
return Path(os.environ["FN_REGISTRY_ROOT"]).resolve()
hardcoded = Path("/home/lucas/fn_registry")
if (hardcoded / "registry.db").exists():
return hardcoded
# Subir desde CWD hasta encontrar registry.db
p = Path.cwd()
for _ in range(10):
if (p / "registry.db").exists():
return p
if p.parent == p:
break
p = p.parent
return hardcoded
FN_REGISTRY_ROOT = _discover_registry_root()
os.environ["FN_REGISTRY_ROOT"] = str(FN_REGISTRY_ROOT)
# ── sys.path: importar funciones Python del registry ────────
_python_functions = FN_REGISTRY_ROOT / "python" / "functions"
for _domain in sorted(_python_functions.iterdir()) if _python_functions.exists() else []:
if _domain.is_dir() and not _domain.name.startswith("_"):
_path = str(_domain)
if _path not in sys.path:
sys.path.insert(0, _path)
# Tambien el directorio padre para imports por dominio: from core import filter_list
_pf = str(_python_functions)
if _pf not in sys.path:
sys.path.insert(0, _pf)
# ── fn_query: consultar registry.db desde el notebook ───────
_REGISTRY_DB = FN_REGISTRY_ROOT / "registry.db"
def fn_query(sql, params=()):
"""Ejecuta una consulta SQL sobre registry.db y retorna las filas.
Ejemplos:
fn_query("SELECT id, description FROM functions WHERE domain = ?", ("finance",))
fn_query("SELECT id FROM functions_fts WHERE functions_fts MATCH ?", ("slice*",))
"""
if not _REGISTRY_DB.exists():
raise FileNotFoundError(f"registry.db no encontrado en {_REGISTRY_DB}")
con = sqlite3.connect(str(_REGISTRY_DB))
con.row_factory = sqlite3.Row
try:
rows = con.execute(sql, params).fetchall()
return [dict(r) for r in rows]
finally:
con.close()
def fn_search(term):
"""Busca funciones y tipos en el registry por nombre o descripcion.
Ejemplo:
fn_search("slice")
fn_search("finance")
"""
fts_term = f"name:{term}* OR description:{term}*"
functions = fn_query(
"SELECT id, kind, purity, lang, description FROM functions "
"WHERE id IN (SELECT id FROM functions_fts WHERE functions_fts MATCH ?) "
"ORDER BY name", (fts_term,)
)
types = fn_query(
"SELECT id, algebraic, lang, description FROM types "
"WHERE id IN (SELECT id FROM types_fts WHERE types_fts MATCH ?) "
"ORDER BY name", (fts_term,)
)
return {"functions": functions, "types": types}
def fn_code(function_id):
"""Retorna el codigo fuente de una funcion del registry.
Ejemplo:
print(fn_code("filter_list_py_core"))
"""
rows = fn_query("SELECT code FROM functions WHERE id = ?", (function_id,))
if not rows:
raise KeyError(f"Funcion no encontrada: {function_id}")
return rows[0]["code"]
# ── Mensaje de bienvenida ───────────────────────────────────
print(f"fn_registry conectado: {FN_REGISTRY_ROOT}")
print(f" registry.db: {'OK' if _REGISTRY_DB.exists() else 'NO ENCONTRADO'}")
print(f" Python functions: {_pf}")
print(f" Helpers: fn_query(), fn_search(), fn_code()")
+1
View File
@@ -0,0 +1 @@
8888
+7
View File
@@ -0,0 +1,7 @@
{
"126a9dee-916b-4ca8-bd9a-dd6ebd9382d3": {
"version": "2.4.0",
"created_at": "2026-05-12T21:54:36.754629+00:00",
"document_version": "2.0.0"
}
}
Binary file not shown.
+12
View File
@@ -0,0 +1,12 @@
{
"mcpServers": {
"jupyter": {
"command": "/home/lucas/fn_registry/projects/imagegen/analysis/spike_diffusers_vs_sdcpp/.venv/bin/python",
"args": ["-m", "jupyter_mcp_server.server"],
"env": {
"SERVER_URL": "http://localhost:8888",
"TOKEN": ""
}
}
}
}
+1
View File
@@ -0,0 +1 @@
3.13
View File
+17
View File
@@ -0,0 +1,17 @@
---
name: spike_diffusers_vs_sdcpp
lang: py
domain: datascience
description: "Spike Fase 0: validar contrato GenerationConfig en SD Turbo via diffusers vs stable-diffusion.cpp"
tags: [ml, imagegen, spike]
uses_functions: []
uses_types: []
framework: "jupyterlab"
entry_point: "notebooks/main.ipynb"
dir_path: "projects/imagegen/analysis/spike_diffusers_vs_sdcpp"
repo_url: ""
---
## Notas
Spike Fase 0: validar contrato GenerationConfig en SD Turbo via diffusers vs stable-diffusion.cpp
+279
View File
@@ -0,0 +1,279 @@
════════════════════════════════════════════════
Jupyter Lab + Colaboracion en puerto 8888
════════════════════════════════════════════════
Abre: http://localhost:8888
Ctrl+C para detener
[W 2026-05-12 23:48:57.001 ServerApp] ServerApp.token config is deprecated in 2.0. Use IdentityProvider.token.
[I 2026-05-12 23:48:57.853 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2026-05-12 23:48:57.857 ServerApp] jupyter_mcp_server | extension was successfully linked.
[I 2026-05-12 23:48:57.857 ServerApp] jupyter_mcp_tools | extension was successfully linked.
[I 2026-05-12 23:48:57.859 ServerApp] jupyter_server_fileid | extension was successfully linked.
[I 2026-05-12 23:48:57.861 ServerApp] jupyter_server_nbmodel | extension was successfully linked.
[I 2026-05-12 23:48:57.866 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2026-05-12 23:48:57.869 ServerApp] jupyter_server_ydoc | extension was successfully linked.
[I 2026-05-12 23:48:57.872 ServerApp] jupyterlab | extension was successfully linked.
[I 2026-05-12 23:48:57.875 ServerApp] notebook | extension was successfully linked.
[I 2026-05-12 23:48:57.884 ServerApp] notebook_shim | extension was successfully linked.
[W 2026-05-12 23:48:57.916 ServerApp] All authentication is disabled. Anyone who can connect to this server will be able to run code.
[I 2026-05-12 23:48:57.916 ServerApp] notebook_shim | extension was successfully loaded.
[I 2026-05-12 23:48:57.919 ServerApp] jupyter_lsp | extension was successfully loaded.
[05/12/26 23:48:58] INFO Auto-enrolled document extension.py:195
'notebook.ipynb' as 'default'
INFO Jupyter MCP Server Extension extension.py:197
settings initialized
INFO Registered MCP handlers at /mcp/ extension.py:233
INFO - MCP protocol: /mcp (SSE-based) extension.py:234
INFO - Health check: /mcp/healthz extension.py:235
INFO - List tools: /mcp/tools/list extension.py:236
INFO - Call tool: /mcp/tools/call extension.py:237
[I 2026-05-12 23:48:58.339 ServerApp] jupyter_mcp_server | extension was successfully loaded.
[I 2026-05-12 23:48:58.340 ServerApp] Registered jupyter_mcp_tools server extension
[I 2026-05-12 23:48:58.340 ServerApp] jupyter_mcp_tools | extension was successfully loaded.
[I 2026-05-12 23:48:58.340 FileIdExtension] Configured File ID manager: ArbitraryFileIdManager
[I 2026-05-12 23:48:58.340 FileIdExtension] ArbitraryFileIdManager : Configured root dir: /home/lucas/fn_registry/projects/imagegen/analysis/spike_diffusers_vs_sdcpp
[I 2026-05-12 23:48:58.340 FileIdExtension] ArbitraryFileIdManager : Configured database path: /home/lucas/.local/share/jupyter/file_id_manager.db
[I 2026-05-12 23:48:58.341 FileIdExtension] ArbitraryFileIdManager : Successfully connected to database file.
[I 2026-05-12 23:48:58.341 FileIdExtension] ArbitraryFileIdManager : Creating File ID tables and indices with journal_mode = DELETE
[I 2026-05-12 23:48:58.342 FileIdExtension] Attached event listeners.
[I 2026-05-12 23:48:58.342 ServerApp] jupyter_server_fileid | extension was successfully loaded.
[I 2026-05-12 23:48:58.343 ServerApp] jupyter_server_nbmodel | extension was successfully loaded.
[I 2026-05-12 23:48:58.344 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2026-05-12 23:48:58.347 ServerApp] jupyter_server_ydoc | extension was successfully loaded.
[I 2026-05-12 23:48:58.348 LabApp] JupyterLab extension loaded from /home/lucas/fn_registry/projects/imagegen/analysis/spike_diffusers_vs_sdcpp/.venv/lib/python3.13/site-packages/jupyterlab
[I 2026-05-12 23:48:58.348 LabApp] JupyterLab application directory is /home/lucas/fn_registry/projects/imagegen/analysis/spike_diffusers_vs_sdcpp/.venv/share/jupyter/lab
[I 2026-05-12 23:48:58.349 LabApp] Extension Manager is 'pypi'.
[I 2026-05-12 23:48:58.375 ServerApp] jupyterlab | extension was successfully loaded.
[I 2026-05-12 23:48:58.377 ServerApp] notebook | extension was successfully loaded.
[I 2026-05-12 23:48:58.380 ServerApp] Serving notebooks from local directory: /home/lucas/fn_registry/projects/imagegen/analysis/spike_diffusers_vs_sdcpp
[I 2026-05-12 23:48:58.380 ServerApp] Jupyter Server 2.18.2 is running at:
[I 2026-05-12 23:48:58.380 ServerApp] http://localhost:8888/lab
[I 2026-05-12 23:48:58.380 ServerApp] http://127.0.0.1:8888/lab
[I 2026-05-12 23:48:58.380 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 2026-05-12 23:49:00.234 ServerApp] Skipped non-installed server(s): basedpyright, bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyrefly, pyright, python-language-server, python-lsp-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server
[E 2026-05-12 23:49:06.001 ServerApp] Error unpacking user from cookie: 'avatar_url'
[W 2026-05-12 23:49:06.001 ServerApp] Clearing invalid/expired login cookie username-localhost-8888
[I 2026-05-12 23:49:08.166 LabApp] Build is up to date
[W 2026-05-12 23:49:09.210 ServerApp] 404 GET /api/contents/notebooks/09_spacy_es_openie.ipynb?content=0&hash=0&1778622549310 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 1.17ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.210 ServerApp] 404 GET /api/contents/notebooks/09_spacy_es_openie.ipynb?content=0&hash=0&1778622549310 (127.0.0.1): No such file or directory: notebooks/09_spacy_es_openie.ipynb
[W 2026-05-12 23:49:09.211 ServerApp] 404 GET /api/contents/notebooks/08_improving_gliner2.ipynb?content=0&hash=0&1778622549310 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 1.75ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.211 ServerApp] 404 GET /api/contents/notebooks/08_improving_gliner2.ipynb?content=0&hash=0&1778622549310 (127.0.0.1): No such file or directory: notebooks/08_improving_gliner2.ipynb
[W 2026-05-12 23:49:09.211 ServerApp] 404 GET /api/contents/notebooks/06_improvements.ipynb?content=0&hash=0&1778622549311 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 1.96ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.211 ServerApp] 404 GET /api/contents/notebooks/06_improvements.ipynb?content=0&hash=0&1778622549311 (127.0.0.1): No such file or directory: notebooks/06_improvements.ipynb
[W 2026-05-12 23:49:09.212 ServerApp] 404 GET /api/contents/notebooks/07_nuextract_vs_gliner2.ipynb?content=0&hash=0&1778622549311 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 2.15ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.212 ServerApp] 404 GET /api/contents/notebooks/07_nuextract_vs_gliner2.ipynb?content=0&hash=0&1778622549311 (127.0.0.1): No such file or directory: notebooks/07_nuextract_vs_gliner2.ipynb
[W 2026-05-12 23:49:09.217 ServerApp] 404 GET /api/contents/notebooks/05_long_text_and_pdf.ipynb?content=0&hash=0&1778622549311 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 0.96ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.217 ServerApp] 404 GET /api/contents/notebooks/05_long_text_and_pdf.ipynb?content=0&hash=0&1778622549311 (127.0.0.1): No such file or directory: notebooks/05_long_text_and_pdf.ipynb
[W 2026-05-12 23:49:09.219 ServerApp] 404 GET /api/contents/notebooks/04_gliner2_winner.ipynb?content=0&hash=0&1778622549311 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 1.06ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.219 ServerApp] 404 GET /api/contents/notebooks/04_gliner2_winner.ipynb?content=0&hash=0&1778622549311 (127.0.0.1): No such file or directory: notebooks/04_gliner2_winner.ipynb
[W 2026-05-12 23:49:09.220 ServerApp] 404 GET /api/contents/notebooks/02_e2e_spanish_graph.ipynb?content=0&hash=0&1778622549311 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 1.62ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.220 ServerApp] 404 GET /api/contents/notebooks/02_e2e_spanish_graph.ipynb?content=0&hash=0&1778622549311 (127.0.0.1): No such file or directory: notebooks/02_e2e_spanish_graph.ipynb
[W 2026-05-12 23:49:09.221 ServerApp] 404 GET /api/contents/notebooks/03_mrebel_vs_glirel.ipynb?content=0&hash=0&1778622549311 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 1.28ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.221 ServerApp] 404 GET /api/contents/notebooks/03_mrebel_vs_glirel.ipynb?content=0&hash=0&1778622549311 (127.0.0.1): No such file or directory: notebooks/03_mrebel_vs_glirel.ipynb
[W 2026-05-12 23:49:09.222 ServerApp] 404 GET /api/contents/notebooks/01_gliner_glirel_tuning.ipynb?content=0&hash=0&1778622549312 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 1.36ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.222 ServerApp] 404 GET /api/contents/notebooks/01_gliner_glirel_tuning.ipynb?content=0&hash=0&1778622549312 (127.0.0.1): No such file or directory: notebooks/01_gliner_glirel_tuning.ipynb
[W 2026-05-12 23:49:09.223 ServerApp] 404 GET /api/contents/notebooks/06_improvements.ipynb?content=0&hash=0&1778622549312 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 0.48ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.223 ServerApp] 404 GET /api/contents/notebooks/06_improvements.ipynb?content=0&hash=0&1778622549312 (127.0.0.1): No such file or directory: notebooks/06_improvements.ipynb
[W 2026-05-12 23:49:09.234 ServerApp] 404 GET /api/contents/notebooks/07_nuextract_vs_gliner2.ipynb?content=0&hash=0&1778622549312 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 1.48ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.234 ServerApp] 404 GET /api/contents/notebooks/07_nuextract_vs_gliner2.ipynb?content=0&hash=0&1778622549312 (127.0.0.1): No such file or directory: notebooks/07_nuextract_vs_gliner2.ipynb
[W 2026-05-12 23:49:09.247 ServerApp] 404 GET /api/contents/notebooks/08_improving_gliner2.ipynb?content=0&hash=0&1778622549313 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 0.95ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.247 ServerApp] 404 GET /api/contents/notebooks/08_improving_gliner2.ipynb?content=0&hash=0&1778622549313 (127.0.0.1): No such file or directory: notebooks/08_improving_gliner2.ipynb
[W 2026-05-12 23:49:09.258 ServerApp] 404 GET /api/contents/notebooks/05_long_text_and_pdf.ipynb?content=0&hash=0&1778622549313 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 0.87ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.259 ServerApp] 404 GET /api/contents/notebooks/05_long_text_and_pdf.ipynb?content=0&hash=0&1778622549313 (127.0.0.1): No such file or directory: notebooks/05_long_text_and_pdf.ipynb
[W 2026-05-12 23:49:09.271 ServerApp] 404 GET /api/contents/notebooks/04_gliner2_winner.ipynb?content=0&hash=0&1778622549313 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 1.05ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.271 ServerApp] 404 GET /api/contents/notebooks/04_gliner2_winner.ipynb?content=0&hash=0&1778622549313 (127.0.0.1): No such file or directory: notebooks/04_gliner2_winner.ipynb
[W 2026-05-12 23:49:09.284 ServerApp] 404 GET /api/contents/notebooks/03_mrebel_vs_glirel.ipynb?content=0&hash=0&1778622549313 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 1.19ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.284 ServerApp] 404 GET /api/contents/notebooks/03_mrebel_vs_glirel.ipynb?content=0&hash=0&1778622549313 (127.0.0.1): No such file or directory: notebooks/03_mrebel_vs_glirel.ipynb
[W 2026-05-12 23:49:09.296 ServerApp] 404 GET /api/contents/notebooks/02_e2e_spanish_graph.ipynb?content=0&hash=0&1778622549313 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 1.62ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.296 ServerApp] 404 GET /api/contents/notebooks/02_e2e_spanish_graph.ipynb?content=0&hash=0&1778622549313 (127.0.0.1): No such file or directory: notebooks/02_e2e_spanish_graph.ipynb
[W 2026-05-12 23:49:09.307 ServerApp] 404 GET /api/contents/notebooks/01_gliner_glirel_tuning.ipynb?content=0&hash=0&1778622549313 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 0.95ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.307 ServerApp] 404 GET /api/contents/notebooks/01_gliner_glirel_tuning.ipynb?content=0&hash=0&1778622549313 (127.0.0.1): No such file or directory: notebooks/01_gliner_glirel_tuning.ipynb
[W 2026-05-12 23:49:09.320 ServerApp] 404 GET /api/contents/notebooks/09_spacy_es_openie.ipynb?content=0&hash=0&1778622549313 (b7536e14d02a4faa908e136e0ed86c6c@127.0.0.1) 1.17ms referer=http://localhost:8888/lab
[W 2026-05-12 23:49:09.320 ServerApp] 404 GET /api/contents/notebooks/09_spacy_es_openie.ipynb?content=0&hash=0&1778622549313 (127.0.0.1): No such file or directory: notebooks/09_spacy_es_openie.ipynb
[I 2026-05-12 23:49:09.387 ServerApp] MCP Tools WebSocket connection opened
[W 2026-05-12 23:49:09.387 ServerApp] The websocket_ping_timeout (90000) cannot be longer than the websocket_ping_interval (30000).
Setting websocket_ping_timeout=30000
[I 2026-05-12 23:49:09.443 ServerApp] Registered 414 tools
[I 2026-05-12 23:50:09.127 YDocExtension] Processed 26 Y patches in one minute
[I 2026-05-12 23:50:09.127 YDocExtension] Connected Y users: 1
[I 2026-05-12 23:50:22.974 LabApp] Build is up to date
[I 2026-05-12 23:50:23.307 ServerApp] MCP Tools WebSocket connection opened
[I 2026-05-12 23:50:23.321 ServerApp] Registered 414 tools
[I 2026-05-12 23:50:26.946 ServerApp] MCP Tools WebSocket connection closed
[I 2026-05-12 23:51:10.299 YDocExtension] Processed 30 Y patches in one minute
[I 2026-05-12 23:51:10.299 YDocExtension] Connected Y users: 1
[I 2026-05-12 23:52:11.480 YDocExtension] Processed 10 Y patches in one minute
[I 2026-05-12 23:52:11.480 YDocExtension] Connected Y users: 1
[I 2026-05-12 23:53:12.752 YDocExtension] Processed 10 Y patches in one minute
[I 2026-05-12 23:53:12.752 YDocExtension] Connected Y users: 1
[I 2026-05-12 23:54:13.955 YDocExtension] Processed 11 Y patches in one minute
[I 2026-05-12 23:54:13.956 YDocExtension] Connected Y users: 1
[I 2026-05-12 23:54:35.510 LabApp] Build is up to date
[I 2026-05-12 23:54:35.689 ServerApp] MCP Tools WebSocket connection opened
[I 2026-05-12 23:54:35.710 ServerApp] Registered 414 tools
[I 2026-05-12 23:54:36.398 ServerApp] Request for Y document (now indexed) 'notebooks/01_spike_sd_turbo.ipynb' with room ID: 31306ee6-c779-40d6-9b9a-f5f6ea48a7d2
[I 2026-05-12 23:54:36.748 YDocExtension] Creating FileLoader for: notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-12 23:54:36.751 YDocExtension] Watching file: notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-12 23:54:36.755 ServerApp] Initializing room json:notebook:31306ee6-c779-40d6-9b9a-f5f6ea48a7d2
/home/lucas/fn_registry/projects/imagegen/analysis/spike_diffusers_vs_sdcpp/.venv/lib/python3.13/site-packages/nbformat/__init__.py:96: MissingIDFieldWarning: Cell is missing an id field, this will become a hard error in future nbformat versions. You may want to use `normalize()` on your notebooks before validations (available since nbformat 5.1.4). Previous versions of nbformat are fixing this issue transparently, and will stop doing so in the future.
validate(nb)
[W 2026-05-12 23:54:36.796 ServerApp] Notebook notebooks/01_spike_sd_turbo.ipynb is not trusted
[I 2026-05-12 23:54:36.865 ServerApp] Content in room json:notebook:31306ee6-c779-40d6-9b9a-f5f6ea48a7d2 loaded from file notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-12 23:54:37.315 ServerApp] Kernel started: 6e733996-a5bd-49f0-a130-dae0092c6d76
[I 2026-05-12 23:54:37.902 ServerApp] Saving the content from room json:notebook:31306ee6-c779-40d6-9b9a-f5f6ea48a7d2
[I 2026-05-12 23:54:37.906 YDocExtension] Saving file: notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-12 23:54:38.298 ServerApp] Adapting from protocol version 5.3 (kernel 6e733996-a5bd-49f0-a130-dae0092c6d76) to 5.4 (client).
[I 2026-05-12 23:54:38.299 ServerApp] Connecting to kernel 6e733996-a5bd-49f0-a130-dae0092c6d76.
[I 2026-05-12 23:54:38.320 ServerApp] Adapting from protocol version 5.3 (kernel 6e733996-a5bd-49f0-a130-dae0092c6d76) to 5.4 (client).
[I 2026-05-12 23:54:38.321 ServerApp] Connecting to kernel 6e733996-a5bd-49f0-a130-dae0092c6d76.
[I 2026-05-12 23:54:38.339 ServerApp] Adapting from protocol version 5.3 (kernel 6e733996-a5bd-49f0-a130-dae0092c6d76) to 5.4 (client).
[I 2026-05-12 23:54:38.340 ServerApp] Connecting to kernel 6e733996-a5bd-49f0-a130-dae0092c6d76.
[I 2026-05-12 23:54:39.430 ServerApp] Saving the content from room json:notebook:31306ee6-c779-40d6-9b9a-f5f6ea48a7d2
[I 2026-05-12 23:54:39.431 YDocExtension] Saving file: notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-12 23:54:44.478 ServerApp] Adapting from protocol version 5.3 (kernel 6e733996-a5bd-49f0-a130-dae0092c6d76) to 5.4 (client).
[I 2026-05-12 23:54:44.479 ServerApp] Connecting to kernel 6e733996-a5bd-49f0-a130-dae0092c6d76.
[I 2026-05-12 23:55:15.193 YDocExtension] Processed 50 Y patches in one minute
[I 2026-05-12 23:55:15.193 YDocExtension] Connected Y users: 3
[I 2026-05-12 23:56:16.499 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-12 23:56:16.499 YDocExtension] Connected Y users: 3
[I 2026-05-12 23:57:17.754 YDocExtension] Processed 26 Y patches in one minute
[I 2026-05-12 23:57:17.754 YDocExtension] Connected Y users: 3
[I 2026-05-12 23:58:19.081 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-12 23:58:19.081 YDocExtension] Connected Y users: 3
[I 2026-05-12 23:59:20.365 YDocExtension] Processed 28 Y patches in one minute
[I 2026-05-12 23:59:20.365 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:00:21.681 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:00:21.681 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:01:22.979 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:01:22.979 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:02:24.366 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:02:24.366 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:03:25.702 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:03:25.702 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:04:27.117 YDocExtension] Processed 26 Y patches in one minute
[I 2026-05-13 00:04:27.117 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:05:28.471 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:05:28.471 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:06:29.949 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:06:29.949 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:07:31.312 YDocExtension] Processed 26 Y patches in one minute
[I 2026-05-13 00:07:31.312 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:08:32.786 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:08:32.786 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:09:34.161 YDocExtension] Processed 26 Y patches in one minute
[I 2026-05-13 00:09:34.161 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:10:35.628 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:10:35.628 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:11:37.032 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:11:37.033 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:12:38.483 YDocExtension] Processed 26 Y patches in one minute
[I 2026-05-13 00:12:38.483 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:13:39.907 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:13:39.907 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:14:41.375 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:14:41.376 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:15:42.805 YDocExtension] Processed 26 Y patches in one minute
[I 2026-05-13 00:15:42.805 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:16:44.285 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:16:44.285 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:17:45.718 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:17:45.718 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:18:47.181 YDocExtension] Processed 28 Y patches in one minute
[I 2026-05-13 00:18:47.182 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:19:48.635 YDocExtension] Processed 27 Y patches in one minute
[I 2026-05-13 00:19:48.635 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:20:50.111 YDocExtension] Processed 28 Y patches in one minute
[I 2026-05-13 00:20:50.111 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:21:51.569 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:21:51.569 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:22:53.057 YDocExtension] Processed 32 Y patches in one minute
[I 2026-05-13 00:22:53.057 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:23:54.512 YDocExtension] Processed 27 Y patches in one minute
[I 2026-05-13 00:23:54.512 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:24:56.006 YDocExtension] Processed 28 Y patches in one minute
[I 2026-05-13 00:24:56.006 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:25:57.469 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:25:57.469 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:26:58.965 YDocExtension] Processed 28 Y patches in one minute
[I 2026-05-13 00:26:58.965 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:28:00.433 YDocExtension] Processed 27 Y patches in one minute
[I 2026-05-13 00:28:00.433 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:29:01.935 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:29:01.935 YDocExtension] Connected Y users: 3
[W 2026-05-13 00:29:44.869 ServerApp] 404 GET /api/config (4a1f62ea98b14a7d93e2aaa7e900c8e2@127.0.0.1) 19.83ms referer=None
[I 2026-05-13 00:30:03.407 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:30:03.407 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:30:04.883 ServerApp] Adapting from protocol version 5.3 (kernel 6e733996-a5bd-49f0-a130-dae0092c6d76) to 5.4 (client).
[I 2026-05-13 00:30:04.884 ServerApp] Connecting to kernel 6e733996-a5bd-49f0-a130-dae0092c6d76.
[I 2026-05-13 00:30:07.375 ServerApp] Saving file at /notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-13 00:30:07.392 ServerApp] Out-of-band changes. Overwriting the content in room json:notebook:31306ee6-c779-40d6-9b9a-f5f6ea48a7d2
[I 2026-05-13 00:30:12.971 ServerApp] Adapting from protocol version 5.3 (kernel 6e733996-a5bd-49f0-a130-dae0092c6d76) to 5.4 (client).
[I 2026-05-13 00:30:12.971 ServerApp] Connecting to kernel 6e733996-a5bd-49f0-a130-dae0092c6d76.
[I 2026-05-13 00:30:12.990 ServerApp] Saving file at /notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-13 00:30:13.186 ServerApp] Out-of-band changes. Overwriting the content in room json:notebook:31306ee6-c779-40d6-9b9a-f5f6ea48a7d2
[I 2026-05-13 00:30:13.242 ServerApp] Adapting from protocol version 5.3 (kernel 6e733996-a5bd-49f0-a130-dae0092c6d76) to 5.4 (client).
[I 2026-05-13 00:30:13.243 ServerApp] Connecting to kernel 6e733996-a5bd-49f0-a130-dae0092c6d76.
[I 2026-05-13 00:30:13.342 ServerApp] Saving file at /notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-13 00:30:14.209 ServerApp] Out-of-band changes. Overwriting the content in room json:notebook:31306ee6-c779-40d6-9b9a-f5f6ea48a7d2
[I 2026-05-13 00:30:19.555 ServerApp] Adapting from protocol version 5.3 (kernel 6e733996-a5bd-49f0-a130-dae0092c6d76) to 5.4 (client).
[I 2026-05-13 00:30:19.555 ServerApp] Connecting to kernel 6e733996-a5bd-49f0-a130-dae0092c6d76.
[I 2026-05-13 00:30:29.963 ServerApp] Saving file at /notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-13 00:30:30.282 ServerApp] Out-of-band changes. Overwriting the content in room json:notebook:31306ee6-c779-40d6-9b9a-f5f6ea48a7d2
[I 2026-05-13 00:30:37.079 ServerApp] Adapting from protocol version 5.3 (kernel 6e733996-a5bd-49f0-a130-dae0092c6d76) to 5.4 (client).
[I 2026-05-13 00:30:37.079 ServerApp] Connecting to kernel 6e733996-a5bd-49f0-a130-dae0092c6d76.
[I 2026-05-13 00:30:40.047 ServerApp] Saving file at /notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-13 00:30:40.070 ServerApp] Out-of-band changes. Overwriting the content in room json:notebook:31306ee6-c779-40d6-9b9a-f5f6ea48a7d2
[I 2026-05-13 00:30:45.968 ServerApp] Adapting from protocol version 5.3 (kernel 6e733996-a5bd-49f0-a130-dae0092c6d76) to 5.4 (client).
[I 2026-05-13 00:30:45.968 ServerApp] Connecting to kernel 6e733996-a5bd-49f0-a130-dae0092c6d76.
[I 2026-05-13 00:30:46.674 ServerApp] Saving file at /notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-13 00:30:47.016 ServerApp] Adapting from protocol version 5.3 (kernel 6e733996-a5bd-49f0-a130-dae0092c6d76) to 5.4 (client).
[I 2026-05-13 00:30:47.017 ServerApp] Connecting to kernel 6e733996-a5bd-49f0-a130-dae0092c6d76.
[I 2026-05-13 00:30:47.107 ServerApp] Out-of-band changes. Overwriting the content in room json:notebook:31306ee6-c779-40d6-9b9a-f5f6ea48a7d2
[I 2026-05-13 00:30:47.562 ServerApp] Saving file at /notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-13 00:30:47.865 ServerApp] Adapting from protocol version 5.3 (kernel 6e733996-a5bd-49f0-a130-dae0092c6d76) to 5.4 (client).
[I 2026-05-13 00:30:47.865 ServerApp] Connecting to kernel 6e733996-a5bd-49f0-a130-dae0092c6d76.
[I 2026-05-13 00:30:48.134 ServerApp] Out-of-band changes. Overwriting the content in room json:notebook:31306ee6-c779-40d6-9b9a-f5f6ea48a7d2
[I 2026-05-13 00:30:49.178 ServerApp] Saving file at /notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-13 00:30:49.505 ServerApp] Adapting from protocol version 5.3 (kernel 6e733996-a5bd-49f0-a130-dae0092c6d76) to 5.4 (client).
[I 2026-05-13 00:30:49.506 ServerApp] Connecting to kernel 6e733996-a5bd-49f0-a130-dae0092c6d76.
[I 2026-05-13 00:30:49.936 ServerApp] Saving file at /notebooks/01_spike_sd_turbo.ipynb
[I 2026-05-13 00:30:50.170 ServerApp] Out-of-band changes. Overwriting the content in room json:notebook:31306ee6-c779-40d6-9b9a-f5f6ea48a7d2
[I 2026-05-13 00:31:04.900 YDocExtension] Processed 26 Y patches in one minute
[I 2026-05-13 00:31:04.900 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:32:06.391 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:32:06.391 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:33:07.895 YDocExtension] Processed 27 Y patches in one minute
[I 2026-05-13 00:33:07.895 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:34:09.397 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:34:09.397 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:35:10.914 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:35:10.914 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:36:12.422 YDocExtension] Processed 28 Y patches in one minute
[I 2026-05-13 00:36:12.422 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:37:13.945 YDocExtension] Processed 27 Y patches in one minute
[I 2026-05-13 00:37:13.945 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:38:15.455 YDocExtension] Processed 28 Y patches in one minute
[I 2026-05-13 00:38:15.455 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:39:16.985 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:39:16.986 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:40:18.507 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:40:18.507 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:41:20.046 YDocExtension] Processed 26 Y patches in one minute
[I 2026-05-13 00:41:20.046 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:42:21.576 YDocExtension] Processed 31 Y patches in one minute
[I 2026-05-13 00:42:21.576 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:43:23.121 YDocExtension] Processed 26 Y patches in one minute
[I 2026-05-13 00:43:23.121 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:44:24.657 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:44:24.657 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:45:26.207 YDocExtension] Processed 28 Y patches in one minute
[I 2026-05-13 00:45:26.207 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:46:27.752 YDocExtension] Processed 27 Y patches in one minute
[I 2026-05-13 00:46:27.753 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:47:29.313 YDocExtension] Processed 29 Y patches in one minute
[I 2026-05-13 00:47:29.313 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:48:30.905 YDocExtension] Processed 27 Y patches in one minute
[I 2026-05-13 00:48:30.906 YDocExtension] Connected Y users: 3
[I 2026-05-13 00:49:32.464 YDocExtension] Processed 28 Y patches in one minute
[I 2026-05-13 00:49:32.464 YDocExtension] Connected Y users: 3
+6
View File
@@ -0,0 +1,6 @@
def main():
print("Hello from spike-diffusers-vs-sdcpp!")
if __name__ == "__main__":
main()
@@ -0,0 +1,374 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "3451405a",
"metadata": {},
"source": [
"# Spike 01 — SD Turbo via diffusers backend\n",
"\n",
"**Objetivo:** validar contrato `GenerationConfig_py_ml` + backend `diffusers_generate_py_ml` con SD Turbo. Sanity check antes de invertir en sd.cpp / FLUX.\n",
"\n",
"**Criterio PASS:**\n",
"- 4 imagenes generadas, seeds deterministas, mismo seed → imagen identica entre runs.\n",
"- `vram_peak_mb` < 6000 MB.\n",
"- `duration_ms` < 5000 ms/imagen.\n",
"- `image_grid` 2x2 visible.\n",
"\n",
"**Criterio FAIL:** cualquiera de los anteriores no se cumple → replantear contrato o backend.\n",
"\n",
"**Lo que NO se valida aqui:** LoRA loading, comparacion vs sd.cpp, samplers != euler_a (SD Turbo solo soporta 1-step euler_a).\n",
"\n",
"**Funciones del registry usadas:**\n",
"- `cuda_available_py_ml`, `gpu_info_py_ml`, `vram_budget_py_ml`\n",
"- `diffusers_load_pipeline_py_ml`, `diffusers_generate_py_ml`, `diffusers_unload_py_ml`\n",
"- `image_grid_py_ml`, `image_save_png_py_ml`\n",
"- Tipos: `GenerationConfig`, `ModelRef`, `ImageGenResult`"
]
},
{
"cell_type": "markdown",
"id": "4b43e6a2",
"metadata": {},
"source": [
"## 1. Hardware check\n",
"\n",
"Verificar CUDA + GPU antes de empezar. Si no hay GPU, el resto del notebook correra en CPU (lento)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f395460",
"metadata": {},
"outputs": [],
"source": [
"import sys, os\n",
"FN_ROOT = os.environ.get(\"FN_REGISTRY_ROOT\", \"/home/lucas/fn_registry\")\n",
"sys.path.insert(0, os.path.join(FN_ROOT, \"python/functions/ml\"))\n",
"\n",
"from cuda_available import cuda_available\n",
"from gpu_info import gpu_info\n",
"from vram_budget import vram_budget\n",
"\n",
"cuda = cuda_available()\n",
"gpus = gpu_info()\n",
"print(\"CUDA:\", cuda)\n",
"print(\"GPUs:\", gpus)"
]
},
{
"cell_type": "markdown",
"id": "6b7c5272",
"metadata": {},
"source": [
"## 2. Hipotesis VRAM\n",
"\n",
"SD Turbo es derivado de SD 1.5 (~1.5GB fp16). Usamos `vram_budget` con `sd15/fp16` como proxy. Esperamos `fits=True` y `required_mb` ~2000-4000."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0b7eb904",
"metadata": {},
"outputs": [],
"source": [
"total_mb = gpus[0][\"vram_total_mb\"] if gpus else 8000 # fallback CPU/sim\n",
"budget = vram_budget(\n",
" gpu_vram_total_mb=total_mb,\n",
" model_type=\"sd15\",\n",
" quantization=\"fp16\",\n",
" width=512, height=512,\n",
")\n",
"print(\"VRAM total:\", total_mb, \"MB\")\n",
"print(\"Budget:\", budget)"
]
},
{
"cell_type": "markdown",
"id": "a89fec8c",
"metadata": {},
"source": [
"## 3. Construir 4 `GenerationConfig`\n",
"\n",
"Seeds fijos: 42, 123, 7, 999. Prompts variados. SD Turbo: `steps=1`, `cfg_scale=0.0` (no usa guidance), `sampler=euler_a`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b210dfc6",
"metadata": {},
"outputs": [],
"source": [
"# Forzar imports limpios para evitar double-import pydantic\n",
"for _mod in [\"sampler_name\", \"model_ref\", \"lora_ref\", \"generation_config\", \"image_gen_result\"]:\n",
" sys.modules.pop(_mod, None)\n",
"\n",
"from model_ref import ModelRef\n",
"from generation_config import GenerationConfig\n",
"\n",
"VAULT = \"/home/lucas/vaults/imagegen_models/diffusers/sd-turbo\"\n",
"\n",
"model = ModelRef(\n",
" name=\"stabilityai/sd-turbo\",\n",
" model_type=\"sd15\",\n",
" quantization=\"fp16\",\n",
" path=VAULT,\n",
")\n",
"\n",
"PROMPTS = [\n",
" (\"a cinematic shot of a baby racoon wearing a tiny crown\", 42),\n",
" (\"watercolor of a cozy library with floating books\", 123),\n",
" (\"isometric pixel art of a robot fishing on a pier\", 7),\n",
" (\"oil painting of a fox playing chess against a cat\", 999),\n",
"]\n",
"\n",
"configs = [\n",
" GenerationConfig(\n",
" prompt=p,\n",
" seed=s,\n",
" steps=1,\n",
" cfg_scale=0.0,\n",
" sampler=\"euler_a\",\n",
" width=512,\n",
" height=512,\n",
" model=model,\n",
" )\n",
" for p, s in PROMPTS\n",
"]\n",
"for c in configs:\n",
" print(c.seed, c.prompt[:60])"
]
},
{
"cell_type": "markdown",
"id": "743b6bb2",
"metadata": {},
"source": [
"## 4. Cargar pipeline SD Turbo\n",
"\n",
"Primera carga ~10-30s (mete pesos en VRAM). Llamadas subsiguientes: cacheadas."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "de0f03b2",
"metadata": {},
"outputs": [],
"source": [
"from diffusers_load_pipeline import diffusers_load_pipeline\n",
"\n",
"pipe = diffusers_load_pipeline(model=model, device=\"auto\", dtype=\"fp16\")\n",
"print(\"Pipeline:\", type(pipe).__name__)\n",
"print(\"Scheduler:\", type(pipe.scheduler).__name__)\n",
"print(\"Device:\", next(pipe.unet.parameters()).device)"
]
},
{
"cell_type": "markdown",
"id": "a328f117",
"metadata": {},
"source": [
"## 5. Generar 4 imagenes\n",
"\n",
"Una a una. Captura `duration_ms` + `vram_peak_mb` por imagen. SD Turbo 1-step: esperado <2s en GPU NVIDIA moderna."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d1780d91",
"metadata": {},
"outputs": [],
"source": [
"# Forzar imports limpios para alinear tipos con los que usa diffusers_generate\n",
"for _mod in [\"image_gen_result\", \"generation_config\", \"model_ref\", \"lora_ref\", \"sampler_name\"]:\n",
" sys.modules.pop(_mod, None)\n",
"\n",
"from diffusers_generate import diffusers_generate\n",
"from generation_config import GenerationConfig as GC2\n",
"from model_ref import ModelRef as MR2\n",
"\n",
"# Reconstruir configs con los tipos recien re-importados (alineados con diffusers_generate)\n",
"model2 = MR2(**model.model_dump())\n",
"configs2 = [GC2(**c.model_dump()) for c in configs]\n",
"\n",
"results = []\n",
"for c in configs2:\n",
" r = diffusers_generate(pipe, c)\n",
" print(f\"seed={c.seed} duration={r.duration_ms}ms vram_peak={r.vram_peak_mb}MB\")\n",
" results.append(r)\n",
"print(\"Total:\", len(results))"
]
},
{
"cell_type": "markdown",
"id": "ffda5ccc",
"metadata": {},
"source": [
"## 6. Grid 2x2 + display\n",
"\n",
"Imagenes lado a lado con labels (prompt acortado + seed)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a3dc597a",
"metadata": {},
"outputs": [],
"source": [
"from image_grid import image_grid\n",
"\n",
"labels = [f\"seed={r.meta.get('seed', '?')} | {c.prompt[:40]}...\" for c, r in zip(configs2, results)]\n",
"grid = image_grid(\n",
" images=[r.image for r in results],\n",
" cols=2,\n",
" labels=labels,\n",
" gap_px=12,\n",
")\n",
"grid"
]
},
{
"cell_type": "markdown",
"id": "ae4e3184",
"metadata": {},
"source": [
"## 7. Guardar grid + configs a vault\n",
"\n",
"PNG con metadata embebida (prompt/seed) en `~/vaults/imagegen_models/outputs/`. JSON canonico en `configs/`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7ca8a69",
"metadata": {},
"outputs": [],
"source": [
"from image_save_png import image_save_png\n",
"from genconfig_save_json import genconfig_save_json\n",
"import datetime, os as _os\n",
"\n",
"OUT_DIR = \"/home/lucas/vaults/imagegen_models/outputs\"\n",
"CFG_DIR = \"/home/lucas/vaults/imagegen_models/configs\"\n",
"stamp = datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")\n",
"\n",
"grid_path = image_save_png(\n",
" grid,\n",
" _os.path.join(OUT_DIR, f\"spike01_grid_{stamp}.png\"),\n",
" metadata={\"experiment\": \"spike01_sd_turbo\", \"model\": model2.name, \"n\": str(len(results))},\n",
")\n",
"print(\"grid:\", grid_path)\n",
"\n",
"for i, (c, r) in enumerate(zip(configs2, results)):\n",
" img_path = image_save_png(\n",
" r.image,\n",
" _os.path.join(OUT_DIR, f\"spike01_seed{c.seed}_{stamp}.png\"),\n",
" metadata={\"prompt\": c.prompt, \"seed\": str(c.seed), \"steps\": str(c.steps), \"sampler\": c.sampler},\n",
" )\n",
" cfg_path = genconfig_save_json(c, _os.path.join(CFG_DIR, f\"spike01_seed{c.seed}_{stamp}.json\"))\n",
" print(f\" [{i}] {img_path}\")\n",
" print(f\" {cfg_path}\")"
]
},
{
"cell_type": "markdown",
"id": "071982d6",
"metadata": {},
"source": [
"## 8. Tabla resumen + veredicto"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4a4a18c4",
"metadata": {},
"outputs": [],
"source": [
"rows = []\n",
"for c, r in zip(configs2, results):\n",
" rows.append({\n",
" \"seed\": c.seed,\n",
" \"prompt\": c.prompt[:50] + \"...\",\n",
" \"duration_ms\": r.duration_ms,\n",
" \"vram_peak_mb\": r.vram_peak_mb,\n",
" })\n",
"\n",
"try:\n",
" import pandas as pd\n",
" df = pd.DataFrame(rows)\n",
" display(df)\n",
"except ImportError:\n",
" for row in rows:\n",
" print(row)\n",
"\n",
"max_dur = max(r.duration_ms for r in results)\n",
"max_vram = max((r.vram_peak_mb or 0) for r in results)\n",
"pass_dur = max_dur < 5000\n",
"pass_vram = max_vram < 6000\n",
"verdict = \"PASS\" if (pass_dur and pass_vram) else \"FAIL\"\n",
"print(f\"\\nMax duration: {max_dur} ms (target <5000) -> {'OK' if pass_dur else 'FAIL'}\")\n",
"print(f\"Max VRAM peak: {max_vram} MB (target <6000) -> {'OK' if pass_vram else 'FAIL'}\")\n",
"print(f\"\\nVEREDICTO: {verdict}\")"
]
},
{
"cell_type": "markdown",
"id": "19701ac7",
"metadata": {},
"source": [
"## 9. Cleanup VRAM"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d25cfb9c",
"metadata": {},
"outputs": [],
"source": [
"from diffusers_unload import diffusers_unload\n",
"diffusers_unload(pipe)\n",
"diffusers_unload(None) # clear cache global\n",
"print(\"unloaded\")"
]
},
{
"cell_type": "markdown",
"id": "f331dc00",
"metadata": {},
"source": [
"## 10. Siguiente paso\n",
"\n",
"Si PASS:\n",
"- Notebook `02_seed_reproducibility.ipynb` — mismo seed, dos runs, verificar hash identico.\n",
"- Notebook `03_sdxl_turbo.ipynb` cuando se descargue (~6.5GB).\n",
"- Lanzar Ola 3.B (sd.cpp Python bindings) + descargar FLUX schnell GGUF para validacion cruzada.\n",
"\n",
"Si FAIL:\n",
"- Revisar `vram_budget` table si VRAM peak excede.\n",
"- Revisar `diffusers_generate` si duration excede (offloading, dtype incorrecto).\n",
"- Replantear contrato `GenerationConfig` si la firma no cuadra."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
File diff suppressed because one or more lines are too long
+21
View File
@@ -0,0 +1,21 @@
[project]
name = "spike-diffusers-vs-sdcpp"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"accelerate>=1.13.0",
"diffusers>=0.37.1",
"huggingface-hub>=1.14.0",
"jupyter>=1.1.1",
"jupyter-collaboration>=4.4.0",
"jupyter-mcp-server>=1.0.2",
"jupyterlab>=4.5.7",
"matplotlib>=3.10.9",
"numpy>=2.4.4",
"pandas>=3.0.3",
"pillow>=12.2.0",
"safetensors>=0.7.0",
"transformers>=5.8.0",
]
+50
View File
@@ -0,0 +1,50 @@
#!/bin/bash
# Jupyter Lab — modo colaborativo con autodeteccion de puerto
# Generado por write_jupyter_launcher (fn_registry)
find_free_port() {
for port in 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899; do
if ! ss -tln 2>/dev/null | grep -q ":${port} " && \
! lsof -i:"$port" >/dev/null 2>&1; then
echo $port
return
fi
done
echo 8888
}
PORT=${1:-$(find_free_port)}
cd "$(dirname "$0")"
echo $PORT > .jupyter-port
source .venv/bin/activate 2>/dev/null || true
# IPython startup: cargar .ipython/ local (FN_REGISTRY_ROOT, helpers, sys.path)
if [ -d "$(pwd)/.ipython" ]; then
export IPYTHONDIR="$(pwd)/.ipython"
fi
if ! python -c "import jupyter_collaboration" 2>/dev/null; then
echo "ERROR: jupyter-collaboration no esta instalado"
echo "Instala con: uv add jupyter-collaboration"
exit 1
fi
echo "════════════════════════════════════════════════"
echo " Jupyter Lab + Colaboracion en puerto $PORT"
echo "════════════════════════════════════════════════"
echo ""
echo " Abre: http://localhost:$PORT"
echo " Ctrl+C para detener"
echo ""
jupyter lab \
--port=$PORT \
--no-browser \
--ServerApp.token='' \
--ServerApp.password='' \
--ServerApp.disable_check_xsrf=True \
--ServerApp.allow_origin='*' \
--ServerApp.root_dir="$(pwd)" \
--collaborative
Generated
+3638
View File
File diff suppressed because it is too large Load Diff