Skip to content

Count infinite histogram samples once in edge buckets - #5361

Open
sylvesterkaczmarek wants to merge 1 commit into
NVIDIA:mainfrom
sylvesterkaczmarek:fix/histogram-infinity-counts-20261004
Open

sylvesterkaczmarek wants to merge 1 commit into
NVIDIA:mainfrom
sylvesterkaczmarek:fix/histogram-infinity-counts-20261004

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Fixes #5360.

Description

Remove the extra degenerate infinity bucket from get_std_histogram_buckets: those samples have already been included in the first or last bucket. Make the positive-infinity check independent of the negative-infinity check so a one-bin histogram can include both endpoints.

The result retains the requested number of bins and counts each infinite sample once. Finite input handling, explicit-range behavior and NaN exclusion remain unchanged. Automatic range inference with infinite inputs is not changed.

Validation

Ten new cases cover negative/positive infinities separately and together, one-bin and all-infinite inputs, finite controls, NaNs, out-of-range finite values, empty inputs, read-only strided views and nonmutation. A dataframe-to-global-histogram check verifies two client datasets produce counts [3, 1, 3], totaling their seven nonmissing samples.

  • New tests against unchanged main: 7 failed, 3 passed.
  • Fixed revision, complete common-statistics test directory: 83 passed, 12 skipped.
  • Scoped equivalents of the style checks in ./runtest.sh -s passed on both changed files: Black, isort and flake8. git diff --check passed.
python -m pytest -o addopts= -q tests/unit_test/app_common/statistics/

Tested on macOS with Python 3.12.11 and NumPy 2.5.3. The full runtest.sh suite and a deployed federated job were not run. No dependency, workflow or configuration changes.

Types of changes

  • Non-breaking correction to histogram counts.
  • New regression tests added.
  • Targeted statistics tests and scoped style checks passed locally.

Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
@sylvesterkaczmarek

Copy link
Copy Markdown
Author

@yhwen @IsaacYangSLA The histogram regression tests and common-statistics suite pass locally (83 passed, 12 skipped), along with scoped style checks. Could you review this and trigger /build when appropriate?

@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Fixes histogram bucket counting for infinite values.

The PR should not merge until global histograms retain counts from clients with differing infinity presence.

Findings

  1. P1 Mixed clients lose histogram counts ▶

Summary

The PR removes a duplicate infinity bucket, counts both infinities in a one-bin histogram, and adds local and two-client regression tests.

  • The global histogram correction remains incomplete when clients have different infinity patterns.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A["Client A: infinite outer edges"] --> M["Aggregate by exact bin range"]
    B["Client B: finite outer edges"] --> M
    M --> D["Unmatched edge counts discarded"]
Loading

Reviews (1) · Last reviewed commit: "Count infinite histogram samples once in..."

bucket_low_value = float("-inf")
bucket_sample_count += num_neginf
elif bucket_count == len(counts) - 1 and num_posinf > 0:
if bucket_count == len(counts) - 1 and num_posinf > 0:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Mixed clients lose histogram counts

When one client has infinite values and another does not, their outer bins have different boundaries. For example, with three bins over (-1, 1), [-inf, 0, inf] produces infinite outer edges, while [-1, 0, 1] produces finite ones. accumulate_hists matches bins by exact boundaries and keeps only the first client's bins, so the combined histogram counts four of the six samples. The new two-client test gives both clients the same infinity pattern and does not catch this case.

Knowledge Base Used: Built-in application components

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Federated statistics histograms count infinite samples twice

1 participant