ml.loggers.stdout

Defines a simple logger that writes to stdout.

I put a bunch of colors in here to make it easier to quickly find logged values of interest, but the colors can be disabled by setting the environment variable DISABLE_COLORS=1

class ml.loggers.stdout.StdoutLoggerConfig(name: str = '???', write_every_n_seconds: float | None = None, write_train_every_n_seconds: float | None = None, write_val_every_n_seconds: float | None = None, precision: int = 4)[source]

Bases: BaseLoggerConfig

precision: int = 4
ml.loggers.stdout.format_number(value: int | float, precision: int) str[source]
ml.loggers.stdout.as_str(value: Any, precision: int) str[source]
class ml.loggers.stdout.StdoutLogger(config: StdoutLoggerConfig)[source]

Bases: BaseLogger[StdoutLoggerConfig]

initialize(log_directory: Path) None[source]
get_log_dict(state: State, namespace: str | None) dict[str, Callable[[], Any]][source]
log_scalar(key: str, value: Callable[[], int | float | Tensor], state: State, namespace: str) None[source]

Logs a scalar value.

Parameters:
  • key – The key to log

  • value – The value to log

  • state – The current log state

  • namespace – The namespace to be logged

log_string(key: str, value: Callable[[], str], state: State, namespace: str) None[source]

Logs a string value.

Parameters:
  • key – The key to log

  • value – The value to log

  • state – The current log state

  • namespace – The namespace to be logged

write(state: State) None[source]

Writes the logs.

Parameters:

state – The current log state

default_write_every_n_seconds(state: State) float[source]

Returns the default write interval in seconds.

Parameters:

state – The state to get the default write interval for

Returns:

The default write interval, in seconds