[LLM] llm supports vnni link on windows (#8543)

* support win vnni link

* fix style

* fix style

* use isa_checker

* fix

* typo

* fix

* update
This commit is contained in:
Yina Chen 2023-07-18 16:43:45 +08:00 committed by GitHub
parent 4f287df664
commit 9a7bc17ca1
7 changed files with 43 additions and 91 deletions

View file

@ -64,31 +64,13 @@ from ctypes import (
c_size_t, c_size_t,
) )
import pathlib import pathlib
from bigdl.llm.utils import get_avx_flags from bigdl.llm.utils import get_shared_lib_info
from bigdl.llm.utils.common import invalidInputError from bigdl.llm.utils.common import invalidInputError
# Load the library # Load the library
def _load_shared_library(lib_base_name: str): def _load_shared_library(lib_base_name: str):
# Determine the file extension based on the platform _base_path, _lib_paths = get_shared_lib_info(lib_base_name=lib_base_name)
if sys.platform.startswith("linux") or sys.platform == "darwin":
lib_ext = ".so"
elif sys.platform == "win32":
lib_ext = ".dll"
else:
invalidInputError(False, "Unsupported platform")
avx = get_avx_flags()
# Construct the paths to the possible shared library names (python/llm/src/bigdl/llm/libs)
_base_path = pathlib.Path(__file__).parent.parent.parent.parent.resolve()
_base_path = _base_path / 'libs'
# Searching for the library in the current directory under the name "libbloom" (default name
# for bloomcpp) and "bloom" (default name for this repo)
_lib_paths = [
_base_path / f"lib{lib_base_name}{avx}{lib_ext}",
_base_path / f"{lib_base_name}{avx}{lib_ext}",
]
if "BLOOM_CPP_LIB" in os.environ: if "BLOOM_CPP_LIB" in os.environ:
lib_base_name = os.environ["BLOOM_CPP_LIB"] lib_base_name = os.environ["BLOOM_CPP_LIB"]

View file

@ -64,30 +64,12 @@ from ctypes import (
) )
import pathlib import pathlib
from bigdl.llm.utils.common import invalidInputError from bigdl.llm.utils.common import invalidInputError
from bigdl.llm.utils import get_avx_flags from bigdl.llm.utils import get_shared_lib_info
# Load the library # Load the library
def _load_shared_library(lib_base_name: str): def _load_shared_library(lib_base_name: str):
# Determine the file extension based on the platform _base_path, _lib_paths = get_shared_lib_info(lib_base_name=lib_base_name)
if sys.platform.startswith("linux") or sys.platform == "darwin":
lib_ext = ".so"
elif sys.platform == "win32":
lib_ext = ".dll"
else:
invalidInputError(False, "Unsupported platform.")
avx = get_avx_flags()
# Construct the paths to the possible shared library names (python/llm/src/bigdl/llm/libs)
_base_path = pathlib.Path(__file__).parent.parent.parent.parent.resolve()
_base_path = _base_path / 'libs'
# Searching for the library in the current directory under the name "libgptneox" (default name
# for gptneoxcpp) and "gptneox" (default name for this repo)
_lib_paths = [
_base_path / f"lib{lib_base_name}{avx}{lib_ext}",
_base_path / f"{lib_base_name}{avx}{lib_ext}",
]
if "GPTNEOX_CPP_LIB" in os.environ: if "GPTNEOX_CPP_LIB" in os.environ:
lib_base_name = os.environ["GPTNEOX_CPP_LIB"] lib_base_name = os.environ["GPTNEOX_CPP_LIB"]

View file

@ -64,30 +64,12 @@ from ctypes import (
) )
import pathlib import pathlib
from bigdl.llm.utils.common import invalidInputError from bigdl.llm.utils.common import invalidInputError
from bigdl.llm.utils import get_avx_flags from bigdl.llm.utils import get_shared_lib_info
# Load the library # Load the library
def _load_shared_library(lib_base_name: str): def _load_shared_library(lib_base_name: str):
# Determine the file extension based on the platform _base_path, _lib_paths = get_shared_lib_info(lib_base_name=lib_base_name)
if sys.platform.startswith("linux") or sys.platform == "darwin":
lib_ext = ".so"
elif sys.platform == "win32":
lib_ext = ".dll"
else:
invalidInputError(False, "Unsupported platform.")
avx = get_avx_flags()
# Construct the paths to the possible shared library names
_base_path = pathlib.Path(__file__).parent.parent.parent.parent.resolve()
_base_path = _base_path / 'libs'
# Searching for the library in the current directory under the name "libllama" (default name
# for llamacpp) and "llama" (default name for this repo)
_lib_paths = [
_base_path / f"lib{lib_base_name}{avx}{lib_ext}",
_base_path / f"{lib_base_name}{avx}{lib_ext}",
]
if "LLAMA_CPP_LIB" in os.environ: if "LLAMA_CPP_LIB" in os.environ:
lib_base_name = os.environ["LLAMA_CPP_LIB"] lib_base_name = os.environ["LLAMA_CPP_LIB"]

View file

@ -64,31 +64,13 @@ from ctypes import (
c_size_t, c_size_t,
) )
import pathlib import pathlib
from bigdl.llm.utils import get_avx_flags from bigdl.llm.utils import get_shared_lib_info
from bigdl.llm.utils.common import invalidInputError from bigdl.llm.utils.common import invalidInputError
# Load the library # Load the library
def _load_shared_library(lib_base_name: str): def _load_shared_library(lib_base_name: str):
# Determine the file extension based on the platform _base_path, _lib_paths = get_shared_lib_info(lib_base_name=lib_base_name)
if sys.platform.startswith("linux") or sys.platform == "darwin":
lib_ext = ".so"
elif sys.platform == "win32":
lib_ext = ".dll"
else:
invalidInputError(False, "Unsupported platform")
avx = get_avx_flags()
# Construct the paths to the possible shared library names (python/llm/src/bigdl/llm/libs)
_base_path = pathlib.Path(__file__).parent.parent.parent.parent.resolve()
_base_path = _base_path / 'libs'
# Searching for the library in the current directory under the name "libbloom" (default name
# for bloomcpp) and "bloom" (default name for this repo)
_lib_paths = [
_base_path / f"lib{lib_base_name}{avx}{lib_ext}",
_base_path / f"{lib_base_name}{avx}{lib_ext}",
]
if "STARCODER_CPP_LIB" in os.environ: if "STARCODER_CPP_LIB" in os.environ:
lib_base_name = os.environ["STARCODER_CPP_LIB"] lib_base_name = os.environ["STARCODER_CPP_LIB"]

View file

@ -15,18 +15,44 @@
# #
import sys import sys
import pathlib
from bigdl.llm.utils.isa_checker import check_avx_vnni, check_avx2, check_avx512_vnni
from bigdl.llm.utils.common import invalidInputError, invalidOperationError from bigdl.llm.utils.common import invalidInputError, invalidOperationError
def get_avx_flags(): def get_cpu_flags():
avx = "" flags = ""
if sys.platform != "win32": if sys.platform != "win32":
import subprocess if check_avx512_vnni():
msg = subprocess.check_output(["lscpu"]).decode("utf-8") flags = "_avx512"
if "avx512_vnni" in msg: elif check_avx_vnni():
avx = "_avx512" flags = "_avx2"
elif "avx2" in msg:
avx = "_avx2"
else: else:
invalidOperationError(False, "Unsupported CPUFLAGS.") invalidOperationError(False, "Unsupported CPUFLAGS.")
return avx else:
flags = "_vnni" if check_avx_vnni() else ""
return flags
def get_shared_lib_info(lib_base_name: str):
# Determine the file extension based on the platform
if sys.platform.startswith("linux") or sys.platform == "darwin":
lib_ext = ".so"
elif sys.platform == "win32":
lib_ext = ".dll"
else:
invalidInputError(False, "Unsupported platform.")
cpuflags = get_cpu_flags()
# Construct the paths to the possible shared library names (python/llm/src/bigdl/llm/libs)
_base_path = pathlib.Path(__file__).parent.parent.resolve()
_base_path = _base_path / 'libs'
# Searching for the library in the current directory under the name "lib{lib_base_name}"
# (default name for llmcpp) and "{lib_base_name}" (default name for this repo)
_lib_paths = [
_base_path / f"lib{lib_base_name}{cpuflags}{lib_ext}",
_base_path / f"{lib_base_name}{cpuflags}{lib_ext}",
]
return _base_path, _lib_paths

View file

@ -16,7 +16,6 @@
from bigdl.llm.models import Llama, Bloom, Gptneox, Starcoder from bigdl.llm.models import Llama, Bloom, Gptneox, Starcoder
from bigdl.llm.utils import get_avx_flags
import pytest import pytest
from unittest import TestCase from unittest import TestCase
import os import os

View file

@ -14,7 +14,6 @@
# limitations under the License. # limitations under the License.
# #
from bigdl.llm.utils import get_avx_flags
from bigdl.llm.langchain.embeddings import BigdlNativeEmbeddings from bigdl.llm.langchain.embeddings import BigdlNativeEmbeddings
from bigdl.llm.langchain.llms import BigdlNativeLLM from bigdl.llm.langchain.llms import BigdlNativeLLM
import pytest import pytest