Skip to main content

Observable Library

Headless Python package for generating and computing training observables.

The source checkout includes the current API reference and a practical usage guide.

Core boundary:

model -> generate observables -> compute values -> return values

No CLI, web UI, notebook product surface, or agent skill is part of the core package.

Install

Python 3.10, 3.11, and 3.12 are supported. Python 3.13 is advisory until its CI lane is promoted to required. Runtime dependencies are numpy>=1.24 and torch>=2.4.1.

Install the published package:

python -m pip install observable-library

Install from a checkout:

python -m pip install .

For development, install the quality and test tools too:

python -m pip install -e ".[dev]"

Licensed under Apache-2.0. Attribution: Jinxin.

Quickstart

import torch
import observable_library as ol

torch.manual_seed(0)
model = torch.nn.Sequential(torch.nn.Linear(2, 1))
optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
observables = ol.generate(model, reductions=["l2_norm"])

source = ol.HookSource(model)
source.attach()
storage = ol.LocalStorage("./run")
runtime = ol.Runtime(
    observables=ol.Pack(observables),
    source=source,
    sink=storage,
    budget=ol.Budget(max_compute_ms=10.0),
)

inputs = torch.tensor([[1.0, -1.0], [0.5, 0.25]])
targets = torch.tensor([[0.5], [-0.25]])
optimizer.zero_grad()
predictions = model(inputs)
loss = torch.nn.functional.mse_loss(predictions, targets)
loss.backward()
values = runtime.observe(step=0)
assert values
observable_id, value = next(iter(values.items()))
stored_value = ol.query(storage, observable_id, step=0)
print(f"{observable_id}: {stored_value}")
optimizer.step()
source.detach()

generate() currently creates observables for every model.named_parameters() entry; it does not generate activation or gradient observables. The Quickstart attaches hooks to show the complete online lifecycle, but parameter-only generated observables read parameters directly and do not require source.attach().

See the shipped examples:

Hand-written Observable construction is an advanced API. Generated and custom observables can share one Pack. This example observes generated parameter norms together with one causal gradient norm, after backward but before the optimizer updates the model:

import torch
import observable_library as ol

torch.manual_seed(3)
model = torch.nn.Sequential(torch.nn.Linear(2, 1))
optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
inputs = torch.tensor([[1.0, -1.0], [0.5, 0.25]])
targets = torch.tensor([[0.5], [-0.25]])

source = ol.HookSource(model)
source.attach()
parameter_observables = ol.generate(model, reductions=["l2_norm"])
gradient_observable = ol.Observable(
    spec=ol.ObservableSpec(source="grad.0.weight", selector="all", reduction="l2_norm"),
    compute=lambda tensors, _context: tensors["grad.0.weight"].norm(),
)
observables = [*parameter_observables, gradient_observable]
runtime = ol.Runtime(observables=ol.Pack(observables), source=source)

optimizer.zero_grad()
loss = torch.nn.functional.mse_loss(model(inputs), targets)
loss.backward()
values = runtime.observe(step=0)
assert values[gradient_observable.spec.id] > 0
assert all(item.spec.id in values for item in parameter_observables)
optimizer.step()
source.detach()

Practical Behavior

  • transforms=["a", "b"] executes exactly b(a(tensor)), then the selected reduction. It does not generate transform subsets or permutations. Transform names are validated when observables are generated; tensor shape and dtype compatibility are checked only when they run.
  • generate() has no public source allowlist. Filter the returned list to reduce Runtime work, or add a hand-written Observable for an activation, gradient, loss, or custom source.
  • Filter is an extension foundation. Users can subclass it and compose filters with & and |, but these filters act on an existing observable list. Built-in generation-stage template filters are not implemented.
  • Runtime.observe() returns values keyed by observable.spec.id, a stable 16-character identifier derived from the full spec. query() supports exact id and step readback only; there is no lookup by display name, source, or reduction.
  • The current public contract supports only selector="all". See the practical usage guide for hook lifetime, source freshness, custom observable, transform, filter, and identity details.

Offline File Source

import numpy as np
import torch
import observable_library as ol

model = torch.nn.Linear(2, 1)
observables = ol.generate(model, reductions=["sum"])
payload = {
    f"param.{name}": parameter.detach().numpy()
    for name, parameter in model.named_parameters()
}
np.savez("tensors.npz", **payload)

source = ol.FileSource("tensors.npz")
runtime = ol.Runtime(observables=observables, source=source)
values = runtime.observe(step=0)

ValueSink is the storage contract. Built-in LocalStorage is only a convenience sink: SQLite metadata plus NumPy NPZ payloads. It supports exact observable id and step readback only. It does not provide a general query API. Future Parquet support belongs in an optional backend or custom ValueSink; it is not built into the current package.

Current Support

The current package supports parameter observable generation, online HookSource, and offline CheckpointSource and FileSource through the shared Runtime. It also supports optional ValueSink and LocalStorage with exact id/step readback and basic budget/frequency scheduling.

Planned capabilities include generation-stage template filters, equivalence and cost calibration, multi-run comparison, and research workflows. The current package has no CLI, UI, or general query surface.

Validation

The examples use small in-memory inputs and do not download datasets.

ruff format --check .
ruff check .
mypy observable_library
python -m pytest tests -q
python -m pytest tests/performance -q -s
python -m pytest tests/integration -q
python -m build

Metadata

Release files for observable-library 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for observable-library 0.1.0
File Size Uploaded Provenance Actions
observable_library-0.1.0.tar.gz 25.1 kB With provenance Details for observable_library-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for observable-library 0.1.0
File Interpreter ABI Platform Actions
observable_library-0.1.0-py3-none-any.whl Python 3 none any Details for observable_library-0.1.0-py3-none-any.whl

Total release size: 50.4 kB

Release files / observable_library-0.1.0.tar.gz

Download URL observable_library-0.1.0.tar.gz
Size 25.1 kB
Tags Source
SHA-256 checksum
How to use checksums
75e647ca9e4fe84a09a13cf2c1073c14e696d1f5acab9cd34b20dfbe5fdfdfc5
BLAKE2b-256 checksum
How to use checksums
2ba3a6f1d821b6304935bd87aa48aded9cf73d1e1b15433ccae1b8cb4527e073
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 20, 2026.

Transparency log

Release files / observable_library-0.1.0-py3-none-any.whl

Download URL observable_library-0.1.0-py3-none-any.whl
Size 25.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e439a59008640e297fa8b718d714285baf571b30cf8b9ce8a6b1eaff4325deae
BLAKE2b-256 checksum
How to use checksums
d62526403ffe757bed4e8205510db3e8d9e3fdb46ac913e08ff1c8f95cece015
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 20, 2026.

Transparency log

Security for observable-library 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for observable_library-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page