Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e6dee73
refactor: re-apply Phase 1 perf/best-practices cleanup (cosmetic + fa…
forkni Jul 10, 2026
1070583
refactor: Phase 2 exception hygiene and observability fixes
forkni Jul 10, 2026
1559d69
chore: migrate deprecated top-level ruff settings to [tool.ruff.lint]
forkni Jul 10, 2026
cf3df18
fix: sync _make_fake_engine test double with TensorRTEngine.__init__
forkni Jul 10, 2026
37443db
fix: Phase 3 correctness and resource-safety fixes
forkni Jul 10, 2026
80c83ce
fix: Phase 4 TensorRT engine-write atomicity and graph/refit robustness
forkni Jul 10, 2026
d56e8fa
perf: instrument unet_step with profiler.region() spans (Sub-phase 5.0)
forkni Jul 10, 2026
d44f1ed
perf: skip redundant set_tensor_address rebind in TRT graph replay (S…
forkni Jul 10, 2026
a1af2b0
perf: sync-free output/PIL/IPC paths (Sub-phase 5.2)
forkni Jul 10, 2026
cda335b
fix: batch-dynamic engines skip l2tc tiling, silencing benign VALIDAT…
forkni Jul 10, 2026
d5efd4d
perf: elide trt.input_staging DtoD copy for kvo/fio UNet cache inputs…
forkni Jul 11, 2026
a9b1669
fix: lower ControlNet dynamic-shape floor 384->256 via shared min_ima…
forkni Jul 11, 2026
75ee38d
perf: normalize blend weights on CPU + persistent ControlNet conditio…
forkni Jul 11, 2026
fcb2ae2
perf: 1-frame-delayed async NSFW safety-checker readback (Sub-phase 5.3)
forkni Jul 11, 2026
9adfebd
perf: persistent multi-ControlNet residual merge buffer (Phase-2 prep)
forkni Jul 11, 2026
abf02a7
perf: 256-byte alignment guard for zero-copy bind path (audit M2)
forkni Jul 11, 2026
f8ff50f
perf: zero-copy bind ControlNet residual UNet inputs (Phase-2 D2)
forkni Jul 11, 2026
50171bf
refactor: harden TRT runtime API usage (audit M1/H1/H2)
forkni Jul 11, 2026
f0e1b80
refactor: modernize ONNX compile/export path — create_network(), drop…
forkni Jul 11, 2026
3d8ff10
fix: make ControlNet zero-copy revert permanent; harden staging bind-…
forkni Jul 11, 2026
3081e35
fix: enforce keyword-only StreamParameterUpdater binding; correct see…
forkni Jul 11, 2026
56ffd65
perf: FP8 build disk-space preflight and hardened intermediate cleanup
forkni Jul 11, 2026
e1be616
style: apply ruff format to builder.py (CGW restage gap left prior co…
forkni Jul 11, 2026
e417a4e
refactor: centralize wrapper/updater params in param_schema (single s…
forkni Jul 12, 2026
e81e119
style: adopt expanded ruff ruleset + safe auto-fixes repo-wide
forkni Jul 12, 2026
6bd9df9
chore: add pyrefly baseline freezing pre-existing type errors
forkni Jul 12, 2026
d23e79d
style: whitelist idiomatic call-defaults; re-enable B008/RUF009
forkni Jul 12, 2026
d5140d7
fix: chain exception causes + resolve real-bug lints; re-enable rules
forkni Jul 12, 2026
d25a291
fix: harden RealESRGAN fallback loader with torch.load(weights_only=T…
forkni Jul 12, 2026
658dcfa
chore: add Claude review workflow to PR2 branch for head-ref validation
forkni Jul 13, 2026
ed0521b
chore: widen Claude review allowedTools (Skill, python/pytest, /tmp W…
forkni Jul 13, 2026
a6e00fc
chore: raise Claude review max-turns to 60, discourage filesystem-wid…
forkni Jul 13, 2026
47a87eb
fix: correct NSFW verdict-to-frame attribution and guard pin_memory o…
forkni Jul 14, 2026
2d24369
chore: add Claude review workflow to PR3 branch for head-ref validation
forkni Jul 14, 2026
4f8b75a
chore: add Claude review workflow to PR4 branch for head-ref validation
forkni Jul 14, 2026
0761485
chore: add Claude review workflow to PR5 branch for head-ref validation
forkni Jul 14, 2026
179639f
Merge remote-tracking branch 'fork/SDTD_032_dev' into perf/unet-step-…
forkni Jul 19, 2026
a7e43ea
Merge remote-tracking branch 'fork/perf/unet-step-subphase-5x' into p…
forkni Jul 19, 2026
dbfa7a2
Merge remote-tracking branch 'fork/perf/trt-zero-copy-audit-hardening…
forkni Jul 19, 2026
c017756
Merge remote-tracking branch 'fork/refactor/param-schema-fp8-prefligh…
forkni Jul 19, 2026
c46b8b9
chore: fix import ordering in merge-carried diagnostics files
forkni Jul 19, 2026
a2cc4b6
Merge remote-tracking branch 'fork/SDTD_032_dev' into perf/trt-zero-c…
forkni Jul 19, 2026
212c46f
Merge remote-tracking branch 'fork/perf/trt-zero-copy-audit-hardening…
forkni Jul 19, 2026
d60d509
Merge remote-tracking branch 'fork/refactor/param-schema-fp8-prefligh…
forkni Jul 19, 2026
12c3a83
Merge remote-tracking branch 'fork/SDTD_032_dev' into chore/ruff-pyre…
forkni Jul 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demo/realtime-img2img/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def load_controlnet_registry():
"""Load ControlNet registry from config file"""
try:
registry_path = Path(__file__).parent / "controlnet_registry.yaml"
with open(registry_path, "r") as f:
with open(registry_path) as f:
config_data = yaml.safe_load(f)

# Extract the available_controlnets section
Expand All @@ -27,7 +27,7 @@ def load_default_settings():
"""Load default settings from YAML config file"""
try:
registry_path = Path(__file__).parent / "controlnet_registry.yaml"
with open(registry_path, "r") as f:
with open(registry_path) as f:
config_data = yaml.safe_load(f)

return config_data.get("defaults", {})
Expand Down
1 change: 0 additions & 1 deletion demo/realtime-img2img/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from fastapi import WebSocket
from starlette.websockets import WebSocketState


Connections = Dict[UUID, Dict[str, Union[WebSocket, asyncio.Queue]]]


Expand Down
2 changes: 0 additions & 2 deletions demo/realtime-img2img/img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import sys


sys.path.append(
os.path.join(
os.path.dirname(__file__),
Expand All @@ -18,7 +17,6 @@
from PIL import Image
from pydantic import BaseModel, Field


# Default values for pipeline parameters
default_negative_prompt = "black and white, blurry, low resolution, pixelated, pixel art, low quality, low fidelity"

Expand Down
7 changes: 5 additions & 2 deletions demo/realtime-img2img/input_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _monitor_gamepad(self) -> None:
finally:
try:
pygame.quit()
except:
except: # noqa: E722 # TODO: pre-existing, untouched by this refactor
pass


Expand All @@ -161,6 +161,7 @@ class InputManager:
def __init__(self):
self.inputs: Dict[str, InputControl] = {}
self.parameter_update_callback: Optional[Callable[[str, float], None]] = None
self._background_tasks: set = set()

def add_input(self, input_id: str, input_control: InputControl) -> None:
"""Add an input control"""
Expand All @@ -171,7 +172,9 @@ def add_input(self, input_id: str, input_control: InputControl) -> None:
def remove_input(self, input_id: str) -> None:
"""Remove an input control"""
if input_id in self.inputs:
asyncio.create_task(self.inputs[input_id].stop())
task = asyncio.create_task(self.inputs[input_id].stop())
self._background_tasks.add(task)
task.add_done_callback(self._background_tasks.discard)
del self.inputs[input_id]
logging.info(f"InputManager: Removed input control {input_id}")

Expand Down
15 changes: 7 additions & 8 deletions demo/realtime-img2img/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from img2img import Pipeline
from input_control import InputManager


# fix mime error on windows
mimetypes.add_type("application/javascript", ".js")

Expand Down Expand Up @@ -333,7 +332,7 @@ def add_controlnet(self, controlnet_config: dict):
def remove_controlnet(self, index: int):
"""Remove ControlNet from AppState - SINGLE SOURCE OF TRUTH"""
if index < len(self.controlnet_info["controlnets"]):
removed = self.controlnet_info["controlnets"].pop(index)
removed = self.controlnet_info["controlnets"].pop(index) # noqa: F841 # TODO: pre-existing, untouched by this refactor
# Re-index remaining controlnets
for i, controlnet in enumerate(self.controlnet_info["controlnets"]):
controlnet["index"] = i
Expand Down Expand Up @@ -380,7 +379,7 @@ def remove_hook_processor(self, hook_type: str, processor_index: int):
if hook_type in self.pipeline_hooks:
processors = self.pipeline_hooks[hook_type]["processors"]
if processor_index < len(processors):
removed = processors.pop(processor_index)
removed = processors.pop(processor_index) # noqa: F841 # TODO: pre-existing, untouched by this refactor
# Re-index remaining processors
for i, processor in enumerate(processors):
processor["index"] = i
Expand Down Expand Up @@ -538,7 +537,7 @@ def generate_pipeline_config(self):
if self.ipadapter_info["enabled"]:
config["use_ipadapter"] = True
# Preserve original ipadapters config but update runtime values
if "ipadapters" in config and config["ipadapters"]:
if config.get("ipadapters"):
# Update existing config with current values
config["ipadapters"][0].update(
{"scale": self.ipadapter_info["scale"], "weight_type": self.ipadapter_info["weight_type"]}
Expand Down Expand Up @@ -880,8 +879,8 @@ def get_available_controlnets():
def _create_pipeline(self):
"""Create pipeline using AppState as single source of truth"""
logger.info("_create_pipeline: Creating pipeline using AppState as single source of truth")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
torch_dtype = torch.float16
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # noqa: F841 # TODO: pre-existing, untouched by this refactor
torch_dtype = torch.float16 # noqa: F841 # TODO: pre-existing, untouched by this refactor

# Generate pipeline config from AppState - SINGLE SOURCE OF TRUTH
pipeline_config = self.app_state.generate_pipeline_config()
Expand All @@ -906,7 +905,7 @@ def _create_pipeline(self):
if "use_safety_checker" in pipeline_config:
args_dict["safety_checker"] = pipeline_config["use_safety_checker"]

updated_args = Args(**args_dict)
updated_args = Args(**args_dict) # noqa: F841 # TODO: pre-existing, untouched by this refactor

# Create Pipeline instance with the pre-created wrapper and config
pipeline = Pipeline(wrapper=wrapper, config=pipeline_config)
Expand Down Expand Up @@ -941,7 +940,7 @@ def _cleanup_temp_files(self):
try:
if os.path.exists(temp_path):
os.unlink(temp_path)
except:
except: # noqa: E722 # TODO: pre-existing, untouched by this refactor
pass
self._temp_config_files.clear()

Expand Down
4 changes: 2 additions & 2 deletions demo/realtime-img2img/routes/common/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def handle_api_request(

except Exception as e:
logging.exception(f"{operation_name}: Failed to parse request: {e}")
raise HTTPException(status_code=400, detail=f"Invalid request format: {str(e)}")
raise HTTPException(status_code=400, detail=f"Invalid request format: {e!s}") from e


def create_success_response(message: str, **extra_data) -> JSONResponse:
Expand Down Expand Up @@ -74,7 +74,7 @@ def handle_api_error(error: Exception, operation_name: str, status_code: int = 5
HTTPException with standardized error message
"""
logging.error(f"{operation_name}: Failed: {error}")
return HTTPException(status_code=status_code, detail=f"Failed to {operation_name.lower()}: {str(error)}")
return HTTPException(status_code=status_code, detail=f"Failed to {operation_name.lower()}: {error!s}")


def validate_pipeline(pipeline: Any, operation_name: str) -> None:
Expand Down
40 changes: 19 additions & 21 deletions demo/realtime-img2img/routes/controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
)
from .common.dependencies import get_app_instance, get_available_controlnets


router = APIRouter(prefix="/api", tags=["controlnet"])


Expand Down Expand Up @@ -48,7 +47,7 @@ async def upload_controlnet_config(file: UploadFile = File(...), app_instance=De
try:
config_data = yaml.safe_load(content.decode("utf-8"))
except yaml.YAMLError as e:
raise HTTPException(status_code=400, detail=f"Invalid YAML format: {str(e)}")
raise HTTPException(status_code=400, detail=f"Invalid YAML format: {e!s}") from e

# YAML is source of truth - completely replace any runtime modifications
app_instance.app_state.uploaded_config = config_data
Expand Down Expand Up @@ -78,12 +77,12 @@ async def upload_controlnet_config(file: UploadFile = File(...), app_instance=De
# Get config prompt if available
config_prompt = config_data.get("prompt", None)
# Get negative prompt if available
config_negative_prompt = config_data.get("negative_prompt", None)
config_negative_prompt = config_data.get("negative_prompt", None) # noqa: F841 # TODO: pre-existing, untouched by this refactor

# Get t_index_list from config if available
from app_config import DEFAULT_SETTINGS

t_index_list = config_data.get("t_index_list", DEFAULT_SETTINGS.get("t_index_list", [35, 45]))
t_index_list = config_data.get("t_index_list", DEFAULT_SETTINGS.get("t_index_list", [35, 45])) # noqa: F841 # TODO: pre-existing, untouched by this refactor

# Get acceleration from config if available
config_acceleration = config_data.get("acceleration", app_instance.args.acceleration)
Expand All @@ -109,7 +108,7 @@ async def upload_controlnet_config(file: UploadFile = File(...), app_instance=De
)

except (ValueError, TypeError):
raise HTTPException(status_code=400, detail="Invalid width/height values in config")
raise HTTPException(status_code=400, detail="Invalid width/height values in config") from None

# Build current resolution string
current_resolution = None
Expand Down Expand Up @@ -165,7 +164,7 @@ async def upload_controlnet_config(file: UploadFile = File(...), app_instance=De

except Exception as e:
logging.exception(f"upload_controlnet_config: Failed to upload configuration: {e}")
raise HTTPException(status_code=500, detail=f"Failed to upload configuration: {str(e)}")
raise HTTPException(status_code=500, detail=f"Failed to upload configuration: {e!s}") from e


@router.get("/controlnet/info")
Expand Down Expand Up @@ -208,7 +207,7 @@ async def get_current_blending_config(app_instance=Depends(get_app_instance)):
)

except Exception as e:
raise handle_api_error(e, "get_current_blending_config")
raise handle_api_error(e, "get_current_blending_config") from e


@router.post("/controlnet/update-strength")
Expand Down Expand Up @@ -243,7 +242,7 @@ async def update_controlnet_strength(request: Request, app_instance=Depends(get_
return create_success_response(f"Updated ControlNet {controlnet_index} strength to {strength}")

except Exception as e:
raise handle_api_error(e, "update_controlnet_strength")
raise handle_api_error(e, "update_controlnet_strength") from e


@router.get("/controlnet/available")
Expand Down Expand Up @@ -274,7 +273,6 @@ async def get_available_controlnets_endpoint(
elif "sd-turbo" in ml or "sd21" in ml or "sd2.1" in ml or "2-1" in ml or "stable-diffusion-2" in ml:
model_type = "sd21"


# Handle case where available_controlnets dependency returns None
if available_controlnets is None:
logging.warning("get_available_controlnets: available_controlnets dependency returned None")
Expand Down Expand Up @@ -304,7 +302,7 @@ async def get_available_controlnets_endpoint(
)

except Exception as e:
raise handle_api_error(e, "get_available_controlnets_endpoint")
raise handle_api_error(e, "get_available_controlnets_endpoint") from e


@router.post("/controlnet/add")
Expand Down Expand Up @@ -383,7 +381,7 @@ async def add_controlnet(
)

except Exception as e:
raise handle_api_error(e, "add_controlnet")
raise handle_api_error(e, "add_controlnet") from e


@router.get("/controlnet/status")
Expand Down Expand Up @@ -411,7 +409,7 @@ async def get_controlnet_status(app_instance=Depends(get_app_instance)):
)

except Exception as e:
raise handle_api_error(e, "get_controlnet_status")
raise handle_api_error(e, "get_controlnet_status") from e


@router.post("/controlnet/remove")
Expand All @@ -435,7 +433,7 @@ async def remove_controlnet(request: Request, app_instance=Depends(get_app_insta
if index < 0 or index >= len(controlnets):
raise HTTPException(status_code=400, detail=f"ControlNet index {index} out of range")

removed_controlnet = controlnets.pop(index)
removed_controlnet = controlnets.pop(index) # noqa: F841 # TODO: pre-existing, untouched by this refactor

# Remove from AppState - SINGLE SOURCE OF TRUTH
app_instance.app_state.remove_controlnet(index)
Expand All @@ -461,7 +459,7 @@ async def remove_controlnet(request: Request, app_instance=Depends(get_app_insta
)

except Exception as e:
raise handle_api_error(e, "remove_controlnet")
raise handle_api_error(e, "remove_controlnet") from e


# Preprocessor endpoints (closely related to ControlNet)
Expand Down Expand Up @@ -504,7 +502,7 @@ async def get_preprocessors_info(app_instance=Depends(get_app_instance)):
)

except Exception as e:
raise handle_api_error(e, "get_preprocessors_info")
raise handle_api_error(e, "get_preprocessors_info") from e


@router.post("/preprocessors/switch")
Expand Down Expand Up @@ -536,7 +534,7 @@ async def switch_preprocessor(request: Request, app_instance=Depends(get_app_ins

# Update the preprocessor in AppState
controlnet = app_instance.app_state.controlnet_info["controlnets"][controlnet_index]
old_preprocessor = controlnet.get("preprocessor", "unknown")
old_preprocessor = controlnet.get("preprocessor", "unknown") # noqa: F841 # TODO: pre-existing, untouched by this refactor
controlnet["preprocessor"] = preprocessor_name
controlnet["preprocessor_params"] = {} # Reset parameters when switching

Expand Down Expand Up @@ -565,7 +563,7 @@ async def switch_preprocessor(request: Request, app_instance=Depends(get_app_ins
return create_success_response(f"Switched ControlNet {controlnet_index} preprocessor to {preprocessor_name}")

except Exception as e:
raise handle_api_error(e, "switch_preprocessor")
raise handle_api_error(e, "switch_preprocessor") from e


@router.post("/preprocessors/update-params")
Expand All @@ -577,7 +575,7 @@ async def update_preprocessor_params(request: Request, app_instance=Depends(get_
data = await request.json()
except Exception as json_error:
logging.error(f"update_preprocessor_params: JSON parsing failed: {json_error}")
raise HTTPException(status_code=400, detail=f"Invalid JSON: {json_error}")
raise HTTPException(status_code=400, detail=f"Invalid JSON: {json_error}") from json_error

controlnet_index = data.get("controlnet_index")
params = data.get("params", {})
Expand Down Expand Up @@ -641,8 +639,8 @@ async def update_preprocessor_params(request: Request, app_instance=Depends(get_
)

except Exception as e:
logging.exception(f"update_preprocessor_params: Exception occurred: {str(e)}")
raise handle_api_error(e, "update_preprocessor_params")
logging.exception(f"update_preprocessor_params: Exception occurred: {e!s}")
raise handle_api_error(e, "update_preprocessor_params") from e


@router.get("/preprocessors/current-params/{controlnet_index}")
Expand Down Expand Up @@ -702,4 +700,4 @@ async def get_current_preprocessor_params(controlnet_index: int, app_instance=De
)

except Exception as e:
raise handle_api_error(e, "get_current_preprocessor_params")
raise handle_api_error(e, "get_current_preprocessor_params") from e
9 changes: 4 additions & 5 deletions demo/realtime-img2img/routes/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from .common.dependencies import get_app_instance


router = APIRouter(prefix="/api/debug", tags=["debug"])


Expand Down Expand Up @@ -37,7 +36,7 @@ async def enable_debug_mode(app_instance=Depends(get_app_instance)):
)
except Exception as e:
logging.exception(f"enable_debug_mode: Failed to enable debug mode: {e}")
raise HTTPException(status_code=500, detail=f"Failed to enable debug mode: {str(e)}")
raise HTTPException(status_code=500, detail=f"Failed to enable debug mode: {e!s}") from e


@router.post("/disable", response_model=DebugResponse)
Expand All @@ -57,7 +56,7 @@ async def disable_debug_mode(app_instance=Depends(get_app_instance)):
)
except Exception as e:
logging.exception(f"disable_debug_mode: Failed to disable debug mode: {e}")
raise HTTPException(status_code=500, detail=f"Failed to disable debug mode: {str(e)}")
raise HTTPException(status_code=500, detail=f"Failed to disable debug mode: {e!s}") from e


@router.post("/step", response_model=DebugResponse)
Expand All @@ -82,7 +81,7 @@ async def step_frame(app_instance=Depends(get_app_instance)):
raise
except Exception as e:
logging.exception(f"step_frame: Failed to step frame: {e}")
raise HTTPException(status_code=500, detail=f"Failed to step frame: {str(e)}")
raise HTTPException(status_code=500, detail=f"Failed to step frame: {e!s}") from e


@router.get("/status", response_model=DebugResponse)
Expand All @@ -97,4 +96,4 @@ async def get_debug_status(app_instance=Depends(get_app_instance)):
)
except Exception as e:
logging.exception(f"get_debug_status: Failed to get debug status: {e}")
raise HTTPException(status_code=500, detail=f"Failed to get debug status: {str(e)}")
raise HTTPException(status_code=500, detail=f"Failed to get debug status: {e!s}") from e
Loading
Loading