Skip to content

Use FP32 working precision for Half LLM sampling - #24021

Closed
HowieYin wants to merge 1 commit into
pytorch:mainfrom
HowieYin:fix-half-sampler-precision
Closed

HowieYin wants to merge 1 commit into
pytorch:mainfrom
HowieYin:fix-half-sampler-precision

Conversation

@HowieYin

@HowieYin HowieYin commented Oct 20, 2026 •

Copy link
Copy Markdown

Summary

Half sampling accumulates softmax and CDF in FP16. With 32768 zero logits, probabilities sum to 16 instead of 1; seed 42 returns token 694 instead of the FP32 result, 11111.

Use the existing FP32 buffer, as in the BF16 path (#22094), for temperature scaling, softmax and sampling. Keep greedy sampling on the original logits.

Test plan

Locally compiled test_sampler.cpp with libtorch and GoogleTest on macOS arm64: ./sampler_test — 11 passed. The three new large-vocabulary tests fail before the fix and pass after it, covering multinomial, top-p and top-k over repeated calls.

Portable C++17 build with ASan/UBSan: ./portable_sampler_test — 3 passed. clang-format 18.1.3 and git diff --check passed.

AI assistance: TRAE.

cc @larryliu0820 @mergennachin @cccclai @helunwencser @jackzhxng @digantdesai

@pytorch-bot

pytorch-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 24 Awaiting Approval

As of commit e786a10 with merge base 03ddd8b (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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

@meta-cla

meta-cla Bot commented Oct 20, 2026

Copy link
Copy Markdown

Hi @HowieYin!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@linux-foundation-easycla

Copy link
Copy Markdown

CLA Not Signed

@HowieYin

Copy link
Copy Markdown
Author

@pytorchbot label "release notes: llm" "module: llm" "bug"

@pytorch-bot pytorch-bot Bot added bug module: llm Issues related to LLM examples and apps, and to the extensions/llm/ code release notes: llm Changes to llm utilities labels Oct 20, 2026
@HowieYin HowieYin closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug module: llm Issues related to LLM examples and apps, and to the extensions/llm/ code release notes: llm Changes to llm utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant