Skip to content

Commit

Permalink
[LLM]Support for linux package (llama, NeoX) & quantize (llama) (inte…
Browse files Browse the repository at this point in the history
…l#8246)

* temp

* update

* update

* remove cmake

* runtime get platform  ->  change platform name using sed

* update

* update

* add platform flags(default: current platform) & delete legacy libs & add neox quantize
  • Loading branch information
cyita authored Jun 2, 2023
1 parent a135cc5 commit 56d69a0
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 156 deletions.
12 changes: 0 additions & 12 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
[submodule "python/llm/vendor/redpajama.cpp"]
path = python/llm/vendor/redpajama.cpp
url = https://github.com/analytics-zoo/redpajama.cpp.git
branch = python-binding
[submodule "python/llm/vendor/bloomz.cpp"]
path = python/llm/vendor/bloomz.cpp
url = https://github.com/analytics-zoo/bloomz.cpp.git
branch = server
[submodule "python/llm/vendor/llama.cpp"]
path = python/llm/vendor/llama.cpp
url = https://github.com/analytics-zoo/llama.cpp.git
branch = cache
58 changes: 0 additions & 58 deletions python/llm/CMakeLists.txt

This file was deleted.

74 changes: 0 additions & 74 deletions python/llm/setup-linux.py

This file was deleted.

71 changes: 62 additions & 9 deletions python/llm/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@
# limitations under the License.
#

# >> Usage:
#
# >>>> Build for the current platform:
# python setup.py clean --all bdist_wheel
# >>>> Windows:
# python setup.py clean --all bdist_wheel --win
# >>>> Linux:
# python setup.py clean --all bdist_wheel --linux

import os
import sys
import fnmatch
from setuptools import setup
import urllib.request
import platform
import shutil

long_description = '''
BigDL LLM
Expand All @@ -29,6 +41,7 @@
BIGDL_PYTHON_HOME = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
VERSION = open(os.path.join(BIGDL_PYTHON_HOME, 'version.txt'), 'r').read().strip()
llm_home = os.path.join(os.path.dirname(os.path.abspath(__file__)), "src")
libs_dir = os.path.join(llm_home, "bigdl", "llm", "libs")


def get_llm_packages():
Expand All @@ -45,36 +58,76 @@ def get_llm_packages():
return llm_packages


lib_urls = [
lib_urls = {}
lib_urls["Windows"] = [
"https://sourceforge.net/projects/analytics-zoo/files/bigdl-llm/llama.dll",
"https://sourceforge.net/projects/analytics-zoo/files/bigdl-llm/quantize-llama.exe",
"https://sourceforge.net/projects/analytics-zoo/files/bigdl-llm/gptneox.dll",
"https://sourceforge.net/projects/analytics-zoo/files/bigdl-llm/quantize-gptneox.exe",
# TODO: add bloomz
]
lib_urls["Linux"] = [
"https://sourceforge.net/projects/analytics-zoo/files/bigdl-llm/libllama_avx2.so",
"https://sourceforge.net/projects/analytics-zoo/files/bigdl-llm/libllama_avx512.so",
"https://sourceforge.net/projects/analytics-zoo/files/bigdl-llm/quantize-llama",
"https://sourceforge.net/projects/analytics-zoo/files/bigdl-llm/libgptneox_avx2.so",
"https://sourceforge.net/projects/analytics-zoo/files/bigdl-llm/libgptneox_avx512.so",
"https://sourceforge.net/projects/analytics-zoo/files/bigdl-llm/quantize-gptneox",
]


def download_libs(url: str):
libs_dir = os.path.join(llm_home, "bigdl", "llm", "libs")
if not os.path.exists(libs_dir):
os.makedirs(libs_dir, exist_ok=True)
def download_libs(url: str, change_permission=False):
libso_file_name = url.split('/')[-1]
libso_file = os.path.join(libs_dir, libso_file_name)
if not os.path.exists(libso_file):
print(">> Downloading from ", url)
urllib.request.urlretrieve(url, libso_file)
if change_permission:
os.chmod(libso_file, 0o775)


def setup_package():

package_data = [
package_data = {}
package_data["Windows"] = [
"libs/llama.dll",
"libs/quantize-llama.exe",
"libs/gptneox.dll",
"libs/quantize-gptneox.exe",
]
package_data["Linux"] = [
"libs/libllama_avx2.so",
"libs/libllama_avx512.so",
"libs/quantize-llama",
"libs/libgptneox_avx2.so",
"libs/libgptneox_avx512.so",
"libs/quantize-gptneox",
]

platform_name = None
if "--win" in sys.argv:
platform_name = "Windows"
sys.argv.remove("--win")
if "--linux" in sys.argv:
platform_name = "Linux"
sys.argv.remove("--linux")

if platform_name is None:
if platform.platform().startswith('Windows'):
platform_name = "Windows"
else:
platform_name = "Linux"

change_permission = True if platform_name == "Linux" else False

# Delete legacy libs
if os.path.exists(libs_dir):
print(f"Deleting existing libs_dir {libs_dir} ....")
shutil.rmtree(libs_dir)
os.makedirs(libs_dir, exist_ok=True)

for url in lib_urls:
download_libs(url)
for url in lib_urls[platform_name]:
download_libs(url, change_permission=change_permission)

metadata = dict(
name='bigdl-llm',
Expand All @@ -88,7 +141,7 @@ def setup_package():
url='https://github.com/intel-analytics/BigDL',
packages=get_llm_packages(),
package_dir={"": "src"},
package_data={"bigdl.llm": package_data},
package_data={"bigdl.llm": package_data[platform_name]},
include_package_data=True,
classifiers=[
'License :: OSI Approved :: Apache Software License',
Expand Down
1 change: 0 additions & 1 deletion python/llm/vendor/bloomz.cpp
Submodule bloomz.cpp deleted from 6d2dee
1 change: 0 additions & 1 deletion python/llm/vendor/llama.cpp
Submodule llama.cpp deleted from 5026ad
1 change: 0 additions & 1 deletion python/llm/vendor/redpajama.cpp
Submodule redpajama.cpp deleted from bec989

0 comments on commit 56d69a0

Please sign in to comment.