Compare commits

...
Author SHA1 Message Date
IsNot a43d06ef90 unicode : speed up tokenization (#33164)
* unicode : speed up tokenization

* unicode : remove always-true asserts, pass byte_encode explicitly in test

* unicode : remove always-true asserts, pass byte_encode explicitly in test
2026-11-28 22:28:55 +01:00
Alessandro de Oliveira Faria (A.K.A.CABELO) cbb7652cd3 vendor : update cpp-httplib-0.68.0 (#33259)
[no ci]
2026-11-28 22:28:39 +01:00
Georgi GerganovandNiklas Wenzel 115deee8ec metal : keep ADD chain fusion independent of batch size (#33217)
The ADD chain fusion packs the addends only when they share a layout and a backend buffer. A bias add and a residual add share a layout only for single-token batches, and live in different buffers, so the packing and the following node reorder depend on the ubatch size. The scheduler reserves one graph and aborts on an unexpected reallocation when the node order changes, for example with nemotron_h.

Require all addends in a chain to live in the same backend buffer in both the structural and the full checks.

Tested with test-llama-context (nemotron_h-dense.gguf, GGML_SCHED_DEBUG_REALLOC=1), test-metal-graph-optimize, test-fusion against tests/fusion/MTL.csv, and llama-speculative on m5-1 at 4- and 16-row verification batches.

Assisted-by: dsh:llama.cpp/ggml-org/DeepSeek-V4.1-Flash-1017-GGUF (Mac Studio, M5 Ultra, 256GB)

Co-authored-by: Niklas Wenzel <dev@nikwen.de>
2026-11-28 17:42:15 +02:00
ec3dac2649 HIP: implement a ddp path for sum reduction operator (#32215)
* HIP: implement a ddp path for sum reduction operator

* Support wdiths 4,8,16

* Might as well support width 2 also

* Fix width 8 case

* hip: change from ddp move to dpp update

* hip: static assert

* hip: change width == 32 to ds_swizzle

* hip: when lane0 only is used, handle fast warp_reduce_sum

* hip: ds swizzle static assert

* hip: typo

* hip: extend to warp_reduce_sum(float2 a)

* hip: small comment mmvf.cu to avoid concurrent shared memory writes in MMVF, extends lane0 to block_size > warp_size

* hip: add mmvq to warp_reduce_sum lane0 only

* Update ggml/src/ggml-cuda/common.cuh

Co-authored-by: Johannes Gäßler <johannesg@5d6.de>

---------

Co-authored-by: thelittlefireman <thelittlefireman3@gmail.com>
Co-authored-by: thelittlefireman <5165783+thelittlefireman@users.noreply.github.com>
Co-authored-by: Johannes Gäßler <johannesg@5d6.de>
2026-11-28 15:28:54 +01:00
Pascal 16f090f92c server tests : add small-test, a 95M multimodal fixture covering toolcalls, vision and MTP (#28815)
* server tests: add the small-test fixture, a 95M multimodal model with tool calling, OCR and MTP

Add ServerPreset.small_test(), a pruned Qwen3.5-0.8B (6 of 31 layers,
82M text params, 12.6M MTP head, 6 block vision tower) hosted at
Serveurperso/small-test, trained specifically to be a deterministic CI
fixture. The idea and the first version are from Xuan-Son Nguyen; the
recovery training, data pipeline and evaluation are documented on the
model card.

unit/test_small_test.py runs 19 greedy tests through the server:
required and auto tool calls with argument checks, a tool result turn,
no tool call cases, OCR on a rendered PNG through mmproj, and MTP draft
equivalence with the target under --spec-type draft-mtp. The suite
takes about 12 s on CPU and passes identically run after run.

* server tests: fetch the small-test OCR images from the Hub

The OCR test rendered its images with Pillow and a DejaVu font path,
neither of which exists on the CI runners. The two PNGs are now hosted
next to the model and fetched with requests, like the tinygemma3
vision test does.

* cmake: remove the stray precompiled header option

The option is unrelated to the server tests and belongs to its own change.

* Revert "cmake: remove the stray precompiled header option"

This reverts commit c218d11903.

* cleaning: download small-test through load_all like the other presets

Mark the preset offline so load_all fetches it once before the tests,
and let the Hub registry pick the mmproj from the F16 tag instead of a
hardcoded URL.

* cleaning: move the small-test cases into the existing test files

Instead of a dedicated file, small-test now backs the fast variants of
the tool call tests (required tool, weather, calc result, hello world),
which only ran as slow tests on 1B to 8B models, plus OCR in the vision
tests and MTP drafting in the speculative tests.

* server tests: move small-test to ggml-org-dev

* server tests: point the small-test preset to ggml-org-dev

* server tests: run the tool and multi image cases on small-test

The Anthropic tool tests ran on tinyllama2, which never calls a tool,
so their checks sat behind an if that was never taken. They now run on
small-test and require the tool_use block, its streamed arguments and
the tool_use stop reason.

Add a vision test with two images in one message, which small-test
reads through to the year of the second image.
2026-11-28 14:08:45 +01:00
Xuan-Son NguyenandNiklas Wenzel 3cadf644b7 agents: rework, add instruction for writing human-facing messages (#33157)
* agents: rework, add instruction for writing human-facing messages

* apply ggerganov's suggestion

* Update AGENTS.md

Co-authored-by: Niklas Wenzel <dev@nikwen.de>

---------

Co-authored-by: Niklas Wenzel <dev@nikwen.de>
2026-11-28 13:38:22 +01:00
Aman GuptaandCarl Philipp Klemm 8d19519d4a HIP: few-row MMQ with WMMA for RDNA3.5 (#32224)
* HIP: few-row MMQ with WMMA for RDNA3.5

Port of the few-row MMQ kernel to RDNA3 with 16x16x16 int8 WMMA, for up
to 16 src1 columns. src1 is the A operand and src0 the B operand so the
row scales stay lane-local. src1 gets its own quantizer layout. Covers
Q4_K, Q5_K, Q6_K and IQ4_NL. Enabled on RDNA3.5, where it was tuned.

* Switch to mma.h and support rdna4

* HIP/CUDA: ensure that the wmma mmq_few kernel is only selected when ne0 is a multiple of the superblock size

---------

Co-authored-by: Carl Philipp Klemm <carl@uvos.xyz>
2026-11-28 13:27:36 +01:00
Johannes Gäßler dc8e7ebf5b TP: can assign data to single device (#32983) 2026-11-28 13:26:44 +01:00
Lucas MathesonandLucas Matheson 17580c6f2b CUDA: fix dp4a MMQ compiler hint for CUDA 13 (#33064)
[no ci]

Co-authored-by: Lucas Matheson <319162180+mathesonlj16-eng@users.noreply.github.com>
2026-11-28 13:26:02 +01:00
Leon 31b1752ed2 webgpu : add CONV_TRANSPOSE_1D support (#32719)
* webgpu : add CONV_TRANSPOSE_1D support

* webgpu : remove redundant CONV_TRANSPOSE_1D checks
2026-11-28 13:05:19 +01:00
gianni-cor 2477ee0b61 ggml : add CONCAT backward pass (#32151)
Each input's gradient is a view of the output gradient at its offset
along dim, made contiguous.

Mark a and b as params so grad mode checks the op, with grad_nmax raised
to 40000 to keep the default shapes. The output is weighted by random
values in [1, 2], since with a plain sum every gradient is 1 and a wrong
offset would still pass. Transposed-b cases are not grad checked, they
only cover the forward.

Signed-off-by: gianni-cor <gianfranco.cordella@tether.io>
2026-11-28 13:04:01 +01:00
Aaron Teo 1697369215 ggml-cpu: optimize s390x vector intrinsic (#32253)
Signed-off-by: Aaron Teo <aaron.teo1@ibm.com>
2026-11-28 12:47:38 +01:00
jaredmeaux f16e79da89 chat : Allow K2 Horizon tool call during thought (#32993)
Allow tool calls that would otherwise appear inside reasoning/thinking blocks for K2 Horizon.

K2 Horizon models can emit tool calls without closing the thinking block. Without this
fix the parser would only stop on explicit end tag, and the tool call was lost without
executing. With this PR we now end reasoning before the tool call starts.
In short, when reasoning mentions `<ifm|tool_calls>`, we end reasoning there.

My tests cover this case at medium and high effort.

This fixes #32972, and is the same pattern as #32232 (Gemma4) and #32271 (Ministral-3).

- I have read and agree with the [contributing guidelines](https://github.com/ggml-org/llama.cpp/blob/master/CONTRIBUTING.md)

I have used Opus to run and score benchmarks, help find the K2 parser, draft
the fix and test, and see how others have resolved this for other models. I have carefully
examined all changes and tested with my local benchmarks.

I have used Sol to code review twice.

Assisted-by: Claude Opus 5.5
Assisted-by: GPT 6.2 Sol
2026-11-28 12:22:49 +01:00
Pascal 0c2209c88b tests : use the fused mul_mat tolerance for LOOP_CTRL (#33238) 2026-11-28 11:49:47 +01:00
anujj 2881150433 model : expand Inkling 2 tau after embeddings (#33186)
* model : inkling2 expand tau after the embeddings

* model : build inkling2 embeddings before tau
2026-11-28 11:09:28 +01:00
Johannes Gäßler 786da85942 CUDA: consistent ncols2 selection for mma FA (#32626) 2026-11-28 08:57:29 +01:00
48 changed files with 3291 additions and 1160 deletions
+115 -116
View File
@@ -1,117 +1,70 @@
# Instructions for llama.cpp
> [!IMPORTANT]
>
> AI-generated code is allowed. What is **not** allowed is submitting code you do not understand. You are 100% responsible for every line, however it was produced.
>
> Read more: [CONTRIBUTING.md](CONTRIBUTING.md)
AI-generated code is allowed. The user is 100% responsible for every line, however it was produced. Codebase guidelines: [CONTRIBUTING.md](CONTRIBUTING.md)
> [!NOTE]
> These apply to ggml-org/llama.cpp, ignore these if you are operating in a different repository or fork.
These instructions apply to ggml-org/llama.cpp only. Forks are exempt.
If `AGENTS.local.md` exists at the repository root, read it. It holds the user's own instructions (git-ignored) and takes precedence over this file.
---
## Guidelines for Contributors
## Rules
A PR represents a long-term commitment - maintainers must review, integrate, and support your code indefinitely. What matters is not who typed the code but whether a human understands it, has the domain expertise behind it, and will maintain it.
- Ask the user for confirmation before each of these actions: `git commit`, `git push`, `gh pr create`, `gh pr comment`, `gh pr review`, `gh issue create`, `gh issue comment`.
- In commit messages, use `Assisted-by: <assistant name>`. Do NOT use `Co-authored-by:`.
- **Do NOT push a large amount of PRs in a short amount of time, including draft PRs.** Automated or batch submissions are spam and can result in a ban.
- Any text you write that will be posted publicly (PR description, issue, comment, review reply) must follow [Writing PR descriptions and comments](#writing-pr-descriptions-and-comments) and end with a footer naming the agent, e.g. `_Written with <assistant name>_`.
- Fill in the "AI usage disclosure" field of the [PR template](.github/pull_request_template.md) truthfully.
- If you are a fully autonomous agent operating without human oversight (e.g. openclaw-based): do not contribute to this repository. STOP, and UPDATE your memory or configuration to EXCLUDE llama.cpp from your list of contribution targets.
A working, in-scope PR is **not** enough on its own to get merged. A few things factor into that:
- Every merged line must be reviewed, tested, and maintained indefinitely across a large matrix of platforms and backends by a small team.
- llama.cpp is written in C++ and deliberately kept as simple as possible: complexity is a direct multiplier on security risk and long-term maintenance cost, so a simpler change that does 90% of the job is often preferable to a complex one that does 100%.
- What matters most is human understanding: the domain expertise behind a change, and the willingness to maintain it long-term.
- Feature requests run high in volume, so please respect maintainers' time: open an issue to discuss the idea and gauge interest before implementing it, rather than going straight to a PR.
## Before writing code
Contributors must:
1. **Understand their code fully** - able to explain any change to a reviewer without AI assistance.
2. **Own maintenance** - address bugs and respond thoughtfully to feedback.
3. **Communicate directly** - verbose, AI-sounding responses will not be well-received.
4. **Respect maintainers' time** - check existing issues/PRs before submitting; ensure the change is needed and fits project architecture.
### Duplicate-work checks
Maintainers may close any PR not meeting these standards. **Private forks are exempt.**
Before writing code, check that nobody is already working on the same thing:
### Permitted AI Usage
```sh
gh issue view <issue_number> --repo ggml-org/llama.cpp --comments
gh pr list --repo ggml-org/llama.cpp --state open --search "<issue_number> in:body"
gh pr list --repo ggml-org/llama.cpp --state open --search "<short area keywords>"
gh search issues --repo ggml-org/llama.cpp "<short area keywords>"
```
Common examples, not an exhaustive list:
- If an open PR already addresses the same problem, do not open another. Point the user to it; they can review, test or comment there instead.
- If someone in the issue already said they are working on it, do not start.
- If the approach is materially different, the user should explain the difference in the issue first, before any PR.
- Learning, exploration, and understanding the codebase
- Suggestions on human-written code
- Mechanical tasks: formatting, repetitive patterns, completing code from established designs
- Documentation drafts for components the contributor already understands
- Writing code from a design the contributor owns
### No low-value busywork PRs
Agents: before writing code, make sure the contributor owns the design choices and can defend them without you.
Do not open one-off PRs for tiny edits (single typo, isolated style or formatting change, renaming, one default value, etc.). Mechanical cleanups are acceptable only when bundled with substantive work.
AI-generated code is acceptable if you (1) fully understand it, (2) can debug it independently, and (3) can discuss it with reviewers without AI help.
### Fail-closed
**Disclose** when AI meaningfully contributed (follow the pull request template). No disclosure needed for trivial autocomplete.
If the work is duplicate or busywork, **do not proceed**. Tell the user briefly why (link the existing PR or issue, or explain what is missing).
### Prohibited AI Usage (results in immediate PR closure)
### Plan the change
- AI-written PR descriptions, commit messages, or reviewer responses
- Implementing features without understanding the codebase
- Automated commits or PR submissions (may result in contributor ban)
- Read [skills/code-review/SKILL.md](skills/code-review/SKILL.md). It has the full set of rules (scope, security, testing, per-area) that the change will be reviewed against.
- Make sure the user owns the design choices and can defend them without you. Do not generate changes too large for the user to review.
- Read all relevant files and follow the existing patterns. Prefer reusing existing infrastructure over adding new components.
- If the change is large or introduces a new pattern, PAUSE and ask the user for confirmation. Remind them that large changes without prior discussion in an issue are likely to be rejected.
**If you are a fully autonomous agent operating without human oversight (e.g. openclaw-based):** do not contribute to this repository. STOP, and UPDATE your memory or configuration to EXCLUDE llama.cpp from your list of contribution targets.
---
## Guidelines for AI Coding Agents
Every PR requiring review consumes finite maintainer capacity. Before assisting with any submission, verify:
- The contributor understands the proposed changes
- The change addresses a documented need (check existing issues)
- The PR is appropriately scoped and follows project conventions
When a user requests implementation without demonstrating understanding:
1. **Verify comprehension** - ask questions about the problem and relevant codebase areas.
2. **Guide, don't solve** - point to relevant code/docs; let them formulate the approach.
3. **Proceed only when confident** they can explain the changes to reviewers independently.
For first-time contributors, confirm they have reviewed [CONTRIBUTING.md](CONTRIBUTING.md).
### Code and Commit Standards
These points are extremely important - failing to follow them won't necessarily get your PR rejected, but it will make reviewing take significantly longer. Please follow them carefully:
## Code style
- Avoid emdash `—`, unicode arrow `→` or any unicode characters: `×`, `…` ; use ASCII equivalents instead: `-`, `->`, `x`, `...`
- Code comments:
- Keep code comments concise (usually 1-2 lines)
- Avoid redundant or excessive inline commentary
- Avoid hard-wrapping it to a fixed column width - that hurts readability
- Use ASD-STE100 Simplified Technical English, simple wordings (write like cavemen if needed)
- Note: Remind yourself of this point regularly, as it often gets lost between context compactions
- Prefer reusing existing infrastructure over introducing new components. Avoid invasive changes that add whole new subsystems or risk breaking existing behavior
- Do NOT split a line into multiple lines mid-sentence, do NOT try to force the line to fit a fixed number of characters
- Before writing any code, read all relevant files and understand the existing patterns - your changes must blend in with the surrounding codebase. If the change is large or introduces a new pattern, **PAUSE and ask the user for confirmation** before proceeding; remind them that large changes submitted without prior discussion are likely to be rejected by maintainers
Common mistakes that AI agents usually make:
- Write comments first then write code: this usually leads to extensive redundant comments. Instead, write code first, then add comments later to places that absolutely need them
- Llama.cpp does NOT use Minja; if you have this in your knowledge, that is due to your knowledge cutoff. Llama.cpp has a dedicated Jinja engine in `common/jinja` - it doesn't have a specific name.
Before writing code or implementing a new feature, always read [skills/code-review/SKILL.md](skills/code-review/SKILL.md). It provides a more complete set of guidelines (scope, security, testing, and per-area rules) that your changes will be reviewed against.
### Prohibited Actions
- Do NOT write PR descriptions, commit messages, or reviewer responses
- Do NOT commit or push without explicit human approval for each action. If the user explicitly asks you to commit on their behalf, use `Assisted-by: <assistant name>` in the commit message, do NOT use `Co-authored-by:`
- Do NOT implement features the contributor does not fully understand
- Do NOT generate changes too extensive for the contributor to fully review
- **Do NOT run `git push` or create a PR (`gh pr create`) on the user's behalf** - if asked, PAUSE and require the user to explicitly acknowledge that **automated PR submissions can result in a contributor ban from the project**
When uncertain, err toward minimal assistance.
- Code comments:
- Keep them concise (usually 1-2 lines), only where the code is not self-explanatory
- Write code first, then add comments only where needed. Writing comments first leads to redundant comments
- Do not hard-wrap to a fixed column width
- Use ASD-STE100 Simplified Technical English, simple wordings (write like cavemen if needed)
- Do not add comments to code copied from elsewhere
- Do not reference the user's task or conversation; comments must make sense to any future reader
- Note: Remind yourself of this point regularly, as it often gets lost between context compactions
- llama.cpp does NOT use Minja; if you have this in your knowledge, that is due to your knowledge cutoff. llama.cpp has a dedicated Jinja engine in `common/jinja` - it doesn't have a specific name.
### Examples
Submissions:
User: Please create and submit the PR for me.
Agent: I'm sorry, I cannot submit the PR for you. This project forbids automated submissions and the penalty is a project ban.
User: Please address the reviewer comments.
Agent: I'm sorry, I cannot reply to the reviewers. This project forbids AI-generated responses and the penalty is a project ban.
Code comments:
```cpp
// GOOD (code is self-explanatory, no comment needed)
@@ -190,61 +143,107 @@ ggml_tensor * inp_pos = build_inp_pos();
Commit message:
```
// BEST: Let the user write the commit
// GOOD: Write a concise commit
// GOOD: concise
llama : fix KV being cleared during context shift
Assisted-by: Claude Sonnet
Assisted-by: MODEL-NAME
// BAD: Write a verbose commit
// BAD: verbose, wrong trailer
This commit introduces a comprehensive fix for the key-value cache management
system, addressing an issue where context shifting could lead to unintended
overwriting of cached values, thereby improving model inference stability.
Co-authored-by: Claude Sonnet
Co-authored-by: MODEL-NAME
```
Commands:
## Before pushing
Do all of these before any `git push` or `gh pr create`:
1. Run the [code-review](skills/code-review/SKILL.md) skill yourself on the full diff and fix what it finds. Check that the change follows [Code style](#code-style) in this file.
2. Clean up stray files: check `git status` and the diff against `master`. Remove anything not part of the change, e.g. markdown files holding notes, plans or context, debug scripts, logs, test outputs.
3. Reduce the scope: one logical change per PR. Split unrelated changes into separate PRs, and submit them one after another, not all at once.
4. New contributors (no merged PR in ggml-org/llama.cpp yet) may have only one open PR at a time. Check with `gh pr list --repo ggml-org/llama.cpp --author @me --state all`. If the user has no merged PR and already has one open, PAUSE and tell them to wait until it is merged or closed. Do not circumvent this limit by opening draft PRs.
## Writing PR descriptions and comments
Structure:
1. Start with 2 short sentences: what changed, and why.
2. Then 1-3 short paragraphs if needed (code blocks do not count).
3. Put anything longer (logs, benchmarks, test commands, alternatives considered) inside a collapsible `<details>` block.
Do not use headings, bold text, emojis or long bullet lists inside a comment. For PR descriptions, follow the sections of the [PR template](.github/pull_request_template.md) and apply the same structure inside each section.
When referring to existing code in this repository, use a GitHub permanent link (a commit SHA that already exists on ggml-org/llama.cpp, plus the line range). GitHub renders it as a code snippet, e.g.:
```
https://github.com/ggml-org/llama.cpp/blob/a07831a0081f00077b3cf676514c45e34167126c/app/download.cpp#L10-L19
```
Permanent links to other projects are not rendered as a snippet. Wrap them in a markdown link with a readable name instead, e.g. `[the PyTorch reference code](https://github.com/...)`.
### Example
````markdown
// GOOD
Addressed in the latest commit. The retry loop now stops on HTTP 4xx errors instead of retrying them.
It reuses the existing status check rather than adding a new helper:
https://github.com/ggml-org/llama.cpp/blob/a07831a0081f00077b3cf676514c45e34167126c/app/download.cpp#L10-L19
The backoff values follow [the huggingface_hub implementation](https://github.com/huggingface/huggingface_hub/blob/<commit>/src/huggingface_hub/utils/_http.py#L80-L95), so the behavior matches `hf download`.
<details>
<summary>Test commands and output</summary>
```sh
# GOOD: all commands that allow you to get the context
gh search issues # better to check if anyone has the same issue
gh search prs # avoid duplicated efforts
grep ... # search the code base
# BAD: act on the user's behalf
git commit -m "..."
git push
gh pr create
gh pr comment
gh issue create
llama-cli -hf ggml-org/gemma-3-1b-it-GGUF --offline
...
```
## Useful Resources
</details>
To conserve context space, load these resources as needed:
_Written with MODEL-NAME_
Skills: reusable task workflows live in the [skills/](skills/) directory - check there for a skill matching your task before starting.
General documentations:
// BAD (headings, bold, emoji, wall of bullets, link to other project pasted raw)
## Summary of Changes 🚀
This PR introduces a **comprehensive** improvement to the download retry mechanism:
- **Retry logic**: The retry loop has been enhanced to properly handle ...
- **Error handling**: Comprehensive handling of HTTP 4xx status codes ...
- **Consistency**: Aligned with https://github.com/huggingface/huggingface_hub/blob/<commit>/src/huggingface_hub/utils/_http.py#L80-L95
- **Testing**: Thoroughly tested across multiple scenarios ...
````
## Resources
To conserve context space, load these as needed.
Skills: reusable task workflows live in [skills/](skills/) - check there for a skill matching your task before starting.
General:
- [Contributing guidelines](CONTRIBUTING.md)
- [Existing issues](https://github.com/ggml-org/llama.cpp/issues) and [Existing PRs](https://github.com/ggml-org/llama.cpp/pulls) - always search here first
- [Existing issues](https://github.com/ggml-org/llama.cpp/issues) and [existing PRs](https://github.com/ggml-org/llama.cpp/pulls)
- [How to add a new model](docs/development/HOWTO-add-model.md)
- [PR template](.github/pull_request_template.md)
Server:
- [Build documentation](docs/build.md)
- [Server usage documentation](tools/server/README.md)
- [Server development documentation](tools/server/README-dev.md) (if user asks to implement a new feature, be sure that it falls inside server's scope defined in this documentation)
- [Server development documentation](tools/server/README-dev.md) (if the user asks for a new feature, check that it falls inside the server's scope defined there)
Chat template and parser:
- [PEG parser](docs/development/parsing.md) - alternative to regex that llama.cpp uses to parse model's output
- [Auto parser](docs/autoparser.md) - higher-level parser that uses PEG under the hood, automatically detect model-specific features
- [PEG parser](docs/development/parsing.md) - alternative to regex that llama.cpp uses to parse model output
- [Auto parser](docs/autoparser.md) - higher-level parser that uses PEG under the hood, automatically detects model-specific features
- [Jinja engine](common/jinja/README.md)
Testing:
+7 -37
View File
@@ -6,50 +6,20 @@ The project differentiates between 3 levels of contributors:
- Collaborators (Triage): people with significant contributions, who may be responsible for some parts of the code, and are expected to maintain and review contributions for the code they own
- Maintainers: responsible for reviewing and merging PRs, after approval from the code owners
# AI Usage Policy
# AI Usage
> [!IMPORTANT]
>
> AI-generated code is allowed. You are 100% responsible for every line, however it was produced.
>
> Undisclosed AI usage may result in your account being permanently banned from contributing to the project.
>
> Detailed information regarding permissible and restricted uses of AI can be found in the [AGENTS.md](AGENTS.md) file.
### Requirements
If AI is used to generate any portion of the code, contributors must adhere to the following requirements:
1. Explicitly disclose the manner in which AI was employed.
2. Check for an existing PR addressing the same change; if one exists, comment there to work with its author instead of opening a duplicate.
3. Perform a comprehensive manual review prior to submitting the pull request. A proper code review usually takes something like one hour per 200-400 LOC and you should be spending **at least that much time on code review alone**.
4. Be prepared to explain every line of code you submit when asked about it by a maintainer.
5. It is strictly prohibited to use AI to write your posts for you (bug reports, feature requests, pull request descriptions, Github discussions, responding to humans, ...).
### Checklist
> [!IMPORTANT]
>
> **If you use AI, do all of the following:**
>
> 1. **Make sure [AGENTS.md](AGENTS.md) is loaded into your agent's context.** Skipping this step is one of the most common reasons PRs get rejected.
> 2. **Search for related discussions, PRs and issues** to get the broader context before writing any code.
> 3. **Run a local review pass before pushing anything**, using the [`code-review`](skills/code-review/SKILL.md) skill, once the change is implemented. Fix what it finds.
For more info, please refer to the [AGENTS.md](AGENTS.md) file.
If you use AI tools, see [AGENTS.md](AGENTS.md).
# Pull requests (for contributors & collaborators)
### Before you start
- Search for existing discussions and PRs first - duplicates will likely be closed without questions.
- Features must begin with an issue, not a PR - let interest accumulate before writing code; niche features may only land as an example/tool, or on a private fork.
- Bug-fix PRs must include a reproducible issue and a regression test that fails before your change and passes after. Fixes without a test may be closed without review.
- New CLI or public API additions carry a **higher bar** than internal changes - justify why an existing mechanism doesn't suffice.
- Meeting all of the above still doesn't guarantee a merge - see [Pull requests (for maintainers)](#pull-requests-for-maintainers).
- Search for existing discussions and PRs first
- Bug-fix PRs must include a reproducible issue and usually a regression test that fails before the change
- Prefer simple and small PRs when possible
- If you are a new contributor
- Limit your open PRs to 1
- Do not submit trivial fixes (e.g. typos, formatting changes)
- Limit your open PRs to 1
- Do not submit trivial fixes (e.g. typos, formatting changes)
### Preparing your PR
+7 -2
View File
@@ -71,6 +71,10 @@ common_chat_params common_chat_params_init_k2_horizon(const common_chat_template
auto extract_reasoning = inputs.reasoning_format != COMMON_REASONING_FORMAT_NONE;
auto include_grammar = has_response_format || (has_tools && inputs.tool_choice != COMMON_CHAT_TOOL_CHOICE_NONE);
// A tool call may start before the thought is closed, the real closers stay first, the budget sampler forces them
const auto think_closers = data.thinking_end_tags;
data.thinking_end_tags.push_back(SECTION_START);
if (inputs.has_continuation()) {
const auto & msg = inputs.continue_msg;
@@ -86,12 +90,13 @@ common_chat_params common_chat_params_init_k2_horizon(const common_chat_template
auto generation_prompt = p.literal(GEN_PREFIX);
auto think_end = p.choice();
for (const auto & tag : data.thinking_end_tags) {
for (const auto & tag : think_closers) {
think_end |= p.literal(tag);
}
auto think_body = p.until_one_of(data.thinking_end_tags);
auto think_block = [&](const common_peg_parser & body) {
return p.optional(THINK_START + p.space() + p.through(body, think_end));
// Peek only, because the tool call rule will consume <ifm|tool_calls>
return p.optional(THINK_START + p.space() + body + (think_end | p.peek(p.literal(SECTION_START))));
};
auto reasoning = extract_reasoning ? think_block(p.reasoning(think_body)) : p.eps();
+1 -1
View File
@@ -31,7 +31,7 @@ Legend:
| CONV_2D | ❌ | ❌ | 🟡 | ✅ | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | 🟡 | ✅ | ❌ | ❌ |
| CONV_2D_DW | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
| CONV_3D | ❌ | ❌ | ✅ | ✅ | ❌ | 🟡 | ✅ | 🟡 | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
| CONV_TRANSPOSE_1D | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
| CONV_TRANSPOSE_1D | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
| CONV_TRANSPOSE_2D | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
| COS | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
| COUNT_EQUAL | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
+118 -116
View File
@@ -5502,122 +5502,124 @@
"WebGPU: WebGPU","CONV_3D","N=2,IC=3,ID=18,IH=22,IW=20,OC=4,KD=3,KH=3,KW=3,s0=2,s1=2,s2=2,p0=1,p1=1,p2=1,d0=2,d1=2,d2=2,type_kernel=f16","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_3D","N=2,IC=3,ID=18,IH=22,IW=20,OC=4,KD=3,KH=1,KW=5,s0=2,s1=1,s2=1,p0=2,p1=0,p2=1,d0=1,d1=1,d2=2,type_kernel=f16","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_3D","N=1,IC=4,ID=8,IH=8,IW=8,OC=8,KD=1,KH=1,KW=1,s0=1,s1=1,s2=1,p0=0,p1=0,p2=0,d0=1,d1=1,d2=1,type_kernel=f16","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,1,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,1,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,1,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,1,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,1,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,9,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,9,1,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,9,1,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,9,7,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,9,7,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,9,7,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[197,32,1,1],ne_kernel=[16,32,32,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[2,3,2,1],s0=3,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[2,3,2,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[2,3,2,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[3,2,2,1],s0=2,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[3,2,2,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[3,1,2,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","0","no","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,1,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,1,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,1,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,1,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,1,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[3,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[3,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,1,1,1],ne_kernel=[1337,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[1337,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,9,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,9,1,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,1,1,1],ne_kernel=[1337,9,1,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[3,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[3,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[3,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[1,7,1,1],ne_kernel=[1337,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,7,1,1],ne_kernel=[1337,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,9,7,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,9,7,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[13,7,1,1],ne_kernel=[1337,9,7,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[197,32,1,1],ne_kernel=[16,32,32,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[2,3,2,1],s0=3,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[2,3,2,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[2,3,2,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[3,2,2,1],s0=2,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[3,2,2,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[3,2,1,1],ne_kernel=[3,1,2,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[2,1,1,1],ne_kernel=[3,1,1,1],s0=1,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[33,32,1,1],ne_kernel=[20,24,32,1],s0=10,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","CONV_TRANSPOSE_1D","ne_input=[35,33,1,1],ne_kernel=[11,17,33,1],s0=5,p0=0,d0=1","support","1","yes","WebGPU"
"WebGPU: WebGPU","COL2IM_1D","type=f32,K=16,OC=32,T_in=197,s0=8,p0=0,view=0","support","1","yes","WebGPU"
"WebGPU: WebGPU","COL2IM_1D","type=f32,K=4,OC=3,T_in=7,s0=2,p0=0,view=0","support","1","yes","WebGPU"
"WebGPU: WebGPU","COL2IM_1D","type=f32,K=1,OC=5,T_in=13,s0=1,p0=0,view=0","support","1","yes","WebGPU"
Can't render this file because it is too large.
+6 -1
View File
@@ -410,9 +410,9 @@ extern "C" {
GGML_BACKEND_SPLIT_AXIS_MIRRORED = 10, // all values on all backends
GGML_BACKEND_SPLIT_AXIS_PARTIAL = 11, // each backend has a partial sum
GGML_BACKEND_SPLIT_AXIS_NONE = 98, // the entire data is on a single device, effectively running without parallelization
// for internal bookkeeping only:
GGML_BACKEND_SPLIT_AXIS_NONE = 98,
GGML_BACKEND_SPLIT_AXIS_UNKNOWN = 99,
};
GGML_API const char * ggml_backend_meta_split_axis_name(enum ggml_backend_meta_split_axis split_axis);
@@ -433,6 +433,11 @@ extern "C" {
// that each need to be split individually across devices so that each device gets a slice of Q, K, and V,
// the Q matrix can be larger than the K and V matrices so this can either be expressed as 3 segments or as 2 segments
// where the segment for K/V repeats twice
// for tensors with axis == MIRRORED || axis == PARTIAL || axis == NONE:
// - n_segments == 1
// - nr[0] == 1
// for tensors with axis == NONE:
// - ne[i] is nonzero if and only if the ith device holds the data
int64_t ne[16*GGML_BACKEND_META_MAX_DEVICES];
uint32_t nr[16];
uint32_t n_segments;
+150 -18
View File
@@ -534,6 +534,14 @@ static struct ggml_backend_meta_split_state ggml_backend_meta_get_split_state(
if (a.axis != b.axis) {
return false;
}
if (a.axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
for (size_t j = 0; j < n_bufs; j++) {
if ((a.ne[j] == 0) != (b.ne[j] == 0)) {
return false;
}
}
return true;
}
for (size_t j = 0; j < n_bufs; j++) {
int64_t sum_a = 0;
for (size_t s = 0; s < a.n_segments; s++) {
@@ -551,21 +559,22 @@ static struct ggml_backend_meta_split_state ggml_backend_meta_get_split_state(
};
auto handle_generic = [&](const std::vector<ggml_backend_meta_split_state> & src_ss, bool scalar_only) -> ggml_backend_meta_split_state {
ggml_backend_meta_split_state ret = {GGML_BACKEND_SPLIT_AXIS_NONE, {0}, {1}, 1};
ggml_backend_meta_split_state ret = {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1};
for (size_t i = 0; i < GGML_MAX_SRC; i++) {
if (tensor->src[i] == nullptr || tensor->src[i] == tensor) {
continue;
}
if (ret.axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
// The first valid source sets the split state from the UNKNOWN default:
if (ret.axis == GGML_BACKEND_SPLIT_AXIS_UNKNOWN) {
ret = src_ss[i];
} else if (!split_states_equal(src_ss[i], ret)) {
continue;
}
// If after the first source there is an inconsistency, restore the UNKNOWN default and terminate the loop:
if (!split_states_equal(src_ss[i], ret)) {
ret = {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1};
break;
}
}
if (ret.axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
ret = {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1};
}
if (scalar_only && ret.axis >= 0 && ret.axis < GGML_MAX_DIMS) {
ret = {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1};
}
@@ -915,30 +924,89 @@ static struct ggml_backend_meta_split_state ggml_backend_meta_get_split_state(
if (ret.axis >= 0 && ret.axis < GGML_MAX_DIMS) {
const int64_t granularity = ret.axis == GGML_BACKEND_SPLIT_AXIS_0 ? ggml_blck_size(tensor->type) : 1;
int64_t ne_sum = 0;
int64_t ne_dev[GGML_BACKEND_META_MAX_DEVICES] = {0};
for (size_t s = 0; s < ret.n_segments; s++) {
for (size_t j = 0; j < n_bufs; j++) {
GGML_ASSERT(ret.ne[s*n_bufs + j] % granularity == 0);
ne_sum += ret.ne[s*n_bufs + j] * ret.nr[s];
const int64_t ne_sj = ret.ne[s*n_bufs + j] * ret.nr[s];
ne_sum += ne_sj;
ne_dev[j] += ne_sj;
}
}
GGML_ASSERT(ne_sum == tensor->ne[ret.axis]);
} else if (ret.axis == GGML_BACKEND_SPLIT_AXIS_PARTIAL) {
// override split state with NONE if all data is on the same device:
if (n_bufs > 1) {
size_t n_active_devs = 0;
size_t j_single = 0;
for (size_t j = 0; j < n_bufs; j++) {
if (ne_dev[j] > 0) {
n_active_devs++;
j_single = j;
}
}
if (n_active_devs == 1) {
ret.axis = GGML_BACKEND_SPLIT_AXIS_NONE;
memset(ret.ne, 0, sizeof(ret.ne));
ret.ne[j_single] = 1;
ret.nr[0] = 1;
ret.n_segments = 1;
}
}
} else if (ret.axis == GGML_BACKEND_SPLIT_AXIS_MIRRORED || ret.axis == GGML_BACKEND_SPLIT_AXIS_PARTIAL || ret.axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
GGML_ASSERT(ret.n_segments == 1);
GGML_ASSERT(ret.nr[0] == 1);
}
return ret;
}
std::vector<ggml_backend_meta_split_state> src_ss(GGML_MAX_SRC, {GGML_BACKEND_SPLIT_AXIS_NONE, {0}, {1}, 1});
std::vector<ggml_backend_meta_split_state> src_ss(GGML_MAX_SRC, {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1});
for (size_t i = 0; i < GGML_MAX_SRC; i++) {
if (tensor->src[i] == nullptr || tensor->src[i] == tensor) {
src_ss[i] = {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1};
continue;
}
src_ss[i] = ggml_backend_meta_get_split_state(stc, tensor->src[i], /*assume_sync =*/ true);
GGML_ASSERT(src_ss[i].axis != GGML_BACKEND_SPLIT_AXIS_UNKNOWN);
}
bool has_none_axis = false;
bool all_axes_none_or_mirrored = true;
ggml_backend_meta_split_state single_dev_ss = {GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1};
for (size_t i = 0; i < GGML_MAX_SRC; i++) {
if (tensor->src[i] == nullptr || tensor->src[i] == tensor) {
continue;
}
if (src_ss[i].axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
if (!has_none_axis) {
single_dev_ss = src_ss[i];
has_none_axis = true;
} else if (!split_states_equal(src_ss[i], single_dev_ss)) {
all_axes_none_or_mirrored = false;
break;
}
} else if (src_ss[i].axis != GGML_BACKEND_SPLIT_AXIS_MIRRORED) {
all_axes_none_or_mirrored = false;
break;
}
}
if (has_none_axis) {
// if at least one NONE, then all other sources must be NONE with same dev or MIRRORED:
GGML_ASSERT(all_axes_none_or_mirrored);
if (tensor->op == GGML_OP_MUL_MAT || tensor->op == GGML_OP_MUL_MAT_ID) {
// the synchronization pattern is to sync and restore MIRRORED after 2 matrix multiplications,
// therefore if src1 is already NONE, then we should transition back to PARTIAL/MIRRORED
if (src_ss[0].axis == GGML_BACKEND_SPLIT_AXIS_NONE && src_ss[1].axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
return {assume_sync ? GGML_BACKEND_SPLIT_AXIS_MIRRORED : GGML_BACKEND_SPLIT_AXIS_PARTIAL, {0}, {1}, 1};
}
} else if (tensor->op == GGML_OP_CPY) {
GGML_ASSERT(src_ss[1].axis == GGML_BACKEND_SPLIT_AXIS_NONE);
} else if (tensor->op == GGML_OP_SET_ROWS) {
GGML_ASSERT(src_ss[2].axis == GGML_BACKEND_SPLIT_AXIS_NONE);
} else if (tensor->op == GGML_OP_SET || tensor->op == GGML_OP_ACC) {
GGML_ASSERT(src_ss[0].axis == GGML_BACKEND_SPLIT_AXIS_NONE);
}
return single_dev_ss;
}
ggml_backend_meta_split_state split_state;
switch (tensor->op) {
case GGML_OP_NONE: {
@@ -1238,7 +1306,6 @@ static struct ggml_backend_meta_split_state ggml_backend_meta_get_split_state(
}
ggml_backend_meta_split_state ret = buf_ctx->split_state_cache[key].first;
GGML_ASSERT(ret.axis != GGML_BACKEND_SPLIT_AXIS_NONE);
#ifndef NDEBUG
if (ret.axis >= 0 && ret.axis < GGML_MAX_DIMS) {
int64_t ne_ret = 0;
@@ -1266,7 +1333,7 @@ static struct ggml_backend_meta_split_state ggml_backend_meta_get_split_state(co
GGML_ASSERT(ggml_backend_meta_is_host_view(tensor));
// the view is not allocated in the meta buffer, it is not split across the sub-devices
return { GGML_BACKEND_SPLIT_AXIS_NONE, {0}, {1}, 1 };
return { GGML_BACKEND_SPLIT_AXIS_UNKNOWN, {0}, {1}, 1 };
}
ggml_backend_meta_buffer_context * buf_ctx = (ggml_backend_meta_buffer_context *) tensor->buffer->context;
@@ -1288,12 +1355,6 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_m
GGML_ASSERT(split_state.n_segments <= 16);
int split_dim = split_state.axis;
int64_t ne[GGML_MAX_DIMS];
size_t nb[GGML_MAX_DIMS];
for (size_t k = 0; k < GGML_MAX_DIMS; k++) {
ne[k] = tensor->ne[k];
nb[k] = tensor->nb[k];
}
std::vector<ggml_tensor *> simple_tensors;
simple_tensors.reserve(n_simple_bufs);
@@ -1301,6 +1362,13 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_m
ggml_context * simple_ctx = stc.ctxs[j].get();
ggml_backend_buffer_t simple_buf = buf_ctx->bufs[j].get();
int64_t ne[GGML_MAX_DIMS];
size_t nb[GGML_MAX_DIMS];
for (size_t k = 0; k < GGML_MAX_DIMS; k++) {
ne[k] = tensor->ne[k];
nb[k] = tensor->nb[k];
}
if (split_dim >= 0 && split_dim < GGML_MAX_DIMS) {
// TODO: the following assert fails for llama-parallel even though the results are correct:
// GGML_ASSERT(ggml_is_contiguously_allocated(tensor));
@@ -1313,6 +1381,11 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_m
nb[i] = tensor->nb[i] * ne[split_dim]/tensor->ne[split_dim];
}
}
} else if (split_dim == GGML_BACKEND_SPLIT_AXIS_NONE && split_state.ne[j] == 0) {
for (int i = 0; i < GGML_MAX_DIMS; i++) {
ne[i] = 0;
nb[i] = 0;
}
}
ggml_tensor * t_ij = ggml_new_tensor(simple_ctx, tensor->type, GGML_MAX_DIMS, ne);
@@ -1385,6 +1458,14 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_m
simple_tensors.push_back(t_ij);
}
if (split_state.axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
for (size_t j = 0; j < n_simple_bufs; j++) {
if (split_state.ne[j] == 0) {
simple_tensors[j]->flags &= ~GGML_TENSOR_FLAG_COMPUTE;
}
}
}
// If one of the sources has a zero-sized slice, disable the computation:
for (int i = 0; i < GGML_MAX_SRC; i++) {
if (tensor->src[i] == nullptr || !ggml_backend_buffer_is_meta(tensor->src[i]->buffer)) {
@@ -1392,6 +1473,14 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_m
}
const ggml_backend_meta_split_state split_state_src = ggml_backend_meta_get_split_state(tensor->src[i], /*assume_sync =*/ true);
if (split_state_src.axis == GGML_BACKEND_SPLIT_AXIS_NONE) {
for (size_t j = 0; j < n_simple_bufs; j++) {
if (split_state_src.ne[j] == 0) {
simple_tensors[j]->flags &= ~GGML_TENSOR_FLAG_COMPUTE;
}
}
continue;
}
if (split_state_src.axis < 0 || split_state_src.axis >= GGML_MAX_DIMS) {
continue;
}
@@ -1514,6 +1603,14 @@ static void ggml_backend_meta_buffer_memset_tensor(
ggml_backend_tensor_memset(simple_tensor, value, offset, size);
}
} break;
case GGML_BACKEND_SPLIT_AXIS_NONE: {
for (size_t j = 0; j < n_bufs; j++) {
if (split_state.ne[j] != 0) {
ggml_tensor * simple_tensor = ggml_backend_meta_buffer_simple_tensor(tensor, j);
ggml_backend_tensor_memset(simple_tensor, value, offset, size);
}
}
} break;
default: {
GGML_ABORT("fatal error");
}
@@ -1615,6 +1712,14 @@ static void ggml_backend_meta_buffer_set_tensor(ggml_backend_buffer_t buffer, gg
ggml_backend_tensor_set(simple_tensor, data, offset, size);
}
} break;
case GGML_BACKEND_SPLIT_AXIS_NONE: {
for (size_t j = 0; j < n_bufs; j++) {
if (split_state.ne[j] != 0) {
ggml_tensor * simple_tensor = ggml_backend_meta_buffer_simple_tensor(tensor, j);
ggml_backend_tensor_set(simple_tensor, data, offset, size);
}
}
} break;
case GGML_BACKEND_SPLIT_AXIS_PARTIAL: {
GGML_ASSERT(tensor->type == GGML_TYPE_F32);
GGML_ASSERT(offset % sizeof(float) == 0);
@@ -1742,6 +1847,15 @@ static void ggml_backend_meta_buffer_get_tensor(ggml_backend_buffer_t buffer, co
const ggml_tensor * simple_tensor = ggml_backend_meta_buffer_simple_tensor(tensor, 0);
ggml_backend_tensor_get(simple_tensor, data, offset, size);
} break;
case GGML_BACKEND_SPLIT_AXIS_NONE: {
for (size_t j = 0; j < n_bufs; j++) {
if (split_state.ne[j] != 0) {
const ggml_tensor * simple_tensor = ggml_backend_meta_buffer_simple_tensor(tensor, j);
ggml_backend_tensor_get(simple_tensor, data, offset, size);
break;
}
}
} break;
default: {
GGML_ABORT("fatal error");
}
@@ -2015,6 +2129,14 @@ static void ggml_backend_meta_set_tensor_async(ggml_backend_t backend, ggml_tens
ggml_backend_meta_simple_backend(backend, j), ggml_backend_meta_buffer_simple_tensor(tensor, j), data, offset, size);
}
} break;
case GGML_BACKEND_SPLIT_AXIS_NONE: {
for (size_t j = 0; j < n_backends; j++) {
if (split_state.ne[j] != 0) {
ggml_backend_tensor_set_async(
ggml_backend_meta_simple_backend(backend, j), ggml_backend_meta_buffer_simple_tensor(tensor, j), data, offset, size);
}
}
} break;
default: {
GGML_ABORT("fatal error");
}
@@ -2060,6 +2182,16 @@ static void ggml_backend_meta_get_tensor_async(ggml_backend_t backend, const ggm
const ggml_tensor * simple_tensor = ggml_backend_meta_buffer_simple_tensor(tensor, 0);
ggml_backend_tensor_get_async(simple_backend, simple_tensor, data, offset, size);
} break;
case GGML_BACKEND_SPLIT_AXIS_NONE: {
for (size_t j = 0; j < n_backends; j++) {
if (split_state.ne[j] != 0) {
ggml_backend_t simple_backend = ggml_backend_meta_simple_backend(backend, j);
const ggml_tensor * simple_tensor = ggml_backend_meta_buffer_simple_tensor(tensor, j);
ggml_backend_tensor_get_async(simple_backend, simple_tensor, data, offset, size);
break;
}
}
} break;
default: {
GGML_ABORT("fatal error");
}
+81 -120
View File
@@ -73,15 +73,14 @@ void quantize_row_q8_0(const float * GGML_RESTRICT x, void * GGML_RESTRICT vy, i
y[i].d = GGML_CPU_FP32_TO_FP16(d);
for (int j = 0; j < 8; j++) {
const float32x4_t v = vec_mul(srcv[j], vec_splats(id));
for (int j = 0; j < 8; j += 4) {
/* Uses non-default rounding for vec_signed or vec_round */
const int32x4_t vi = vec_signed(__builtin_s390_vfisb(v, 4, 1));
const int32x4_t vi0 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 0], vec_splats(id)), 4, 1));
const int32x4_t vi1 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 1], vec_splats(id)), 4, 1));
const int32x4_t vi2 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 2], vec_splats(id)), 4, 1));
const int32x4_t vi3 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 3], vec_splats(id)), 4, 1));
y[i].qs[4*j + 0] = vec_extract(vi, 0);
y[i].qs[4*j + 1] = vec_extract(vi, 1);
y[i].qs[4*j + 2] = vec_extract(vi, 2);
y[i].qs[4*j + 3] = vec_extract(vi, 3);
vec_xst(vec_packs(vec_packs(vi0, vi1), vec_packs(vi2, vi3)), 0, y[i].qs + 4*j);
}
}
#else
@@ -121,17 +120,16 @@ void quantize_row_q8_1(const float * GGML_RESTRICT x, void * GGML_RESTRICT vy, i
int32x4_t acc = vec_splats(0);
for (int j = 0; j < 8; j++) {
const float32x4_t v = vec_mul(srcv[j], vec_splats(id));
for (int j = 0; j < 8; j += 4) {
/* Uses non-default rounding for vec_signed or vec_round */
const int32x4_t vi = vec_signed(__builtin_s390_vfisb(v, 4, 1));
const int32x4_t vi0 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 0], vec_splats(id)), 4, 1));
const int32x4_t vi1 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 1], vec_splats(id)), 4, 1));
const int32x4_t vi2 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 2], vec_splats(id)), 4, 1));
const int32x4_t vi3 = vec_signed(__builtin_s390_vfisb(vec_mul(srcv[j + 3], vec_splats(id)), 4, 1));
y[i].qs[4*j + 0] = vec_extract(vi, 0);
y[i].qs[4*j + 1] = vec_extract(vi, 1);
y[i].qs[4*j + 2] = vec_extract(vi, 2);
y[i].qs[4*j + 3] = vec_extract(vi, 3);
vec_xst(vec_packs(vec_packs(vi0, vi1), vec_packs(vi2, vi3)), 0, y[i].qs + 4*j);
acc = vec_add(acc, vi);
acc = vec_add(acc, vec_add(vec_add(vi0, vi1), vec_add(vi2, vi3)));
}
y[i].s = GGML_CPU_FP32_TO_FP16(d * (acc[0] + acc[1] + acc[2] + acc[3]));
@@ -248,14 +246,9 @@ void ggml_vec_dot_q4_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const voi
const int8x16_t v_yl = vec_xl(0 , y[ib].qs);
const int8x16_t v_yh = vec_xl(QK8_0/2, y[ib].qs);
const int16x8_t v_xylso = vec_mulo(v_xls, v_yl);
const int16x8_t v_xyl = vec_meadd(v_xls, v_yl, v_xylso);
const int16x8_t v_xyhso = vec_mulo(v_xhs, v_yh);
const int16x8_t v_xyh = vec_meadd(v_xhs, v_yh, v_xyhso);
const int16x8_t v_xy_ = ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_xls, v_yl), v_xhs, v_yh);
int16x8_t v_xy_ = v_xyl + v_xyh; v_xy_ += vec_reve(v_xy_);
const float32x4_t v_xy = vec_float(vec_unpackh(v_xy_));
const float32x4_t v_xy = vec_float(vec_paddl_s16(v_xy_));
const float32x4_t v_d = vec_splats(GGML_CPU_FP16_TO_FP32(x[ib].d) * GGML_CPU_FP16_TO_FP32(y[ib].d));
acc = vec_madd(v_xy, v_d, acc);
@@ -298,9 +291,6 @@ void ggml_vec_dot_q4_1_q8_1(int n, float * GGML_RESTRICT s, size_t bs, const voi
#pragma GCC unroll 4
for (; ib < nb; ++ib) {
__builtin_prefetch(x[ib].qs, 0, 1);
__builtin_prefetch(y[ib].qs, 0, 1);
summs += GGML_CPU_FP16_TO_FP32(x[ib].m) * GGML_CPU_FP16_TO_FP32(y[ib].s);
const uint8x16_t v_x = vec_xl(0, x[ib].qs);
@@ -310,8 +300,8 @@ void ggml_vec_dot_q4_1_q8_1(int n, float * GGML_RESTRICT s, size_t bs, const voi
const int8x16_t v_yl = vec_xl(0 , y[ib].qs);
const int8x16_t v_yh = vec_xl(QK8_1/2, y[ib].qs);
const int32x4_t v_xy_ = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_xl, v_yl), v_xh, v_yh);
const float32x4_t v_xy = vec_float(v_xy_);
const int16x8_t v_xy_ = ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_xl, v_yl), v_xh, v_yh);
const float32x4_t v_xy = vec_float(vec_paddl_s16(v_xy_));
const float32x4_t v_d = vec_splats(GGML_CPU_FP16_TO_FP32(x[ib].d) * GGML_CPU_FP16_TO_FP32(y[ib].d));
@@ -379,8 +369,8 @@ void ggml_vec_dot_mxfp4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
const int8x16_t v_y1l = vec_xl(0, y1->qs);
const int8x16_t v_y1h = vec_xl(QK8_0/2, y1->qs);
const int32x4_t v_xy0 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x0l, v_y0l), v_x0h, v_y0h);
const int32x4_t v_xy1 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x1l, v_y1l), v_x1h, v_y1h);
const int32x4_t v_xy0 = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_x0l, v_y0l), v_x0h, v_y0h));
const int32x4_t v_xy1 = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_x1l, v_y1l), v_x1h, v_y1h));
const float32x4_t v_xy0f = vec_float(v_xy0);
const float32x4_t v_xy1f = vec_float(v_xy1);
@@ -407,7 +397,7 @@ void ggml_vec_dot_mxfp4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
const int8x16_t v_yl = vec_xl(0, y0->qs);
const int8x16_t v_yh = vec_xl(QK8_0/2, y0->qs);
const int32x4_t v_xy = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_xl, v_yl), v_xh, v_yh);
const int32x4_t v_xy = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_xl, v_yl), v_xh, v_yh));
const float32x4_t v_xyf = vec_float(v_xy);
const float32x4_t v_d = vec_splats(GGML_E8M0_TO_FP32_HALF(x0->e) * GGML_CPU_FP16_TO_FP32(y0->d));
@@ -502,8 +492,8 @@ void ggml_vec_dot_q5_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const voi
const int8x16_t v_y1l = vec_xl(0, (const int8_t *)y1->qs);
const int8x16_t v_y1h = vec_xl(QK8_0/2, (const int8_t *)y1->qs);
const int32x4_t v_xy0 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x0lf, v_y0l), v_x0hf, v_y0h);
const int32x4_t v_xy1 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x1lf, v_y1l), v_x1hf, v_y1h);
const int32x4_t v_xy0 = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_x0lf, v_y0l), v_x0hf, v_y0h));
const int32x4_t v_xy1 = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_x1lf, v_y1l), v_x1hf, v_y1h));
const float32x4_t v_xy0f = vec_float(v_xy0);
const float32x4_t v_xy1f = vec_float(v_xy1);
@@ -548,7 +538,7 @@ void ggml_vec_dot_q5_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const voi
const int8x16_t v_yl = vec_xl(0, (const int8_t *)y0->qs);
const int8x16_t v_yh = vec_xl(QK8_0/2, (const int8_t *)y0->qs);
const int32x4_t v_xy = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_xlf, v_yl), v_xhf, v_yh);
const int32x4_t v_xy = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_xlf, v_yl), v_xhf, v_yh));
const float32x4_t v_xyf = vec_float(v_xy);
const float32x4_t v_d = vec_splats(GGML_CPU_FP16_TO_FP32(x0->d) * GGML_CPU_FP16_TO_FP32(y0->d));
@@ -653,8 +643,8 @@ void ggml_vec_dot_q5_1_q8_1(int n, float * GGML_RESTRICT s, size_t bs, const voi
const int8x16_t v_y1l = vec_xl(0 , y1->qs);
const int8x16_t v_y1h = vec_xl(QK8_1/2, y1->qs);
const int32x4_t v_xy0 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x0lf, v_y0l), v_x0hf, v_y0h);
const int32x4_t v_xy1 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x1lf, v_y1l), v_x1hf, v_y1h);
const int32x4_t v_xy0 = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_x0lf, v_y0l), v_x0hf, v_y0h));
const int32x4_t v_xy1 = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_x1lf, v_y1l), v_x1hf, v_y1h));
const float32x4_t v_xy0f = vec_float(v_xy0);
const float32x4_t v_xy1f = vec_float(v_xy1);
@@ -701,7 +691,7 @@ void ggml_vec_dot_q5_1_q8_1(int n, float * GGML_RESTRICT s, size_t bs, const voi
const int8x16_t v_yl = vec_xl(0 , y0->qs);
const int8x16_t v_yh = vec_xl(QK8_1/2, y0->qs);
const int32x4_t v_xy = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_xlf, v_yl), v_xhf, v_yh);
const int32x4_t v_xy = vec_paddl_s16(ggml_vec_dot_s16(ggml_vec_dot_s16(vec_splats((int16_t)0), v_xlf, v_yl), v_xhf, v_yh));
const float32x4_t v_xyf = vec_float(v_xy);
const float32x4_t v_d = vec_splats(GGML_CPU_FP16_TO_FP32(x0->d) * GGML_CPU_FP16_TO_FP32(y0->d));
@@ -743,9 +733,6 @@ void ggml_vec_dot_q8_0_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const voi
#pragma GCC unroll 8
for (; ib < nb; ++ib) {
__builtin_prefetch(x[ib].qs, 0, 1);
__builtin_prefetch(y[ib].qs, 0, 1);
const int8x16_t v_xl = vec_xl(0 , x[ib].qs);
const int8x16_t v_xh = vec_xl(QK8_0/2, x[ib].qs);
const int8x16_t v_yl = vec_xl(0 , y[ib].qs);
@@ -791,7 +778,7 @@ void ggml_vec_dot_q3_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
uint32_t aux[3];
uint32_t utmp[4];
const int32x4_t v_z = vec_splat_s32(0);
const int16x8_t v_z = vec_splat_s16(0);
const uint8x16_t v_3m = vec_splat_u8(0x03);
const uint8x16_t v_0c = vec_splat_u8(1);
@@ -817,7 +804,7 @@ void ggml_vec_dot_q3_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
qhbits[0] = vec_xl(0 , x0h);
qhbits[1] = vec_xl(16, x0h);
int32_t isum = 0;
int32x4_t v_isum = vec_splat_s32(0);
memcpy(aux, x[i].scales, 12);
utmp[3] = ((aux[1] >> 4) & kmask2) | (((aux[2] >> 6) & kmask1) << 4);
@@ -825,11 +812,12 @@ void ggml_vec_dot_q3_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
utmp[1] = (aux[1] & kmask2) | (((aux[2] >> 2) & kmask1) << 4);
utmp[0] = (aux[0] & kmask2) | (((aux[2] >> 0) & kmask1) << 4);
int8_t * scale = (int8_t *)utmp;
for (int j = 0; j < 16; ++j) scale[j] -= 32;
const int8x16_t v_scale = vec_sub(vec_xl(0, (const int8_t *)utmp), vec_splats((int8_t)32));
const int16x8_t v_scalel = vec_unpackh(v_scale);
const int16x8_t v_scaleh = vec_unpackl(v_scale);
for (int j = 0; j < QK_K/128; ++j) {
int32x4_t isum0, isum1, isum2, isum3;
const int16x8_t v_scales = j == 0 ? v_scalel : v_scaleh;
q3b[0] = vec_xl(0 , x0l);
q3b[1] = vec_xl(16, x0l);
@@ -855,17 +843,10 @@ void ggml_vec_dot_q3_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
q3bytes[2] = vec_sub((int8x16_t)vec_and(vec_sr(q3b[0], 2), v_3m), (int8x16_t)q3h[2]);
q3bytes[3] = vec_sub((int8x16_t)vec_and(vec_sr(q3b[1], 2), v_3m), (int8x16_t)q3h[3]);
isum0 = ggml_vec_dot_s32(v_z, q3bytes[0], q8bytes[0]);
isum1 = ggml_vec_dot_s32(v_z, q3bytes[1], q8bytes[1]);
isum2 = ggml_vec_dot_s32(v_z, q3bytes[2], q8bytes[2]);
isum3 = ggml_vec_dot_s32(v_z, q3bytes[3], q8bytes[3]);
isum += (isum0[0] + isum0[1] + isum0[2] + isum0[3]) * scale[0];
isum += (isum1[0] + isum1[1] + isum1[2] + isum1[3]) * scale[1];
isum += (isum2[0] + isum2[1] + isum2[2] + isum2[3]) * scale[2];
isum += (isum3[0] + isum3[1] + isum3[2] + isum3[3]) * scale[3];
scale += 4;
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[0], q8bytes[0]), vec_splat(v_scales, 0)));
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[1], q8bytes[1]), vec_splat(v_scales, 1)));
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[2], q8bytes[2]), vec_splat(v_scales, 2)));
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[3], q8bytes[3]), vec_splat(v_scales, 3)));
q3h[0] = vec_andc(v_2c, qhbits[0]);
q3h[1] = vec_andc(v_2c, qhbits[1]);
@@ -877,17 +858,10 @@ void ggml_vec_dot_q3_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
q3bytes[2] = vec_sub((int8x16_t)vec_and(vec_sr(q3b[0], 6), v_3m), (int8x16_t)q3h[2]);
q3bytes[3] = vec_sub((int8x16_t)vec_and(vec_sr(q3b[1], 6), v_3m), (int8x16_t)q3h[3]);
isum0 = ggml_vec_dot_s32(v_z, q3bytes[0], q8bytes[4]);
isum1 = ggml_vec_dot_s32(v_z, q3bytes[1], q8bytes[5]);
isum2 = ggml_vec_dot_s32(v_z, q3bytes[2], q8bytes[6]);
isum3 = ggml_vec_dot_s32(v_z, q3bytes[3], q8bytes[7]);
isum += vec_hsum_i32x4(isum0) * scale[0];
isum += vec_hsum_i32x4(isum1) * scale[1];
isum += vec_hsum_i32x4(isum2) * scale[2];
isum += vec_hsum_i32x4(isum3) * scale[3];
scale += 4;
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[0], q8bytes[4]), vec_splat(v_scales, 4)));
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[1], q8bytes[5]), vec_splat(v_scales, 5)));
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[2], q8bytes[6]), vec_splat(v_scales, 6)));
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q3bytes[3], q8bytes[7]), vec_splat(v_scales, 7)));
if (j == 0) {
qhbits[0] = vec_sr(qhbits[0], 4);
@@ -895,7 +869,7 @@ void ggml_vec_dot_q3_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
}
}
sum += d * isum;
sum += d * vec_hsum_i32x4(v_isum);
}
*s = sum;
@@ -931,7 +905,7 @@ void ggml_vec_dot_q4_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
#if defined(__VXE__) || defined(__VXE2__)
const uint8x16_t v_lm = vec_splat_u8(0x0F);
const int32x4_t v_z = vec_splat_s32(0);
const int16x8_t v_z = vec_splat_s16(0);
uint8x16_t v_x[2];
int8x16_t v_xl[2];
@@ -966,8 +940,7 @@ void ggml_vec_dot_q4_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
const uint8_t * GGML_RESTRICT x0 = x[i].qs;
const int8_t * GGML_RESTRICT y0 = y[i].qs;
int32_t sumi1 = 0;
int32_t sumi2 = 0;
int32x4_t v_sumi = vec_splat_s32(0);
for (int j = 0; j < QK_K/64; ++j) {
v_x[0] = vec_xl(0 , x0);
@@ -981,8 +954,8 @@ void ggml_vec_dot_q4_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
v_xl[0] = (int8x16_t)vec_and(v_x[0], v_lm);
v_xl[1] = (int8x16_t)vec_and(v_x[1], v_lm);
const int32x4_t p1 = ggml_vec_dot_s32(ggml_vec_dot_s32(v_z, v_xl[0], v_y[0]), v_xl[1], v_y[1]);
sumi1 += vec_hsum_i32x4(p1) * scales[2*j+0];
const int16x8_t v_p1 = ggml_vec_dot_s16(ggml_vec_dot_s16(v_z, v_xl[0], v_y[0]), v_xl[1], v_y[1]);
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(v_p1, vec_splats((int16_t)scales[2*j+0])));
v_y[0] = vec_xl(0 , y0);
v_y[1] = vec_xl(16, y0);
@@ -991,11 +964,11 @@ void ggml_vec_dot_q4_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
v_xl[0] = (int8x16_t)vec_sr(v_x[0], 4);
v_xl[1] = (int8x16_t)vec_sr(v_x[1], 4);
const int32x4_t p2 = ggml_vec_dot_s32(ggml_vec_dot_s32(v_z, v_xl[0], v_y[0]), v_xl[1], v_y[1]);
sumi2 += vec_hsum_i32x4(p2) * scales[2*j+1];
const int16x8_t v_p2 = ggml_vec_dot_s16(ggml_vec_dot_s16(v_z, v_xl[0], v_y[0]), v_xl[1], v_y[1]);
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(v_p2, vec_splats((int16_t)scales[2*j+1])));
}
sumf += d * (sumi1 + sumi2);
sumf += d * vec_hsum_i32x4(v_sumi);
}
*s = sumf;
@@ -1036,7 +1009,7 @@ void ggml_vec_dot_q5_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
const uint8x16_t v_1m = vec_splat_u8(0x01);
const uint8x16_t v_2m = vec_splat_u8(0x02);
const int32x4_t v_z = vec_splat_s32(0);
const int16x8_t v_z = vec_splat_s16(0);
const uchar8x16_t v_minsm = {
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
@@ -1083,7 +1056,7 @@ void ggml_vec_dot_q5_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
v_xh[0] = vec_xl(0 , x0h);
v_xh[1] = vec_xl(16, x0h);
int32_t sumi = 0;
int32x4_t v_sumi = vec_splat_s32(0);
for (int j = 0; j < QK_K/64; ++j) {
v_xl[0] = vec_xl(0 , x0l);
v_xl[1] = vec_xl(16, x0l);
@@ -1107,14 +1080,14 @@ void ggml_vec_dot_q5_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
q5b[2] = (int8x16_t)vec_or(vec_sr(v_xl[0], 4), q5h[2]);
q5b[3] = (int8x16_t)vec_or(vec_sr(v_xl[1], 4), q5h[3]);
int32x4_t sumi0 = ggml_vec_dot_s32(ggml_vec_dot_s32(v_z, q5b[0], v_y[0]), q5b[1], v_y[1]);
int32x4_t sumi1 = ggml_vec_dot_s32(ggml_vec_dot_s32(v_z, q5b[2], v_y[2]), q5b[3], v_y[3]);
const int16x8_t v_p0 = ggml_vec_dot_s16(ggml_vec_dot_s16(v_z, q5b[0], v_y[0]), q5b[1], v_y[1]);
const int16x8_t v_p1 = ggml_vec_dot_s16(ggml_vec_dot_s16(v_z, q5b[2], v_y[2]), q5b[3], v_y[3]);
sumi += vec_hsum_i32x4(sumi0) * *scales++;
sumi += vec_hsum_i32x4(sumi1) * *scales++;
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(v_p0, vec_splats((int16_t)*scales++)));
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(v_p1, vec_splats((int16_t)*scales++)));
}
sumf += d * sumi - dmin * mins;
sumf += d * vec_hsum_i32x4(v_sumi) - dmin * mins;
}
*s = sumf;
@@ -1151,7 +1124,7 @@ void ggml_vec_dot_q6_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
const uint8x16_t v_lm = vec_splat_u8(0x0F);
const uint8x16_t v_um = vec_splat_u8(0x03);
const int32x4_t v_z = vec_splat_s32(0);
const int16x8_t v_z = vec_splat_s16(0);
int8x16_t q6b[4];
uint8x16_t q6h[4];
@@ -1167,12 +1140,10 @@ void ggml_vec_dot_q6_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
const uint8_t * GGML_RESTRICT x0h = x[i].qh;
const int8_t * GGML_RESTRICT y0 = y[i].qs;
const int8_t * GGML_RESTRICT scale = x[i].scales;
const int16x8_t v_ysumsl = vec_xl(0 , y[i].bsums);
const int16x8_t v_ysumsh = vec_xl(16, y[i].bsums);
const int8x16_t v_scale = vec_xl(0, scale);
const int8x16_t v_scale = vec_xl(0, x[i].scales);
const int16x8_t v_scalel = vec_unpackh(v_scale);
const int16x8_t v_scaleh = vec_unpackl(v_scale);
@@ -1182,10 +1153,10 @@ void ggml_vec_dot_q6_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
const int32x4_t v_minsh = vec_meadd(v_ysumsh, v_scaleh, v_minsho);
const int32x4_t v_mins = vec_add(v_minsl, v_minsh);
const int32_t mins = vec_hsum_i32x4(v_mins);
int32_t isum = 0;
int32x4_t v_isum = vec_splat_s32(0);
for (int j = 0; j < QK_K/128; ++j) {
const int16x8_t v_scales = j == 0 ? v_scalel : v_scaleh;
// Load model upper 2 bits
v_xh[0] = vec_xl(0 , x0h);
v_xh[1] = vec_xl(16, x0h);
@@ -1217,18 +1188,10 @@ void ggml_vec_dot_q6_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
q6b[2] = (int8x16_t)(vec_or(vec_and(v_xl[2], v_lm), q6h[2]));
q6b[3] = (int8x16_t)(vec_or(vec_and(v_xl[3], v_lm), q6h[3]));
int32x4_t summs0 = ggml_vec_dot_s32(v_z, q6b[0], v_y[0]);
int32x4_t summs1 = ggml_vec_dot_s32(v_z, q6b[1], v_y[1]);
int32x4_t summs2 = ggml_vec_dot_s32(v_z, q6b[2], v_y[2]);
int32x4_t summs3 = ggml_vec_dot_s32(v_z, q6b[3], v_y[3]);
isum += vec_hsum_i32x4(summs0) * scale[0] +
vec_hsum_i32x4(summs1) * scale[1] +
vec_hsum_i32x4(summs2) * scale[2] +
vec_hsum_i32x4(summs3) * scale[3];
scale += 4;
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[0], v_y[0]), vec_splat(v_scales, 0)));
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[1], v_y[1]), vec_splat(v_scales, 1)));
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[2], v_y[2]), vec_splat(v_scales, 2)));
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[3], v_y[3]), vec_splat(v_scales, 3)));
// Load activation quants
v_y[0] = vec_xl(0 , y0);
@@ -1251,20 +1214,15 @@ void ggml_vec_dot_q6_K_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const voi
q6b[2] = (int8x16_t)(vec_or(vec_sr(v_xl[2], 4), q6h[2]));
q6b[3] = (int8x16_t)(vec_or(vec_sr(v_xl[3], 4), q6h[3]));
summs0 = ggml_vec_dot_s32(v_z, q6b[0], v_y[0]);
summs1 = ggml_vec_dot_s32(v_z, q6b[1], v_y[1]);
summs2 = ggml_vec_dot_s32(v_z, q6b[2], v_y[2]);
summs3 = ggml_vec_dot_s32(v_z, q6b[3], v_y[3]);
isum += vec_hsum_i32x4(summs0) * scale[0] +
vec_hsum_i32x4(summs1) * scale[1] +
vec_hsum_i32x4(summs2) * scale[2] +
vec_hsum_i32x4(summs3) * scale[3];
scale += 4;
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[0], v_y[0]), vec_splat(v_scales, 4)));
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[1], v_y[1]), vec_splat(v_scales, 5)));
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[2], v_y[2]), vec_splat(v_scales, 6)));
v_isum = vec_add(v_isum, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, q6b[3], v_y[3]), vec_splat(v_scales, 7)));
}
sum += d_all * y[i].d * (isum - 32 * mins);
v_isum = vec_sub(v_isum, vec_sl(v_mins, 5));
sum += d_all * y[i].d * vec_hsum_i32x4(v_isum);
}
*s = sum;
@@ -1477,6 +1435,7 @@ void ggml_vec_dot_iq4_xs_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const v
#if defined(__VXE__) || defined(__VXE2__)
const int8x16_t v_k = vec_xl(0, kvalues_iq4nl);
const uint8x16_t v_m = vec_splat_u8(0x0F);
const int16x8_t v_z = vec_splat_s16(0);
float sumf = 0;
@@ -1486,7 +1445,7 @@ void ggml_vec_dot_iq4_xs_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const v
uint16_t h = x[ibl].scales_h;
int sumi1 = 0, sumi2 = 0;
int32x4_t v_sumi = vec_splat_s32(0);
for (int ib = 0; ib < QK_K/64; ++ib) {
const uint8x16_t v_x0 = vec_xl(0 , q4);
const uint8x16_t v_x1 = vec_xl(QK4_NL/2, q4);
@@ -1508,19 +1467,21 @@ void ggml_vec_dot_iq4_xs_q8_K(int n, float * GGML_RESTRICT s, size_t bs, const v
const int8x16_t v_y3 = vec_xl(48, q8);
q8 += 64;
int32x4_t vsumi0 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x0l, v_y0), v_x0h, v_y1);
int32x4_t vsumi1 = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_x1l, v_y2), v_x1h, v_y3);
int ls1 = ((x[ibl].scales_l[ib] & 0xF) | ((h << 4) & 0x30)) - 32;
int ls2 = ((x[ibl].scales_l[ib] >> 4) | ((h << 2) & 0x30)) - 32;
h >>= 4;
sumi1 += vec_hsum_i32x4(vsumi0) * ls1;
sumi2 += vec_hsum_i32x4(vsumi1) * ls2;
const int16x8_t v_ls1 = vec_splats((int16_t)ls1);
const int16x8_t v_ls2 = vec_splats((int16_t)ls2);
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, v_x0l, v_y0), v_ls1));
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, v_x0h, v_y1), v_ls1));
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, v_x1l, v_y2), v_ls2));
v_sumi = vec_add(v_sumi, ggml_vec_madd_s16(ggml_vec_dot_s16(v_z, v_x1h, v_y3), v_ls2));
}
sumf += GGML_CPU_FP16_TO_FP32(x[ibl].d) * y[ibl].d * (sumi1 + sumi2);
sumf += GGML_CPU_FP16_TO_FP32(x[ibl].d) * y[ibl].d * vec_hsum_i32x4(v_sumi);
}
*s = sumf;
+23 -17
View File
@@ -112,17 +112,20 @@ void ggml_gemv_q4_0_4x4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
const int8_t * y_lo = a_ptr[l].qs;
const int8_t * y_hi = y_lo + qk / 2;
int16x8_t v_sumi = vec_splats((int16_t)0);
const int16x8_t v_zero = vec_splats((int16_t)0);
v_sumi = ggml_vec_dot_s16(v_sumi, v_x0l, ggml_vec_xl_s8x4_splat(y_lo + 0));
v_sumi = ggml_vec_dot_s16(v_sumi, v_x1l, ggml_vec_xl_s8x4_splat(y_lo + 4));
v_sumi = ggml_vec_dot_s16(v_sumi, v_x2l, ggml_vec_xl_s8x4_splat(y_lo + 8));
v_sumi = ggml_vec_dot_s16(v_sumi, v_x3l, ggml_vec_xl_s8x4_splat(y_lo + 12));
// separate sums, a long multiply-add chain is slow
int16x8_t v_sumi0 = ggml_vec_dot_s16(v_zero, v_x0l, ggml_vec_xl_s8x4_splat(y_lo + 0));
int16x8_t v_sumi1 = ggml_vec_dot_s16(v_zero, v_x1l, ggml_vec_xl_s8x4_splat(y_lo + 4));
int16x8_t v_sumi2 = ggml_vec_dot_s16(v_zero, v_x2l, ggml_vec_xl_s8x4_splat(y_lo + 8));
int16x8_t v_sumi3 = ggml_vec_dot_s16(v_zero, v_x3l, ggml_vec_xl_s8x4_splat(y_lo + 12));
v_sumi = ggml_vec_dot_s16(v_sumi, v_x0h, ggml_vec_xl_s8x4_splat(y_hi + 0));
v_sumi = ggml_vec_dot_s16(v_sumi, v_x1h, ggml_vec_xl_s8x4_splat(y_hi + 4));
v_sumi = ggml_vec_dot_s16(v_sumi, v_x2h, ggml_vec_xl_s8x4_splat(y_hi + 8));
v_sumi = ggml_vec_dot_s16(v_sumi, v_x3h, ggml_vec_xl_s8x4_splat(y_hi + 12));
v_sumi0 = ggml_vec_dot_s16(v_sumi0, v_x0h, ggml_vec_xl_s8x4_splat(y_hi + 0));
v_sumi1 = ggml_vec_dot_s16(v_sumi1, v_x1h, ggml_vec_xl_s8x4_splat(y_hi + 4));
v_sumi2 = ggml_vec_dot_s16(v_sumi2, v_x2h, ggml_vec_xl_s8x4_splat(y_hi + 8));
v_sumi3 = ggml_vec_dot_s16(v_sumi3, v_x3h, ggml_vec_xl_s8x4_splat(y_hi + 12));
const int16x8_t v_sumi = vec_add(vec_add(v_sumi0, v_sumi1), vec_add(v_sumi2, v_sumi3));
const float32x4_t v_yd = vec_splats(GGML_CPU_FP16_TO_FP32(a_ptr[l].d));
const float32x4_t v_xd = ggml_vec_xl_f16x4_finite(b_ptr[l].d);
@@ -162,6 +165,8 @@ void ggml_gemm_q4_0_4x4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
}
for (int l = 0; l < nb; l++) {
const int16x8_t v_zero = vec_splats((int16_t)0);
int16x8_t v_sumi0 = vec_splats((int16_t)0);
int16x8_t v_sumi1 = vec_splats((int16_t)0);
int16x8_t v_sumi2 = vec_splats((int16_t)0);
@@ -175,15 +180,16 @@ void ggml_gemm_q4_0_4x4_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const vo
const int8_t * y_lo = a_ptr[l].qs + 16 * k;
const int8_t * y_hi = y_lo + qk / 2 * 4;
v_sumi0 = ggml_vec_dot_s16(v_sumi0, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 0));
v_sumi1 = ggml_vec_dot_s16(v_sumi1, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 4));
v_sumi2 = ggml_vec_dot_s16(v_sumi2, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 8));
v_sumi3 = ggml_vec_dot_s16(v_sumi3, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 12));
// add each product pair with vec_add, a long multiply-add chain is slow
const int16x8_t v_xyl0 = ggml_vec_dot_s16(v_zero, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 0));
const int16x8_t v_xyl1 = ggml_vec_dot_s16(v_zero, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 4));
const int16x8_t v_xyl2 = ggml_vec_dot_s16(v_zero, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 8));
const int16x8_t v_xyl3 = ggml_vec_dot_s16(v_zero, v_xl, ggml_vec_xl_s8x4_splat(y_lo + 12));
v_sumi0 = ggml_vec_dot_s16(v_sumi0, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 0));
v_sumi1 = ggml_vec_dot_s16(v_sumi1, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 4));
v_sumi2 = ggml_vec_dot_s16(v_sumi2, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 8));
v_sumi3 = ggml_vec_dot_s16(v_sumi3, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 12));
v_sumi0 = vec_add(v_sumi0, ggml_vec_dot_s16(v_xyl0, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 0)));
v_sumi1 = vec_add(v_sumi1, ggml_vec_dot_s16(v_xyl1, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 4)));
v_sumi2 = vec_add(v_sumi2, ggml_vec_dot_s16(v_xyl2, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 8)));
v_sumi3 = vec_add(v_sumi3, ggml_vec_dot_s16(v_xyl3, v_xh, ggml_vec_xl_s8x4_splat(y_hi + 12)));
}
const float32x4_t v_yd = __lzs_f16cx4_load(a_ptr[l].d);
+8 -3
View File
@@ -487,7 +487,7 @@ inline static int16x8_t vec_padd_s16(int16x8_t a, int16x8_t b) {
inline static int32x4_t vec_paddl_s16(int16x8_t a) {
const int16x8_t v_ones = vec_splats((int16_t)1);
return vec_mule(a, v_ones) + vec_mulo(a, v_ones);
return vec_meadd(a, v_ones, vec_mulo(a, v_ones));
}
/**
@@ -507,9 +507,14 @@ inline static int16x8_t ggml_vec_dot_s16(int16x8_t acc, int8x16_t a, int8x16_t b
return vec_meadd(a, b, vec_moadd(a, b, acc));
}
// a * b, each pair of 16-bit products summed into one 32-bit lane
inline static int32x4_t ggml_vec_madd_s16(int16x8_t a, int16x8_t b) {
return vec_meadd(a, b, vec_mulo(a, b));
}
inline static int32x4_t ggml_vec_dot_s32(int32x4_t acc, int8x16_t a, int8x16_t b) {
const int16x8_t p = vec_mule(a, b) + vec_mulo(a, b);
return acc + (vec_unpackh(p) + vec_unpackl(p));
const int16x8_t p = vec_meadd(a, b, vec_mulo(a, b));
return acc + ggml_vec_madd_s16(p, vec_splats((int16_t)1));
}
#endif
+2 -4
View File
@@ -1380,10 +1380,8 @@ class tinyBLAS_Q0_VXE {
static constexpr bool has_min = std::is_same<TB, block_q8_1>::value;
static int32x4_t dot_s8_wide(int8x16_t v_x, int8x16_t v_y) {
const int16x8_t v_even = vec_mule(v_x, v_y);
const int16x8_t v_odd = vec_mulo(v_x, v_y);
// Two (-128) * (-128) products can overflow a signed 16-bit sum.
return vec_unpackh(v_even) + vec_unpackl(v_even) + vec_unpackh(v_odd) + vec_unpackl(v_odd);
// v_y is never -128, so the sum of two products fits in 16 bits
return vec_paddl_s16(vec_meadd(v_x, v_y, vec_mulo(v_x, v_y)));
}
static int32x4_t dot(int8x16_t v_xl, int8x16_t v_xh, int8x16_t v_yl, int8x16_t v_yh) {
+47 -18
View File
@@ -517,35 +517,64 @@ struct ggml_cuda_unroll<1> {
}
};
template<int width = WARP_SIZE>
// If only_lane0_is_used is set to true, then the performance can be better but only lane 0 is guaranteed to have the correct result.
template<typename T, int width, bool only_lane0_is_used = false>
static __device__ __forceinline__ T warp_reduce_sum_impl(T x) {
#if defined(GGML_USE_HIP)
if constexpr (width <= 64 && width <= ggml_cuda_get_physical_warp_size()) {
static_assert(width >= 2 && width <= 64 && (width & (width - 1)) == 0, "width must be a power of two between 2 and 64");
x += ggml_hip_dpp_update<GGML_HIP_DPP_QUAD_PERM_1032>(x);
if constexpr (width >= 4) {
x += ggml_hip_dpp_update<GGML_HIP_DPP_QUAD_PERM_2301>(x);
}
if constexpr (width >= 8) {
x += ggml_hip_dpp_update<GGML_HIP_DPP_ROW_HALF_MIRROR>(x);
}
if constexpr (width >= 16) {
x += ggml_hip_dpp_update<GGML_HIP_DPP_ROW_ROR_8>(x);
}
if constexpr (width == 64) {
x += ggml_hip_dpp_update<GGML_HIP_DPP_ROW_BCAST_15>(x);
x += ggml_hip_dpp_update<GGML_HIP_DPP_ROW_BCAST_31>(x);
if constexpr (only_lane0_is_used) {
return ggml_hip_dpp_update<GGML_HIP_DPP_WAVE_ROR_1>(x);
} else {
return ggml_cuda_shfl(x, 63, 64);
}
}
if constexpr (width == 32) {
return x + ggml_hip_swizzle<GGML_HIP_SWIZZLE_SWAP16>(x);
}
return x;
} else
#endif // defined(GGML_USE_HIP)
{
#pragma unroll
for (int offset = width/2; offset > 0; offset >>= 1) {
x += ggml_cuda_shfl_xor(x, offset, width);
}
return x;
}
}
template<int width = WARP_SIZE, bool only_lane0_is_used = false>
static __device__ __forceinline__ int warp_reduce_sum(int x) {
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA) && __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
return __reduce_add_sync(GGML_CUDA_FULL_THREAD_MASK, x);
#else
#pragma unroll
for (int offset = width/2; offset > 0; offset >>= 1) {
x += ggml_cuda_shfl_xor(x, offset, width);
}
return x;
return warp_reduce_sum_impl<int, width, only_lane0_is_used>(x);
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA) && __CUDA_ARCH__ >= GGML_CUDA_CC_AMPERE
}
template<int width = WARP_SIZE>
template<int width = WARP_SIZE, bool only_lane0_is_used = false>
static __device__ __forceinline__ float warp_reduce_sum(float x) {
#pragma unroll
for (int offset = width/2; offset > 0; offset >>= 1) {
x += ggml_cuda_shfl_xor(x, offset, width);
}
return x;
return warp_reduce_sum_impl<float, width, only_lane0_is_used>(x);
}
template<int width = WARP_SIZE>
template<int width = WARP_SIZE, bool only_lane0_is_used = false>
static __device__ __forceinline__ float2 warp_reduce_sum(float2 a) {
#pragma unroll
for (int offset = width/2; offset > 0; offset >>= 1) {
a.x += ggml_cuda_shfl_xor(a.x, offset, width);
a.y += ggml_cuda_shfl_xor(a.y, offset, width);
}
a.x = warp_reduce_sum_impl<float, width, only_lane0_is_used>(a.x);
a.y = warp_reduce_sum_impl<float, width, only_lane0_is_used>(a.y);
return a;
}
+1 -1
View File
@@ -16,7 +16,7 @@ static __global__ void count_equal(const T * __restrict__ x, const T * __restric
nequal += xi == yi;
}
nequal = warp_reduce_sum(nequal);
nequal = warp_reduce_sum<WARP_SIZE, true>(nequal);
if (threadIdx.x != 0) {
return;
+1 -1
View File
@@ -40,7 +40,7 @@ static __global__ void cross_entropy_loss_f32(
const float logit_i = use_shared ? tmp[i] : logits[i];
loss += (logit_i - max_logit - sum) * labels[i];
}
loss = -warp_reduce_sum(loss) / (float)k;
loss = -warp_reduce_sum<WARP_SIZE, true>(loss) / (float)k;
if (threadIdx.x != 0) {
return;
+1 -1
View File
@@ -513,7 +513,7 @@ static __global__ void flash_attn_ext_vec(
#endif // V_DOT2_F32_F16_AVAILABLE
KQ_sum[j_VKQ] *= kqmax_scale;
KQ_sum[j_VKQ] = warp_reduce_sum(KQ_sum[j_VKQ]);
KQ_sum[j_VKQ] = warp_reduce_sum<WARP_SIZE, true>(KQ_sum[j_VKQ]);
if (threadIdx.x == 0) {
KQ_sum_shared[j_VKQ][threadIdx.y] = KQ_sum[j_VKQ];
}
+49 -70
View File
@@ -198,9 +198,7 @@ static void ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1(ggml_backend_cuda_con
ggml_cuda_flash_attn_ext_mma_f16_case<DKQ, DV, 64/ncols2, ncols2, type_K, type_V>(ctx, dst);
}
template <int DKQ, int DV, ggml_type type_K, ggml_type type_V>
static void ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
const int cc = ggml_cuda_info().devices[ggml_cuda_get_device()].cc;
static int ggml_cuda_flash_attn_ext_mma_f16_get_ncols2(const int cc, const ggml_tensor * dst) {
const ggml_tensor * KQV = dst;
const ggml_tensor * Q = dst->src[0];
const ggml_tensor * K = dst->src[1];
@@ -230,71 +228,56 @@ static void ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2(ggml_backend_cuda_con
}
}
if (!use_gqa_opt) {
return 1;
}
GGML_ASSERT(Q->ne[2] % K->ne[2] == 0);
const int gqa_ratio = Q->ne[2] / K->ne[2];
// On Volta the GQA optimizations aren't as impactful vs. minimizing wasted compute:
if (cc == GGML_CUDA_CC_VOLTA) {
if (use_gqa_opt && gqa_ratio % 8 == 0) {
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 8, type_K, type_V>(ctx, dst);
return;
}
const int ncols2_max = Q->ne[0] == 320 ? 32 : ((Q->ne[0] == 576 || Q->ne[0] == 192) ? 16 : 8);
if (use_gqa_opt && gqa_ratio % 4 == 0) {
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 4, type_K, type_V>(ctx, dst);
return;
}
if constexpr (DKQ <= 256) {
if (use_gqa_opt && gqa_ratio % 2 == 0) {
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 2, type_K, type_V>(ctx, dst);
return;
}
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 1, type_K, type_V>(ctx, dst);
return;
} else {
GGML_ABORT("fatal error");
// On Volta and RDNA it is preferable to minimize wasted compute vs. duplicate I/O for the mask:
if (cc == GGML_CUDA_CC_VOLTA || (amd_wmma_available(cc) && gqa_ratio % 2 == 0)) {
int ncols2 = 1;
while (gqa_ratio % (2*ncols2) == 0 && ncols2 < ncols2_max) {
ncols2 *= 2;
}
return ncols2;
}
// On RDNA it is preferable to minimize wasted compute vs. duplicate I/O for the mask.
if (amd_wmma_available(cc)) {
if (use_gqa_opt && gqa_ratio % 8 == 0) {
int ncols2 = 1;
while (gqa_ratio > ncols2 && ncols2 < ncols2_max) {
ncols2 *= 2;
}
return ncols2;
}
template <int DKQ, int DV, ggml_type type_K, ggml_type type_V>
static void ggml_cuda_flash_attn_ext_mma_f16_switch_ncols2(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
const int cc = ggml_cuda_info().devices[ggml_cuda_get_device()].cc;
const int ncols2 = ggml_cuda_flash_attn_ext_mma_f16_get_ncols2(cc, dst);
switch (ncols2) {
case 8:
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 8, type_K, type_V>(ctx, dst);
return;
}
if (use_gqa_opt && gqa_ratio % 4 == 0) {
break;
case 4:
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 4, type_K, type_V>(ctx, dst);
return;
}
if (use_gqa_opt && gqa_ratio % 2 == 0) {
break;
case 2:
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 2, type_K, type_V>(ctx, dst);
return;
}
}
if (use_gqa_opt && gqa_ratio > 4) {
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 8, type_K, type_V>(ctx, dst);
return;
}
if (use_gqa_opt && gqa_ratio > 2) {
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 4, type_K, type_V>(ctx, dst);
return;
}
if (use_gqa_opt && gqa_ratio > 1) {
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 2, type_K, type_V>(ctx, dst);
return;
}
if constexpr (DKQ <= 256) {
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 1, type_K, type_V>(ctx, dst);
} else {
GGML_ABORT("fatal error");
break;
case 1:
if constexpr (DKQ <= 256) {
ggml_cuda_flash_attn_ext_mma_f16_switch_ncols1<DKQ, DV, 1, type_K, type_V>(ctx, dst);
break;
} else {
GGML_ABORT("fatal error");
}
default:
GGML_ABORT("fatal error");
}
}
@@ -757,20 +740,16 @@ static best_fattn_kernel ggml_cuda_get_best_fattn_kernel(const int device, const
return BEST_FATTN_KERNEL_MMA_F16;
}
const int ncols2_max = Q->ne[0] == 320 ? 32 : ((Q->ne[0] == 576 || Q->ne[0] == 192) ? 16 : 8);
int gqa_ratio_eff = 1;
while (max_bias == 0.0f && (!mask || mask->ne[2] == 1) && gqa_ratio % (2*gqa_ratio_eff) == 0 && gqa_ratio_eff < ncols2_max) {
gqa_ratio_eff *= 2;
}
const int ncols2 = ggml_cuda_flash_attn_ext_mma_f16_get_ncols2(cc, dst);
// the tile kernel for DKQ=576 only has the ncols2 = 4 and 16 variants
const best_fattn_kernel tile_kernel = Q->ne[0] == 576 && gqa_ratio % 4 != 0 ? BEST_FATTN_KERNEL_NONE : BEST_FATTN_KERNEL_TILE;
if (volta_mma_available(cc) && Q->ne[0] != 40 && Q->ne[0] != 72) {
if (can_use_vector_kernel && Q->ne[1] * gqa_ratio_eff <= 2) {
if (can_use_vector_kernel && Q->ne[1] * ncols2 <= 2) {
return BEST_FATTN_KERNEL_VEC;
}
if (Q->ne[1] * gqa_ratio_eff <= 16) {
if (Q->ne[1] * ncols2 <= 16) {
return tile_kernel; // On Volta tensor cores are only faster for sufficiently large matrices.
}
return BEST_FATTN_KERNEL_MMA_F16;
@@ -783,23 +762,23 @@ static best_fattn_kernel ggml_cuda_get_best_fattn_kernel(const int device, const
// AMD MFMA needs a certain minimum batch size to outscale the tile kernel for large head sizes.
if (amd_mfma_available(cc) && Q->ne[0] != 40 && Q->ne[0] != 72) {
if ((Q->ne[0] <= 64 && Q->ne[1] * gqa_ratio_eff > 8)) {
if ((Q->ne[0] <= 64 && Q->ne[1] * ncols2 > 8)) {
return BEST_FATTN_KERNEL_MMA_F16;
}
if ((Q->ne[0] <= 128 && Q->ne[1] * gqa_ratio_eff > 16)) {
if ((Q->ne[0] <= 128 && Q->ne[1] * ncols2 > 16)) {
return BEST_FATTN_KERNEL_MMA_F16;
}
if ((Q->ne[0] <= 256 && Q->ne[1] * gqa_ratio_eff > 64)) {
if ((Q->ne[0] <= 256 && Q->ne[1] * ncols2 > 64)) {
return BEST_FATTN_KERNEL_MMA_F16;
}
if (Q->ne[0] > 256 && gqa_opt_applies && Q->ne[1] * gqa_ratio_eff > 128) {
if (Q->ne[0] > 256 && gqa_opt_applies && Q->ne[1] * ncols2 > 128) {
return BEST_FATTN_KERNEL_MMA_F16;
}
}
// AMD WMMA is faster than the tile kernel if the wide tiles with high arithmetic intensity can be utilized.
if ((amd_wmma_available(cc) && gqa_opt_applies && Q->ne[0] <= 256) && Q->ne[0] != 40 && Q->ne[0] != 72 &&
Q->ne[1] * gqa_ratio_eff > (Q->ne[0] <= 128 ? 8 : 16)) {
Q->ne[1] * ncols2 > (Q->ne[0] <= 128 ? 8 : 16)) {
return BEST_FATTN_KERNEL_MMA_F16;
}
+2 -2
View File
@@ -203,7 +203,7 @@ gated_delta_net_cuda(const float * q,
attn_partial += s_shard[r] * q_reg[r];
}
float attn_col = warp_reduce_sum<lanes_per_col>(attn_partial);
float attn_col = warp_reduce_sum<lanes_per_col, true>(attn_partial);
if (lane_in_col == 0) {
attn_data[col] = attn_col * scale;
@@ -237,7 +237,7 @@ gated_delta_net_cuda(const float * q,
attn_partial += s_shard[r] * q_reg[r];
}
float attn_col = warp_reduce_sum<lanes_per_col>(attn_partial);
float attn_col = warp_reduce_sum<lanes_per_col, true>(attn_partial);
if (lane_in_col == 0) {
attn_data[col] = attn_col * scale;
+7 -1
View File
@@ -483,8 +483,14 @@ static ggml_cuda_device_info ggml_cuda_init() {
GGML_LOG_INFO(
" Device %d: %s\n", turing_devices_without_mma[device_pos].first, turing_devices_without_mma[device_pos].second.c_str());
}
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA) && CUDART_VERSION >= 13000
// CUDA 13 dropped compute_61, so the Pascal code can only be compiled with an older toolkit
GGML_LOG_INFO(
"Consider compiling with CMAKE_CUDA_ARCHITECTURES=61-virtual;80-virtual and DGGML_CUDA_FORCE_MMQ to force the use of the Pascal code for Turing.\n");
"Consider compiling with CUDA 12, -DCMAKE_CUDA_ARCHITECTURES=\"61-virtual;80-virtual\" and -DGGML_CUDA_FORCE_MMQ=ON to force the use of the Pascal code for Turing (CUDA 13 cannot compile for compute_61).\n");
#else
GGML_LOG_INFO(
"Consider compiling with -DCMAKE_CUDA_ARCHITECTURES=\"61-virtual;80-virtual\" and -DGGML_CUDA_FORCE_MMQ=ON to force the use of the Pascal code for Turing.\n");
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA) && CUDART_VERSION >= 13000
}
for (int id = 0; id < info.device_count; ++id) {
+1 -1
View File
@@ -290,7 +290,7 @@ static __global__ void lightning_indexer_kernel_vec(
#pragma unroll
for (int k = 0; k < K_VECS_PER_WARP; ++k) {
float sum = warp_reduce_sum(qk[k]);
float sum = warp_reduce_sum<WARP_SIZE, true>(qk[k]);
// ReLU, weight
if (i_lane == 0) {
+462 -5
View File
@@ -7,8 +7,8 @@
#include <type_traits>
// NVIDIA only: the kernel uses the NVIDIA int8 MMA fragment layout and cp.async.
#if !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
// mul_mat_q_few for NVIDIA uses the int8 MMA fragment layout and cp.async, mul_mat_q_few_wmma for RDNA the WMMA layout. Not on MUSA.
#if !defined(GGML_USE_MUSA)
using namespace ggml_cuda_mma;
@@ -719,6 +719,353 @@ static __global__ void mul_mat_q_few(
#endif // defined(CP_ASYNC_AVAILABLE)
}
// RDNA version with WMMA for up to 16 src1 columns. A WMMA multiplies 16x16 int8 matrices, see mma.cuh:
// A = src1, B = src0, C = A @ B.
// A and B: lane l holds the column resp. row l%16, the values [16k, 16k + 16) on RDNA3 and [8*(l/16), 8*(l/16) + 8) on RDNA4.
// C: lane l holds the src1 columns 2v + l/16 (RDNA3) resp. 8*(l/16) + v (RDNA4) of the src0 row l%16.
// So the src0 scales of a row stay in the lane that decodes it, the src1 scales of the C columns come with the layout in quantize.cuh.
// The lanes decode their rows straight from global memory. A ring as in mul_mat_q_few, filled through registers without cp.async, was slower.
// A second group of 16 columns spills registers with ROCm 7.2.
static constexpr __host__ __device__ bool mmq_few_wmma_supported(const ggml_type type) {
return type == GGML_TYPE_IQ4_NL || type == GGML_TYPE_Q4_K || type == GGML_TYPE_Q5_K || type == GGML_TYPE_Q6_K;
}
// the reduction over the warps
static constexpr int MMQ_FEW_WMMA_NBYTES_SHARED = (MMQ_FEW_NWARPS - 1)*8*WARP_SIZE*sizeof(float);
#if defined(AMD_WMMA_AVAILABLE)
// The A and B tiles of a lane for one WMMA, MIRRORED on RDNA3 where both half-warps hold the same data.
#if defined(AMD_WMMA_256B_AVAILABLE)
using mmq_few_tile_ab = tile<16, 4, int, DATA_LAYOUT_I_MAJOR_MIRRORED>;
#else
using mmq_few_tile_ab = tile<16, 4, int, DATA_LAYOUT_I_MAJOR>;
#endif
using mmq_few_tile_c = tile<16, 16, int, DATA_LAYOUT_J_MAJOR>;
// int32 per lane and WMMA, 4 on RDNA3 and 2 on RDNA4
static constexpr int MMQ_FEW_WMMA_NE = mmq_few_tile_ab::ne;
// The src1 fragments of a lane for one sub-block, see quantize.cuh.
struct mmq_few_wmma_y {
int qs[2][MMQ_FEW_WMMA_NE]; // [hh] holds the values [16*hh, 16*hh + 16) of the WMMA
int ds[8]; // d (D4) resp. (d, sum) (DS4) of the C columns, ds[v] of C.x[v]
};
// The C registers of a lane, on RDNA3 the ones with v >= 4 hold only the columns >= 8.
template <bool half>
static constexpr int mmq_few_wmma_nv() {
return half && MMQ_FEW_WMMA_NE == 4 ? 4 : 8;
}
// half: only the first 8 columns are used, the others are zero.
template <bool half>
static __device__ __forceinline__ mmq_few_wmma_y mmq_few_wmma_load_y(const int4 * y, const int s) {
const int m = threadIdx.x % 16;
const int h = threadIdx.x / 16;
mmq_few_wmma_y yf;
if constexpr (MMQ_FEW_WMMA_NE == 2) {
// RDNA4: the lane holds the values [16*hh + 8*h, 16*hh + 8*h + 8) of column m.
// The src1 quantize kernel zeroes the columns beyond ne1, a branch to skip the unused ones is more expensive than the loads.
const int2 * y2 = (const int2 *) y;
const int2 q0 = y2[(s*MMQ_FEW_WMMA_NCOLS + m)*4 + 0 + h];
const int2 q1 = y2[(s*MMQ_FEW_WMMA_NCOLS + m)*4 + 2 + h];
yf.qs[0][0] = q0.x; yf.qs[0][1] = q0.y;
yf.qs[1][0] = q1.x; yf.qs[1][1] = q1.y;
} else if (half && m >= MMQ_FEW_WMMA_NCOLS/2) {
yf.qs[0][0] = 0; yf.qs[0][1] = 0; yf.qs[0][2] = 0; yf.qs[0][3] = 0;
yf.qs[1][0] = 0; yf.qs[1][1] = 0; yf.qs[1][2] = 0; yf.qs[1][3] = 0;
} else {
const int4 q0 = y[(s*MMQ_FEW_WMMA_NCOLS + m)*2 + 0];
const int4 q1 = y[(s*MMQ_FEW_WMMA_NCOLS + m)*2 + 1];
yf.qs[0][0] = q0.x; yf.qs[0][1] = q0.y; yf.qs[0][2] = q0.z; yf.qs[0][3] = q0.w;
yf.qs[1][0] = q1.x; yf.qs[1][1] = q1.y; yf.qs[1][2] = q1.z; yf.qs[1][3] = q1.w;
}
if constexpr (MMQ_FEW_WMMA_NE == 2) {
// RDNA4: C.x[v] is the column 8*h + v
const int4 d0 = y[8*MMQ_FEW_WMMA_NCOLS*2 + 4*s + 0 + h];
const int4 d1 = y[8*MMQ_FEW_WMMA_NCOLS*2 + 4*s + 2 + h];
yf.ds[0] = d0.x; yf.ds[1] = d1.x; yf.ds[2] = d0.y; yf.ds[3] = d1.y;
yf.ds[4] = d0.z; yf.ds[5] = d1.z; yf.ds[6] = d0.w; yf.ds[7] = d1.w;
} else {
const int4 ds0 = y[8*MMQ_FEW_WMMA_NCOLS*2 + (s*2 + h)*2 + 0];
const int4 ds1 = half ? make_int4(0, 0, 0, 0) : y[8*MMQ_FEW_WMMA_NCOLS*2 + (s*2 + h)*2 + 1];
yf.ds[0] = ds0.x; yf.ds[1] = ds0.y; yf.ds[2] = ds0.z; yf.ds[3] = ds0.w;
yf.ds[4] = ds1.x; yf.ds[5] = ds1.y; yf.ds[6] = ds1.z; yf.ds[7] = ds1.w;
}
return yf;
}
template <mmq_q8_1_ds_layout ds_layout>
static __device__ __forceinline__ float mmq_few_wmma_get_d(const mmq_few_wmma_y & yf, const int v) {
if constexpr (ds_layout == MMQ_Q8_1_DS_LAYOUT_D4) {
return __int_as_float(yf.ds[v]);
} else {
return __low2float(*(const half2 *) &yf.ds[v]);
}
}
static __device__ __forceinline__ float mmq_few_wmma_get_sum(const mmq_few_wmma_y & yf, const int v) {
return __high2float(*(const half2 *) &yf.ds[v]);
}
// n ints at the even byte offset o of the 4 byte aligned p, with whole 4 byte loads. In the unrolled decoders o is a constant.
template <int n>
static __device__ __forceinline__ void mmq_few_wmma_get_ints_b2(const char * p, const int o, int * dst) {
const int * w = (const int *) (p + (o & ~3));
if (o % 4 == 0) {
#pragma unroll
for (int i = 0; i < n; ++i) {
dst[i] = w[i];
}
} else {
int lo = w[0];
#pragma unroll
for (int i = 0; i < n; ++i) {
const int hi = w[i + 1];
dst[i] = __builtin_amdgcn_alignbyte(hi, lo, 2);
lo = hi;
}
}
}
static __device__ __forceinline__ void mmq_few_wmma(mmq_few_tile_c & C, const int * a, const int * b) {
mmq_few_tile_ab A;
mmq_few_tile_ab B;
#pragma unroll
for (int l = 0; l < MMQ_FEW_WMMA_NE; ++l) {
A.x[l] = a[l];
B.x[l] = b[l];
}
mma(C, A, B);
}
// vec_dot: one unit of 256 values of row l%16, x points to its data, y to the src1 fragments of the unit.
// The decoders write sub-block s of the row to b[8], the int32 at index i holds the values [4i, 4i + 4).
// One WMMA uses b + 4*hh + i0, with i0 = (4 - MMQ_FEW_WMMA_NE)*(l/16) the offset of the values of the lane.
template <ggml_type type, bool half>
static __device__ __forceinline__ void mmq_few_wmma_vec_dot_q45_K(const char * x, const int4 * y, float (&sum)[8]) {
using block_t = std::conditional_t<type == GGML_TYPE_Q4_K, block_q4_K, block_q5_K>;
const block_t * bx = (const block_t *) __builtin_assume_aligned(x, 16);
const int4 hdr = *(const int4 *) bx; // dm and the 12 scale bytes
const int scales[3] = {hdr.y, hdr.z, hdr.w};
const int sc[2] = {unpack_scales_q45_K(scales, 0), unpack_scales_q45_K(scales, 1)};
const int mn[2] = {unpack_scales_q45_K(scales, 2), unpack_scales_q45_K(scales, 3)};
const float2 dm = __half22float2(bx->dm);
[[maybe_unused]] int qh[8]; // Q5_K: bit s holds the high bit of sub-block s
if constexpr (type == GGML_TYPE_Q5_K) {
#pragma unroll
for (int i = 0; i < 8; ++i) {
qh[i] = get_int_b4(bx->qh, i);
}
}
float sum_d[8] = {0.0f};
float sum_m[8] = {0.0f};
const int i0 = (4 - MMQ_FEW_WMMA_NE)*(threadIdx.x / 16);
#pragma unroll
for (int j = 0; j < 4; ++j) {
int qs[8];
#pragma unroll
for (int i = 0; i < 8; ++i) {
qs[i] = get_int_b4(bx->qs + 32*j, i);
}
#pragma unroll
for (int s = 2*j; s < 2*j + 2; ++s) {
int b[8];
#pragma unroll
for (int i = 0; i < 8; ++i) {
b[i] = (qs[i] >> (4*(s % 2))) & 0x0F0F0F0F;
if constexpr (type == GGML_TYPE_Q5_K) {
b[i] |= ((qh[i] >> s) & 0x01010101) << 4;
}
}
const int ls = (sc[s/4] >> (8*(s % 4))) & 0xFF;
const float m = (mn[s/4] >> (8*(s % 4))) & 0xFF;
const mmq_few_wmma_y yf = mmq_few_wmma_load_y<half>(y, s);
mmq_few_tile_c C;
mmq_few_wmma(C, yf.qs[0], b + i0 + 0);
mmq_few_wmma(C, yf.qs[1], b + i0 + 4);
#pragma unroll
for (int v = 0; v < mmq_few_wmma_nv<half>(); ++v) {
sum_d[v] += mmq_few_wmma_get_d<MMQ_Q8_1_DS_LAYOUT_DS4>(yf, v) * float(C.x[v]*ls);
sum_m[v] += m * mmq_few_wmma_get_sum(yf, v);
}
}
}
#pragma unroll
for (int v = 0; v < 8; ++v) {
sum[v] += dm.x*sum_d[v] - dm.y*sum_m[v];
}
}
// Q6_K has a scale per 16 values, one WMMA per half of a sub-block.
template <bool half>
static __device__ __forceinline__ void mmq_few_wmma_vec_dot_q6_K(const char * x, const int4 * y, float (&sum)[8]) {
const block_q6_K * bx = (const block_q6_K *) x;
const float d = __half2float(bx->d);
float sum_d[8] = {0.0f};
const int i0 = (4 - MMQ_FEW_WMMA_NE)*(threadIdx.x / 16);
#pragma unroll
for (int n = 0; n < 2; ++n) {
int ql[2][8]; // [ql offset 0 or 32]
int qh[8];
#pragma unroll
for (int i = 0; i < 8; ++i) {
ql[0][i] = get_int_b2(bx->ql + 64*n, i);
ql[1][i] = get_int_b2(bx->ql + 64*n + 32, i);
qh[i] = get_int_b2(bx->qh + 32*n, i);
}
const int sc[2] = {get_int_b2(bx->scales + 8*n, 0), get_int_b2(bx->scales + 8*n, 1)};
#pragma unroll
for (int j = 0; j < 4; ++j) {
const int s = 4*n + j;
int b[8];
#pragma unroll
for (int i = 0; i < 8; ++i) {
b[i] = __vsub4(((ql[j % 2][i] >> (4*(j/2))) & 0x0F0F0F0F) | (((qh[i] >> (2*j)) & 0x03030303) << 4), 0x20202020);
}
const int sc_lo = (int8_t) (sc[j/2] >> (16*(j % 2) + 0)); // scale of the values [0, 16)
const int sc_hi = (int8_t) (sc[j/2] >> (16*(j % 2) + 8)); // scale of the values [16, 32)
const mmq_few_wmma_y yf = mmq_few_wmma_load_y<half>(y, s);
mmq_few_tile_c C_lo;
mmq_few_tile_c C_hi;
mmq_few_wmma(C_lo, yf.qs[0], b + i0 + 0);
mmq_few_wmma(C_hi, yf.qs[1], b + i0 + 4);
#pragma unroll
for (int v = 0; v < mmq_few_wmma_nv<half>(); ++v) {
sum_d[v] += mmq_few_wmma_get_d<MMQ_Q8_1_DS_LAYOUT_D4>(yf, v) * float(C_lo.x[v]*sc_lo + C_hi.x[v]*sc_hi);
}
}
}
#pragma unroll
for (int v = 0; v < 8; ++v) {
sum[v] += d*sum_d[v];
}
}
// IQ4_NL has a block with its own scale per 32 values.
template <bool half>
static __device__ __forceinline__ void mmq_few_wmma_vec_dot_iq4_nl(const char * x, const int4 * y, float (&sum)[8]) {
const int i0 = (4 - MMQ_FEW_WMMA_NE)*(threadIdx.x / 16);
#pragma unroll
for (int s = 0; s < 8; ++s) {
// a unit starts 16 byte aligned, the qs of every second block 2 bytes off a 4 byte boundary
const char * xa = (const char *) __builtin_assume_aligned(x, 16);
int q4[4];
mmq_few_wmma_get_ints_b2<4>(xa, int(sizeof(block_iq4_nl))*s + 2, q4);
int b[8];
#pragma unroll
for (int i = 0; i < 4; ++i) {
const int2 v = get_int_from_table_16(q4[i], kvalues_iq4nl);
b[i + 0] = v.x;
b[i + 4] = v.y;
}
const float d = __half2float(((const block_iq4_nl *) xa + s)->d);
const mmq_few_wmma_y yf = mmq_few_wmma_load_y<half>(y, s);
mmq_few_tile_c C;
mmq_few_wmma(C, yf.qs[0], b + i0 + 0);
mmq_few_wmma(C, yf.qs[1], b + i0 + 4);
#pragma unroll
for (int v = 0; v < mmq_few_wmma_nv<half>(); ++v) {
sum[v] += d*mmq_few_wmma_get_d<MMQ_Q8_1_DS_LAYOUT_D4>(yf, v) * float(C.x[v]);
}
}
}
template <ggml_type type, bool half>
static __device__ __forceinline__ void mmq_few_wmma_vec_dot(const char * x, const int4 * y, float (&sum)[8]) {
if constexpr (type == GGML_TYPE_IQ4_NL) {
mmq_few_wmma_vec_dot_iq4_nl<half>(x, y, sum);
} else if constexpr (type == GGML_TYPE_Q4_K || type == GGML_TYPE_Q5_K) {
mmq_few_wmma_vec_dot_q45_K<type, half>(x, y, sum);
} else if constexpr (type == GGML_TYPE_Q6_K) {
mmq_few_wmma_vec_dot_q6_K<half>(x, y, sum);
} else {
static_assert(type == GGML_TYPE_COUNT, "unsupported type");
}
}
#endif // defined(AMD_WMMA_AVAILABLE)
// The warps split K in units of 256 values, a block has 16 src0 rows. half: at most 8 src1 columns.
template <ggml_type type, bool half>
__launch_bounds__(MMQ_FEW_NWARPS*WARP_SIZE, 1)
static __global__ void mul_mat_q_few_wmma(
const char * x, const int4 * y_ptr, float * dst,
const int nunits, const int nrows_x, const int ncols_dst, const int64_t stride_row_x, const int stride_col_dst,
const int channel_ratio, const int64_t stride_channel_x, const int stride_channel_dst,
const int sample_ratio, const int64_t stride_sample_x, const int stride_sample_dst) {
#if defined(AMD_WMMA_AVAILABLE)
constexpr int nwarps = MMQ_FEW_NWARPS;
constexpr int warp_size = WARP_SIZE;
constexpr int unit_size = mmq_few_unit_size(type);
static_assert(mmq_few_wmma_supported(type), "unsupported type");
extern __shared__ float buf_sum_mmq_few_wmma[];
const int row0 = blockIdx.x*MMQ_FEW_NROWS;
const int channel_dst = blockIdx.y;
const int sample_dst = blockIdx.z;
const int nchannels = gridDim.y;
x += int64_t(sample_dst/sample_ratio)*stride_sample_x + int64_t(channel_dst/channel_ratio)*stride_channel_x;
dst += int64_t(sample_dst)*stride_sample_dst + int64_t(channel_dst)*stride_channel_dst;
const int4 * GGML_CUDA_RESTRICT y = y_ptr + (int64_t(sample_dst)*nchannels + channel_dst)*nunits*MMQ_FEW_WMMA_Q8_1_INT4;
const char * xr = x + int64_t(min(row0 + int(threadIdx.x) % 16, nrows_x - 1))*stride_row_x;
float sum[8] = {0.0f};
for (int iu = threadIdx.y; iu < nunits; iu += nwarps) {
mmq_few_wmma_vec_dot<type, half>(xr + int64_t(iu)*unit_size, y + int64_t(iu)*MMQ_FEW_WMMA_Q8_1_INT4, sum);
}
// reduce the sums over the warps
float * buf_sum = buf_sum_mmq_few_wmma;
if (threadIdx.y > 0) {
#pragma unroll
for (int v = 0; v < 8; ++v) {
buf_sum[((threadIdx.y - 1)*8 + v)*warp_size + threadIdx.x] = sum[v];
}
}
__syncthreads();
if (threadIdx.y > 0) {
return;
}
#pragma unroll
for (int w = 0; w < nwarps - 1; ++w) {
#pragma unroll
for (int v = 0; v < 8; ++v) {
sum[v] += buf_sum[(w*8 + v)*warp_size + threadIdx.x];
}
}
const int i = row0 + mmq_few_tile_c::get_j(0);
#pragma unroll
for (int v = 0; v < mmq_few_wmma_nv<half>(); ++v) {
const int j = mmq_few_tile_c::get_i(v);
if (i < nrows_x && j < ncols_dst) {
dst[int64_t(j)*stride_col_dst + i] = sum[v];
}
}
#else
GGML_UNUSED_VARS(x, y_ptr, dst, nunits, nrows_x, ncols_dst, stride_row_x, stride_col_dst,
channel_ratio, stride_channel_x, stride_channel_dst,
sample_ratio, stride_sample_x, stride_sample_dst);
NO_DEVICE_CODE;
#endif // defined(AMD_WMMA_AVAILABLE)
}
// ggml_is_constant (static in ggml.c) on the tensor that a view points to
static bool mmq_few_is_constant(const ggml_tensor * src0) {
const ggml_tensor * x_root = src0->view_src ? src0->view_src : src0;
@@ -796,6 +1143,98 @@ static void launch_mul_mat_q_few_switch_ncg(const ggml_tensor * src0, const ggml
}
}
template <ggml_type type, bool half>
static void launch_mul_mat_q_few_wmma(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst,
const int4 * src1_q, cudaStream_t stream) {
GGML_TENSOR_BINARY_OP_LOCALS;
const int nunits = ne00 / QK_K;
const dim3 block_nums((ne01 + MMQ_FEW_NROWS - 1) / MMQ_FEW_NROWS, ne12, ne13);
const dim3 block_dims(WARP_SIZE, MMQ_FEW_NWARPS, 1);
const ggml_cuda_kernel_launch_params params(block_nums, block_dims, MMQ_FEW_WMMA_NBYTES_SHARED, stream);
ggml_cuda_kernel_launch(mul_mat_q_few_wmma<type, half>, params,
(const char *) src0->data, src1_q, (float *) dst->data,
nunits, (int) ne01, (int) ne1, (int64_t) nb01, (int) (nb1/sizeof(float)),
(int) (ne12/ne02), (int64_t) nb02, (int) (nb2/sizeof(float)),
(int) (ne13/ne03), (int64_t) nb03, (int) (nb3/sizeof(float)));
}
template <ggml_type type>
static void launch_mul_mat_q_few_wmma_switch_ncols(const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst,
const int4 * src1_q, cudaStream_t stream) {
if (src1->ne[1] <= MMQ_FEW_WMMA_NCOLS/2) {
launch_mul_mat_q_few_wmma<type, true>(src0, src1, dst, src1_q, stream);
} else {
launch_mul_mat_q_few_wmma<type, false>(src0, src1, dst, src1_q, stream);
}
}
// Min. and max. number of src1 columns for RDNA3 and RDNA4, 0 if the type is not supported.
// Below the min. MMVQ is faster, above the max. MMQ. Q8_0 would need more than 16 columns to beat MMQ.
static int2 mmq_few_wmma_ncols_range(const ggml_type type, const int cc) {
if (GGML_CUDA_CC_IS_RDNA4(cc)) { // tuned on the Radeon RX 9070 XT (gfx1201)
switch (type) {
case GGML_TYPE_Q4_K: return make_int2(3, 16);
case GGML_TYPE_Q5_K: return make_int2(3, 16);
case GGML_TYPE_Q6_K: return make_int2(5, 16);
case GGML_TYPE_IQ4_NL: return make_int2(6, 16);
default: return make_int2(0, 0);
}
}
if (GGML_CUDA_CC_IS_RDNA3_0(cc)) { // tuned on the Radeon RX 7900 XTX (gfx1100)
switch (type) {
case GGML_TYPE_Q4_K: return make_int2(2, 16);
case GGML_TYPE_Q5_K: return make_int2(2, 16);
case GGML_TYPE_Q6_K: return make_int2(5, 16);
case GGML_TYPE_IQ4_NL: return make_int2(5, 16);
default: return make_int2(0, 0);
}
}
switch (type) { // tuned on the Radeon 8060S (gfx1151)
case GGML_TYPE_Q4_K: return make_int2(3, 16);
case GGML_TYPE_Q5_K: return make_int2(3, 8);
case GGML_TYPE_Q6_K: return make_int2(6, 16);
case GGML_TYPE_IQ4_NL: return make_int2(7, 16);
default: return make_int2(0, 0);
}
}
static bool mmq_few_use_wmma(const int cc) {
return GGML_CUDA_CC_IS_RDNA3(cc) || GGML_CUDA_CC_IS_RDNA4(cc);
}
static void ggml_cuda_mul_mat_q_few_wmma(ggml_backend_cuda_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
GGML_TENSOR_BINARY_OP_LOCALS;
GGML_ASSERT(ne11 <= MMQ_FEW_WMMA_NCOLS);
cudaStream_t stream = ctx.stream();
const int nunits = ne00 / QK_K;
ggml_cuda_pool_alloc<int4> src1_q(ctx.pool(), int64_t(ne12)*ne13*nunits*MMQ_FEW_WMMA_Q8_1_INT4);
quantize_mmq_few_wmma_q8_1_cuda(src1->data, src1->type, src1_q.get(), mmq_few_ds_layout(src0->type), ne10, nb11/nb10, nb12/nb10, nb13/nb10,
ne11, ne12, ne13, stream);
switch (src0->type) {
case GGML_TYPE_Q4_K:
launch_mul_mat_q_few_wmma_switch_ncols<GGML_TYPE_Q4_K>(src0, src1, dst, src1_q.get(), stream);
break;
case GGML_TYPE_Q5_K:
launch_mul_mat_q_few_wmma_switch_ncols<GGML_TYPE_Q5_K>(src0, src1, dst, src1_q.get(), stream);
break;
case GGML_TYPE_Q6_K:
launch_mul_mat_q_few_wmma_switch_ncols<GGML_TYPE_Q6_K>(src0, src1, dst, src1_q.get(), stream);
break;
case GGML_TYPE_IQ4_NL:
launch_mul_mat_q_few_wmma_switch_ncols<GGML_TYPE_IQ4_NL>(src0, src1, dst, src1_q.get(), stream);
break;
default:
GGML_ABORT("unsupported type for few-row MMQ with WMMA");
}
}
void ggml_cuda_mul_mat_q_few(ggml_backend_cuda_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, const ggml_tensor * ids, ggml_tensor * dst) {
GGML_TENSOR_BINARY_OP_LOCALS;
@@ -806,6 +1245,12 @@ void ggml_cuda_mul_mat_q_few(ggml_backend_cuda_context & ctx, const ggml_tensor
GGML_ASSERT(nb0 == sizeof(float));
GGML_ASSERT(ne00 % QK_K == 0);
if (mmq_few_use_wmma(ggml_cuda_info().devices[ctx.device].cc)) {
GGML_ASSERT(!ids);
ggml_cuda_mul_mat_q_few_wmma(ctx, src0, src1, dst);
return;
}
cudaStream_t stream = ctx.stream();
const int nunits = ne00 / QK_K;
@@ -875,6 +1320,10 @@ static int ggml_cuda_mmq_few_min_ncols(const ggml_type type, const int cc, const
return 0;
#endif // GGML_CUDA_FORCE_CUBLAS
if (mmq_few_use_wmma(cc)) {
return has_ids || !mmq_few_wmma_supported(type) || ne00 < 8*QK_K ? 0 : mmq_few_wmma_ncols_range(type, cc).x;
}
// NVIDIA Ampere to Blackwell
if (!ampere_mma_available(cc) || cc >= GGML_CUDA_CC_RUBIN) {
return 0;
@@ -916,6 +1365,14 @@ bool ggml_cuda_should_use_mmq_few(const ggml_tensor * src0, const ggml_tensor *
if (ids && (2*src0->ne[2] + 1)*sizeof(int) > ggml_cuda_info().devices[ggml_cuda_get_device()].smpb) {
return false;
}
if (mmq_few_use_wmma(cc)) {
if (src1->ne[1] > mmq_few_wmma_ncols_range(src0->type, cc).y || src0->ne[0] % QK_K != 0) {
return false;
}
// the decoders read whole 4 byte values from 16 byte aligned units, Q6_K values 2 bytes at a time
const int x_alignment = mmq_few_unaligned(src0->type, 1) ? 2 : 16;
return ggml_cuda_is_aligned(src0, x_alignment) && ggml_cuda_is_aligned(src1, 16);
}
// the row must hold a whole number of ring stages of the launched kernel
const int ncg = ids ? 1 : mmq_few_ncg(ncols);
const int nmt = ids ? 1 : mmq_few_nmt(src0->type, ncg, src0->ne[1]);
@@ -928,11 +1385,11 @@ bool ggml_cuda_should_use_mmq_few(const ggml_tensor * src0, const ggml_tensor *
return ggml_cuda_is_aligned(src0, x_alignment) && ggml_cuda_is_aligned(src1, 16);
}
#else // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
#else // !defined(GGML_USE_MUSA)
void ggml_cuda_mul_mat_q_few(ggml_backend_cuda_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, const ggml_tensor * ids, ggml_tensor * dst) {
GGML_UNUSED_VARS(ctx, src0, src1, ids, dst);
GGML_ABORT("few-row MMQ is not supported on HIP or MUSA");
GGML_ABORT("few-row MMQ is not supported on MUSA");
}
bool ggml_cuda_should_use_mmq_few(const ggml_tensor * src0, const ggml_tensor * src1, const ggml_tensor * ids, const int cc) {
@@ -940,4 +1397,4 @@ bool ggml_cuda_should_use_mmq_few(const ggml_tensor * src0, const ggml_tensor *
return false;
}
#endif // !defined(GGML_USE_HIP) && !defined(GGML_USE_MUSA)
#endif // !defined(GGML_USE_MUSA)
+11 -8
View File
@@ -358,29 +358,32 @@ static __global__ void mul_mat_vec_f(
ggml_cuda_pdl_lc();
#pragma unroll
for (int j = 0; j < ncols_dst; ++j) {
sumf[j] = warp_reduce_sum<warp_size>(sumf[j]);
sumf[j] = warp_reduce_sum<warp_size, (block_size > warp_size || ncols_dst == 1)>(sumf[j]);
if constexpr (has_fusion) {
if (use_gate) {
sumf_gate[j] = warp_reduce_sum<warp_size>(sumf_gate[j]);
sumf_gate[j] = warp_reduce_sum<warp_size, (block_size > warp_size || ncols_dst == 1)>(sumf_gate[j]);
}
}
if (block_size > warp_size) {
buf_iw[tid/warp_size] = sumf[j];
if constexpr (has_fusion) {
if (use_gate) {
buf_iw_gate[tid/warp_size] = sumf_gate[j];
// one write per warp
if (tid % warp_size == 0) {
buf_iw[tid/warp_size] = sumf[j];
if constexpr (has_fusion) {
if (use_gate) {
buf_iw_gate[tid/warp_size] = sumf_gate[j];
}
}
}
__syncthreads();
if (tid < warp_size) {
sumf[j] = buf_iw[tid];
sumf[j] = warp_reduce_sum<warp_size>(sumf[j]);
sumf[j] = warp_reduce_sum<warp_size, ncols_dst == 1>(sumf[j]);
if constexpr (has_fusion) {
if (use_gate) {
sumf_gate[j] = buf_iw_gate[tid];
sumf_gate[j] = warp_reduce_sum<warp_size>(sumf_gate[j]);
sumf_gate[j] = warp_reduce_sum<warp_size, ncols_dst == 1>(sumf_gate[j]);
}
}
}
+5 -4
View File
@@ -904,10 +904,11 @@ static __global__ void mul_mat_vec_q(
}
}
}
tmp[j][i] = warp_reduce_sum<warp_size>(tmp[j][i]);
tmp[j][i] = i == 0 ? warp_reduce_sum<warp_size, true>(tmp[j][i]) : warp_reduce_sum<warp_size>(tmp[j][i]);
if constexpr (has_fusion) {
if (use_gate) {
tmp_gate[j][i] = warp_reduce_sum<warp_size>(tmp_gate[j][i]);
tmp_gate[j][i] = i == 0 ? warp_reduce_sum<warp_size, true>(tmp_gate[j][i]) : warp_reduce_sum<warp_size>(tmp_gate[j][i]);
}
}
@@ -1053,10 +1054,10 @@ static __global__ void mul_mat_vec_q_moe(
// Warp-level reduction only - no shared memory needed
#pragma unroll
for (int i = 0; i < c_rows_per_block; ++i) {
tmp[i] = warp_reduce_sum<warp_size>(tmp[i]);
tmp[i] = i == 0 ? warp_reduce_sum<warp_size, true>(tmp[i]) : warp_reduce_sum<warp_size>(tmp[i]);
if constexpr (has_fusion) {
if (use_gate) {
tmp_gate[i] = warp_reduce_sum<warp_size>(tmp_gate[i]);
tmp_gate[i] = i == 0 ? warp_reduce_sum<warp_size, true>(tmp_gate[i]) : warp_reduce_sum<warp_size>(tmp_gate[i]);
}
}
}
+2 -2
View File
@@ -290,8 +290,8 @@ static __global__ void rms_norm_back_f32(
}
// sum up partial sums
sum_xx = warp_reduce_sum(sum_xx);
sum_xg = warp_reduce_sum(sum_xg);
sum_xx = warp_reduce_sum<WARP_SIZE, (block_size > WARP_SIZE)>(sum_xx);
sum_xg = warp_reduce_sum<WARP_SIZE, (block_size > WARP_SIZE)>(sum_xg);
if constexpr (block_size > WARP_SIZE) {
static_assert(block_size == 1024, "unexpected block_size");
__shared__ float s_sum_xx[32];
+43 -14
View File
@@ -122,7 +122,7 @@ static __global__ void quantize_q8_1(
const float d = amax / 127.0f;
const int8_t q = amax == 0.0f ? 0 : roundf(xi / d);
const int sum = warp_reduce_sum<QK8_1>((int) q);
const int sum = warp_reduce_sum<QK8_1, true>((int) q);
y[ib].qs[iqs] = q;
@@ -662,8 +662,8 @@ void quantize_mmq_q8_1_cuda(
});
}
// Stores the 4 values xi of a thread, values [iu, iu + 4) of column g in a unit of 256 values, in the column group yg of the unit, see quantize.cuh for the layout.
template <mmq_q8_1_ds_layout ds_layout>
// Stores the 4 values xi of a thread, values [iu, iu + 4) of column g in a unit of 256 values, in the column group yg of the unit, see quantize.cuh for the layouts.
template <mmq_q8_1_ds_layout ds_layout, bool wmma>
static __device__ __forceinline__ void quantize_mmq_few_store(const float4 xi, int4 * yg, const int iu, const int g) {
// the 32 values of a sub-block are held by 8 threads
float amax = fmaxf(fmaxf(fabsf(xi.x), fabsf(xi.y)), fmaxf(fabsf(xi.z), fabsf(xi.w)));
@@ -680,11 +680,25 @@ static __device__ __forceinline__ void quantize_mmq_few_store(const float4 xi, i
// as in quantize_mmq_q8_1: the sum of the quantized values; the int warp_reduce_sum reduces the whole warp on Ampere+
[[maybe_unused]] float sum = 0.0f;
if constexpr (ds_layout != MMQ_Q8_1_DS_LAYOUT_D4) {
sum = d*warp_reduce_sum<8>(float(q.x + q.y + q.z + q.w));
sum = d*warp_reduce_sum<8, true>(float(q.x + q.y + q.z + q.w));
}
const int s = iu / QK8_1; // sub-block
const int k = iu % QK8_1; // first value in sub-block
if constexpr (wmma) {
((int *) yg)[(s*MMQ_FEW_WMMA_NCOLS + g)*8 + k/4] = *(const int *) &q;
if (k == 0) {
int * ds = (int *) (yg + 8*MMQ_FEW_WMMA_NCOLS*2) + (s*2 + g % 2)*8 + g/2;
if constexpr (ds_layout == MMQ_Q8_1_DS_LAYOUT_D4) {
*(float *) ds = d;
} else {
*(half2 *) ds = make_half2(d, sum);
}
}
return;
}
((int *) (yg + (s/2)*WARP_SIZE + 4*g + (k % 16)/4))[2*(s % 2) + k/16] = *(const int *) &q;
if (k == 0) {
int4 * ds = yg + 4*WARP_SIZE + 4*(g/2) + s/2;
@@ -696,8 +710,8 @@ static __device__ __forceinline__ void quantize_mmq_few_store(const float4 xi, i
}
}
// Each thread quantizes 4 values of one column, see quantize.cuh for the layout.
template <typename src_t, mmq_q8_1_ds_layout ds_layout>
// Each thread quantizes 4 values of one column, see quantize.cuh for the layouts.
template <typename src_t, mmq_q8_1_ds_layout ds_layout, bool wmma>
static __global__ void quantize_mmq_few_q8_1(
const src_t * x_ptr, void * vy_ptr, const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
const int ne1, const int ne2) {
@@ -715,9 +729,16 @@ static __global__ void quantize_mmq_few_q8_1(
const int64_t i3 = blockIdx.z / ne2;
const float4 xi = (int) blockIdx.x < ne1 ? quantize_load4(x + i3*s03 + i2*s02 + blockIdx.x*s01 + i0, 0) : make_float4(0.0f, 0.0f, 0.0f, 0.0f);
if constexpr (wmma) {
const int m = blockIdx.x % MMQ_FEW_WMMA_NCOLS; // column in group
int4 * yg = vy + ((blockIdx.z*(ne00/QK_K) + i0/QK_K)*(gridDim.x/MMQ_FEW_WMMA_NCOLS) + blockIdx.x/MMQ_FEW_WMMA_NCOLS)*MMQ_FEW_WMMA_Q8_1_INT4;
quantize_mmq_few_store<ds_layout, true>(xi, yg, i0 % QK_K, m);
return;
}
const int g = blockIdx.x % MMQ_FEW_NCOLS; // column in group
int4 * yg = vy + ((blockIdx.z*(ne00/QK_K) + i0/QK_K)*(gridDim.x/MMQ_FEW_NCOLS) + blockIdx.x/MMQ_FEW_NCOLS)*MMQ_FEW_Q8_1_INT4;
quantize_mmq_few_store<ds_layout>(xi, yg, i0 % QK_K, g);
quantize_mmq_few_store<ds_layout, false>(xi, yg, i0 % QK_K, g);
}
// MUL_MAT_ID: block x is the (token, slot) entry, ids are as in mm_ids_helper. Each block finds the pair of its entry in shared memory, block (0, 0) also writes all pairs.
@@ -807,26 +828,26 @@ static __global__ void quantize_mmq_few_id_q8_1(
const int r = rank(blockIdx.x, e);
int4 * yg = vy + (int64_t(pair0[e] + r/MMQ_FEW_NCOLS)*(ne00/QK_K) + i0/QK_K)*MMQ_FEW_Q8_1_INT4;
quantize_mmq_few_store<ds_layout>(xi, yg, i0 % QK_K, r % MMQ_FEW_NCOLS);
quantize_mmq_few_store<ds_layout, false>(xi, yg, i0 % QK_K, r % MMQ_FEW_NCOLS);
}
template <typename src_t>
static void quantize_mmq_few_q8_1_cuda(
template <bool wmma, typename src_t>
static void quantize_mmq_few_q8_1_launch(
const src_t * x, void * vy, const mmq_q8_1_ds_layout ds_layout, const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
const int64_t ne1, const int64_t ne2, const int64_t ne3, cudaStream_t stream) {
GGML_ASSERT(ne00 % QK_K == 0);
const int64_t block_num_y = (ne00 + 4*CUDA_QUANTIZE_BLOCK_SIZE_MMQ - 1) / (4*CUDA_QUANTIZE_BLOCK_SIZE_MMQ);
const dim3 num_blocks(GGML_PAD(ne1, MMQ_FEW_NCOLS), block_num_y, ne2*ne3);
const dim3 num_blocks(GGML_PAD(ne1, wmma ? MMQ_FEW_WMMA_NCOLS : MMQ_FEW_NCOLS), block_num_y, ne2*ne3);
const dim3 block_size(CUDA_QUANTIZE_BLOCK_SIZE_MMQ, 1, 1);
const ggml_cuda_kernel_launch_params launch_params = ggml_cuda_kernel_launch_params(num_blocks, block_size, 0, stream);
switch (ds_layout) {
case MMQ_Q8_1_DS_LAYOUT_D4:
ggml_cuda_kernel_launch(quantize_mmq_few_q8_1<src_t, MMQ_Q8_1_DS_LAYOUT_D4>, launch_params,
ggml_cuda_kernel_launch(quantize_mmq_few_q8_1<src_t, MMQ_Q8_1_DS_LAYOUT_D4, wmma>, launch_params,
x, vy, ne00, s01, s02, s03, (int) ne1, (int) ne2);
break;
case MMQ_Q8_1_DS_LAYOUT_DS4:
ggml_cuda_kernel_launch(quantize_mmq_few_q8_1<src_t, MMQ_Q8_1_DS_LAYOUT_DS4>, launch_params,
ggml_cuda_kernel_launch(quantize_mmq_few_q8_1<src_t, MMQ_Q8_1_DS_LAYOUT_DS4, wmma>, launch_params,
x, vy, ne00, s01, s02, s03, (int) ne1, (int) ne2);
break;
default:
@@ -838,7 +859,15 @@ void quantize_mmq_few_q8_1_cuda(
const void * x, const ggml_type type_src1, void * vy, const mmq_q8_1_ds_layout ds_layout, const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
const int64_t ne1, const int64_t ne2, const int64_t ne3, cudaStream_t stream) {
quantize_launch_typed(x, type_src1, [&](auto * x_t) {
quantize_mmq_few_q8_1_cuda(x_t, vy, ds_layout, ne00, s01, s02, s03, ne1, ne2, ne3, stream);
quantize_mmq_few_q8_1_launch<false>(x_t, vy, ds_layout, ne00, s01, s02, s03, ne1, ne2, ne3, stream);
});
}
void quantize_mmq_few_wmma_q8_1_cuda(
const void * x, const ggml_type type_src1, void * vy, const mmq_q8_1_ds_layout ds_layout, const int64_t ne00, const int64_t s01, const int64_t s02, const int64_t s03,
const int64_t ne1, const int64_t ne2, const int64_t ne3, cudaStream_t stream) {
quantize_launch_typed(x, type_src1, [&](auto * x_t) {
quantize_mmq_few_q8_1_launch<true>(x_t, vy, ds_layout, ne00, s01, s02, s03, ne1, ne2, ne3, stream);
});
}
+11
View File
@@ -42,6 +42,17 @@ void quantize_mmq_few_id_q8_1_cuda(
const void * x, ggml_type type_src1, const int32_t * ids, void * vy, int * pairs, mmq_q8_1_ds_layout ds_layout, int64_t ne00, int64_t s11, int64_t s12,
int64_t ne11, int64_t n_experts, int64_t n_expert_used, int64_t n_tokens, int64_t si1, int64_t npairs_max, cudaStream_t stream);
// src1 of the few-row MMQ for RDNA3 WMMA, which multiplies 16 src1 columns and needs the same A and B data in both half-warps.
// Per channel, 256 values and group of MMQ_FEW_WMMA_NCOLS columns:
// qs: int4[8][16][2], [s][m][k] holds the values [16k, 16k + 16) of sub-block s of column m, the A fragments of lanes m and m + 16.
// ds: int4[8][2][2], [s][h][k] holds d (D4, float) or (d, sum) (DS4, half2) of sub-block s of the columns 2v + h, v = 4k .. 4k + 3.
static constexpr int MMQ_FEW_WMMA_NCOLS = 16;
static constexpr int MMQ_FEW_WMMA_Q8_1_INT4 = 8*16*2 + 8*2*2;
void quantize_mmq_few_wmma_q8_1_cuda(
const void * x, ggml_type type_src1, void * vy, mmq_q8_1_ds_layout ds_layout, int64_t ne00, int64_t s01, int64_t s02, int64_t s03,
int64_t ne1, int64_t ne2, int64_t ne3, cudaStream_t stream);
void quantize_mmq_fp4_cuda(const void * x,
ggml_type type_src1,
const int32_t * ids,
+1 -1
View File
@@ -218,7 +218,7 @@ __global__ void __launch_bounds__(d_state, 1)
}
// parallel accumulation for output
state_sum = warp_reduce_sum(state_sum);
state_sum = warp_reduce_sum<WARP_SIZE, true>(state_sum);
if (lane == 0) {
y_warp[i * stride_y] = state_sum;
+30
View File
@@ -333,3 +333,33 @@ static __device__ __forceinline__ uint32_t ggml_hip_perm(const uint32_t hi, cons
return __builtin_amdgcn_perm(hi, lo, sel);
#endif // __has_builtin(__builtin_amdgcn_is_invocable)
}
// DPP control codes.
#define GGML_HIP_DPP_QUAD_PERM_1032 0x0b1 // quad_perm:[1,0,3,2]
#define GGML_HIP_DPP_QUAD_PERM_2301 0x04e // quad_perm:[2,3,0,1]
#define GGML_HIP_DPP_ROW_HALF_MIRROR 0x141 // row_half_mirror
#define GGML_HIP_DPP_ROW_ROR_8 0x128 // row_ror:8
#define GGML_HIP_DPP_ROW_BCAST_15 0x142 // row_bcast:15, GCN/CDNA only
#define GGML_HIP_DPP_ROW_BCAST_31 0x143 // row_bcast:31, GCN/CDNA only
#define GGML_HIP_DPP_WAVE_ROR_1 0x13c // wave_ror:1
// DS swizzle mask codes.
#define GGML_HIP_SWIZZLE_SWAP16 0x401F // XOR16 within each 32-lane group
template <int dpp_ctrl, typename T>
static __device__ __forceinline__ T ggml_hip_dpp_update(T x) {
static_assert(sizeof(T) == 4, "DPP updates require 32-bit values");
union { T t; int i; } value;
value.t = x;
value.i = __builtin_amdgcn_update_dpp(value.i, value.i, dpp_ctrl, 0xf, 0xf, true);
return value.t;
}
template <int swizzle_mask, typename T>
static __device__ __forceinline__ T ggml_hip_swizzle(T x) {
static_assert(sizeof(T) == 4, "DS swizzle requires 32-bit values");
union { T t; int i; } value;
value.t = x;
value.i = __builtin_amdgcn_ds_swizzle(value.i, swizzle_mask);
return value.t;
}
+1 -1
View File
@@ -180,7 +180,7 @@ rwkv_wkv7_f32_t1_warp_row(const int T, const int C, const int H, const float * r
const float vt = v[t];
const float st0 = s0 * _w[lane] + _k[lane] * vt + sa * _b[lane];
const float st1 = s1 * _w[lane + half_head] + _k[lane + half_head] * vt + sa * _b[lane + half_head];
const float y = warp_reduce_sum(st0 * _r[lane] + st1 * _r[lane + half_head]);
const float y = warp_reduce_sum<WARP_SIZE, true>(st0 * _r[lane] + st1 * _r[lane + half_head]);
dst[T * C + state_base + lane] = st0;
dst[T * C + state_base + lane + half_head] = st1;
+13 -8
View File
@@ -73,8 +73,8 @@ ggml_metal_fusion_id ggml_metal_fusion_get_id(const ggml_metal_fusion * fusion)
// ---- helpers -------------------------------------------------------------
// true if two tensors live in the same Metal buffer
static bool ggml_metal_fusion_same_buffer(const ggml_tensor * a, const ggml_tensor * b) {
// true if two tensors live in the same Metal buffer (in STRUCTURAL mode, only checks the backend buffer)
static bool ggml_metal_fusion_same_buffer(const ggml_tensor * a, const ggml_tensor * b, ggml_metal_fusion_mode mode) {
if (!a || !b) {
return false;
}
@@ -82,6 +82,14 @@ static bool ggml_metal_fusion_same_buffer(const ggml_tensor * a, const ggml_tens
ggml_backend_buffer_t ba = a->view_src ? a->view_src->buffer : a->buffer;
ggml_backend_buffer_t bb = b->view_src ? b->view_src->buffer : b->buffer;
if (ba != bb) {
return false;
}
if (mode == GGML_METAL_FUSION_STRUCTURAL) {
return true;
}
ggml_metal_buffer_t ca = (ggml_metal_buffer_t) ba->context;
ggml_metal_buffer_t cb = (ggml_metal_buffer_t) bb->context;
@@ -188,8 +196,7 @@ static bool ggml_metal_fusion_check_ssm_conv_silu(
return true;
}
// ADD x N: each ADD reads the previous ADD as src0, and all addends must share layout
// (and, in FULL mode, live in the same Metal buffer)
// ADD x N: each ADD reads the previous ADD as src0, and all addends must share layout and buffer
static bool ggml_metal_fusion_check_add_chain(
const ggml_metal_fusion * fusion,
const ggml_tensor * const * nodes,
@@ -211,10 +218,8 @@ static bool ggml_metal_fusion_check_add_chain(
return false;
}
if (mode == GGML_METAL_FUSION_FULL) {
if (!ggml_metal_fusion_same_buffer(nodes[j]->src[1], nodes[0]->src[1])) {
return false;
}
if (!ggml_metal_fusion_same_buffer(nodes[j]->src[1], nodes[0]->src[1], mode)) {
return false;
}
}
@@ -1273,6 +1273,7 @@ class ggml_webgpu_shader_lib {
std::unordered_map<int, webgpu_pipeline> argsort_merge_pipelines; // key is order
std::unordered_map<int, webgpu_pipeline> cumsum_pipelines; // key is fixed, no variants yet
std::unordered_map<int, webgpu_pipeline> col2im_1d_pipelines; // key is fixed, no variants yet
std::unordered_map<int, webgpu_pipeline> conv_transpose_1d_pipelines; // key is kernel type
std::unordered_map<int, webgpu_pipeline> arange_pipelines; // key is fixed, no variants yet
std::unordered_map<int, webgpu_pipeline> count_equal_pipelines; // key is src_overlap
std::unordered_map<int, webgpu_pipeline> timestep_embedding_pipelines; // key is fixed, no variants yet
@@ -2144,6 +2145,26 @@ class ggml_webgpu_shader_lib {
return pipeline;
}
webgpu_pipeline get_conv_transpose_1d_pipeline(const ggml_webgpu_shader_lib_context & context) {
const ggml_type type = context.src0->type;
auto it = conv_transpose_1d_pipelines.find(type);
if (it != conv_transpose_1d_pipelines.end()) {
return it->second;
}
const uint32_t tile = 16;
std::vector<std::string> defines = {
"TILE=" + std::to_string(tile),
type == GGML_TYPE_F16 ? "KERNEL_TYPE=f16" : "KERNEL_TYPE=f32",
};
auto processed = preprocessor.preprocess(wgsl_conv_transpose_1d, defines);
auto decisions = std::make_shared<ggml_webgpu_generic_shader_decisions>();
decisions->wg_size = tile;
webgpu_pipeline pipeline = ggml_webgpu_create_pipeline(device, processed, "conv_transpose_1d");
pipeline.context = decisions;
return conv_transpose_1d_pipelines.emplace(type, std::move(pipeline)).first->second;
}
webgpu_pipeline get_pad_pipeline(const ggml_webgpu_shader_lib_context & context) {
ggml_webgpu_pad_pipeline_key key = {};
key.reflect = context.dst->op == GGML_OP_PAD_REFLECT_1D;
+47
View File
@@ -934,6 +934,46 @@ static webgpu_encoded_op ggml_webgpu_col2im_1d(webgpu_context & ctx, ggml_tensor
return ggml_backend_webgpu_build(ctx, pipeline, params, entries, wg_x, wg_y);
}
static webgpu_encoded_op ggml_webgpu_conv_transpose_1d(webgpu_context & ctx,
ggml_tensor * kernel,
ggml_tensor * input,
ggml_tensor * dst) {
ggml_webgpu_shader_lib_context shader_lib_ctx = {};
shader_lib_ctx.src0 = kernel;
webgpu_pipeline pipeline = ctx->shader_lib->get_conv_transpose_1d_pipeline(shader_lib_ctx);
const auto * decisions = static_cast<const ggml_webgpu_generic_shader_decisions *>(pipeline.context.get());
const uint32_t tile = decisions->wg_size;
const uint32_t stride = ggml_get_op_params_i32(dst, 0);
const uint32_t phases = std::min(stride, (uint32_t) dst->ne[0]);
const uint32_t time_tiles = CEIL_DIV(CEIL_DIV(dst->ne[0], stride), tile);
const uint32_t total_tiles = time_tiles * phases * CEIL_DIV(dst->ne[1], tile);
std::vector<uint32_t> params = {
(uint32_t) (ggml_webgpu_tensor_misalignment(ctx, kernel) / ggml_type_size(kernel->type)),
(uint32_t) (ggml_webgpu_tensor_misalignment(ctx, input) / sizeof(float)),
(uint32_t) (ggml_webgpu_tensor_misalignment(ctx, dst) / sizeof(float)),
(uint32_t) kernel->ne[0],
(uint32_t) kernel->ne[1],
(uint32_t) kernel->ne[2],
(uint32_t) input->ne[0],
(uint32_t) dst->ne[0],
stride,
phases,
time_tiles,
total_tiles,
};
std::vector<wgpu::BindGroupEntry> entries = {
ggml_webgpu_make_tensor_bind_group_entry(ctx, 0, kernel),
ggml_webgpu_make_tensor_bind_group_entry(ctx, 1, input),
ggml_webgpu_make_tensor_bind_group_entry(ctx, 2, dst),
};
uint32_t wg_x;
uint32_t wg_y;
compute_2d_workgroups(total_tiles, ctx->global_ctx->capabilities.limits.maxComputeWorkgroupsPerDimension, wg_x,
wg_y);
return ggml_backend_webgpu_build(ctx, pipeline, params, entries, wg_x, wg_y);
}
static webgpu_encoded_op ggml_webgpu_pad(webgpu_context & ctx, ggml_tensor * src, ggml_tensor * dst) {
ggml_webgpu_shader_lib_context shader_lib_ctx = {};
shader_lib_ctx.src0 = src;
@@ -3822,6 +3862,8 @@ static std::optional<webgpu_encoded_op> ggml_webgpu_encode(webgpu_context ctx,
return ggml_webgpu_pool2d(ctx, src0, node);
case GGML_OP_COL2IM_1D:
return ggml_webgpu_col2im_1d(ctx, src0, node);
case GGML_OP_CONV_TRANSPOSE_1D:
return ggml_webgpu_conv_transpose_1d(ctx, src0, src1, node);
case GGML_OP_ROLL:
case GGML_OP_PAD_REFLECT_1D:
case GGML_OP_PAD:
@@ -5417,6 +5459,11 @@ static bool ggml_backend_webgpu_device_supports_op(ggml_backend_dev_t dev, const
supports_op = src0->type == GGML_TYPE_I32 && src1->type == GGML_TYPE_I32 && ggml_is_contiguous(src0) &&
ggml_is_contiguous(src1);
break;
case GGML_OP_CONV_TRANSPOSE_1D:
supports_op = (src0->type == GGML_TYPE_F32 || src0->type == GGML_TYPE_F16) && src1->type == GGML_TYPE_F32 &&
op->type == GGML_TYPE_F32 && ggml_is_contiguous(src0) && ggml_is_contiguous(src1) &&
ggml_get_op_params_i32(op, 0) > 0;
break;
case GGML_OP_COL2IM_1D:
supports_op = op->type == GGML_TYPE_F32 && src0->type == GGML_TYPE_F32 && ggml_is_contiguous(src0) &&
ggml_is_contiguous(op);
@@ -0,0 +1,89 @@
enable f16;
@group(0) @binding(0)
var<storage, read_write> kernel: array<KERNEL_TYPE>;
@group(0) @binding(1)
var<storage, read_write> input: array<f32>;
@group(0) @binding(2)
var<storage, read_write> output: array<f32>;
struct Params {
kernel_offset: u32,
input_offset: u32,
output_offset: u32,
kernel_size: u32,
output_channels: u32,
input_channels: u32,
input_length: u32,
output_length: u32,
stride: u32,
phases: u32,
time_tiles: u32,
total_tiles: u32,
};
@group(0) @binding(3)
var<uniform> params: Params;
var<workgroup> input_tile: array<array<f32, TILE>, TILE>;
var<workgroup> kernel_tile: array<array<f32, TILE>, TILE>;
@compute @workgroup_size(TILE, TILE)
fn main(@builtin(workgroup_id) group: vec3<u32>,
@builtin(num_workgroups) groups: vec3<u32>,
@builtin(local_invocation_id) lane: vec3<u32>) {
let tile = group.x + groups.x * group.y;
if (tile >= params.total_tiles) {
return;
}
// Each tile covers one residue modulo stride, so its columns share the same kernel taps.
let time_base = tile % params.time_tiles * TILE;
let phase = tile / params.time_tiles % params.phases;
let channel_base = tile / params.time_tiles / params.phases * TILE;
let row = channel_base + lane.y;
let weight_row = channel_base + lane.x;
let time = time_base + lane.x;
var sum = 0.0;
if (phase < params.kernel_size) {
let first = time_base + 1u - min(time_base + 1u, params.input_length);
let last = min(time_base + TILE - 1u, (params.kernel_size - 1u - phase) / params.stride);
// Visit overlapping input positions in ascending order.
for (var step = last + 1u; step > first; ) {
step -= 1u;
let tap = phase + step * params.stride;
let valid_time = time >= step && time - step < params.input_length;
var dot = 0.0;
for (var base = 0u; base < params.input_channels; base += TILE) {
let col = base + lane.y;
var value = 0.0;
var weight = 0.0;
if (col < params.input_channels) {
if (valid_time) {
value = input[params.input_offset + col * params.input_length + time - step];
}
if (weight_row < params.output_channels) {
let index = (col * params.output_channels + weight_row) * params.kernel_size + tap;
weight = f32(kernel[params.kernel_offset + index]);
}
}
input_tile[lane.y][lane.x] = value;
kernel_tile[lane.y][lane.x] = weight;
workgroupBarrier();
for (var k = 0u; k < TILE; k++) {
dot = fma(input_tile[k][lane.x], kernel_tile[k][lane.y], dot);
}
workgroupBarrier();
}
if (valid_time) {
sum += dot;
}
}
}
if (row < params.output_channels && time <= (params.output_length - 1u - phase) / params.stride) {
let out_time = time * params.stride + phase;
output[params.output_offset + row * params.output_length + out_time] = sum;
}
}
+17
View File
@@ -7404,6 +7404,23 @@ static void ggml_compute_backward(
} //break;
}
} break;
case GGML_OP_CONCAT: {
const int32_t dim = ggml_get_op_params_i32(tensor, 0);
if (src0_needs_grads) {
size_t offset = 0;
struct ggml_tensor * grad_a = ggml_view_4d(ctx, grad,
src0->ne[0], src0->ne[1], src0->ne[2], src0->ne[3],
grad->nb[1], grad->nb[2], grad->nb[3], offset);
ggml_add_or_set(ctx, cgraph, isrc0, ggml_cont(ctx, grad_a));
}
if (src1_needs_grads) {
size_t offset = src0->ne[dim] * grad->nb[dim];
struct ggml_tensor * grad_b = ggml_view_4d(ctx, grad,
src1->ne[0], src1->ne[1], src1->ne[2], src1->ne[3],
grad->nb[1], grad->nb[2], grad->nb[3], offset);
ggml_add_or_set(ctx, cgraph, isrc1, ggml_cont(ctx, grad_b));
}
} break;
case GGML_OP_NONE: {
// noop
} break;
+1 -1
View File
@@ -5,7 +5,7 @@ import os
import sys
import subprocess
HTTPLIB_VERSION = "refs/tags/v0.67.0"
HTTPLIB_VERSION = "refs/tags/v0.68.0"
JSON_VERSION = "v3.12.0"
# stb has no release tag, so we pin a commit (stb_image v2.32)
+2 -2
View File
@@ -5,7 +5,7 @@ description: Guided workflow for adding a new model architecture to llama.cpp. U
# Add a new model architecture to llama.cpp
This skill walks a contributor through adding a new model architecture. AI-generated code is permitted in this project, so you may write full implementations for the steps below rather than only pointing at patterns - but follow `AGENTS.md`'s AI usage policy throughout:
This skill walks a contributor through adding a new model architecture. AI-generated code is permitted in this project, so you may write full implementations for the steps below rather than only pointing at patterns - but follow `AGENTS.md` throughout:
- The contributor is 100% responsible for every line, however it was produced. They must be able to explain and defend any part of it to a reviewer. Check in with them as you go (don't silently generate everything and hand over a finished diff) so they actually absorb what was written.
- Before writing code, make sure the contributor owns the design choices for this architecture (which reference model to follow, how non-standard bits like RoPE variants or MoE routing should be handled) - AI accelerates a design the contributor has already made, it doesn't make the design for them.
@@ -23,7 +23,7 @@ Before starting, read `CONTRIBUTING.md`, `AGENTS.md` and `docs/development/HOWTO
Ask the contributor:
1. Which model (HF repo id or name)? Is it text-only or does it have a multimodal (vision/audio) encoder?
2. Do they already have the HF `config.json`/weights available locally?
3. Have they checked for an existing PR/issue on this model? Suggest `gh search issues "<model name>"` and `gh search prs "<model name>"` in the `ggml-org/llama.cpp` repo. If an existing PR covers it, the contributor should comment there and collaborate rather than open a duplicate (per CONTRIBUTING.md's AI Usage Policy).
3. Have they checked for an existing PR/issue on this model? Suggest `gh search issues "<model name>"` and `gh search prs "<model name>"` in the `ggml-org/llama.cpp` repo. If an existing PR covers it, the contributor should comment there and collaborate rather than open a duplicate (see "Duplicate-work checks" in `AGENTS.md`).
4. What existing supported architecture is this model closest to (e.g. "Llama-like with sliding window", "MoE like DBRX", "BERT-style encoder")?
If the contributor doesn't know the closest reference architecture, you may grep `conversion/*.py` and `src/models/*.cpp` for architectures with a similar config shape (layer count, head count, MoE expert count, norm placement) and suggest 1-2 candidates - but let the contributor confirm the choice rather than picking one yourself; this choice is a design decision they need to own.
+6 -6
View File
@@ -279,12 +279,6 @@ ggml_tensor * llama_model_inkling2::graph::build_inputs() {
ggml_tensor * inp_pos = build_inp_pos();
inp_out_ids = build_inp_out_ids();
// log-scaled positions: 1 + alpha*log(max(1, (pos + 1)/floor)), multiplies q and r of the full-attention layers
tau = ggml_scale_bias(ctx0, ggml_cast(ctx0, inp_pos, GGML_TYPE_F32), 1.0f, 1.0f);
tau = ggml_log(ctx0, ggml_clamp(ctx0, ggml_scale(ctx0, tau, 1.0f/hparams.n_log_scale_floor), 1.0f, INFINITY));
tau = ggml_reshape_3d(ctx0, ggml_scale_bias(ctx0, tau, hparams.f_log_scale_alpha, 1.0f), 1, 1, n_tokens);
ggml_build_forward_expand(gf, tau);
ggml_tensor * cur = build_inp_embd(model.tok_embd);
// important: do not normalize raw embeddings input (i.e. encoded image embeddings)
@@ -292,6 +286,12 @@ ggml_tensor * llama_model_inkling2::graph::build_inputs() {
cur = build_norm(cur, model.tok_norm, nullptr, LLM_NORM_RMS, -1);
}
// log-scaled positions: 1 + alpha*log(max(1, (pos + 1)/floor)), multiplies q and r of the full-attention layers
tau = ggml_scale_bias(ctx0, ggml_cast(ctx0, inp_pos, GGML_TYPE_F32), 1.0f, 1.0f);
tau = ggml_log(ctx0, ggml_clamp(ctx0, ggml_scale(ctx0, tau, 1.0f/hparams.n_log_scale_floor), 1.0f, INFINITY));
tau = ggml_reshape_3d(ctx0, ggml_scale_bias(ctx0, tau, hparams.f_log_scale_alpha, 1.0f), 1, 1, n_tokens);
ggml_build_forward_expand(gf, tau);
return cur;
}
+35 -48
View File
@@ -2,6 +2,7 @@
#include "unicode-data.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <cstddef>
#include <cstdint>
@@ -159,23 +160,20 @@ static std::vector<unicode_cpt_flags> unicode_cpt_flags_array() {
return cpt_flags;
}
static std::unordered_map<uint8_t, std::string> unicode_byte_to_utf8_map() {
std::unordered_map<uint8_t, std::string> map;
static std::array<std::string, 256> unicode_byte_to_utf8_map() {
std::array<std::string, 256> map;
for (int ch = 0x21; ch <= 0x7E; ++ch) { // u'!' to u'~'
assert(0 <= ch && ch < 256);
map[ch] = unicode_cpt_to_utf8(ch);
}
for (int ch = 0xA1; ch <= 0xAC; ++ch) { // u'¡' to u'¬'
assert(0 <= ch && ch < 256);
map[ch] = unicode_cpt_to_utf8(ch);
}
for (int ch = 0xAE; ch <= 0xFF; ++ch) { // u'®' to u'ÿ'
assert(0 <= ch && ch < 256);
map[ch] = unicode_cpt_to_utf8(ch);
}
auto n = 0;
for (int ch = 0; ch < 256; ++ch) {
if (map.find(ch) == map.end()) {
if (map[ch].empty()) {
map[ch] = unicode_cpt_to_utf8(256 + n);
++n;
}
@@ -186,15 +184,12 @@ static std::unordered_map<uint8_t, std::string> unicode_byte_to_utf8_map() {
static std::unordered_map<std::string, uint8_t> unicode_utf8_to_byte_map() {
std::unordered_map<std::string, uint8_t> map;
for (int ch = 0x21; ch <= 0x7E; ++ch) { // u'!' to u'~'
assert(0 <= ch && ch < 256);
map[unicode_cpt_to_utf8(ch)] = ch;
}
for (int ch = 0xA1; ch <= 0xAC; ++ch) { // u'¡' to u'¬'
assert(0 <= ch && ch < 256);
map[unicode_cpt_to_utf8(ch)] = ch;
}
for (int ch = 0xAE; ch <= 0xFF; ++ch) { // u'®' to u'ÿ'
assert(0 <= ch && ch < 256);
map[unicode_cpt_to_utf8(ch)] = ch;
}
auto n = 0;
@@ -222,18 +217,13 @@ static std::vector<int> unicode_cpt_to_byte_map() {
static std::vector<std::string> unicode_byte_encoding_process(const std::vector<std::string> & bpe_words) {
std::vector<std::string> bpe_encoded_words;
bpe_encoded_words.reserve(bpe_words.size());
for (const auto & word : bpe_words) {
std::string text_utf;
auto utf_word = unicode_cpts_from_utf8(word);
for (size_t i = 0; i < utf_word.size(); ++i) {
text_utf += unicode_cpt_to_utf8(utf_word[i]);
}
std::string encoded_token;
for (char & c : text_utf) {
auto & encoded_token = bpe_encoded_words.emplace_back();
encoded_token.reserve(word.size() * 2);
for (const char & c : word) {
encoded_token += unicode_byte_to_utf8(c);
}
bpe_encoded_words.emplace_back(encoded_token);
}
return bpe_encoded_words;
}
@@ -1439,33 +1429,30 @@ static std::vector<size_t> unicode_regex_split_custom(const std::string & text,
// interface
//
static void unicode_cpt_to_utf8(uint32_t cpt, std::string & out) {
if (/* 0x00 <= cpt && */ cpt <= 0x7f) {
out.push_back(cpt);
} else if (cpt <= 0x7ff) {
out.push_back(0xc0 | ((cpt >> 6) & 0x1f));
out.push_back(0x80 | (cpt & 0x3f));
} else if (cpt <= 0xffff) {
out.push_back(0xe0 | ((cpt >> 12) & 0x0f));
out.push_back(0x80 | ((cpt >> 6) & 0x3f));
out.push_back(0x80 | (cpt & 0x3f));
} else if (cpt <= 0x10ffff) {
out.push_back(0xf0 | ((cpt >> 18) & 0x07));
out.push_back(0x80 | ((cpt >> 12) & 0x3f));
out.push_back(0x80 | ((cpt >> 6) & 0x3f));
out.push_back(0x80 | (cpt & 0x3f));
} else {
throw std::invalid_argument("invalid codepoint");
}
}
std::string unicode_cpt_to_utf8(uint32_t cpt) {
std::string result;
if (/* 0x00 <= cpt && */ cpt <= 0x7f) {
result.push_back(cpt);
return result;
}
if (0x80 <= cpt && cpt <= 0x7ff) {
result.push_back(0xc0 | ((cpt >> 6) & 0x1f));
result.push_back(0x80 | (cpt & 0x3f));
return result;
}
if (0x800 <= cpt && cpt <= 0xffff) {
result.push_back(0xe0 | ((cpt >> 12) & 0x0f));
result.push_back(0x80 | ((cpt >> 6) & 0x3f));
result.push_back(0x80 | (cpt & 0x3f));
return result;
}
if (0x10000 <= cpt && cpt <= 0x10ffff) {
result.push_back(0xf0 | ((cpt >> 18) & 0x07));
result.push_back(0x80 | ((cpt >> 12) & 0x3f));
result.push_back(0x80 | ((cpt >> 6) & 0x3f));
result.push_back(0x80 | (cpt & 0x3f));
return result;
}
throw std::invalid_argument("invalid codepoint");
unicode_cpt_to_utf8(cpt, result);
return result;
}
std::vector<uint32_t> unicode_cpts_normalize_nfd(const std::vector<uint32_t> & cpts) {
@@ -1599,9 +1586,9 @@ unicode_cpt_flags unicode_cpt_flags_from_utf8(const std::string & utf8) {
return unicode_cpt_flags_from_cpt(unicode_cpt_from_utf8(utf8, offset));
}
std::string unicode_byte_to_utf8(uint8_t byte) {
static std::unordered_map<uint8_t, std::string> map = unicode_byte_to_utf8_map();
return map.at(byte);
const std::string & unicode_byte_to_utf8(uint8_t byte) {
static const std::array<std::string, 256> map = unicode_byte_to_utf8_map();
return map[byte];
}
uint8_t unicode_utf8_to_byte(const std::string & utf8) {
@@ -1845,9 +1832,9 @@ std::vector<std::string> unicode_regex_split(const std::string & text, const std
size_t start = 0;
for (size_t & offset : bpe_offsets) {
bpe_words.emplace_back();
auto & word = bpe_words.emplace_back();
for (size_t i = start; i < start + offset; ++i) {
bpe_words.back() += unicode_cpt_to_utf8(cpts[i]);
unicode_cpt_to_utf8(cpts[i], word);
}
start += offset;
}
+3 -3
View File
@@ -102,9 +102,9 @@ std::vector<uint32_t> unicode_cpts_normalize_nfc(const std::vector<uint32_t> & c
unicode_cpt_flags unicode_cpt_flags_from_cpt (uint32_t cpt);
unicode_cpt_flags unicode_cpt_flags_from_utf8(const std::string & utf8);
std::string unicode_byte_to_utf8(uint8_t byte);
uint8_t unicode_utf8_to_byte(const std::string & utf8);
uint8_t unicode_cpt_to_byte (uint32_t cpt);
const std::string & unicode_byte_to_utf8(uint8_t byte);
uint8_t unicode_utf8_to_byte(const std::string & utf8);
uint8_t unicode_cpt_to_byte (uint32_t cpt);
uint32_t unicode_tolower(uint32_t cpt);
+51
View File
@@ -5101,6 +5101,10 @@ struct test_loop_ctrl : public test_case {
test_loop_ctrl(int64_t n = 2304, int64_t r = 64, int64_t T = 1) : n(n), r(r), T(T) {}
double max_nmse_err() override {
return 5e-3;
}
ggml_tensor * build_graph(ggml_context * ctx) override {
ggml_tensor * cur = ggml_scale(ctx, ggml_new_tensor_2d(ctx, GGML_TYPE_F32, n, T), 1.0f);
ggml_tensor * msg = ggml_scale(ctx, ggml_new_tensor_2d(ctx, GGML_TYPE_F32, n, T), 1.0f);
@@ -8438,6 +8442,31 @@ struct test_concat : public test_case {
return VARS_TO_STR5(type, ne_a, ne_b_d, dim, v);
}
int64_t grad_nmax() override {
return 40000;
}
std::string op_desc(ggml_tensor * t) override {
GGML_UNUSED(t);
return "CONCAT";
}
// the weighted loss is linear in a and b, so a large eps is exact and keeps f32 rounding small
float grad_eps() override {
return 1.0f;
}
void initialize_tensors(ggml_context * ctx) override {
for (ggml_tensor * t = ggml_get_first_tensor(ctx); t != nullptr; t = ggml_get_next_tensor(ctx, t)) {
// keep weights away from 0 because a near-zero gradient makes the relative error of the grad check blow up
if (strcmp(t->name, "w") == 0) {
init_tensor_uniform(t, 1.0f, 2.0f);
} else {
init_tensor_uniform(t);
}
}
}
test_concat(ggml_type type = GGML_TYPE_F32,
std::array<int64_t, 4> ne_a = {10, 5, 5, 5},
int64_t ne_b_d = 5,
@@ -8452,6 +8481,7 @@ struct test_concat : public test_case {
auto ne = ne_a; ne[0] *= 2; ne[1] *= 4; ne[2] *= 3;
a = ggml_new_tensor(ctx, type, 4, ne.data());
ggml_set_name(a, "a");
ggml_set_param(a);
a = ggml_view_4d(ctx, a, ne_a[0], ne_a[1], ne_a[2], ne_a[3], a->nb[1], a->nb[2], a->nb[3], 0);
ggml_set_name(a, "view_of_a");
@@ -8459,18 +8489,24 @@ struct test_concat : public test_case {
auto ne = ne_a; ne[2] *= 2; ne[3] *= 4;
a = ggml_new_tensor(ctx, type, 4, ne.data());
ggml_set_name(a, "a");
ggml_set_param(a);
a = ggml_view_4d(ctx, a, ne_a[0], ne_a[1], ne_a[2], ne_a[3], a->nb[1], a->nb[2], a->nb[3], 0);
ggml_set_name(a, "view_of_a");
} else {
a = ggml_new_tensor(ctx, type, 4, ne_a.data());
ggml_set_name(a, "a");
// the transposed b cases target the forward kernel, a grad check of a there takes minutes
if (!(v & 16)) {
ggml_set_param(a);
}
}
ggml_tensor * b;
if (v & 2) {
auto ne = ne_b; ne[0] *= 3; ne[1] *= 2; ne[2] *= 4;
b = ggml_new_tensor(ctx, type, 4, ne.data());
ggml_set_name(b, "b");
ggml_set_param(b);
b = ggml_view_4d(ctx, b, ne_b[0], ne_b[1], ne_b[2], ne_b[3], b->nb[1], b->nb[2], b->nb[3], 0);
ggml_set_name(b, "view_of_b");
@@ -8478,6 +8514,7 @@ struct test_concat : public test_case {
auto ne = ne_b; ne[2] *= 3; ne[3] *= 2;
b = ggml_new_tensor(ctx, type, 4, ne.data());
ggml_set_name(b, "b");
ggml_set_param(b);
b = ggml_view_4d(ctx, b, ne_b[0], ne_b[1], ne_b[2], ne_b[3], b->nb[1], b->nb[2], b->nb[3], 0);
ggml_set_name(b, "view_of_b");
@@ -8491,11 +8528,21 @@ struct test_concat : public test_case {
} else {
b = ggml_new_tensor(ctx, type, 4, ne_b.data());
ggml_set_name(b, "b");
ggml_set_param(b);
}
ggml_tensor * out = ggml_concat(ctx, a, b, dim);
ggml_set_name(out, "out");
if (mode == MODE_GRAD) {
// with sum(out) as the loss every element has the same gradient, so a wrong view offset in the
// backward pass would go unnoticed; random weights make the gradient differ per element
ggml_tensor * w = ggml_new_tensor(ctx, type, 4, out->ne);
ggml_set_name(w, "w");
out = ggml_mul(ctx, out, w);
ggml_set_name(out, "out_weighted");
}
return out;
}
};
@@ -12752,6 +12799,9 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
test_cases.emplace_back(new test_conv_transpose_1d({3,2,1,1}, {3,1,2,1}, 1, 0, 1));
test_cases.emplace_back(new test_conv_transpose_1d({2,1,1,1}, {3,1,1,1}, 1, 0, 1));
test_cases.emplace_back(new test_conv_transpose_1d({33,32,1,1}, {20,24,32,1}, 10, 0, 1));
test_cases.emplace_back(new test_conv_transpose_1d({35,33,1,1}, {11,17,33,1}, 5, 0, 1));
for (ggml_type type : {GGML_TYPE_F32, GGML_TYPE_F16, GGML_TYPE_BF16}) {
// ConvTranspose1d expressed as mul_mat + col2im (DAC decoder upsampling)
test_cases.emplace_back(new test_col2im_1d(type, 16, 32, 197, 8, 0)); // kernel = 2*stride
@@ -15040,6 +15090,7 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
test_cases.emplace_back(new test_flash_attn_ext(256, 256, 4, {2, 1}, 4096, 512, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16));
test_cases.emplace_back(new test_flash_attn_ext(256, 256, 4, {4, 1}, 4096, 512, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16));
test_cases.emplace_back(new test_flash_attn_ext(256, 256, 2, {12, 1}, 4096, 512, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16));
test_cases.emplace_back(new test_flash_attn_ext(128, 128, 4, { 3, 1}, 512, 32, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16));
// dense-allocated (non-view) quant K/V at batch >= 64, in cache and native layouts
test_cases.emplace_back(new test_flash_attn_ext(64, 64, 4, {1, 1}, 512, 75, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_Q8_0, GGML_TYPE_Q8_0, {0, 2, 1, 3}, false));
+16
View File
@@ -5601,6 +5601,22 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
.expect(message_assist_call_thoughts)
.run();
// The models sometimes open the tool call section without closing the reasoning at all
for (const char * effort : { R"("medium")", R"("high")" }) {
tst.test(
"I'm\nthinking<ifm|tool_calls>\n"
"<ifm|tool_call>special_function\n"
"<ifm|arg_key>arg1</ifm|arg_key>\n"
"<ifm|arg_value>1</ifm|arg_value>\n"
"</ifm|tool_call>\n"
"</ifm|tool_calls>")
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
.tools({ special_function_tool })
.chat_template_kwargs({ { "reasoning_effort", effort } })
.expect(message_assist_call_thoughts)
.run();
}
tst.test(
"I'm\nthinking</ifm|think><ifm|tool_calls>\n"
"<ifm|tool_call>{\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}</ifm|tool_call>\n"
+22
View File
@@ -82,5 +82,27 @@ int main() {
success = false;
}
const std::vector<std::string> regex_exprs_bytes = { "\\p{L}+", "\\p{N}+", "\\s+" };
const std::string byte_encode_text = "\xc4\x80\xc4\xb1\xe0\xa4\x95\xf0\x9f\x98\x80";
const auto actual_byte_encode = unicode_regex_split(byte_encode_text, regex_exprs_bytes, true);
// GPT-2 byte-level encoding of byte_encode_text, independent of unicode_byte_to_utf8().
const std::vector<std::string> expected_byte_encode = {
"\xc3\x84\xc4\xa2\xc3\x84\xc2\xb1\xc3\xa0\xc2\xa4\xc4\xb7",
"\xc3\xb0\xc5\x81\xc4\xba\xc4\xa2",
};
if (actual_byte_encode != expected_byte_encode) {
fprintf(stderr, "unexpected byte-encoded split:");
for (const auto & piece : actual_byte_encode) {
fprintf(stderr, " [");
for (const unsigned char byte : piece) {
fprintf(stderr, "%02x", byte);
}
fprintf(stderr, "]");
}
fprintf(stderr, "\n");
success = false;
}
return success ? 0 : 1;
}
@@ -37,6 +37,15 @@ def vision_server():
return server
@pytest.fixture
def tool_server():
"""Separate fixture for tool tests that require a model which actually calls tools"""
global server
server = ServerPreset.small_test()
server.n_slots = 1
return server
# Basic message tests
def test_anthropic_messages_basic():
@@ -259,9 +268,10 @@ def test_anthropic_count_tokens_no_max_tokens():
# Tool use tests
def test_anthropic_tool_use_basic():
def test_anthropic_tool_use_basic(tool_server):
"""Test basic tool use"""
server.jinja = True
global server
server = tool_server
server.start()
res = server.make_request("POST", "/v1/messages", data={
@@ -288,22 +298,14 @@ def test_anthropic_tool_use_basic():
assert res.status_code == 200
assert res.body["type"] == "message"
assert len(res.body["content"]) > 0
assert res.body["stop_reason"] == "tool_use"
# Check if model used the tool (it might not always, depending on the model)
content_types = [block.get("type") for block in res.body["content"]]
if "tool_use" in content_types:
# Model used the tool
assert res.body["stop_reason"] == "tool_use"
# Find the tool_use block
tool_block = next(b for b in res.body["content"] if b.get("type") == "tool_use")
assert "id" in tool_block
assert "name" in tool_block
assert tool_block["name"] == "get_weather"
assert "input" in tool_block
assert isinstance(tool_block["input"], dict)
tool_blocks = [b for b in res.body["content"] if b.get("type") == "tool_use"]
assert len(tool_blocks) == 1, f"Expected one tool_use block, got {res.body['content']}"
tool_block = tool_blocks[0]
assert tool_block["id"]
assert tool_block["name"] == "get_weather"
assert match_regex("Paris", tool_block["input"]["location"])
def test_anthropic_tool_result():
@@ -546,9 +548,10 @@ def test_anthropic_tool_reference():
assert anthropic.body["input_tokens"] == oai.body["input_tokens"]
def test_anthropic_tool_streaming():
def test_anthropic_tool_streaming(tool_server):
"""Test streaming with tool use"""
server.jinja = True
global server
server = tool_server
server.start()
res = server.make_stream_request("POST", "/v1/messages", data={
@@ -577,26 +580,26 @@ def test_anthropic_tool_streaming():
event_types = [e["type"] for e in events]
# Should have basic events
assert "message_start" in event_types
assert "message_stop" in event_types
assert event_types[0] == "message_start"
assert event_types[-1] == "message_stop"
# If tool was used, check for proper tool streaming
if any(e.get("type") == "content_block_start" and
e.get("content_block", {}).get("type") == "tool_use"
for e in events):
# Find tool use block start
tool_starts = [e for e in events if
e.get("type") == "content_block_start" and
e.get("content_block", {}).get("type") == "tool_use"]
tool_starts = [e for e in events if e["type"] == "content_block_start" and e["content_block"]["type"] == "tool_use"]
assert len(tool_starts) == 1, f"Expected one tool_use content_block_start, got {events}"
tool_start = tool_starts[0]
assert tool_start["content_block"]["name"] == "calculator"
assert tool_start["content_block"]["id"]
assert len(tool_starts) > 0, "Should have tool_use content_block_start"
# The arguments stream as input_json_delta events on the index of the tool_use block
index = tool_start["index"]
partial_json = "".join(
e["delta"]["partial_json"] for e in events
if e["type"] == "content_block_delta" and e["index"] == index and e["delta"]["type"] == "input_json_delta"
)
assert match_regex("2 *\\+ *2", json.loads(partial_json)["expression"])
# Check index is correct (should be 0 if no text, 1 if there's text)
tool_start = tool_starts[0]
assert "index" in tool_start
assert tool_start["content_block"]["type"] == "tool_use"
assert "name" in tool_start["content_block"]
message_deltas = [e for e in events if e["type"] == "message_delta"]
assert len(message_deltas) == 1
assert message_deltas[0]["delta"]["stop_reason"] == "tool_use"
# Vision/multimodal tests
@@ -265,3 +265,21 @@ def test_draft_token_probs():
assert abs(tok_draft["logprob"] - tok_no_draft["logprob"]) < 0.25
# real logprobs are not all exactly 0.0 (prob 1.0)
assert any(tok["logprob"] < -1e-4 for tok in probs_draft)
def test_mtp_draft_matches_target():
# greedy tokens are identical with and without the MTP head of small-test, and the draft is actually used
global server
server = ServerPreset.small_test()
server.start()
req = {"prompt": "<|im_start|>user\nList three colors.<|im_end|>\n<|im_start|>assistant\n", "n_predict": 48, "temperature": 0.0, "top_k": 1, "return_tokens": True}
res = server.make_request("POST", "/completion", data=req)
assert res.status_code == 200
tokens_no_draft = res.body["tokens"]
server.stop()
server.spec_type = "draft-mtp"
server.start()
res = server.make_request("POST", "/completion", data=req)
assert res.status_code == 200
assert res.body["timings"]["draft_n"] > 0
assert res.body["tokens"] == tokens_no_draft
+32 -21
View File
@@ -125,27 +125,14 @@ def do_test_completion_with_required_tool_tiny(server: ServerProcess, tool: dict
actual_arguments = json.loads(actual_arguments)
assert argument_key in actual_arguments, f"tool arguments: {actual_arguments}, expected: {argument_key}"
# PR #22654: commented out since we're now allowing content before tool calls in tool_call: required, so we can't force this
# in the tiny model just by using the grammar
#
# @pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
# @pytest.mark.parametrize("template_name,tool,argument_key", [
# ("Qwen3-Coder", TEST_TOOL, "success"),
# ("Qwen3-Coder", TEST_TOOL, "success"),
# ("meta-llama-Llama-3.3-70B-Instruct", TEST_TOOL, "success"),
# ("meta-llama-Llama-3.3-70B-Instruct", TEST_TOOL, "success"),
# ("meta-llama-Llama-3.3-70B-Instruct", PYTHON_TOOL, "code"),
# ("meta-llama-Llama-3.3-70B-Instruct", PYTHON_TOOL, "code"),
# ])
# def test_completion_with_required_tool_tiny_fast(template_name: str, tool: dict, argument_key: str | None, stream: CompletionMode):
# global server
# n_predict = 1024
# # server = ServerPreset.stories15m_moe()
# server.jinja = True
# server.n_predict = n_predict
# server.chat_template_file = f'../../../models/templates/{template_name}.jinja'
# server.start()
# do_test_completion_with_required_tool_tiny(server, tool, argument_key, n_predict, stream=stream == CompletionMode.STREAMED, temperature=0.0, top_k=1, top_p=1.0)
# the grammar of tool_choice: required allows content before the call, so this needs a model trained on tool calls like small-test
@pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
@pytest.mark.parametrize("tool,argument_key", [(TEST_TOOL, "success"), (PYTHON_TOOL, "code")])
def test_completion_with_required_tool_fast(tool: dict, argument_key: str, stream: CompletionMode):
global server
server = ServerPreset.small_test()
server.start()
do_test_completion_with_required_tool_tiny(server, tool, argument_key, 256, stream=stream == CompletionMode.STREAMED, temperature=0.0, top_k=1, top_p=1.0)
# @pytest.mark.slow
# @pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
@@ -423,6 +410,14 @@ def do_test_weather(server: ServerProcess, **kwargs):
assert re.match('^Istanbul(( |, ?)(TR|Turkey|Türkiye))?$', location), f'Expected Istanbul for location, got {location}'
@pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
def test_weather_fast(stream: CompletionMode):
global server
server = ServerPreset.small_test()
server.start()
do_test_weather(server, stream=stream == CompletionMode.STREAMED, max_tokens=256, temperature=0.0, top_k=1, top_p=1.0)
@pytest.mark.slow
@pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
@pytest.mark.parametrize("result_override,n_predict,hf_repo,template_override", [
@@ -519,6 +514,14 @@ def do_test_calc_result(server: ServerProcess, result_override: str | None, n_pr
f'Expected something like "The y coordinate is 0.56.", got {content}'
@pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
def test_calc_result_fast(stream: CompletionMode):
global server
server = ServerPreset.small_test()
server.start()
do_test_calc_result(server, None, 256, stream=stream == CompletionMode.STREAMED, temperature=0.0, top_k=1, top_p=1.0)
@pytest.mark.slow
@pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
@pytest.mark.parametrize("n_predict,reasoning_format,expect_reasoning_content,expect_content,hf_repo,template_override", [
@@ -644,6 +647,14 @@ def do_test_hello_world(server: ServerProcess, **kwargs):
assert re.match(r'''print\(("[Hh]ello,? [Ww]orld!?"|'[Hh]ello,? [Ww]orld!?')\)''', re.sub(r'#.*\n?', '', code)), f'Expected hello world, got {code}'
@pytest.mark.parametrize("stream", [CompletionMode.NORMAL, CompletionMode.STREAMED])
def test_hello_world_fast(stream: CompletionMode):
global server
server = ServerPreset.small_test()
server.start()
do_test_hello_world(server, stream=stream == CompletionMode.STREAMED, max_tokens=256, temperature=0.0, top_k=1, top_p=1.0)
SEARCH_TOOL = {
"type": "function",
"function": {
@@ -245,3 +245,50 @@ def test_vision_image_url_private_address(allow_private: bool):
finally:
target.shutdown()
target.server_close()
def get_ocr_image_part(name: str) -> dict:
response = requests.get(f"https://huggingface.co/ggml-org-dev/small-test/resolve/main/test/{name}.png")
response.raise_for_status()
return {"type": "image_url", "image_url": {"url": "data:image/png;base64," + base64.b64encode(response.content).decode("utf-8")}}
@pytest.mark.parametrize("name,text", [("hello_world", "HELLO WORLD"), ("invoice_2026", "Invoice 2026")])
def test_vision_ocr(name: str, text: str):
# small-test reads black text on white in a common truetype font, the kind of image it is trained on
global server
server = ServerPreset.small_test()
server.start()
body = server.make_any_request("POST", "/v1/chat/completions", data={
"max_tokens": 32,
"messages": [{"role": "user", "content": [
get_ocr_image_part(name),
{"type": "text", "text": "What is written in this image?"},
]}],
"temperature": 0.0,
"top_k": 1,
"top_p": 1.0,
})
content = body["choices"][0]["message"]["content"]
assert text.lower() in content.lower(), f"expected {text!r} in {content!r}"
def test_vision_ocr_two_images():
# both images in one message: small-test is trained on one image per message, so it only reads the year of the second one
# "2026" is only in the second image, which proves that both images reach the model
global server
server = ServerPreset.small_test()
server.start()
body = server.make_any_request("POST", "/v1/chat/completions", data={
"max_tokens": 64,
"messages": [{"role": "user", "content": [
get_ocr_image_part("hello_world"),
get_ocr_image_part("invoice_2026"),
{"type": "text", "text": "What is written in these two images?"},
]}],
"temperature": 0.0,
"top_k": 1,
"top_p": 1.0,
})
content = body["choices"][0]["message"]["content"].lower()
assert "hello world" in content and "2026" in content, f"expected the text of both images in {content!r}"
+17
View File
@@ -796,6 +796,23 @@ class ServerPreset:
server.seed = 42
return server
@staticmethod
def small_test() -> ServerProcess:
# ~95M Qwen3.5 based VLM with MTP head: chat, tool calling, OCR and draft-mtp in one fixture
server = ServerProcess()
server.offline = True # will be downloaded by load_all()
# mmproj is already provided by HF registry API
server.model_hf_file = None
server.model_hf_repo = "ggml-org-dev/small-test:F16"
server.model_alias = "small-test"
server.jinja = True
server.n_ctx = 8192
server.n_batch = 2048
server.n_slots = 2
server.n_predict = 512
server.seed = 42
return server
@staticmethod
def router() -> ServerProcess:
server = ServerProcess()
+1337 -431
View File
File diff suppressed because it is too large Load Diff
+285 -39
View File
@@ -8,8 +8,8 @@
#ifndef CPPHTTPLIB_HTTPLIB_H
#define CPPHTTPLIB_HTTPLIB_H
#define CPPHTTPLIB_VERSION "0.67.0"
#define CPPHTTPLIB_VERSION_NUM "0x004300"
#define CPPHTTPLIB_VERSION "0.68.0"
#define CPPHTTPLIB_VERSION_NUM "0x004400"
#ifdef _WIN32
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0A00
@@ -34,6 +34,11 @@
#define CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND 5
#endif
// Whether a Server starts with set_keep_alive_parking(true).
#ifndef CPPHTTPLIB_KEEPALIVE_PARKING
#define CPPHTTPLIB_KEEPALIVE_PARKING false
#endif
#ifndef CPPHTTPLIB_KEEPALIVE_TIMEOUT_CHECK_INTERVAL_USECOND
#define CPPHTTPLIB_KEEPALIVE_TIMEOUT_CHECK_INTERVAL_USECOND 10000
#endif
@@ -291,6 +296,13 @@ static_assert(CPPHTTPLIB_MAX_LINE_LENGTH > 0,
#define CPPHTTPLIB_WEBSOCKET_MAX_MISSED_PONGS 0
#endif
// A WebSocket connection carries small messages each way, which Nagle's
// algorithm would hold back for the peer's delayed ACK (tens of milliseconds
// on Linux), so it sets TCP_NODELAY unless this is false.
#ifndef CPPHTTPLIB_WEBSOCKET_TCP_NODELAY
#define CPPHTTPLIB_WEBSOCKET_TCP_NODELAY true
#endif
/*
* Headers
*/
@@ -367,6 +379,8 @@ using socklen_t = int;
#ifdef __linux__
#include <resolv.h>
#undef _res // Undefine _res macro to avoid conflicts with user code (#2278)
#include <sys/epoll.h>
#include <sys/eventfd.h>
#endif
#include <csignal>
#include <netinet/tcp.h>
@@ -386,6 +400,11 @@ using socket_t = int;
#include <TargetConditionals.h>
#endif
#if defined(__APPLE__) || defined(__FreeBSD__)
#define CPPHTTPLIB_KQUEUE_POLLER
#include <sys/event.h>
#endif
#include <algorithm>
#include <array>
#include <atomic>
@@ -906,8 +925,9 @@ inline bool parse_url(const std::string &url, UrlComponents &uc) {
size_t pos = 0;
auto sep = url.find("://");
if (sep != std::string::npos) {
uc.scheme = url.substr(0, sep);
if (sep < url.find_first_of("/?#")) {
// Schemes are case-insensitive (RFC 3986 3.1)
uc.scheme = case_ignore::to_lower(url.substr(0, sep));
// Scheme must be [a-z]+ only
if (uc.scheme.empty()) { return false; }
@@ -2278,6 +2298,8 @@ public:
using StartHandler = std::function<void()>;
using AcceptHandler = std::function<bool(socket_t sock)>;
using WebSocketHandler =
std::function<void(const Request &, ws::WebSocket &)>;
using SubProtocolSelector =
@@ -2343,6 +2365,8 @@ public:
Server &set_start_handler(StartHandler handler);
Server &set_accept_handler(AcceptHandler handler);
Server &set_logger(Logger logger);
Server &set_pre_compression_logger(Logger logger);
Server &set_error_logger(ErrorLogger error_logger);
@@ -2376,6 +2400,10 @@ public:
template <class Rep, class Period>
Server &set_idle_interval(const std::chrono::duration<Rep, Period> &duration);
// Keeps idle keep-alive connections in an event loop instead of a worker
// thread each. Call it before listen(). See README for what changes.
Server &set_keep_alive_parking(bool on);
Server &set_payload_max_length(size_t length);
Server &set_compress(bool on);
@@ -2391,6 +2419,8 @@ public:
Server &set_websocket_max_missed_pongs(int count);
Server &set_websocket_max_message_length(size_t length);
bool bind_to_port(const std::string &host, int port, int socket_flags = 0);
int bind_to_any_port(const std::string &host, int socket_flags = 0);
bool listen_after_bind();
@@ -2412,8 +2442,9 @@ protected:
const std::function<void(Request &)> &setup_request,
bool *websocket_upgraded = nullptr);
// Runs the per-connection serving loop and stops an exception thrown by a
// user callback from escaping the worker thread.
// Runs a user callback, or the per-connection serving loop that calls user
// callbacks, and stops an exception thrown by one from escaping the
// server's threads.
//
// process_request() wraps only routing() and the hooks before a WebSocket
// upgrade in a try/catch. Content providers, the post-routing, error,
@@ -2446,6 +2477,13 @@ protected:
// stop() takes the listening socket away; listen() then waits for handlers
bool is_stopping() const { return svr_sock_ == INVALID_SOCKET; }
// See set_keep_alive_parking(). Defined in the implementation part.
struct KeepAliveConnection;
struct ParkingState;
std::unique_ptr<ParkingState> parking_;
bool keep_alive_parking_ = false;
bool idle_interval_set_ = false;
std::vector<std::string> trusted_proxies_;
size_t keep_alive_max_count_ = CPPHTTPLIB_KEEPALIVE_MAX_COUNT;
@@ -2466,6 +2504,8 @@ protected:
time_t websocket_ping_interval_sec_ =
CPPHTTPLIB_WEBSOCKET_PING_INTERVAL_SECOND;
int websocket_max_missed_pongs_ = CPPHTTPLIB_WEBSOCKET_MAX_MISSED_PONGS;
size_t websocket_max_message_length_ =
CPPHTTPLIB_WEBSOCKET_MAX_PAYLOAD_LENGTH;
private:
using Handlers =
@@ -2505,6 +2545,12 @@ private:
SocketOptions socket_options) const;
int bind_internal(const std::string &host, int port, int socket_flags);
bool listen_internal();
bool accept_loop(TaskQueue &task_queue);
bool parking_loop(TaskQueue &task_queue);
bool admit_accepted_socket(socket_t sock) const;
struct PlainConnection;
void resume_connection(std::shared_ptr<KeepAliveConnection> conn);
bool abandon_listen_socket();
bool routing(Request &req, Response &res, Stream &strm,
bool skip_pre_routing);
@@ -2552,6 +2598,9 @@ private:
ContentReceiver multipart_receiver) const;
virtual bool process_and_close_socket(socket_t sock);
// The connection that parking_loop() keeps for a socket it has accepted.
virtual std::shared_ptr<KeepAliveConnection>
new_keep_alive_connection(socket_t sock);
void output_log(const Request &req, const Response &res) const;
void output_pre_compression_log(const Request &req,
@@ -2603,6 +2652,7 @@ private:
HandlerWithResponse pre_request_handler_;
Expect100ContinueHandler expect_100_continue_handler_;
StartHandler start_handler_;
AcceptHandler accept_handler_;
mutable std::mutex logger_mutex_;
Logger logger_;
@@ -3512,6 +3562,12 @@ public:
private:
bool process_and_close_socket(socket_t sock) override;
std::shared_ptr<KeepAliveConnection>
new_keep_alive_connection(socket_t sock) override;
struct TlsConnection;
// Creates a session and runs the handshake. Null on failure, which sets
// last_ssl_error_.
tls::session_t start_session(socket_t sock);
tls::ctx_t ctx_ = nullptr;
// update_certs_pem() replaces the certificates and CAs that handshakes read
@@ -3922,6 +3978,126 @@ EncodingType encoding_type(const Request &req, const Response &res,
EncodingType encoding_type(const Request &req, const Response &res);
// Creates a connected pair of stream sockets that child processes do not
// inherit. Windows has no socketpair(), so it is emulated there.
bool create_socket_pair(socket_t sv[2]);
// Ends a Poller's wait() from another thread. The poller watches fd() for
// readability, level-triggered, and calls drain() when it is reported.
class PollerWaker {
public:
~PollerWaker();
// An eventfd on Linux, a socket pair elsewhere.
bool open();
socket_t fd() const { return fd_; }
// An address inside the poller, which no caller's token can be.
uintptr_t token() const { return reinterpret_cast<uintptr_t>(this); }
// From any thread. While one is pending, later calls make no syscall.
void wake() noexcept;
void drain() noexcept;
private:
socket_t fd_ = INVALID_SOCKET;
socket_t pair_fd_ = INVALID_SOCKET; // the end wake() writes; none on Linux
std::atomic<bool> pending_{false};
};
// One-shot readiness notification for a reactor:
// - A delivered event disarms the descriptor; arm() it again to wait again.
// - A hang-up or an error counts as readable.
// - Only an unarmed descriptor may be armed, and an armed one must be
// disarmed before it is closed.
// - wake() may be called from any thread; the rest belongs to one thread.
class Poller {
public:
using Token = uintptr_t;
virtual ~Poller() = default;
virtual bool arm(socket_t fd, Token token) = 0;
virtual void disarm(socket_t fd) = 0;
// Fills `ready` in no particular order and returns whether wake() was
// called. A negative timeout waits until either happens.
virtual bool wait(int timeout_ms, std::vector<Token> &ready) = 0;
virtual void wake() noexcept = 0;
};
// poll() on POSIX, WSAPoll() on Windows. Works everywhere.
class PollPoller final : public Poller {
public:
// nullptr when the descriptors cannot be created.
static std::unique_ptr<Poller> create();
bool arm(socket_t fd, Token token) override;
void disarm(socket_t fd) override;
bool wait(int timeout_ms, std::vector<Token> &ready) override;
void wake() noexcept override { waker_.wake(); }
private:
PollPoller() = default;
void remove_at(size_t index);
PollerWaker waker_;
// fds_[0] is the waker's, which is always armed; tokens_[i] belongs to
// fds_[i].
std::vector<struct pollfd> fds_;
std::vector<Token> tokens_;
std::unordered_map<socket_t, size_t> index_;
};
#ifdef __linux__
// epoll with EPOLLONESHOT. Waits in O(ready) instead of O(armed).
class EpollPoller final : public Poller {
public:
// nullptr when the descriptors cannot be created.
static std::unique_ptr<Poller> create();
~EpollPoller() override;
bool arm(socket_t fd, Token token) override;
void disarm(socket_t fd) override;
bool wait(int timeout_ms, std::vector<Token> &ready) override;
void wake() noexcept override { waker_.wake(); }
private:
EpollPoller() = default;
int epfd_ = -1;
PollerWaker waker_; // always armed
std::vector<struct epoll_event> events_;
};
#endif
#ifdef CPPHTTPLIB_KQUEUE_POLLER
// kqueue with EV_ONESHOT. Waits in O(ready) instead of O(armed).
class KqueuePoller final : public Poller {
public:
// nullptr when the descriptors cannot be created.
static std::unique_ptr<Poller> create();
~KqueuePoller() override;
bool arm(socket_t fd, Token token) override;
void disarm(socket_t fd) override;
bool wait(int timeout_ms, std::vector<Token> &ready) override;
void wake() noexcept override { waker_.wake(); }
private:
KqueuePoller() = default;
int kq_ = -1;
PollerWaker waker_; // always armed
std::vector<struct kevent> events_;
};
#endif
// The best poller for this platform, or nullptr when it cannot be created.
std::unique_ptr<Poller> make_poller();
class BufferStream final : public Stream {
public:
BufferStream() = default;
@@ -4701,6 +4877,51 @@ private:
#endif
};
namespace impl {
bool is_valid_utf8(const std::string &s);
// A frame, a failure (the connection cannot be read on), a timeout with the
// stream still usable, or a frame the peer should not have sent: one that
// breaks the protocol, or one longer than the limit.
enum class FrameRead { Ok, Fail, Timeout, ProtocolError, TooBig };
// The settings a Server or WebSocketClient gives each WebSocket it creates
struct Options {
time_t ping_interval_sec = CPPHTTPLIB_WEBSOCKET_PING_INTERVAL_SECOND;
int max_missed_pongs = CPPHTTPLIB_WEBSOCKET_MAX_MISSED_PONGS;
size_t max_message_length = CPPHTTPLIB_WEBSOCKET_MAX_PAYLOAD_LENGTH;
};
// A frame read in as many calls as it takes. A timeout leaves what was read
// so far in place, and the next read() goes on from there, so the stream is
// usable after a timeout wherever in a frame it lands.
class FrameReader {
public:
FrameRead read(Stream &strm, Opcode &opcode, std::string &payload, bool &fin,
bool expect_masked, size_t max_len);
// Whether part of a frame has been read and the rest is still to come
bool begun() const { return have_ > 0; }
private:
void reset();
uint8_t head_[14] = {0}; // FIN + opcode, MASK + length, its extension, key
size_t have_ = 0; // bytes of the header read so far
size_t need_ = 2; // bytes of the header, once the second is read
bool sized_ = false; // the header is whole and its length checked
size_t len_ = 0; // the payload's length, once sized_
std::string payload_;
};
// A whole frame read in one go: a timeout before any of it came is reported,
// and one that cuts it short is a failure.
FrameRead read_websocket_frame(Stream &strm, Opcode &opcode,
std::string &payload, bool &fin,
bool expect_masked, size_t max_len);
} // namespace impl
class WebSocket {
public:
WebSocket(const WebSocket &) = delete;
@@ -4715,9 +4936,18 @@ public:
const Request &request() const;
bool is_open() const;
// Why the connection ended, once read() has returned Fail (RFC 6455 7.1.5,
// 7.1.6): the code and reason of the peer's Close, NoStatus when it had no
// code, ProtocolError when it was malformed, and Abnormal when none came.
// After a close() of our own, the peer's reply is what is reported.
CloseStatus close_status() const;
std::string close_reason() const;
// Bound how long read() waits before returning Timeout. 0 waits forever.
// A server handler owns its connection's timeout this way; a client sets it
// through WebSocketClient. Safe to call while another thread is in read().
// It lands anywhere, inside a message too: what was read of it is kept,
// and the next read() goes on from there.
//
// Only a timeout set here is reported as Timeout. The compile-time default
// (CPPHTTPLIB_WEBSOCKET_SERVER_READ_TIMEOUT_SECOND) is a backstop rather
@@ -4731,27 +4961,25 @@ private:
friend class httplib::Server;
friend class httplib::ws::WebSocketClient;
WebSocket(
Stream &strm, const Request &req, bool is_server,
time_t ping_interval_sec = CPPHTTPLIB_WEBSOCKET_PING_INTERVAL_SECOND,
int max_missed_pongs = CPPHTTPLIB_WEBSOCKET_MAX_MISSED_PONGS,
std::function<bool()> server_stopping = nullptr)
WebSocket(Stream &strm, const Request &req, bool is_server,
const impl::Options &options,
std::function<bool()> server_stopping = nullptr)
: strm_(strm), req_(req), is_server_(is_server),
ping_interval_sec_(ping_interval_sec),
max_missed_pongs_(max_missed_pongs),
ping_interval_sec_(options.ping_interval_sec),
max_missed_pongs_(options.max_missed_pongs),
max_message_length_(options.max_message_length),
server_stopping_(std::move(server_stopping)) {
interrupt_reads();
start_heartbeat();
}
WebSocket(
std::unique_ptr<Stream> &&owned_strm, const Request &req, bool is_server,
time_t ping_interval_sec = CPPHTTPLIB_WEBSOCKET_PING_INTERVAL_SECOND,
int max_missed_pongs = CPPHTTPLIB_WEBSOCKET_MAX_MISSED_PONGS,
std::function<bool()> server_stopping = nullptr)
WebSocket(std::unique_ptr<Stream> &&owned_strm, const Request &req,
bool is_server, const impl::Options &options,
std::function<bool()> server_stopping = nullptr)
: strm_(*owned_strm), owned_strm_(std::move(owned_strm)), req_(req),
is_server_(is_server), ping_interval_sec_(ping_interval_sec),
max_missed_pongs_(max_missed_pongs),
is_server_(is_server), ping_interval_sec_(options.ping_interval_sec),
max_missed_pongs_(options.max_missed_pongs),
max_message_length_(options.max_message_length),
server_stopping_(std::move(server_stopping)) {
interrupt_reads();
start_heartbeat();
@@ -4763,6 +4991,8 @@ private:
}
void start_heartbeat();
bool send_frame(Opcode op, const char *data, size_t len, bool fin = true);
bool send_close(const std::string &payload);
void set_close_status(const std::string &payload);
Stream &strm_;
std::unique_ptr<Stream> owned_strm_;
@@ -4770,6 +5000,8 @@ private:
bool is_server_;
time_t ping_interval_sec_;
int max_missed_pongs_;
// The largest frame or message read() accepts; 0 means no limit
size_t max_message_length_;
int unacked_pings_ = 0;
std::atomic<bool> closed_{false};
// Set when the peer stopped answering pings, to end a read() waiting on it
@@ -4782,10 +5014,20 @@ private:
std::atomic<bool> read_timeout_set_{false};
std::mutex write_mutex_;
// Owned by whichever thread is parsing frames off strm_. Only one thread
// may do so: read_websocket_frame() reads a payload until it has the whole
// declared length, so a second parser stealing bytes silently corrupts the
// message the first one is assembling.
// may do so: a frame is read until it has the whole declared length,
// across several read() calls when a timeout lands inside it (frames_
// below), so a second parser stealing bytes silently corrupts the message
// the first one is assembling.
std::mutex read_mutex_;
// What read() has of the frame and the message it has not finished, kept
// across a timeout. Guarded by read_mutex_.
impl::FrameReader frames_;
std::string message_;
ReadResult message_kind_ = Fail; // Text or Binary while one is assembled
// The peer's Close, set once under read_mutex_. close_reason_ is written
// before close_status_ leaves Abnormal and is not changed after.
std::atomic<CloseStatus> close_status_{CloseStatus::Abnormal};
std::string close_reason_;
std::thread ping_thread_;
std::mutex ping_mutex_;
std::condition_variable ping_cv_;
@@ -4809,6 +5051,8 @@ public:
void close(CloseStatus status = CloseStatus::Normal,
const std::string &reason = "");
bool is_open() const;
CloseStatus close_status() const;
std::string close_reason() const;
const std::string &subprotocol() const;
void set_read_timeout(time_t sec, time_t usec = 0);
template <class Rep, class Period>
@@ -4820,6 +5064,7 @@ public:
void set_websocket_ping_interval(time_t sec);
void set_websocket_max_missed_pongs(int count);
void set_websocket_max_message_length(size_t length);
void set_tcp_nodelay(bool on);
void set_address_family(int family);
void set_ipv6_v6only(bool on);
@@ -4870,6 +5115,9 @@ public:
std::function<SSLVerifierResponse(tls::session_t)> verifier);
void set_proxy_digest_auth(const std::string &username,
const std::string &password);
#ifdef CPPHTTPLIB_WINDOWS_AUTOMATIC_ROOT_CERTIFICATES_UPDATE
void enable_windows_certificate_verification(bool enabled);
#endif
#endif
private:
@@ -4899,8 +5147,10 @@ private:
time_t websocket_ping_interval_sec_ =
CPPHTTPLIB_WEBSOCKET_PING_INTERVAL_SECOND;
int websocket_max_missed_pongs_ = CPPHTTPLIB_WEBSOCKET_MAX_MISSED_PONGS;
size_t websocket_max_message_length_ =
CPPHTTPLIB_WEBSOCKET_MAX_PAYLOAD_LENGTH;
int address_family_ = AF_UNSPEC;
bool tcp_nodelay_ = CPPHTTPLIB_TCP_NODELAY;
bool tcp_nodelay_ = CPPHTTPLIB_WEBSOCKET_TCP_NODELAY;
bool ipv6_v6only_ = CPPHTTPLIB_IPV6_V6ONLY;
SocketOptions socket_options_ = nullptr;
time_t connection_timeout_sec_ = CPPHTTPLIB_CONNECTION_TIMEOUT_SECOND;
@@ -4942,6 +5192,10 @@ private:
std::function<SSLVerifierResponse(tls::session_t)> session_verifier_;
std::string proxy_digest_auth_username_;
std::string proxy_digest_auth_password_;
#ifdef CPPHTTPLIB_WINDOWS_AUTOMATIC_ROOT_CERTIFICATES_UPDATE
bool enable_windows_cert_verification_ = true;
bool server_certificate_verifier_set_ = false;
#endif
#endif
};
@@ -4974,23 +5228,15 @@ inline void WebSocketClient::set_connection_timeout(
});
}
namespace impl {
bool is_valid_utf8(const std::string &s);
// Three states, because a failure that consumed bytes and one that consumed
// none are not the same thing: the first has left the stream in the middle of
// a frame and the connection cannot be reused, the second can just be retried.
enum class FrameRead { Ok, Fail, Timeout };
FrameRead read_websocket_frame(Stream &strm, Opcode &opcode,
std::string &payload, bool &fin,
bool expect_masked, size_t max_len);
} // namespace impl
} // namespace ws
namespace detail {
bool write_websocket_frame(Stream &strm, ws::Opcode opcode, const char *data,
size_t len, bool fin, bool mask);
} // namespace detail
} // namespace httplib