Skip to content

Conversation

@seyeong-han
Copy link
Contributor

Summary

Fixes a critical bug where aggregate_sampling_time_ms in the Stats struct was not initialized, causing it to contain garbage data from uninitialized memory.

Problem

The aggregate_sampling_time_ms member variable was declared without initialization:

long aggregate_sampling_time_ms;  // uninitialized!

This resulted in absurd sampling time reports like:

Sampling time over 68 tokens: 8433599.048000 (seconds)  // ~97.5 days!

The actual sampling time should have been milliseconds, not millions of seconds. Since the code accumulates timing data onto this variable (stats_.aggregate_sampling_time_ms += ...), the garbage initial value propagated through all calculations.

Solution

Initialize the variable to zero in both locations:

long aggregate_sampling_time_ms = 0;

Impact

After this fix, sampling time metrics will report realistic values (e.g., 0.010-0.100 seconds for typical token generation) instead of garbage values.

@pytorch-bot
Copy link

pytorch-bot bot commented Nov 13, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/15820

Note: Links to docs will display an error until the docs builds have been completed.

❌ 5 New Failures

As of commit 74639c6 with merge base c247604 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 13, 2025
@github-actions
Copy link

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a critical bug where the aggregate_sampling_time_ms member variable in the Stats struct was uninitialized, causing it to accumulate garbage values from uninitialized memory. The fix initializes the variable to 0 at declaration in both affected files.

  • Initializes aggregate_sampling_time_ms = 0 in the main Stats struct definition
  • Applies the same fix to a duplicate Stats struct in the Qualcomm example code

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
extension/llm/runner/stats.h Initialize aggregate_sampling_time_ms to 0 in the main Stats struct
examples/qualcomm/qaihub_scripts/llama/runner/runner.h Initialize aggregate_sampling_time_ms to 0 in the Qualcomm-specific Stats struct

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mergennachin mergennachin merged commit 3826f44 into pytorch:main Nov 17, 2025
145 of 152 checks passed
jirioc pushed a commit to nxp-upstream/executorch that referenced this pull request Dec 19, 2025
…#15820)

## Summary
Fixes a critical bug where `aggregate_sampling_time_ms` in the `Stats`
struct was not initialized, causing it to contain garbage data from
uninitialized memory.

## Problem
The `aggregate_sampling_time_ms` member variable was declared without
initialization:
```cpp
long aggregate_sampling_time_ms;  // uninitialized!
```
This resulted in absurd sampling time reports like:

```
Sampling time over 68 tokens: 8433599.048000 (seconds)  // ~97.5 days!
```

The actual sampling time should have been milliseconds, not millions of
seconds. Since the code accumulates timing data onto this variable
(`stats_.aggregate_sampling_time_ms += ...`), the garbage initial value
propagated through all calculations.

## Solution

Initialize the variable to zero in both locations:

`long aggregate_sampling_time_ms = 0;`

## Impact

After this fix, sampling time metrics will report realistic values
(e.g., 0.010-0.100 seconds for typical token generation) instead of
garbage values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants