Skip to content

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]

@pytorch-bot
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.

❌ 1 New Failure, 1 Cancelled Job, 1 Unrelated Failure

As of commit fbc366a with merge base 80250f8 (image):

NEW FAILURE - The following job has failed:

CANCELLED JOB - The following job was cancelled. Please retry:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

  • pull / test-binary-size-linux-gcc / linux-job (gh) (trunk failure)
    /pytorch/executorch/kernels/portable/cpu/op_stack.cpp:129:26: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘ssize_t’ {aka ‘long int’} [-Werror=sign-compare]

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
Copy link
Contributor

@jackzhxng jackzhxng left a comment

Choose a reason for hiding this comment

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

Thanks for the fix. Curious what speedup you saw from setting the num threads to your p-core count?

Copy link
Contributor

@kimishpatel kimishpatel left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution

@digantdesai
Copy link
Contributor

Generation tok/s: 15.131355739212273
Generation tok/s: 37.82838934803068

Why two lines?

@github-actions
Copy link

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
If you want the bot to never mark this PR stale again, add the no-stale label.
Stale pull requests will automatically be closed after 30 days of inactivity.

@github-actions github-actions bot added the stale PRs inactive for over 60 days label Oct 21, 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 stale PRs inactive for over 60 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants