Skip to content

Add OpenVINO backend #15307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 114 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
355da54
Add ggml-openvino base files
YangleiZouIntel Oct 29, 2024
4453fc3
add openvino as optional backend for Llama.cpp ggml
zhanmyz Nov 13, 2024
e5035ff
* Configure the device(default CPU) that uses OpenVINO to compile th…
zhanmyz Nov 19, 2024
1f0600f
Solve the issue of abnormal model output caused by using OpenVINO ADD…
zhanmyz Nov 21, 2024
22aac2e
Add OpenVINO MUL operator to GGML of Llama.cpp.
zhanmyz Dec 2, 2024
75e55c0
Add compile options
zhanmyz Dec 2, 2024
f1821d1
add OpenVINO frontend convert process steps
zhanmyz Dec 4, 2024
290249c
add get openvino available ops function
zhanmyz Dec 5, 2024
46a5662
Add PoC of integration of openvino frontend. Main changes: ggml-ov-fr…
yumengbo Nov 16, 2024
6bf6b7a
Implement GgmlOvDecoder. Add dump functions.
yumengbo Nov 19, 2024
3c12e98
Convert subgraph with add, sub, mul, div op to ov model and do infer …
yumengbo Nov 22, 2024
cf29563
Add GGML_OV_FRONTEND option. Add readme.
yumengbo Nov 22, 2024
870cdb7
Change output for infer request to set output tensor. Support scale, …
yumengbo Dec 5, 2024
6942273
add GET_ROWS operator of OpenVINO to GGML of llama.cpp
zhanmyz Dec 9, 2024
4fa1177
Update build.md and add operation mapping(GGML to OpenVINO)
zhanmyz Dec 10, 2024
77c74da
add the rms_norm operator implemented using OpenVINO to the GGML back…
zhanmyz Dec 16, 2024
11edfa6
Fix issue for output memory copy of infer request
yumengbo Dec 12, 2024
98c9350
Change to implementation following pytorch frontend
yumengbo Dec 12, 2024
e6729a8
Add support for UNARY SILU op . Fix pytorch impl bugs.
yumengbo Dec 17, 2024
d48cb65
Support Softmax op
yumengbo Dec 18, 2024
d8c05a6
Support Softmax op
yumengbo Dec 18, 2024
8715fd2
Support ROPE op.
yumengbo Dec 21, 2024
e8cf08f
Add support for RMS_NORM OP
zhanmyz Dec 19, 2024
9711f27
Add MUL_MAT,CPY,CONT as operators implemented in OpenVINO for GGML ba…
zhanmyz Jan 14, 2025
d88e931
Move CPY from GGML OV Backend to OV Frontend
zhanmyz Jan 22, 2025
3023596
add implementation of MUL_MAT, CPY, CONT of GGML ops using OV ops
zhanmyz Feb 18, 2025
a59a1c1
add implementation of CPY when the output tensor is non-contiguous
zhanmyz Feb 19, 2025
d9e8387
add tmp source code files
zhanmyz Feb 25, 2025
5e3369a
Execute singel CONT operator is OK
zhanmyz Feb 25, 2025
9667b1d
Execute CONT & VIEW operators in OV Frontend is OK
zhanmyz Mar 1, 2025
3e53cc6
OV Frontend supports GET_ROWS/RMS_NORM/MUL/MUL_MAT graph conversion o…
zhanmyz Mar 3, 2025
568cb2e
OV Frontend supports GET_ROWS/RMS_NORM/MUL/MUL_MAT/ROPE/SCALE/SOFTMAX…
zhanmyz Mar 5, 2025
7e1f1c3
Change the input parameter shape of CONT operator
zhanmyz Mar 5, 2025
57c7ea9
Change the input and ouput node shape of MUL_MAT operator
zhanmyz Mar 5, 2025
6c17b0f
Change the input and ouput node shape of MUL_MAT operator
zhanmyz Mar 5, 2025
d6f72e9
change CONT and MULMAT input node shape
zhanmyz Mar 6, 2025
e0e1902
All adjacent ops can conversion but calculation result is wrong and n…
zhanmyz Mar 6, 2025
4c377ae
1. All operators implemented using OpenVINO can be successfully execu…
zhanmyz Mar 9, 2025
ed3664e
1. Update the implementation of CPY node when it's non-contiguous
zhanmyz Mar 11, 2025
980e1be
Minor Update
zhanmyz Mar 11, 2025
6c897cd
Try to add VIEW node to OV Frontend and have some issues that need to…
zhanmyz Mar 12, 2025
9b21a21
1. In the Prompt process and predict first token stage, the PERMUTE n…
zhanmyz Mar 15, 2025
f660c7a
add debug info
zhanmyz Mar 17, 2025
6deef5a
Process Prompt and predict first token is OK
zhanmyz Mar 26, 2025
bf7a08c
1. Solve the AC issue of Permute+VIEW and MULMAL issue in the phase o…
zhanmyz Mar 31, 2025
55ba7c5
1. Delete some comments
zhanmyz Mar 31, 2025
647903a
* Use find_package in CMake to configure OpenVINO
wine99 Apr 14, 2025
7fef08d
change op mappings to list in openvino_supports_op
wine99 Apr 15, 2025
04d54f5
2nd+ token correct by fix CPY in OV, remove single op backend compute…
wine99 Apr 15, 2025
11da046
Arbitrary token len (>32) work; Fix bug in mulmat
wine99 Apr 17, 2025
8b1b763
FEAT: do PERMUTE eagerly
wine99 Apr 21, 2025
4ca42bc
FEAT: Add interleaved mode for ROPE
wine99 Apr 22, 2025
dfec8bf
REFACTOR: support weigts as constant
wine99 Apr 28, 2025
500c022
STYLE: minor refactor
wine99 Apr 28, 2025
3483111
PERF: share const nodes for weights for diff infer
wine99 Apr 28, 2025
8fc4d70
BUILD: update build doc, add cmake preset, add CACHE_DIR env var
wine99 Apr 29, 2025
243a558
FEAT: improve debug capability
wine99 Apr 30, 2025
6cef832
PERF: compile once (dynamic graph + cache)
wine99 May 8, 2025
832e091
Rebase - Bring up to date and fix build process
virajwad May 9, 2025
c217825
fix build error
wine99 May 13, 2025
e81fc1b
FIX: backend buffer type issue
wine99 May 13, 2025
93279d4
STYLE: clang-format
wine99 May 9, 2025
f844e53
FEAT: Add all conversion code from ov side
wine99 May 9, 2025
7141a08
PERF: favor low precision matmul
wine99 May 13, 2025
ef9bbef
STYLE and minor REFACTOR
wine99 May 13, 2025
30c95c8
FIX: Re-add tensor names in cgraph, Add another case for RESHAPE
wine99 May 14, 2025
91503f8
FIX: input shape of KQ_mask
wine99 May 14, 2025
aa276f1
PERF: add weight constant in parallel
wine99 May 14, 2025
e0399b7
FIX: set_max_token_len
wine99 May 16, 2025
e87deda
PERF: use Slice+Concat in writing cache_v
wine99 May 16, 2025
f6611bf
Update build doc
wine99 May 20, 2025
56bce00
Add cgraph tensor output name to OV op name
wine99 May 22, 2025
61fda10
Update openvino build instructions
ravi9 May 29, 2025
1dd475c
Add initial NPU support
wine99 May 27, 2025
89b89d3
draft NPU support version 2: prefill + kvcache
wine99 May 29, 2025
db205af
NPU support version 2: prefill + kvcache
wine99 Jun 3, 2025
ea2025e
Change due to ggml cgraph changes, not correct yet
wine99 Jun 4, 2025
63871a9
Change due to ggml cgraph changes, llama-3.2 CPU work
wine99 Jun 16, 2025
ae8ea7e
Add AMD64 to CMakeLists
wine99 Jun 16, 2025
2310200
Change due to ggml cgraph changes, all device work
wine99 Jun 16, 2025
23c35c1
Refactor: clean, fix warning
wine99 Jun 20, 2025
d0aa83e
Update clang-format
wine99 Jun 23, 2025
83c0e3a
Statful transformation for CPU GPU
wine99 Jun 26, 2025
84825f0
Add SwiGLU
wine99 Jul 3, 2025
fb8a3f6
Fuse to SDPA
wine99 Jul 3, 2025
d3be35a
Replace Concat with Broadcast in MulMat for GQA
wine99 Jul 4, 2025
45ac2ac
Pull out indices creation for kv cache update
wine99 Jul 6, 2025
4e3d589
Refactor: remove past_token_len from extra_inputs
wine99 Jul 9, 2025
033dbab
Fix Phi3 SwiGLU and SoftMax
wine99 Jul 9, 2025
3ed5def
Pull out sin cos from rope
wine99 Jul 9, 2025
731d9e4
Reduce memory: free ov weights node after graph conversion
wine99 Jul 11, 2025
469620c
Fix CPY due to cgraph change
wine99 Jul 17, 2025
b83338d
Added OpenVINO CI/CD. Updated docs
ravi9 Jul 18, 2025
49afa88
Fix llama-cli
wine99 Jul 23, 2025
04030b1
Fix Phi3 ROPE; Add test-backend-ops
wine99 Jul 21, 2025
7e1ad15
Fix NPU
wine99 Jul 23, 2025
8e16ccc
Fix llama-bench; Clang-format
wine99 Jul 24, 2025
30f5156
Fix llama-perplexity
wine99 Jul 24, 2025
6d05d5d
temp. changes for mark decomp
cavusmustafa Jul 29, 2025
1aad01d
matmul in fp32
wine99 Jul 29, 2025
ed2ef18
mulmat input conversion fix
cavusmustafa Jul 30, 2025
263d49f
mulmat type conversion update
cavusmustafa Jul 30, 2025
1f84333
add mark decomp pass
cavusmustafa Jul 30, 2025
b027724
Revert changes in fuse_to_sdpa
wine99 Jul 30, 2025
3d8d0ad
Update build.md
ravi9 Jul 31, 2025
f15d53a
Fix test-backend-ops
wine99 Jul 31, 2025
3eba120
Skip test-thread-safety; Run ctest only in ci/run.sh
wine99 Jul 31, 2025
c7d41e0
Use CiD for NPU
wine99 Aug 1, 2025
aa9e095
Optimize tensor conversion, improve TTFT
wine99 Aug 4, 2025
93b5c2e
Support op SET_ROWS
wine99 Aug 13, 2025
fef3760
Fix NPU
wine99 Aug 14, 2025
ae84719
Remove CPY
wine99 Aug 14, 2025
4292a41
Fix test-backend-ops
wine99 Aug 14, 2025
dcf7cf6
Minor updates for raising PR
wine99 Aug 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions .devops/openvino.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
ARG OPENVINO_VERSION_MAJOR=2025.2
ARG OPENVINO_VERSION_FULL=2025.2.0.19140.c01cd93e24d
ARG UBUNTU_VERSION=24.04

# Optional proxy build arguments - empty by default
ARG http_proxy=
ARG https_proxy=

## Build Image
FROM ubuntu:${UBUNTU_VERSION} AS build

# Pass proxy args to build stage
ARG http_proxy
ARG https_proxy

RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
gnupg \
wget \
git \
cmake \
ninja-build \
build-essential \
libtbb12 \
libcurl4-openssl-dev && \
rm -rf /var/lib/apt/lists/*

# Install OpenVINO for Ubuntu 24.04
ARG OPENVINO_VERSION_MAJOR
ARG OPENVINO_VERSION_FULL
RUN mkdir -p /opt/intel && \
wget https://storage.openvinotoolkit.org/repositories/openvino/packages/${OPENVINO_VERSION_MAJOR}/linux/openvino_toolkit_ubuntu24_${OPENVINO_VERSION_FULL}_x86_64.tgz && \
tar -xf openvino_toolkit_ubuntu24_${OPENVINO_VERSION_FULL}_x86_64.tgz && \
mv openvino_toolkit_ubuntu24_${OPENVINO_VERSION_FULL}_x86_64 /opt/intel/openvino_${OPENVINO_VERSION_MAJOR} && \
cd /opt/intel/openvino_${OPENVINO_VERSION_MAJOR} && \
echo "Y" | ./install_dependencies/install_openvino_dependencies.sh && \
cd - && \
ln -s /opt/intel/openvino_${OPENVINO_VERSION_MAJOR} /opt/intel/openvino

ENV OpenVINO_DIR=/opt/intel/openvino

WORKDIR /app

COPY . .

# Build Stage
RUN bash -c "source ${OpenVINO_DIR}/setupvars.sh && \
cmake -B build/ReleaseOV -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DGGML_OPENVINO=ON && \
cmake --build build/ReleaseOV -j$(nproc)"

# Copy all necessary libraries
RUN mkdir -p /app/lib && \
find build/ReleaseOV -name '*.so*' -exec cp {} /app/lib \; && \
find ${OpenVINO_DIR}/runtime/lib/intel64 -name '*.so*' -exec cp -P {} /app/lib \; 2>/dev/null || \
find ${OpenVINO_DIR}/lib/intel64 -name '*.so*' -exec cp -P {} /app/lib \;

# Create runtime directories and copy binaries
RUN mkdir -p /app/full \
&& cp build/ReleaseOV/bin/* /app/full/ \
&& cp *.py /app/full \
&& cp -r gguf-py /app/full \
&& cp -r requirements /app/full \
&& cp requirements.txt /app/full \
&& cp .devops/tools.sh /app/full/tools.sh

## Base Runtime Image
FROM ubuntu:${UBUNTU_VERSION} AS base

# Pass proxy args to runtime stage
ARG http_proxy
ARG https_proxy

RUN apt-get update \
&& apt-get install -y libgomp1 libtbb12 curl\
&& apt autoremove -y \
&& apt clean -y \
&& rm -rf /tmp/* /var/tmp/* \
&& find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete \
&& find /var/cache -type f -delete

COPY --from=build /app/lib/ /app/

### Full (all binaries)
FROM base AS full

ARG http_proxy
ARG https_proxy

COPY --from=build /app/full /app/

WORKDIR /app

RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
python3 \
python3-venv \
python3-pip && \
python3 -m venv /ov-venv && \
/ov-venv/bin/pip install --no-cache-dir --upgrade pip setuptools wheel && \
/ov-venv/bin/pip install --no-cache-dir -r requirements.txt && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /tmp/* /var/tmp/* && \
find /var/cache/apt/archives /var/lib/apt/lists -not -name lock -type f -delete && \
find /var/cache -type f -delete

ENTRYPOINT ["/bin/bash", "-c", "source /ov-venv/bin/activate && exec /app/tools.sh \"$@\"", "--"]


### Light, CLI only
FROM base AS light

COPY --from=build /app/full/llama-cli /app/

WORKDIR /app

ENTRYPOINT [ "/app/llama-cli" ]

### Server, Server only
FROM base AS server

ENV LLAMA_ARG_HOST=0.0.0.0

COPY --from=build /app/full/llama-server /app/

WORKDIR /app

HEALTHCHECK CMD [ "curl", "-f", "http://localhost:8080/health" ]

ENTRYPOINT [ "/app/llama-server" ]
39 changes: 39 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,45 @@ jobs:
-DGGML_SYCL_F16=ON
cmake --build build --config Release -j $(nproc)
ubuntu-24-cmake-openvino:
runs-on: ubuntu-24.04

steps:
- name: Clone
id: checkout
uses: actions/checkout@v4

- name: ccache
uses: hendrikmuhs/[email protected]
with:
key: ubuntu-24-cmake-openvino-no-preset-v1
evict-old-files: 1d

- name: Dependencies
id: depends
run: |
export OPENVINO_VERSION_MAJOR=2025.2
export OPENVINO_VERSION_FULL=2025.2.0.19140.c01cd93e24d
sudo apt-get update
sudo apt-get install -y build-essential libcurl4-openssl-dev libtbb12 cmake ninja-build python3-pip curl wget tar
sudo mkdir -p /opt/intel
wget -O openvino_${OPENVINO_VERSION_MAJOR}.tgz https://storage.openvinotoolkit.org/repositories/openvino/packages/${OPENVINO_VERSION_MAJOR}/linux/openvino_toolkit_ubuntu24_${OPENVINO_VERSION_FULL}_x86_64.tgz
tar -xf openvino_${OPENVINO_VERSION_MAJOR}.tgz
sudo mv openvino_toolkit_ubuntu24_${OPENVINO_VERSION_FULL}_x86_64 /opt/intel/openvino_${OPENVINO_VERSION_MAJOR}
rm openvino_${OPENVINO_VERSION_MAJOR}.tgz
cd /opt/intel/openvino_${OPENVINO_VERSION_MAJOR}
echo "Y" | sudo -E ./install_dependencies/install_openvino_dependencies.sh && cd -
sudo ln -s /opt/intel/openvino_${OPENVINO_VERSION_MAJOR} /opt/intel/openvino
- name: Build
id: cmake_build
run: |
source /opt/intel/openvino/setupvars.sh
cmake -B build/ReleaseOV -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DGGML_OPENVINO=ON
cmake --build build/ReleaseOV --config Release -j $(nproc)
build-linux-cross:
uses: ./.github/workflows/build-linux-cross.yml

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- { tag: "musa", dockerfile: ".devops/musa.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: true }
- { tag: "intel", dockerfile: ".devops/intel.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: true }
- { tag: "vulkan", dockerfile: ".devops/vulkan.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: false }
- { tag: "openvino", dockerfile: ".devops/openvino.Dockerfile", platforms: "linux/amd64", full: true, light: true, server: true, free_disk_space: false }
# Note: the rocm images are failing due to a compiler error and are disabled until this is fixed to allow the workflow to complete
#- {tag: "rocm", dockerfile: ".devops/rocm.Dockerfile", platforms: "linux/amd64,linux/arm64", full: true, light: true, server: true, free_disk_space: true }
steps:
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,63 @@ jobs:
path: llama-${{ steps.tag.outputs.name }}-bin-ubuntu-vulkan-x64.zip
name: llama-bin-ubuntu-vulkan-x64.zip

ubuntu-24-openvino:
runs-on: ubuntu-24.04

steps:
- name: Clone
id: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: ccache
uses: hendrikmuhs/[email protected]
with:
key: ubuntu-24-cmake-openvino-release-no-preset-v1
evict-old-files: 1d

- name: Dependencies
id: depends
run: |
export OPENVINO_VERSION_MAJOR=2025.2
export OPENVINO_VERSION_FULL=2025.2.0.19140.c01cd93e24d
sudo apt-get update
sudo apt-get install -y build-essential libcurl4-openssl-dev libtbb12 cmake ninja-build python3-pip curl wget tar
sudo mkdir -p /opt/intel
wget -O openvino_${OPENVINO_VERSION_MAJOR}.tgz https://storage.openvinotoolkit.org/repositories/openvino/packages/${OPENVINO_VERSION_MAJOR}/linux/openvino_toolkit_ubuntu24_${OPENVINO_VERSION_FULL}_x86_64.tgz
tar -xf openvino_${OPENVINO_VERSION_MAJOR}.tgz
sudo mv openvino_toolkit_ubuntu24_${OPENVINO_VERSION_FULL}_x86_64 /opt/intel/openvino_${OPENVINO_VERSION_MAJOR}
rm openvino_${OPENVINO_VERSION_MAJOR}.tgz
cd /opt/intel/openvino_${OPENVINO_VERSION_MAJOR}
echo "Y" | sudo -E ./install_dependencies/install_openvino_dependencies.sh && cd -
sudo ln -s /opt/intel/openvino_${OPENVINO_VERSION_MAJOR} /opt/intel/openvino
- name: Build
id: cmake_build
run: |
source /opt/intel/openvino/setupvars.sh
cmake -B build/ReleaseOV -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DGGML_OPENVINO=ON
cmake --build build/ReleaseOV --config Release -j $(nproc)
- name: Determine tag name
id: tag
uses: ./.github/actions/get-tag-name

- name: Pack artifacts
id: pack_artifacts
run: |
cp LICENSE ./build/ReleaseOV/bin/
zip -r llama-${{ steps.tag.outputs.name }}-bin-ubuntu-openvino-x64.zip ./build/ReleaseOV/bin/*
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
path: llama-${{ steps.tag.outputs.name }}-bin-ubuntu-openvino-x64.zip
name: llama-bin-ubuntu-openvino-x64.zip

windows-cpu:
runs-on: windows-2025

Expand Down
12 changes: 12 additions & 0 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
# # with MUSA support
# GG_BUILD_MUSA=1 bash ./ci/run.sh ./tmp/results ./tmp/mnt
#
# # with OPENVINO support
# GG_BUILD_OPENVINO=1 GG_BUILD_LOW_PERF=1 GGML_OPENVINO_DEVICE=CPU bash ./ci/run.sh ./tmp/results ./tmp/mnt
#

if [ -z "$2" ]; then
echo "usage: $0 <output-dir> <mnt-dir>"
Expand Down Expand Up @@ -93,6 +96,15 @@ if [ ! -z ${GG_BUILD_MUSA} ]; then
MUSA_ARCH=${MUSA_ARCH:-21}
CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_MUSA=ON -DMUSA_ARCHITECTURES=${MUSA_ARCH}"
fi

if [ ! -z ${GG_BUILD_OPENVINO} ]; then
if [ -z ${OpenVINO_DIR} ]; then
echo "OpenVINO_DIR not found, please install OpenVINO via archives and enable it by:"
echo "source /opt/intel/openvino/setupvars.sh"
exit 1
fi
CMAKE_EXTRA="${CMAKE_EXTRA} -DGGML_OPENVINO=ON"
fi
## helpers

# download a file if it does not exist or if it is outdated
Expand Down
Loading