mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-11-26 23:29:34 +00:00
Some checks failed
Behavior Check / ubuntu (push) Waiting to run
Behavior Check / windows (push) Waiting to run
CI (3rd-party) / ubuntu-24-llguidance (push) Waiting to run
CI (snapdragon) / android-ndk-snapdragon (push) Waiting to run
CI (snapdragon) / linux-iot-snapdragon (push) Waiting to run
CI (snapdragon) / Test on QDC Device (QCS9075M) (push) Blocked by required conditions
CI (snapdragon) / Test on QDC Device (SM8850) (push) Blocked by required conditions
CI (android) / default (push) Waiting to run
CI (android) / ndk (push) Waiting to run
CI (android) / arm64 (push) Waiting to run
CI (apple) / macos-latest-arm64 (push) Waiting to run
CI (cpu) / ubuntu (arm64, ubuntu-24.04-arm) (push) Waiting to run
CI (cpu) / ubuntu (x64, ubuntu-22.04) (push) Waiting to run
CI (cpu) / windows / arm64 (push) Waiting to run
CI (cpu) / windows / x64-cpu-static (push) Waiting to run
CI (cpu) / windows / x64-openblas (push) Waiting to run
CI (cpu) / build-cmake-pkg (push) Waiting to run
CI (CUDA, ubuntu) / cuda (push) Waiting to run
CI (CUDA, ubuntu) / hip (push) Waiting to run
CI (CUDA, ubuntu) / musa (push) Waiting to run
CI (ibm) / ubuntu-26-s390x (VXE OFF) (push) Waiting to run
CI (ibm) / ubuntu-26-s390x (VXE ON) (push) Waiting to run
CI (ibm) / ubuntu-26-zdnn-s390x (push) Waiting to run
CI (ibm) / ubuntu-24-ppc64le (push) Waiting to run
CI (opencl) / windows-2025-opencl-adreno (push) Waiting to run
CI (openvino) / ubuntu-24-openvino (push) Waiting to run
CI (openvino) / openvino-windows-2022 (push) Waiting to run
CI (riscv) / ubuntu-cpu-riscv64-native (push) Waiting to run
CI (sanitize) / ctest (ubuntu-26.04, ADDRESS) (push) Waiting to run
CI (sanitize) / ctest (ubuntu-26.04, THREAD) (push) Waiting to run
CI (sanitize) / ctest (ubuntu-26.04, UNDEFINED) (push) Waiting to run
CI (sycl) / ubuntu-24-sycl (fp16, ON) (push) Waiting to run
CI (sycl) / ubuntu-24-sycl (fp32, OFF) (push) Waiting to run
CI (sycl) / windows-latest-sycl (push) Waiting to run
CI (virtgpu) / ubuntu-24-virtgpu (push) Waiting to run
CI (vulkan) / ubuntu-arm64 (push) Waiting to run
CI (vulkan) / ubuntu-llvmpipe (push) Waiting to run
CI (vulkan) / windows / arm64 (push) Waiting to run
CI (vulkan) / windows / x64 (push) Waiting to run
CI (wasi) / ubuntu-webgpu (push) Waiting to run
CI (wasm) / ubuntu-webgpu (push) Waiting to run
CI (webgpu) / format (push) Waiting to run
CI (self-hosted CPU backend) / cpu-arm64-high-perf-graviton4 (push) Waiting to run
CI (self-hosted CPU backend) / cpu-x64-high-perf (push) Waiting to run
CI (self-hosted CUDA backend) / gpu-cuda (push) Waiting to run
CI (self-hosted CUDA backend) / gpu-rocm (push) Waiting to run
CI (self-hosted KleidiAI backend) / cpu-arm64-graviton4-kleidiai (push) Waiting to run
CI (self-hosted Metal backend) / gpu-metal (push) Waiting to run
CI (self-hosted OpenVINO backend) / gpu-openvino-low-perf (push) Waiting to run
CI (self-hosted Vulkan backend) / gpu-vulkan-nvidia-cm (push) Waiting to run
CI (self-hosted Vulkan backend) / gpu-vulkan-nvidia-cm2 (push) Waiting to run
CI (self-hosted Vulkan backend) / gpu-vulkan-apple (push) Waiting to run
CI (self-hosted Vulkan backend) / gpu-vulkan-intel-linux (push) Waiting to run
CI (self-hosted Vulkan backend) / gpu-vulkan-intel-windows (push) Waiting to run
CI (self-hosted WebGPU backend) / gpu-webgpu-nvidia (push) Waiting to run
CI (self-hosted WebGPU backend) / gpu-webgpu-apple (push) Waiting to run
Code Style Checker / model-naming (push) Waiting to run
EditorConfig Checker / editorconfig (push) Waiting to run
HIP quality check / ubuntu-22-hip-quality-check (push) Waiting to run
Models Backend Check / cuda (push) Waiting to run
Models Backend Check / metal (push) Waiting to run
Models Backend Check / rocm (push) Waiting to run
Models Backend Check / vulkan-nvidia (push) Waiting to run
Models Backend Check / vulkan-amd (push) Waiting to run
Models Backend Check / webgpu-nvidia (push) Waiting to run
Python check requirements.txt / check-requirements (push) Waiting to run
flake8 Lint / Lint (push) Waiting to run
Python Type-Check / python type-check (push) Waiting to run
Release / ubuntu-cuda (13.5, x64) (push) Blocked by required conditions
Release / check-release (push) Waiting to run
Release / macos-cpu (arm64, arm64, -DGGML_METAL_EMBED_LIBRARY=ON -DCMAKE_OSX_DEPLOYMENT_TARGET=13.3, macos-26) (push) Blocked by required conditions
Release / macos-cpu (x64, x64, -DGGML_METAL=OFF -DCMAKE_OSX_DEPLOYMENT_TARGET=13.3, macos-15-intel) (push) Blocked by required conditions
Release / ubuntu-cpu (26.04-s390x, ubuntu-26.04-s390x) (push) Blocked by required conditions
Release / ubuntu-cpu (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
Release / ubuntu-cpu (s390x, ubuntu-24.04-s390x) (push) Blocked by required conditions
Release / ubuntu-cpu (x64, ubuntu-22.04) (push) Blocked by required conditions
Release / ubuntu-vulkan (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
Release / ubuntu-vulkan (x64, ubuntu-22.04) (push) Blocked by required conditions
Release / ubuntu-cuda (13.5, arm64) (push) Blocked by required conditions
Release / ubuntu-cuda (12.8, x64) (push) Blocked by required conditions
Release / android-arm64 (push) Blocked by required conditions
Release / android-arm64-snapdragon (push) Blocked by required conditions
Release / linux-arm64-snapdragon (push) Blocked by required conditions
Release / ubuntu-24-openvino (push) Blocked by required conditions
Release / windows-openvino (push) Blocked by required conditions
Release / windows-cpu / arm64 (push) Blocked by required conditions
Release / windows-cpu / x64 (push) Blocked by required conditions
Release / windows-rocm (10.0.0, x64, gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1153;gfx1200;gfx1201) (push) Blocked by required conditions
Release / windows (arm64, opencl-adreno, -G "Ninja Multi-Config" -D CMAKE_TOOLCHAIN_FILE=cmake/arm64-windows-llvm.cmake -DCMAKE_PREFIX_PATH="$env:RUNNER_TEMP/opencl-arm64-release" -DGGML_OPENCL=ON -DGGML_OPENCL_USE_ADRENO_KERNELS=ON, ggml-opencl) (push) Blocked by required conditions
Release / windows (arm64, vulkan, -G "Ninja Multi-Config" -DGGML_VULKAN=ON -D CMAKE_TOOLCHAIN_FILE=cmake/arm64-windows-llvm.cmake, ggml-vulkan) (push) Blocked by required conditions
Release / windows (x64, vulkan, -DGGML_VULKAN=ON, ggml-vulkan) (push) Blocked by required conditions
Release / windows-cuda (13.5, arm64) (push) Blocked by required conditions
Release / windows-cuda (12.4, x64) (push) Blocked by required conditions
Release / windows-cuda (13.5, x64) (push) Blocked by required conditions
Release / windows-sycl (push) Blocked by required conditions
Release / ubuntu-24-sycl (fp16, ON) (push) Blocked by required conditions
Release / ubuntu-24-sycl (fp32, OFF) (push) Blocked by required conditions
Release / ubuntu-24-rocm (10.0.0, x64, gfx908;gfx90a;gfx942;gfx950;gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1200;gfx1201) (push) Blocked by required conditions
Release / ubuntu-26-zdnn (push) Blocked by required conditions
Release / ios-xcode (push) Blocked by required conditions
Release / ui-build (push) Blocked by required conditions
Server (sanitize) / server (RelWithDebInfo, ADDRESS) (push) Waiting to run
Server (sanitize) / server (RelWithDebInfo, UNDEFINED) (push) Waiting to run
Server (self-hosted) / server-metal (push) Waiting to run
Server (self-hosted) / server-cuda (push) Waiting to run
Server (self-hosted) / server-kleidiai (push) Waiting to run
Server / ubuntu (push) Waiting to run
Server / windows (push) Waiting to run
Update Operations Documentation / update-ops-docs (push) Waiting to run
Check vendor / check-vendor (push) Has been cancelled
Check Pre-Tokenizer Hashes / pre-tokenizer-hashes (push) Has been cancelled
UI / Build static output (push) Has been cancelled
UI (self-hosted) / Build static output (push) Has been cancelled
UI (self-hosted) / Checks (push) Has been cancelled
UI (self-hosted) / E2E Tests (push) Has been cancelled
UI / Checks (push) Has been cancelled
UI / E2E Tests (push) Has been cancelled
* mtmd: support MageVL-Cowork model * mtmd: keep magevl rope_freqs at model level and check its shape The rope factors are shared by every layer, so they live in clip_model instead of a pointer copied into each clip_layer. The loader now checks that v.rope_freqs is F32 with d_head elements and that d_head splits into the 4:6:6 pairs the graph expects. --------- Co-authored-by: Pascal <admin@serveurperso.com>
77 lines
3.2 KiB
Python
77 lines
3.2 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Callable, Iterable, TYPE_CHECKING
|
|
|
|
import torch
|
|
|
|
if TYPE_CHECKING:
|
|
from torch import Tensor
|
|
|
|
from .base import MmprojModel, ModelBase, gguf
|
|
|
|
|
|
@ModelBase.register("LlavaOnevision2ForConditionalGeneration")
|
|
@ModelBase.example("microsoft/Mage-VL-Cowork")
|
|
class MageVLVisionModel(MmprojModel):
|
|
# a rope pair uses 2 different angles: the graph runs 2 ropes on heads permuted to [evens | odds]
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
assert self.hparams_vision is not None
|
|
|
|
self.n_embd = self.find_vparam(["hidden_size"])
|
|
self.n_head = self.find_vparam(["num_attention_heads"])
|
|
self.d_head = self.n_embd // self.n_head
|
|
|
|
d_half = self.d_head // 2
|
|
assert d_half % 16 == 0, "the 4:6:6 split of the rope requires d_head to be a multiple of 32"
|
|
|
|
# 4:6:6 split for t:h:w
|
|
n_t = 4 * (d_half // 16)
|
|
n_s = 6 * (d_half // 16)
|
|
theta = float(self.find_vparam(["rope_theta"]))
|
|
freq_t = 1.0 / theta ** (torch.arange(n_t, dtype=torch.float64) / n_t)
|
|
freq_s = 1.0 / theta ** (torch.arange(n_s, dtype=torch.float64) / n_s)
|
|
freq = torch.cat([freq_t, freq_s, freq_s])
|
|
self.rope_freq = torch.cat([freq, freq])
|
|
|
|
def pair_axis(i: int) -> int:
|
|
dim = (2 * i) % d_half
|
|
return 0 if dim < n_t else 1 if dim < n_t + n_s else 2
|
|
|
|
self.rope_pairs = sorted(range(d_half), key=pair_axis)
|
|
|
|
def set_gguf_parameters(self):
|
|
super().set_gguf_parameters()
|
|
self.gguf_writer.add_clip_projector_type(gguf.VisionProjectorType.MAGEVL)
|
|
self.gguf_writer.add_vision_attention_layernorm_eps(self.find_vparam(["layer_norm_eps"]))
|
|
self.gguf_writer.add_vision_spatial_merge_size(self.find_vparam(["spatial_merge_size"]))
|
|
self.gguf_writer.add_vision_min_pixels(int(self.preprocessor_config["min_pixels"]))
|
|
self.gguf_writer.add_vision_max_pixels(int(self.preprocessor_config["max_pixels"]))
|
|
|
|
@classmethod
|
|
def filter_tensors(cls, item: tuple[str, Callable[[], Tensor]]) -> tuple[str, Callable[[], Tensor]] | None:
|
|
name, _ = item
|
|
|
|
if not name.startswith("visual."):
|
|
return None
|
|
|
|
return super().filter_tensors(item)
|
|
|
|
def generate_extra_tensors(self) -> Iterable[tuple[str, Tensor]]:
|
|
# ggml uses theta = pos / rope_freqs
|
|
pairs = torch.tensor(self.rope_pairs)
|
|
freq_a = self.rope_freq[2 * pairs]
|
|
freq_b = self.rope_freq[2 * pairs + 1]
|
|
yield ("visual.rope_freqs.weight", (1.0 / torch.cat([freq_a, freq_b])).to(torch.float32))
|
|
|
|
def permute_qk(self, data_torch: Tensor) -> Tensor:
|
|
rows = [2 * i for i in self.rope_pairs] + [2 * i + 1 for i in self.rope_pairs]
|
|
return data_torch.reshape(self.n_head, self.d_head, -1)[:, rows].reshape(data_torch.shape)
|
|
|
|
def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iterable[tuple[str, Tensor]]:
|
|
if ".self_attn.qkv." in name:
|
|
q, k, v = data_torch.split(self.n_embd, dim=0)
|
|
data_torch = torch.cat([self.permute_qk(q), self.permute_qk(k), v], dim=0)
|
|
|
|
yield from super().modify_tensors(data_torch, name, bid)
|