easydel.utils.helpers#

class easydel.utils.helpers.ColorFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]#

Bases: Formatter

format(record: LogRecord) str[source]#

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

class easydel.utils.helpers.DummyStream[source]#

Bases: object

A null device-like stream that discards all writes.

flush(*args, **kwargs)[source]#
write(*args, **kwargs)[source]#
class easydel.utils.helpers.LazyLogger(name: str, level: Optional[int] = None)[source]#

Bases: object

class easydel.utils.helpers.Timer(name)[source]#

Bases: object

elapsed_time(reset=True)[source]#
reset()[source]#
start()[source]#
stop()[source]#
class easydel.utils.helpers.Timers(use_wandb, tensorboard_writer: Any)[source]#

Bases: object

log(names, normalizer=1.0, reset=True)[source]#
timed(name, log=True, reset=True)[source]#
write(names, iteration, normalizer=1.0, reset=False)[source]#
easydel.utils.helpers.capture_time()[source]#

A context manager that measures elapsed time.

Returns

Callable that returns the current elapsed time while the context is active, or the final elapsed time after the context exits.

Example

with capture_time() as get_time:

# Do some work print(f”Current time: {get_time()}”)

print(f”Final time: {get_time()}”)

easydel.utils.helpers.check_bool_flag(name: str, default: bool = True) bool[source]#
easydel.utils.helpers.get_cache_dir() Path[source]#
easydel.utils.helpers.get_logger(name: str, level: Optional[int] = None) LazyLogger[source]#

Function to create a lazy logger that only initializes when first used.

Parameters
  • name (str) – The name of the logger.

  • level (Optional[int]) – The logging level. Defaults to environment variable LOGGING_LEVEL_ED or “INFO”.

Returns

A lazy logger instance that initializes on first use.

Return type

LazyLogger

easydel.utils.helpers.quiet(suppress_stdout=True, suppress_stderr=True)[source]#

Context manager to temporarily suppress stdout and/or stderr output. :param suppress_stdout: Whether to suppress stdout :type suppress_stdout: bool :param suppress_stderr: Whether to suppress stderr :type suppress_stderr: bool

Usage:
with suppress_output():

# Code that generates unwanted output print(“This won’t be displayed”)

Note

This will suppress ALL output to the specified streams within the context, including output from C extensions and system calls.

easydel.utils.helpers.set_loggers_level(level: int = 30)[source]#

Function to set the logging level of all loggers to the specified level.

Parameters

level – int: The logging level to set. Defaults to logging.WARNING.