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-runstatsVerified import paths — ran on the pinned version, not inferred.
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`.
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.
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.
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.
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+.