Registry / ai-ml / torch-runstats

torch-runstats

JSON →
library0.2.0pypypiunverified

torch-runstats provides efficient running/online statistics (mean, standard deviation, variance, count) for PyTorch tensors. It's designed for scenarios where data arrives sequentially or cannot be stored in its entirety. The current version is 0.2.0, and its release cadence is slow, suggesting a mature and stable library for its specific functionality.

pip install torch-runstats
INSTALL
IMPORT
SIG · TORCH-RUNSTATS
T
torch-runstats
ai-mlpythonv0.2.0
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RunningMeanStd
from torch_runstats import RunningMeanStd
from torch_runstats import RunningMeanStd

This quickstart demonstrates how to initialize and use `RunningMeanStd` and `RunningStats` to track statistics for streaming data. It highlights the `shape` parameter for multi-dimensional data and implicitly shows `mask_nan=True` (default in v0.2.0) functionality for `RunningStats`.

import torch from torch_runstats import RunningMeanStd, RunningStats # Example with RunningMeanStd # Initialize for a feature vector of size 3 rms = RunningMeanStd(shape=(3,)) # Simulate incoming data x1 = torch.randn(10, 3) x2 = torch.randn(5, 3) rms.update(x1) rms.update(x2) print(f"Running Mean: {rms.mean}") print(f"Running Std Dev: {rms.std}") # Example with RunningStats (more general, includes variance and count) rs = RunningStats(shape=(2,)) y1 = torch.tensor([[1.0, 2.0], [3.0, 4.0]]) y2 = torch.tensor([[5.0, 6.0], [float('nan'), 8.0]]) # Demonstrating NaN masking rs.update(y1) rs.update(y2) print(f"Running Stats Mean: {rs.mean}") print(f"Running Stats Std Dev: {rs.std}") print(f"Running Stats Count: {rs.count}") # NaN in y2 is ignored by default
Debug
Known issues
gotchaThe `shape` parameter in `RunningMeanStd` and `RunningStats` initialization is crucial. It defines the shape of the *feature vector* for which statistics are computed, not the batch dimension. Incorrect `shape` leads to dimension mismatch errors during `update`.
fix
Ensure `shape` matches the last dimension(s) of your input tensors (e.g., for `N x F` tensor, `shape=(F,)`). If you want statistics per feature across multiple dimensions, adjust `shape` accordingly.
affects: >=0.1.0
gotchaBy default, from version 0.2.0, `mask_nan=True` for `RunningStats`, meaning `NaN` values in the input tensor are ignored when computing statistics and count. This might change behavior for users upgrading from v0.1.0 or expecting `NaN` to propagate.
fix
If you need `NaN` values to propagate or want to explicitly handle them, be aware of this default. For `RunningMeanStd`, `NaN`s will propagate, as it doesn't have a `mask_nan` parameter directly.
affects: >=0.2.0
gotchaStandard deviation (`std`) or variance can be zero or `NaN` if `RunningStats` or `RunningMeanStd` has not accumulated at least two distinct data points. Accessing `std` too early will result in `NaN` or `0`.
fix
Check `instance.count` before relying on `instance.std` if small sample sizes are possible. Handle `NaN` or `0` cases in downstream logic if your application requires valid `std` at all times.
affects: >=0.1.0
breakingThe dependency on `torch_scatter` was removed in version 0.2.0. While this primarily impacts internal implementation and reduces install size, users who might have indirectly relied on `torch_scatter` being present due to `torch-runstats` might find it missing.
fix
If your project directly or indirectly used `torch_scatter`, ensure it's explicitly listed in your project's dependencies if you upgrade `torch-runstats` to v0.2.0+.
affects: >=0.2.0
Upgrade
Version history
0.2.0latest on PyPI · released Nov 23, 2021
Audit
Dependencies
torchrequiredCore dependency for tensor operations and GPU acceleration.
Agent activity
28 hits · last 30 days
node
26
OpenAI (training)
1
Resources