Skip to content

meta : handle host views - #30217

Merged
ggerganov merged 3 commits into
masterfrom
gg/meta-handle-host-views
Oct 9, 2026
Merged

ggerganov merged 3 commits into
masterfrom
gg/meta-handle-host-views

Conversation

@ggerganov

@ggerganov ggerganov commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Overview

ref: #29535 (comment)

My analysis is that views of host-buffer tensors can end up assigned into the meta backend splits. This usually happens when we perform some reshape of the extracted token embeddings before using them:

// for example, something like this
// embd is typically placed in a host buffer
embd = ggml_get_rows(model.token_embd, ids);

// ... other ops can optionally go here ...

embd = ggml_reshape_3d(embd, x, y, z);
res = ggml_mul_mat(model.w, embd);

I tried to modify the scheduler to prevent that (i.e. always keep the reshapes/views in the host split), but it gets a bit tricky since we don't have a guarantee where the reshapes/views nodes will end up in the graph - they are not always arranged next to the host ops (GET_ROWS in this case) depending on what other ops are performed before the res computation.

I don't see a reason why the meta backend cannot just ignore these nodes. After all, they don't cause any problem with other backends, so it seems something that should be fixed in the Meta backend. There is already a related FIXME comment. This PR extends the logic to handle this.

Additional information

The K2 Horizon model can now be used with -sm tensor. This is also helps with a follow-up refactoring in #30160 .

Requirements

@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Oct 9, 2026
@ggerganov
ggerganov marked this pull request as ready for review October 9, 2026 10:25
@ggerganov

Copy link
Copy Markdown
Member Author

@JohannesGaessler PTAL when you have some time and let me know if this changes looks OK to you.

@JohannesGaessler

Copy link
Copy Markdown
Contributor

Related PR by @yomaytk : #28075 . I'll take a look at this PR as well but the fundamental issue as I see it is that the backend scheduler is assigning backend IDs in contradiction of what the ggml backend API says should be supported in terms of buffer types. So my understanding is that this is a bug in the ggml backend scheduler that is simply surfacing through the meta backend.

@JohannesGaessler JohannesGaessler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay, I think I misunderstood what this PR attempts to do. Still, in my view the fundamental issue is that there are seemingly unrelated tensors in the graph's nodes that don't actually do anything.

@JohannesGaessler

Copy link
Copy Markdown
Contributor

My opinion is that we can merge something like this as an ad-hoc fix but please add a TODO that going forward we should look into a better solution.

A view shares the memory of its view_src, so ggml-alloc never allocates a view in
the buffer of the split it lands in - the scheduler copies the source into the
split and the ops that use the view read that copy. The view node itself is a noop
and does not need a split of its own, but the meta backend asserted when one was
left inside a meta split:

  - ggml_backend_meta_get_split_state() dereferenced tensor->buffer->context
  - the graph rebuild mapped every node with ggml_backend_meta_buffer_simple_tensor()

Accept such nodes when they are views of host tensors, which also generalizes the
previous s_copy_main workaround. This fixes the assert hit by KV cache views when
using --split-mode tensor with partial offload.

Assisted-by: pi:llama.cpp/Qwen3.8-Flash-Next
@ggerganov
ggerganov force-pushed the gg/meta-handle-host-views branch from 27a975a to ba2454e Compare October 9, 2026 10:49
@ggerganov

Copy link
Copy Markdown
Member Author

I added a TODO in the latest commit.

@ggerganov
ggerganov merged commit e60eff9 into master Oct 9, 2026
28 of 33 checks passed
@ggerganov
ggerganov deleted the gg/meta-handle-host-views branch October 9, 2026 13:01
ckti pushed a commit to ckti/llama.cpp-consolidated that referenced this pull request Oct 12, 2026
* meta : handle views of tensors allocated on the host

A view shares the memory of its view_src, so ggml-alloc never allocates a view in
the buffer of the split it lands in - the scheduler copies the source into the
split and the ops that use the view read that copy. The view node itself is a noop
and does not need a split of its own, but the meta backend asserted when one was
left inside a meta split:

  - ggml_backend_meta_get_split_state() dereferenced tensor->buffer->context
  - the graph rebuild mapped every node with ggml_backend_meta_buffer_simple_tensor()

Accept such nodes when they are views of host tensors, which also generalizes the
previous s_copy_main workaround. This fixes the assert hit by KV cache views when
using --split-mode tensor with partial offload.

Assisted-by: pi:llama.cpp/Qwen3.8-Flash-Next

* archs : re-enable sm tensor for K2 Horizon

* cont : add TODO and reference
thelittlefireman pushed a commit to thelittlefireman/llama.cpp that referenced this pull request Oct 12, 2026
* meta : handle views of tensors allocated on the host

A view shares the memory of its view_src, so ggml-alloc never allocates a view in
the buffer of the split it lands in - the scheduler copies the source into the
split and the ops that use the view read that copy. The view node itself is a noop
and does not need a split of its own, but the meta backend asserted when one was
left inside a meta split:

  - ggml_backend_meta_get_split_state() dereferenced tensor->buffer->context
  - the graph rebuild mapped every node with ggml_backend_meta_buffer_simple_tensor()

Accept such nodes when they are views of host tensors, which also generalizes the
previous s_copy_main workaround. This fixes the assert hit by KV cache views when
using --split-mode tensor with partial offload.

Assisted-by: pi:llama.cpp/Qwen3.8-Flash-Next

* archs : re-enable sm tensor for K2 Horizon

* cont : add TODO and reference
@BrewTestBot BrewTestBot mentioned this pull request Oct 15, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants