Skip to content

BugFix: Modify TPS metric calculation. Add default cpu threads for hybrid CPU system. #11063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hebangwen
Copy link

Summary

This PR introduces two minor fix for Llama runner:

  1. Modify TPS metric calculation. Currently, TPS metric uses all token as the numerator, including the tokens from prefilling, not generated tokens. So we need to get the generated tokens by decoding, i.e. len(tokens) - len(prompt_tokens) - 1.
  2. Use a default CPU threads setting. In hybrid CPU system, using all CPU threads will make a pretty high inference latency due to high workloads in efficient cores. So I set num_threads to 4 as a general setting.

Release notes: examples

Test plan

CPU: Intel Core-14900KF. 8 performance cores and 16 efficient cores, with total 32 CPU threads.

System: Ubuntu 22.04

Testing command:

python -m examples.models.llama.runner.native \
--model qwen3-4b \
--pte qwen3-4b.pte \
--tokenizer ~/.cache/huggingface/hub/models--Qwen--Qwen3-4B/snapshots/531c80e289d6cff3a7cd8c0db8110231d23a6f7a/tokenizer.json \
--tokenizer_config ~/.cache/huggingface/hub/models--Qwen--Qwen3-4B/snapshots/531c80e289d6cff3a7cd8c0db8110231d23a6f7a/tokenizer_config.json \
--prompt "Write a hello-world programme in c++. Code is:" \
--params examples/models/qwen3/4b_config.json \
--max_len 20 \
-kv \
--temperature 0.8

without this PR

INFO:root:Looking for libcustom_ops_aot_lib.so in executorch/extension/llm/custom_ops
INFO:root:Loading custom ops library: executorch/extension/llm/custom_ops/libcustom_ops_aot_lib.so
Warning - given vocab_size in params is unequal to tokenizer vocab size.
[program.cpp:134] InternalConsistency verification requested but not available
 #include <iostream> using namespace std;

Prefill time: 0.20537757873535156
Generation tok/s: 0.19834848596001395
Response: [671, 997, 366, 9665, 29, 1667, 4473, 1460, 26]

with this PR

INFO:root:Looking for libcustom_ops_aot_lib.so in executorch/extension/llm/custom_ops
INFO:root:Loading custom ops library: executorch/extension/llm/custom_ops/libcustom_ops_aot_lib.so
Warning - given vocab_size in params is unequal to tokenizer vocab size.
[program.cpp:134] InternalConsistency verification requested but not available
 #include <iostream> using namespace std;

Prefill time: 0.29981303215026855
Generation tok/s: 15.131355739212273
Generation tok/s: 37.82838934803068
Response: [671, 997, 366, 9665, 29, 1667, 4473, 1460, 26]

Copy link

pytorch-bot bot commented May 22, 2025

🔗 Helpful Links

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

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

✅ No Failures

As of commit f2f59a9 with merge base d8c26ee (image):
💚 Looks good so far! There are no failures yet. 💚

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

@facebook-github-bot
Copy link
Contributor

Hi @hebangwen!

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!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-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 May 22, 2025
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@hebangwen
Copy link
Author

@pytorchbot label "release notes: examples"

@pytorch-bot pytorch-bot bot added the release notes: examples Changes to any of our example LLMs integrations, such as Llama3 and Llava label May 22, 2025
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. release notes: examples Changes to any of our example LLMs integrations, such as Llama3 and Llava
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants