Skip to main content

Log first, ask questions later.

Project description

noko

[api reference]

Log first, ask questions later.

noko is a numerical logging library designed for logging as many variables at once on as many timescales as possible.

The prototypical use case for noko is the following:

loss.backward()
noko.log_row("grad_step", locals(), level=noko.TRACE)
optimizer.step()

Which would produce a log file "grad_step.csv", with information on all local variables at every gradient step.

State of the Library

noko is quite useful already, but I'm continuing to refine the API, add new features as I find need of them, and fix bugs as I encounter them.

If you use the library at this time, you should expect API churn, so depend on a specific version.

The current recommended install method is:

pip install "git+https://github.com/krzentner/noko.git@v0.1.1#egg=noko[recommended]"

Key Idea

Most numerical logging libraries expect you to log one key at a time. noko instead expects you to log one "row" at a time, into a named "table". In the above example, the table is named "grad_step", and the row is all local variables.

noko will then go through all values in the row, and determine how to summarize them. For example, it will summarize a pytorch neural network using the min, max, mean, and std of each parameter, as well as those values for the gradient of each parameter (if available).

Once summarized, noko outputs that row to all noko backends that have a log level at least as sensitive as the provided level.

Backends

Always available:

  • newline delimited json (.ndjson)
  • comma separated values (.csv)
  • pprint (usually only used for stdout)

Requires optional dependencies:

  • tensorboard (will use torch.utils.tensorboard or tensorboardX or tf.summary)
  • parquet (requires pyarrow)

Row Summarization

noko runs a preprocessing step on each provided row before logging it. This pre-process is typically lossy, and summarizes large input arrays into a few scalars. This is necessary to be able to log all local variables, and is an unavoidable trade-off of noko's design. If you want to be able to exactly recover a value passed to noko, format it to a str or bytes first, and use the csv, ndjson, or parquet backends.

For built-in datatypes (dictionaries, lists, tuples), preprocessing runs recursively. For commonly used numerical libraries (numpy, pytorch), there are adapter modules to summarize common datatypes.

If you want your type to be flattened, you can define a custom summarizer. The standard way to do this is to use declare_summarizer, which can be used without modifying the source for the particular type being summarized.

Example of summarizing a custom type "MyPoint":

from noko import declare_summarizer, summarize, ScalarTypes

@declare_summarizer(MyPoint):
def summarize_mypoint(point, prefix: str, dst: dict[str, ScalarTypes]):
    # Include x and y fields directly
    dst[f"{prefix}.x"] = point.x
    dst[f"{prefix}.y"] = point.y
    # Recursively summarize metadata
    summarize(point.metadata, f"{prefix}.metadata", dst)

Sometimes you may have local variables that don't make sense to log in noko (e.g. long lists). In that case the recommended pattern is:

row = locals()
del row["my_long_list"]
noko.log_row("my_locals", row)

Extra Utilities

noko has some other useful tricks for reproducibility which can be accessed via calling noko.init_extra().

These include:

  • wandb sync and config logging (if wandb is installed).
  • automatically setting the global seed values for most libraries if present in the config
  • automatically creating a git commit of the current code on a separate branch noko-checkpoints, and adding diffs using that checkpoint to the log directory (requires GitPython to be installed).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

noko-0.3.0.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

noko-0.3.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file noko-0.3.0.tar.gz.

File metadata

  • Download URL: noko-0.3.0.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.14

File hashes

Hashes for noko-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b16b5a63cb5060727027c1cfdd1c3272e98185938bab84330f44a28cf14007f9
MD5 1c617c1459bb3b697ced2ca00adfe7f8
BLAKE2b-256 f422aad74c354f1a0fc089c82e53cf7410797b902e647a634f09cadb53810b06

See more details on using hashes here.

File details

Details for the file noko-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: noko-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.14

File hashes

Hashes for noko-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2eb691b1797eb1dce5a231fc56758e4edb438adacd796083509c0f8630dfd4f9
MD5 177ca9a32dac48c0cc4245c2f1ad69fc
BLAKE2b-256 73598610e092b4292a358e90ff92f6ef74fbc17888002cda66f573c1c39661cb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page