mirror of
https://github.com/vladmandic/automatic
synced 2026-09-20 01:31:13 +02:00
add more job state updates and update history tab
Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
@@ -62,7 +62,7 @@ def download_civit_preview(model_path: str, preview_url: str):
|
||||
block_size = 16384 # 16KB blocks
|
||||
written = 0
|
||||
img = None
|
||||
jobid = shared.state.begin('Download')
|
||||
jobid = shared.state.begin('Download CivitAI')
|
||||
if pbar is None:
|
||||
pbar = p.Progress(p.TextColumn('[cyan]Download'), p.DownloadColumn(), p.BarColumn(), p.TaskProgressColumn(), p.TimeRemainingColumn(), p.TimeElapsedColumn(), p.TransferSpeedColumn(), p.TextColumn('[yellow]{task.description}'), console=shared.console)
|
||||
try:
|
||||
@@ -139,7 +139,7 @@ def download_civit_model_thread(model_name: str, model_url: str, model_path: str
|
||||
|
||||
res += f' size={round((starting_pos + total_size)/1024/1024, 2)}Mb'
|
||||
shared.log.info(res)
|
||||
jobid = shared.state.begin('Download')
|
||||
jobid = shared.state.begin('Download CivitAI')
|
||||
block_size = 16384 # 16KB blocks
|
||||
written = starting_pos
|
||||
global pbar # pylint: disable=global-statement
|
||||
|
||||
@@ -51,6 +51,7 @@ def preprocess_image(
|
||||
has_models:bool = False,
|
||||
):
|
||||
t0 = time.time()
|
||||
jobid = shared.state.begin('Preprocess')
|
||||
|
||||
# run resize before
|
||||
if p.resize_mode_before != 0 and p.resize_name_before != 'None':
|
||||
@@ -246,4 +247,5 @@ def preprocess_image(
|
||||
|
||||
t1 = time.time()
|
||||
process_timer.add('proc', t1-t0)
|
||||
shared.state.end(jobid)
|
||||
return processed_image, blended_image
|
||||
|
||||
@@ -160,6 +160,7 @@ class Processor():
|
||||
self.load_config[k] = v
|
||||
|
||||
def load(self, processor_id: str = None, force: bool = True) -> str:
|
||||
from modules.shared import state
|
||||
try:
|
||||
t0 = time.time()
|
||||
processor_id = processor_id or self.processor_id
|
||||
@@ -179,6 +180,7 @@ class Processor():
|
||||
cls = config[processor_id]['class']
|
||||
# log.debug(f'Control Processor loading: id="{processor_id}" class={cls.__name__}')
|
||||
debug(f'Control Processor config={self.load_config}')
|
||||
jobid = state.begin('Load processor')
|
||||
if 'DWPose' in processor_id:
|
||||
det_ckpt = 'https://download.openmmlab.com/mmdetection/v2.0/yolox/yolox_l_8x8_300e_coco/yolox_l_8x8_300e_coco_20211126_140236-d3bd2b23.pth'
|
||||
if 'Tiny' == config['DWPose']['model']:
|
||||
@@ -209,6 +211,7 @@ class Processor():
|
||||
else:
|
||||
self.model = cls() # class instance only
|
||||
t1 = time.time()
|
||||
state.end(jobid)
|
||||
self.processor_id = processor_id
|
||||
log.debug(f'Control Processor loaded: id="{processor_id}" class={self.model.__class__.__name__} time={t1-t0:.2f}')
|
||||
return f'Processor loaded: {processor_id}'
|
||||
|
||||
@@ -597,12 +597,9 @@ def control_run(state: str = '', # pylint: disable=keyword-arg-before-vararg
|
||||
if processed_image is not None and isinstance(processed_image, Image.Image):
|
||||
output_images.append(processed_image)
|
||||
|
||||
if is_generator:
|
||||
if is_generator and frame is not None and video is not None:
|
||||
image_txt = f'{output_image.width}x{output_image.height}' if output_image is not None else 'None'
|
||||
if video is not None:
|
||||
msg = f'Control output | {index} of {frames} skip {video_skip_frames} | Frame {image_txt}'
|
||||
else:
|
||||
msg = f'Control output | {index} of {len(inputs)} | Image {image_txt}'
|
||||
msg = f'Control output | {index} of {frames} skip {video_skip_frames} | Frame {image_txt}'
|
||||
yield (output_image, blended_image, msg) # result is control_output, proces_output
|
||||
|
||||
if video is not None and frame is not None:
|
||||
@@ -643,5 +640,7 @@ def control_run(state: str = '', # pylint: disable=keyword-arg-before-vararg
|
||||
if len(info_txt) > 0:
|
||||
html_txt = html_txt + infotext_to_html(info_txt[0])
|
||||
if is_generator:
|
||||
jobid = shared.state.begin('UI')
|
||||
yield (output_images, blended_image, html_txt, output_filename)
|
||||
shared.state.end(jobid)
|
||||
return (output_images, blended_image, html_txt, output_filename)
|
||||
|
||||
@@ -4,7 +4,7 @@ import threading
|
||||
from typing import Union
|
||||
from diffusers import StableDiffusionPipeline, StableDiffusionXLPipeline, FluxPipeline, StableDiffusion3Pipeline, ControlNetModel
|
||||
from modules.control.units import detect
|
||||
from modules.shared import log, opts, cmd_opts, listdir
|
||||
from modules.shared import log, opts, cmd_opts, state, listdir
|
||||
from modules import errors, sd_models, devices, model_quant
|
||||
from modules.processing import StableDiffusionProcessingControl
|
||||
|
||||
@@ -308,6 +308,7 @@ class ControlNet():
|
||||
log.error(f'Control {what} model load: id="{model_id}" unknown base model')
|
||||
return
|
||||
self.reset()
|
||||
jobid = state.begin(f'Load {what}')
|
||||
if model_path.endswith('.safetensors'):
|
||||
self.load_safetensors(model_id, model_path, cls, config)
|
||||
else:
|
||||
@@ -365,6 +366,7 @@ class ControlNet():
|
||||
t1 = time.time()
|
||||
self.model_id = model_id
|
||||
log.info(f'Control {what} model loaded: id="{model_id}" path="{model_path}" cls={cls.__name__} time={t1-t0:.2f}')
|
||||
state.end(jobid)
|
||||
return f'{what} loaded model: {model_id}'
|
||||
except Exception as e:
|
||||
log.error(f'Control {what} model load: id="{model_id}" {e}')
|
||||
|
||||
@@ -61,7 +61,7 @@ def reset_model():
|
||||
|
||||
|
||||
def load_model(variant:str=None, pipeline:str=None, text_encoder:str=None, text_encoder_2:str=None, feature_extractor:str=None, image_encoder:str=None, transformer:str=None):
|
||||
shared.state.begin('Load')
|
||||
shared.state.begin('Load FramePack')
|
||||
if variant is not None:
|
||||
if variant not in models.keys():
|
||||
raise ValueError(f'FramePack: variant="{variant}" invalid')
|
||||
|
||||
@@ -84,6 +84,7 @@ def worker(
|
||||
prompts = list(reversed(prompts))
|
||||
|
||||
def text_encode(prompt, i:int=None):
|
||||
jobid = shared.state.begin('TE Encode')
|
||||
pbar.update(task, description=f'text encode section={i}')
|
||||
t0 = time.time()
|
||||
torch.manual_seed(seed)
|
||||
@@ -102,9 +103,11 @@ def worker(
|
||||
llama_vec_n, llama_attention_mask_n = utils.crop_or_pad_yield_mask(llama_vec_n, length=512)
|
||||
sd_models.apply_balanced_offload(shared.sd_model)
|
||||
timer.process.add('prompt', time.time()-t0)
|
||||
shared.state.end(jobid)
|
||||
return llama_vec, llama_vec_n, llama_attention_mask, llama_attention_mask_n, clip_l_pooler, clip_l_pooler_n
|
||||
|
||||
def latents_encode(input_image, end_image):
|
||||
jobid = shared.state.begin('VAE Encode')
|
||||
pbar.update(task, description='image encode')
|
||||
# shared.log.debug(f'FramePack: image encode init={input_image.shape} end={end_image.shape if end_image is not None else None}')
|
||||
t0 = time.time()
|
||||
@@ -126,6 +129,7 @@ def worker(
|
||||
end_latent = None
|
||||
sd_models.apply_balanced_offload(shared.sd_model)
|
||||
timer.process.add('encode', time.time()-t0)
|
||||
shared.state.end(jobid)
|
||||
return start_latent, end_latent
|
||||
|
||||
def vision_encode(input_image, end_image):
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ def atomically_save_image():
|
||||
Image.MAX_IMAGE_PIXELS = None # disable check in Pillow and rely on check below to allow large custom image sizes
|
||||
while True:
|
||||
image, filename, extension, params, exifinfo, filename_txt, is_grid = save_queue.get()
|
||||
jobid = shared.state.begin('Save')
|
||||
jobid = shared.state.begin('Save image')
|
||||
shared.state.image_history += 1
|
||||
if len(exifinfo) > 2:
|
||||
with open(paths.params_path, "w", encoding="utf8") as file:
|
||||
|
||||
@@ -135,7 +135,7 @@ def interrogate(image, mode, caption=None):
|
||||
|
||||
|
||||
def interrogate_image(image, clip_model, blip_model, mode):
|
||||
jobid = shared.state.begin('Interrogate')
|
||||
jobid = shared.state.begin('Interrogate CLiP')
|
||||
try:
|
||||
if shared.sd_loaded:
|
||||
from modules.sd_models import apply_balanced_offload # prevent circular import
|
||||
|
||||
@@ -605,7 +605,7 @@ def sa2(question: str, image: Image.Image, repo: str = None):
|
||||
|
||||
def interrogate(question:str='', system_prompt:str=None, prompt:str=None, image:Image.Image=None, model_name:str=None, quiet:bool=False):
|
||||
global quant_args # pylint: disable=global-statement
|
||||
jobid = shared.state.begin('Interrogate')
|
||||
jobid = shared.state.begin('Interrogate LLM')
|
||||
t0 = time.time()
|
||||
quant_args = model_quant.create_config(module='LLM')
|
||||
model_name = model_name or shared.opts.interrogate_vlm_model
|
||||
|
||||
@@ -188,6 +188,7 @@ def load_image_encoder(pipe: diffusers.DiffusionPipeline, adapter_names: list[st
|
||||
|
||||
# load image encoder used by ip adapter
|
||||
if pipe.image_encoder is None or clip_loaded != f'{clip_repo}/{clip_subfolder}':
|
||||
jobid = shared.state.begin('Load encoder')
|
||||
try:
|
||||
if shared.sd_model_type == 'sd3':
|
||||
image_encoder = transformers.SiglipVisionModel.from_pretrained(clip_repo, torch_dtype=devices.dtype, cache_dir=shared.opts.hfcache_dir)
|
||||
@@ -209,6 +210,7 @@ def load_image_encoder(pipe: diffusers.DiffusionPipeline, adapter_names: list[st
|
||||
shared.log.error(f'IP adapter load: encoder="{clip_repo}/{clip_subfolder}" {e}')
|
||||
errors.display(e, 'IP adapter: type=encoder')
|
||||
return False
|
||||
shared.state.end(jobid)
|
||||
sd_models.move_model(pipe.image_encoder, devices.device)
|
||||
return True
|
||||
|
||||
@@ -217,6 +219,7 @@ def load_feature_extractor(pipe):
|
||||
# load feature extractor used by ip adapter
|
||||
if pipe.feature_extractor is None:
|
||||
try:
|
||||
jobid = shared.state.begin('Load extractor')
|
||||
if shared.sd_model_type == 'sd3':
|
||||
feature_extractor = transformers.SiglipImageProcessor.from_pretrained(SIGLIP_ID, torch_dtype=devices.dtype, cache_dir=shared.opts.hfcache_dir)
|
||||
else:
|
||||
@@ -231,6 +234,7 @@ def load_feature_extractor(pipe):
|
||||
shared.log.error(f'IP adapter load: extractor {e}')
|
||||
errors.display(e, 'IP adapter: type=extractor')
|
||||
return False
|
||||
shared.state.end(jobid)
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -137,6 +137,7 @@ def task_specific_kwargs(p, model):
|
||||
def set_pipeline_args(p, model, prompts:list, negative_prompts:list, prompts_2:typing.Optional[list]=None, negative_prompts_2:typing.Optional[list]=None, prompt_attention:typing.Optional[str]=None, desc:typing.Optional[str]='', **kwargs):
|
||||
t0 = time.time()
|
||||
shared.sd_model = sd_models.apply_balanced_offload(shared.sd_model)
|
||||
argsid = shared.state.begin('Params')
|
||||
apply_circular(p.tiling, model)
|
||||
args = {}
|
||||
has_vae = hasattr(model, 'vae') or (hasattr(model, 'pipe') and hasattr(model.pipe, 'vae'))
|
||||
@@ -445,4 +446,5 @@ def set_pipeline_args(p, model, prompts:list, negative_prompts:list, prompts_2:t
|
||||
else:
|
||||
_args[k] = v
|
||||
|
||||
shared.state.end(argsid)
|
||||
return _args
|
||||
|
||||
@@ -316,6 +316,7 @@ def vae_decode(latents, model, output_type='np', vae_type='Full', width=None, he
|
||||
|
||||
|
||||
def vae_encode(image, model, vae_type='Full'): # pylint: disable=unused-variable
|
||||
jobid = shared.state.begin('VAE Encode')
|
||||
import torchvision.transforms.functional as f
|
||||
if shared.state.interrupted or shared.state.skipped:
|
||||
return []
|
||||
@@ -331,6 +332,7 @@ def vae_encode(image, model, vae_type='Full'): # pylint: disable=unused-variable
|
||||
else:
|
||||
latents = taesd_vae_encode(image=tensor)
|
||||
devices.torch_gc()
|
||||
shared.state.end(jobid)
|
||||
return latents
|
||||
|
||||
|
||||
|
||||
@@ -1122,7 +1122,7 @@ def reload_model_weights(sd_model=None, info=None, op='model', force=False, revi
|
||||
if checkpoint_info is None:
|
||||
unload_model_weights(op=op)
|
||||
return None
|
||||
jobid = shared.state.begin('Load')
|
||||
jobid = shared.state.begin('Load model')
|
||||
if sd_model is None:
|
||||
sd_model = model_data.sd_model if op == 'model' or op == 'dict' else model_data.sd_refiner
|
||||
if sd_model is None: # previous model load failed
|
||||
|
||||
@@ -319,6 +319,7 @@ class StyleDatabase:
|
||||
if seeds is None or not isinstance(prompts, list):
|
||||
shared.log.error(f'Styles invalid seeds: {seeds}')
|
||||
return prompts, negatives
|
||||
jobid = shared.state.begin('Styles')
|
||||
parsed_positive = []
|
||||
parsed_negative = []
|
||||
for i in range(len(prompts)):
|
||||
@@ -331,6 +332,7 @@ class StyleDatabase:
|
||||
prompt = apply_styles_to_prompt(prompt, [self.find_style(x).negative_prompt for x in styles])
|
||||
prompt = apply_wildcards_to_prompt(prompt, [self.find_style(x).wildcards for x in styles], seeds[i])
|
||||
parsed_negative.append(prompt)
|
||||
shared.state.end(jobid)
|
||||
return parsed_positive, parsed_negative
|
||||
|
||||
def apply_styles_to_prompt(self, prompt, styles, wildcards:bool=True):
|
||||
|
||||
@@ -29,6 +29,7 @@ def save_video_atomic(images, filename, video_type: str = 'none', duration: floa
|
||||
except Exception as e:
|
||||
shared.log.error(f'Save video: cv2: {e}')
|
||||
return
|
||||
jobid = shared.state.begin('Save video')
|
||||
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
||||
if video_type.lower() in ['gif', 'png']:
|
||||
append = images.copy()
|
||||
@@ -56,6 +57,7 @@ def save_video_atomic(images, filename, video_type: str = 'none', duration: floa
|
||||
video_writer.write(img)
|
||||
size = os.path.getsize(filename)
|
||||
shared.log.info(f'Save video: file="{filename}" frames={len(frames)} duration={duration} fourcc={fourcc} size={size}')
|
||||
shared.state.end(jobid)
|
||||
|
||||
|
||||
def save_video(p, images, filename = None, video_type: str = 'none', duration: float = 2.0, loop: bool = False, interpolate: int = 0, scale: float = 1.0, pad: int = 1, change: float = 0.3, sync: bool = False):
|
||||
|
||||
@@ -15,7 +15,7 @@ def load_model(selected: models_def.Model):
|
||||
return ''
|
||||
sd_models.unload_model_weights()
|
||||
t0 = time.time()
|
||||
jobid = shared.state.begin('Load')
|
||||
jobid = shared.state.begin('Load model')
|
||||
|
||||
video_cache.apply_teacache_patch(selected.dit_cls)
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ def save_video(
|
||||
size = pixels.element_size() * pixels.numel()
|
||||
shared.log.debug(f'Video: video={mp4_video} export={mp4_frames} safetensors={mp4_sf} interpolate={mp4_interpolate}')
|
||||
shared.log.debug(f'Video: encode={t} raw={size} latent={pixels.shape} fps={mp4_fps} codec={mp4_codec} ext={mp4_ext} options="{mp4_opt}"')
|
||||
jobid = shared.state.begin('Save video')
|
||||
try:
|
||||
if stream is not None:
|
||||
stream.output_queue.push(('progress', (None, 'Saving video...')))
|
||||
@@ -124,4 +125,5 @@ def save_video(
|
||||
shared.log.error(f'Video save: raw={size} {e}')
|
||||
errors.display(e, 'video')
|
||||
timer.process.add('save', time.time()-t_save)
|
||||
shared.state.end(jobid)
|
||||
return t, output_video
|
||||
|
||||
Reference in New Issue
Block a user