Skip to content

Remove "first token must be BOS" restriction - #2153

Merged
ggerganov merged 1 commit into
ggml-org:masterfrom
oobabooga:master
Jul 9, 2023
Merged

ggerganov merged 1 commit into
ggml-org:masterfrom
oobabooga:master

Conversation

@oobabooga

Copy link
Copy Markdown
Contributor

Currently, the llama_eval_internal function requires the first token in the tokens array to be a BOS token (=1).

I believe that this is not necessary, as

  1. Intentionally removing the BOS token can make generations more creative. With the BOS token, the prompt is associated to text at the beginning of a new document in the training dataset. Without it, the prompt can be associated to text at any location.

In other words, the BOS token adds a "beginning of document" bias that can be optionally removed.

  1. This is not desirable while evaluating the model perplexity, since in most cases the sequence of ids will be mid-document.

I originally encountered the "first token must be BOS" error while trying to evaluate llama.cpp using a transformers wrapper that I am working on here. The evaluation fails because the first token in the sequence provided by my code, which is based on this tutorial, is not BOS.

@ggerganov ggerganov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I added this check since the initial batch of OpenLLaMA models suffered significantly if the first token was not BOS.
I haven't checked what happened later - have some vague memory that this issue was resolved with later releases, so it is probably not needed any more.

@ggerganov
ggerganov merged commit 1d16309 into ggml-org:master Jul 9, 2023
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
phuongncn pushed a commit to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4 that referenced this pull request Apr 28, 2026
ljubomirj pushed a commit to ljubomirj/llama.cpp that referenced this pull request May 6, 2026
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
bong-water-water-bong pushed a commit to bong-water-water-bong/llama.cpp that referenced this pull request Sep 8, 2026
…ebind proposal

Smaller route than Option A of BATCHED-FLASH-IMPL-PLAN.md: per-stream
binding-offset rebinding of the existing decode-split kernel. DispatchBinding
is value+byte-range and transients already bind as inputs, so contiguous
batched tensors need NO copy kernel and NO kernel rewrite — matcher emits
N×rows dispatches with stream offsets (s*nb[3]) and the same partial/q8
transients. Lane-level open items: completion-counter scaling, transient
sharing under rows×streams, q8 alternate per stream, mask column semantics.
The np4 cache_v_l0 view abort stays a separate item.
bong-water-water-bong pushed a commit to bong-water-water-bong/llama.cpp that referenced this pull request Sep 8, 2026
… (offset-rebind)

Batched (ne3>1) decode-split flash matcher: per-(stream,row) dispatches with
per-stream s*nb[3] offset rebinding of the EXISTING kernel — no kernel change
(BATCHED-FLASH-OFFSET-PROPOSAL.md). Contiguity-gated stream dim; per-dispatch
partial/counter transients (sharing one set at offset 0 raced the
online-softmax reduce).

Verified on strixhalo (zaya q4nx-c43, np2):
- the batched node is CLAIMED (was 'unsupported HRX node FLASH_ATTN_EXT
  f32[128,8,4,2]' graph -1)
- per-position logits: stream 0 ≈ CPU-exact (9079/236761/107/4906 argmax
  order, small fp deltas) — the flash attention math itself is correct
- residual bug (downstream, not this matcher): the q8 alternate consumer
  reads stream 1 one row stale (B's logits = A's previous-step logits) —
  batched q8 row indexing in the consuming dispatch

Separate finding recorded on the issues: this branch's device decode is not
oracle-correct with a REAL continuation (dense qwen3 + 30B collapsed; zaya
diverges at tok 4) — the ggml-org#2147 decode-norm reorder fix is on
fix/qwen3-decode-norm, not this lineage. Earlier 'token-identical' claims
from the rt_tok harness were measured on a degenerate continuation (harness
bug, corrected on ggml-org#2117/ggml-org#2116/ggml-org#2145).
bong-water-water-bong pushed a commit to bong-water-water-bong/llama.cpp that referenced this pull request Sep 8, 2026
…U boundary on lm_head input

Program-dump-verified: the batched flash matcher bindings are correct
(per-stream strides, per-dispatch transients) and stream-0 logits are
CPU-exact. The np2 B-stream staleness is the CPU-side lm_head (zaya vocab
262272 > 262144 device cap) reading the final hidden [2048,2] across the
HRX->CPU boundary with a mis-mapped row 1 — the round-16e boundary class on
the device->CPU direction. Corroborated by MUL_MAT->CPU making both streams
garbage. Fix = scheduler boundary copy for batched tensors (or device lm_head
coverage); also requires the ggml-org#2147 decode-norm lineage for any decode-quality
validation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants