Skip to content

Expose generation timings from server & update completions.js - #2116

Merged
tobi merged 4 commits into
masterfrom
llama_server_completions
Jul 5, 2023
Merged

tobi merged 4 commits into
masterfrom
llama_server_completions

Conversation

@tobi

@tobi tobi commented Jul 5, 2023

Copy link
Copy Markdown

I still had some stashed changes floating around before the merge. This is pretty basic cleanups, but makes it even easier to use the completion.js. Now you can just:

        import { llama } from '/completion.js'

        const prompt = `### Instruction:
Write dad jokes, each one paragraph.
You can use html formatting if needed.

### Response:`

        for await (const chunk of llama(prompt)) {
          document.write(chunk.data.content)
        }

Who knew that javascript had generators at this point? It's honestly not a bad language anymore it turns out 😆.

I also wanted to expose the generation speed in the frontend.

image

For that I moved the timing generation to return a new llama_get_timings and switched llama_print_timings to use this. This is changing llama.h/cpp so please let me know if this is is gross.

@tobi
tobi requested a review from ggerganov July 5, 2023 19:26
@tobi

tobi commented Jul 5, 2023

Copy link
Copy Markdown
Author

Some goodies for #1998

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

C API changes approved 👍

@tobi

tobi commented Jul 5, 2023 •

Copy link
Copy Markdown
Author

C API changes approved

ty for the help

@tobi
tobi merged commit 31cfbb1 into master Jul 5, 2023
@ghost ghost mentioned this pull request Jul 6, 2023
4 tasks done
@SlyEcho

SlyEcho commented Jul 9, 2023

Copy link
Copy Markdown
Contributor

Why are there so many whitespace changes? Especially when it's going against the coding style?

{
const auto timings = llama_get_timings(llama.ctx);

assert(timings.n_eval == llama.num_tokens_predicted);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

warning: comparison of integers of different signs: 'const int32_t' (aka 'const int') and 'size_t' (aka 'unsigned long') [-Wsign-compare]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This line also crashes my server every time because they are not the same. I am running everything with the defaults, type "Hello Llama" and it crashes at the assert (guanaco-7B.ggmlv3.q5_K_M).

Commenting this line out seems to work just fine for me although I am not sure what unwanted behaviors I might get. seems like if this is not critical, it should be logged as a warning rather than cause an exception.

Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
…rg#2116)

* use javascript generators as much cleaner API

Also add ways to access completion as promise and EventSource

* export llama_timings as struct and expose them in server

* update readme, update baked includes

* llama : uniform variable names + struct init

---------

Co-authored-by: Georgi Gerganov <[email protected]>
phuongncn pushed a commit to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4 that referenced this pull request Apr 28, 2026
…rg#2116)

* use javascript generators as much cleaner API

Also add ways to access completion as promise and EventSource

* export llama_timings as struct and expose them in server

* update readme, update baked includes

* llama : uniform variable names + struct init

---------

Co-authored-by: Georgi Gerganov <[email protected]>
ljubomirj pushed a commit to ljubomirj/llama.cpp that referenced this pull request May 6, 2026
…rg#2116)

* use javascript generators as much cleaner API

Also add ways to access completion as promise and EventSource

* export llama_timings as struct and expose them in server

* update readme, update baked includes

* llama : uniform variable names + struct init

---------

Co-authored-by: Georgi Gerganov <[email protected]>
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
…rg#2116)

* use javascript generators as much cleaner API

Also add ways to access completion as promise and EventSource

* export llama_timings as struct and expose them in server

* update readme, update baked includes

* llama : uniform variable names + struct init

---------

Co-authored-by: Georgi Gerganov <[email protected]>
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
…rg#2116)

* use javascript generators as much cleaner API

Also add ways to access completion as promise and EventSource

* export llama_timings as struct and expose them in server

* update readme, update baked includes

* llama : uniform variable names + struct init

---------

Co-authored-by: Georgi Gerganov <[email protected]>
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).
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.

5 participants