From f9480a1047f186b8562cdd1d2e0218ef48d27392 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Fri, 27 Jun 2025 09:04:32 -0400 Subject: [PATCH] add --trace for trace-logging and suppress empty torch logging Signed-off-by: Vladimir Mandic --- CHANGELOG.md | 2 ++ installer.py | 28 ++++++++++++++++++++++------ modules/loader.py | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 997a8f8ae..849ed50af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - **Changes** - Support Remote VAE with *Omnigen, Lumina 2 and PixArt* + - Add `--trace` command line param that enables trace logging - Use Diffusers version of *OmniGen* - Control move global settings to control elements -> control settings tab - Control add setting to run hires with or without control @@ -60,6 +61,7 @@ - Fix process batch with batch count - Fix process batch double image save - Fix unapply texture tiling + - Suppress torch empty logging ## Update for 2025-06-16 diff --git a/installer.py b/installer.py index 9d8016343..e86b89cd6 100644 --- a/installer.py +++ b/installer.py @@ -129,6 +129,13 @@ def setup_logging(): def get(self): return self.buffer + class LogFilter(logging.Filter): + def __init__(self): + super().__init__() + + def filter(self, record): + return len(record.getMessage()) > 2 + t_start = time.time() from functools import partial, partialmethod from logging.handlers import RotatingFileHandler @@ -147,7 +154,7 @@ def setup_logging(): logging.Logger.trace = partialmethod(logging.Logger.log, logging.TRACE) logging.trace = partial(logging.log, logging.TRACE) - level = logging.DEBUG if args.debug else logging.INFO + level = logging.DEBUG if (args.debug or args.trace) else logging.INFO log.setLevel(logging.DEBUG) # log to file is always at level debug for facility `sd` log.print = rprint global console # pylint: disable=global-statement @@ -173,22 +180,30 @@ def setup_logging(): while log.hasHandlers() and len(log.handlers) > 0: log.removeHandler(log.handlers[0]) + log_filter = LogFilter() # handlers rh = RichHandler(show_time=True, omit_repeated_times=False, show_level=True, show_path=False, markup=False, rich_tracebacks=True, log_time_format='%H:%M:%S-%f', level=level, console=console) + if args.trace: + rh.formatter = logging.Formatter('[%(module)s][%(pathname)s:%(lineno)d] %(message)s') + rh.addFilter(log_filter) rh.setLevel(level) log.addHandler(rh) fh = RotatingFileHandler(log_file, maxBytes=32*1024*1024, backupCount=9, encoding='utf-8', delay=True) # 10MB default for log rotation + if args.trace: + fh.formatter = logging.Formatter(f'%(asctime)s | {hostname} | %(name)s | %(levelname)s | %(module)s | | %(pathname)s:%(lineno)d | %(message)s') + else: + fh.formatter = logging.Formatter(f'%(asctime)s | {hostname} | %(name)s | %(levelname)s | %(module)s | %(message)s') + fh.addFilter(log_filter) + fh.setLevel(logging.DEBUG) + log.addHandler(fh) global log_rolled # pylint: disable=global-statement if not log_rolled and args.debug and not args.log: fh.doRollover() log_rolled = True - fh.formatter = logging.Formatter(f'%(asctime)s | {hostname} | %(name)s | %(levelname)s | %(module)s | %(message)s') - fh.setLevel(logging.DEBUG) - log.addHandler(fh) - rb = RingBuffer(100) # 100 entries default in log ring buffer + rb.addFilter(log_filter) rb.setLevel(level) log.addHandler(rb) log.buffer = rb.buffer @@ -1528,7 +1543,8 @@ def add_args(parser): group_log = parser.add_argument_group('Logging') group_log.add_argument("--log", type=str, default=os.environ.get("SD_LOG", None), help="Set log file, default: %(default)s") - group_log.add_argument('--debug', default=os.environ.get("SD_DEBUG",False), action='store_true', help="Run installer with debug logging, default: %(default)s") + group_log.add_argument('--debug', default=os.environ.get("SD_DEBUG",False), action='store_true', help="Run with debug logging, default: %(default)s") + group_log.add_argument("--trace", default=os.environ.get("SD_TRACE", False), action='store_true', help="Run with trace logging, default: %(default)s") group_log.add_argument("--profile", default=os.environ.get("SD_PROFILE", False), action='store_true', help="Run profiler, default: %(default)s") group_log.add_argument('--docs', default=os.environ.get("SD_DOCS", False), action='store_true', help="Mount API docs, default: %(default)s") group_log.add_argument("--api-log", default=os.environ.get("SD_APILOG", False), action='store_true', help="Log all API requests") diff --git a/modules/loader.py b/modules/loader.py index cb554c38e..674167d20 100644 --- a/modules/loader.py +++ b/modules/loader.py @@ -38,6 +38,7 @@ try: import torch._logging # pylint: disable=ungrouped-imports torch._logging._internal.DEFAULT_LOG_LEVEL = logging.ERROR # pylint: disable=protected-access torch._logging.set_logs(all=logging.ERROR, bytecode=False, aot_graphs=False, aot_joint_graph=False, ddp_graphs=False, graph=False, graph_code=False, graph_breaks=False, graph_sizes=False, guards=False, recompiles=False, recompiles_verbose=False, trace_source=False, trace_call=False, trace_bytecode=False, output_code=False, kernel_code=False, schedule=False, perf_hints=False, post_grad_graphs=False, onnx_diagnostics=False, fusion=False, overlap=False, export=None, modules=None, cudagraphs=False, sym_node=False, compiled_autograd_verbose=False) # pylint: disable=protected-access + import torch._dynamo torch._dynamo.config.verbose = False # pylint: disable=protected-access torch._dynamo.config.suppress_errors = True # pylint: disable=protected-access except Exception as e: