vx-lang / vx-lang/Vx

llama2 benchmark copies carry the four numerical defects fixed in 997d3d87

Open
#322 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug testing
Dominant language
Rust
Stars
14
Forks
2
Avg merge
12h 42m
Merged PRs (30d)
61

Description

benchmarks/llama2_100.vx and benchmarks/llama2_scaling.vx carry all four of the numerical defects fixed in tests/backend/pass/llama2.vx by 997d3d87. Any timing these files have produced describes a model that is not Llama.

The defects, as they appear in the benchmark copies

Defect llama2_100.vx llama2_scaling.vx
Attention scale hardcoded 32.0 (// Assuming 256/8=32); stories15M head_size is 48 :170 :170
RMSNorm divisor hardcoded 256.0 / 512.0; actual dim is 288, hidden_dim 768 :232, :233, :329 :232, :233, :329
RoPE passes the global index instead of i % head_size, so every head past the first runs off the end of the frequency ladder :260 :260
Attention softmax written val - max_val.exp(), which parses as val - exp(max_val) — the method call binds tighter than the subtraction, so it is not a softmax present present

The fixes are mechanical and are exactly those in 997d3d87: derive dim_f, hidden_dim_f and head_size_f from the config with as f32 (available since hiraditya/Vx.1#240), compute head_dim = i % head_size before calling vx_get_rope_freq, and split the softmax into let shifted = val - max_val; shifted.exp().

Why this matters beyond tidiness

These are the files behind cargo vx-bench and the llama2 scaling numbers. The arithmetic cost per token is unchanged by the fixes — same matmul shapes, same loop trip counts — so previously published timings are not invalidated in magnitude. What is invalidated is any claim that the benchmark runs Llama inference: it runs a transformer with a broken softmax and a scrambled positional encoding, and produces degenerate text.

Two consequences to decide on:

  • If any benchmark result has been quoted anywhere as "Llama2 inference in Vx", it should be re-run after the fix so the claim and the computation agree.
  • benchmarks/ane_decode_bench.vx:199 passes a variable named head_dim to vx_get_rope_freq; worth confirming it is the within-head index and not the head size.

Suggested approach

Rather than patching three divergent copies of the same transformer, consider whether the benchmark files can import the kernels from one place. Four copies of this forward pass now exist (tests/backend/pass/llama2.vx, llama2_v2.vx, examples/llama.vx, and the two benchmarks), and they disagree with each other: llama2_v2.vx and examples/llama.vx compute the RoPE modulo correctly while the others do not. That divergence is the actual defect generator.

Verification bar for the fix: token-level parity against llama2.c on stories15M with greedy sampling from BOS, the same check 997d3d87 used (64/64 token ids identical).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing benchmarks/llama2_100.vx and benchmarks/llama2_scaling.vx with the corrected implementation in tests/backend/pass/llama2.vx and commit 997d3d87. Apply the corresponding numerical fixes, inspect benchmarks/ane_decode_bench.vx:199, and verify 64/64 token-id parity against llama2.c on stories15M with greedy sampling from BOS.

Written by the indexing model from the issue text.

Assessment

Domain
machine-learning, performance, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.