Skip to content

Added benchmark for LLaMA 3 model for attention tests#3930

Merged
howardzhang-cv merged 34 commits intomainfrom
gh/howardzhang-cv/20/head
Mar 9, 2026
Merged

Added benchmark for LLaMA 3 model for attention tests#3930
howardzhang-cv merged 34 commits intomainfrom
gh/howardzhang-cv/20/head

Conversation

@howardzhang-cv
Copy link
Contributor

@howardzhang-cv howardzhang-cv commented Feb 21, 2026

Stack from ghstack (oldest at bottom):

Summary

  • Added new benchmark for new low precision attention API
  • uses Llama3-8b model, prefill
  • 2-phase test
    • perplexity using the WikiText-2 test set
    • runtime over different sequence lengths (1024 -> 131072)
  • Can set baseline and test models between different backends: (fa2, fa3, fa3_fp8, fa4, fa4_fp8)
  • has options to control torch.compile usage, warmup_iters, sequence length, number of runtime test iterations, rope fusion

Example Run

python benchmarks/prototype/attention/eval_llama3_model.py --baseline fa3 --test fa3_fp8

[ghstack-poisoned]
[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Feb 21, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/3930

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

✅ No Failures

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

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

howardzhang-cv added a commit that referenced this pull request Feb 21, 2026
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: 528c2ec
Pull-Request: #3930
@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 Feb 21, 2026
@howardzhang-cv howardzhang-cv marked this pull request as draft February 21, 2026 02:49
# =============================================================================


def load_wikitext2_tokens(tokenizer, seq_len: int):
Copy link
Contributor

@namgyu-youn namgyu-youn Feb 21, 2026

Choose a reason for hiding this comment

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

We don't have to define wiki-text tokenizer here. Instead, we can run lm-eval directly like

# Calibrate
evaluator.simple_evaluate(
HFLM(pretrained=model, tokenizer=tokenizer),
tasks=tasks,
limit=limit,
batch_size=1,
)
quantize_(model, config_class(base_config, step="convert"), filter_fn=filter_fn)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I changed it to use this instead

return chunks


def compute_perplexity(model, chunks, device: str, backend_name: str) -> float:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also not needed. See above comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

return math.exp(avg_loss)


def benchmark_runtime(
Copy link
Contributor

@namgyu-youn namgyu-youn Feb 21, 2026

Choose a reason for hiding this comment

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

Q. Can we compute forward pass latency using vLLM directly, similar to e2e?

vllm bench throughput --model $OUTPUT_DIR --dtype bfloat16 $PREFILL_ARGS 2>&1 | tee -a "$LOG_FILE"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately not. Unlike the other quantization APIs in TorchAO, the low precision attention path requires replacing F.scaled_dot_product_attention with a specific attention backend capable of low precision attention (e.g. FA3/4). So we need to ensure that our model calls F.SDPA.

}

RANDOM_SEED = 42
DEFAULT_MODEL_ID = "meta-llama/Llama-3.1-8B"
Copy link
Contributor

@namgyu-youn namgyu-youn Feb 21, 2026

Choose a reason for hiding this comment

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

What does DEFAULT_MODEL_ID do? Should it be called by args (--model_id) default directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 23, 2026
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: 528c2ec
Pull-Request: pytorch#3930
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 24, 2026
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: 528c2ec
Pull-Request: pytorch#3930
[ghstack-poisoned]
[ghstack-poisoned]
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 25, 2026
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: 240c54f
Pull-Request: pytorch#3930
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 25, 2026
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: 240c54f
Pull-Request: pytorch#3930
[ghstack-poisoned]
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Feb 25, 2026
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: c635ea3
Pull-Request: #3930
@howardzhang-cv howardzhang-cv added benchmark module: not user facing Use this tag if you don't want this PR to show up in release notes labels Feb 25, 2026
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 25, 2026
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: c635ea3
Pull-Request: pytorch#3930
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 25, 2026
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: c635ea3
Pull-Request: pytorch#3930
[ghstack-poisoned]
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Feb 25, 2026
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: e397044
Pull-Request: #3930
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 25, 2026
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: e397044
Pull-Request: pytorch#3930
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 26, 2026
Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: e397044
Pull-Request: pytorch#3930
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Mar 2, 2026
Benchmark script for evaluating FP8 attention on LLaMA 3 models.
Measures perplexity on WikiText-2 and runtime performance across
sequence lengths with and without RoPE fusion.

ghstack-source-id: 859f523
Pull-Request: pytorch#3930
[ghstack-poisoned]
[ghstack-poisoned]
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Mar 2, 2026
Benchmark script for evaluating FP8 attention on LLaMA 3 models.
Measures perplexity on WikiText-2 and runtime performance across
sequence lengths with and without RoPE fusion.

ghstack-source-id: b24335c
Pull-Request: pytorch#3930
[ghstack-poisoned]
[ghstack-poisoned]
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Mar 3, 2026
Benchmark script for evaluating FP8 attention on LLaMA 3 models.
Measures perplexity on WikiText-2 and runtime performance across
sequence lengths with and without RoPE fusion.

ghstack-source-id: c3386ef
Pull-Request: pytorch#3930
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Mar 3, 2026
Benchmark script for evaluating FP8 attention on LLaMA 3 models.
Measures perplexity on WikiText-2 and runtime performance across
sequence lengths with and without RoPE fusion.

ghstack-source-id: c3386ef
Pull-Request: pytorch#3930
Copy link
Contributor

@namgyu-youn namgyu-youn left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for addressing all the comments!

[ghstack-poisoned]
[ghstack-poisoned]
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Mar 3, 2026
Benchmark script for evaluating FP8 attention on LLaMA 3 models.
Measures perplexity on WikiText-2 and runtime performance across
sequence lengths with and without RoPE fusion.

ghstack-source-id: c3386ef
Pull-Request: pytorch#3930
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Mar 5, 2026
Benchmark script for evaluating FP8 attention on LLaMA 3 models.
Measures perplexity on WikiText-2 and runtime performance across
sequence lengths with and without RoPE fusion.

ghstack-source-id: c3386ef
Pull-Request: pytorch#3930
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Mar 5, 2026
Benchmark script for evaluating FP8 attention on LLaMA 3 models.
Measures perplexity on WikiText-2 and runtime performance across
sequence lengths with and without RoPE fusion.

ghstack-source-id: c3386ef
Pull-Request: pytorch#3930
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@howardzhang-cv howardzhang-cv changed the base branch from gh/howardzhang-cv/20/base to main March 9, 2026 22:18
@howardzhang-cv howardzhang-cv merged commit 21fc296 into main Mar 9, 2026
36 checks passed
@howardzhang-cv howardzhang-cv deleted the gh/howardzhang-cv/20/head branch March 9, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmark CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: not user facing Use this tag if you don't want this PR to show up in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants