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 exactlyb(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-writtenObservablefor an activation, gradient, loss, or custom source.Filteris 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 byobservable.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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file observable_library-0.1.0.tar.gz.
File metadata
- Download URL: observable_library-0.1.0.tar.gz
- Upload date:
- Size: 25.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75e647ca9e4fe84a09a13cf2c1073c14e696d1f5acab9cd34b20dfbe5fdfdfc5
|
|
| MD5 |
7ddb62a075bca0534a8ce0372621e159
|
|
| BLAKE2b-256 |
2ba3a6f1d821b6304935bd87aa48aded9cf73d1e1b15433ccae1b8cb4527e073
|
Provenance
The following attestation bundles were made for observable_library-0.1.0.tar.gz:
Publisher:
publish.yml on MetaCircleAI/Observable-Library
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
observable_library-0.1.0.tar.gz -
Subject digest:
75e647ca9e4fe84a09a13cf2c1073c14e696d1f5acab9cd34b20dfbe5fdfdfc5 - Sigstore transparency entry: 2205316524
- Sigstore integration time:
-
Permalink:
MetaCircleAI/Observable-Library@763d1ff9e5531f30a9dd3c9ddab2e33c30df84d0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MetaCircleAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@763d1ff9e5531f30a9dd3c9ddab2e33c30df84d0 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file observable_library-0.1.0-py3-none-any.whl.
File metadata
- Download URL: observable_library-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e439a59008640e297fa8b718d714285baf571b30cf8b9ce8a6b1eaff4325deae
|
|
| MD5 |
b01e6a550ccfce16b8a164b498b216c1
|
|
| BLAKE2b-256 |
d62526403ffe757bed4e8205510db3e8d9e3fdb46ac913e08ff1c8f95cece015
|
Provenance
The following attestation bundles were made for observable_library-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on MetaCircleAI/Observable-Library
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
observable_library-0.1.0-py3-none-any.whl -
Subject digest:
e439a59008640e297fa8b718d714285baf571b30cf8b9ce8a6b1eaff4325deae - Sigstore transparency entry: 2205316538
- Sigstore integration time:
-
Permalink:
MetaCircleAI/Observable-Library@763d1ff9e5531f30a9dd3c9ddab2e33c30df84d0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MetaCircleAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@763d1ff9e5531f30a9dd3c9ddab2e33c30df84d0 -
Trigger Event:
workflow_dispatch
-
Statement type: