feat(attention): generation context

A module-level context tells attention consumers what is running: the
component role (transformer, text encoder, vae), the index of the
denoiser forward about to run, the pass length, and the model. It is
opened and closed around process_images, reset per denoising pass beside
the callback setup, and advanced by both step sources: the classic
callback passes the completed step plus one, the modular pre-forward
hook counts forwards. Roles come from the existing text encoder and vae
hijacks and the modular phase hooks. The step also lives in a device
scalar updated in place, so a compiled reader keeps its graph across
steps.
This commit is contained in:
CalamitousFelicitousness
2026-08-22 22:16:26 +01:00
parent 9d1d7c839a
commit 4509b145cd
9 changed files with 176 additions and 17 deletions
+3
View File
@@ -5,6 +5,7 @@ import numpy as np
from PIL import Image, ImageOps
from modules import shared, devices, errors, images, scripts_manager, memstats, script_callbacks, extra_networks, sd_models, sd_checkpoint, sd_vae, processing_helpers, processing_grading, timer, masking
from modules.logger import log
from modules.attention import context as attention_context
from modules.sd_hijack_hypertile import context_hypertile_vae, context_hypertile_unet
from modules.processing_info import create_infotext
from modules.processing_class import ( # pylint: disable=unused-import
@@ -199,6 +200,7 @@ def process_images(p: StableDiffusionProcessing) -> Processed | None:
script_callbacks.before_process_callback(p)
timer.process.record('pre')
attention_context.begin(shared.sd_model, p.steps)
if shared.cmd_opts.profile:
timer.startup.profile = True
@@ -232,6 +234,7 @@ def process_images(p: StableDiffusionProcessing) -> Processed | None:
results = process_images_inner(p)
finally:
attention_context.end()
script_callbacks.after_process_callback(p)
if p.override_settings_restore_afterwards: # restore opts to original state