diff --git a/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/README.md b/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_host/README.md similarity index 100% rename from intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/README.md rename to intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_host/README.md diff --git a/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/codegen.yaml b/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_host/codegen.yaml similarity index 100% rename from intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/codegen.yaml rename to intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_host/codegen.yaml diff --git a/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/run.sh b/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_host/run.sh similarity index 88% rename from intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/run.sh rename to intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_host/run.sh index 815fe1a3c8c..a2f89562d9c 100644 --- a/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/run.sh +++ b/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_host/run.sh @@ -16,7 +16,7 @@ # limitations under the License. # Kill the exist and re-run -ps -ef |grep 'run_code_gen' |awk '{print $2}' |xargs kill -9 +ps -ef |grep 'run_multi_host' |awk '{print $2}' |xargs kill -9 # KMP export KMP_BLOCKTIME=1 @@ -30,4 +30,4 @@ export LD_PRELOAD=${CONDA_PREFIX}/lib/libiomp5.so # tc malloc export LD_PRELOAD=${LD_PRELOAD}:${CONDA_PREFIX}/lib/libtcmalloc.so -numactl -l -C 0-47 python -m run_code_gen 2>&1 | tee run.log +numactl -l -C 0-47 python -m run_multi_host 2>&1 | tee run.log diff --git a/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/run_code_gen.py b/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_host/run_multi_host.py similarity index 100% rename from intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/run_code_gen.py rename to intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_host/run_multi_host.py diff --git a/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_socket/README.md b/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_socket/README.md new file mode 100644 index 00000000000..520f5f797c8 --- /dev/null +++ b/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_socket/README.md @@ -0,0 +1,73 @@ +This README serves as a guide to set up the backend for a code generation chatbot utilizing the NeuralChat framework. You can deploy this code generation chatbot across various platforms, including Intel XEON Scalable Processors, Habana's Gaudi processors (HPU), Intel Data Center GPU and Client GPU, Nvidia Data Center GPU, and Client GPU. + +This code generation chatbot demonstrates how to deploy it specifically on Intel XEON processors. To run the 34b or 70b level LLM model, we require implementing model parallelism using multi-node strategy. + + +# Setup Conda + +First, you need to install and configure the Conda environment: + +```shell +# Download and install Miniconda +wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh +bash `Miniconda*.sh` +source ~/.bashrc +# Create Conda Virtual Environment +conda create -n your_env_name python=3.10 -y +conda activate your_env_name +``` + + +# Install Python Dependencies + +Install Dependencies from conda & pip +```shell +conda install astunparse ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses -y +conda install jemalloc gperftools -c conda-forge -y + +pip install transformers +``` + +Install DeepSpeed from source code +```shell +# git clone Deepspeed source code +git clone https://github.com/microsoft/DeepSpeed.git +cd DeepSpeed +# cherry-pick commits +git remote add DeepSpeedSYCLSupport https://github.com/delock/DeepSpeedSYCLSupport.git +git fetch DeepSpeedSYCLSupport +git cherry-pick cd070bf8 +# cherry-pick commits +git remote add ftian1 https://github.com/ftian1/DeepSpeed.git +git fetch ftian1 +git log ftian1/master --pretty=format:"%h" -4 +git cherry-pick a3ce24dc +git cherry-pick 6d3174a2 +git cherry-pick 7fc67306 +# install DeepSpeed from source code +pip install . +``` + +Install OneCCL +```shell +git clone https://github.com/oneapi-src/oneCCL.git +cd oneCCL +mkdir build +cd build +cmake .. +make -j install +source _install/env/setvars.sh +python -m pip install oneccl_bind_pt --index-url https://pytorch-extension.intel.com/release-whl/stable/cpu/us/ +``` + +Install IPEX CPU version: + +```shell +python -m pip install intel_extension_for_pytorch --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/cpu/us/ +``` + +# Run the Code Generation Chatbot Server + +```shell +deepspeed --bind_cores_to_rank ./run_multi_socket.py +``` diff --git a/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_socket/run_multi_socket.py b/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_socket/run_multi_socket.py new file mode 100644 index 00000000000..8742ced6f5c --- /dev/null +++ b/intel_extension_for_transformers/neural_chat/examples/deployment/codegen/backend/xeon/multi_socket/run_multi_socket.py @@ -0,0 +1,64 @@ +# !/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2023 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import os +import torch +import deepspeed +from deepspeed.accelerator import get_accelerator +from transformers import pipeline, AutoTokenizer + + +dtype = torch.bfloat16 +local_rank = int(os.getenv("LOCAL_RANK", "0")) +model = "facebook/opt-125m" +task = "text-generation" +world_size = 2 + +# We have to load these large models on CPU with pipeline because not +# enough GPU memory +tokenizer = AutoTokenizer.from_pretrained(model, use_fast=True) +pipe = pipeline(task, + model=model, + tokenizer=tokenizer, + torch_dtype=dtype, + trust_remote_code=True, + device=torch.device("cpu"), + framework="pt") + +pipe.model = deepspeed.init_inference(pipe.model, dtype=dtype, mp_size=world_size, replace_with_kernel_inject=False) +ds_config = { + "weight_quantization": { + "post_init_quant": { + '*': { + 'num_bits': 4, + 'group_size': 32, + 'group_dim': 1, + 'symmetric': False + }, + } + } +} +from deepspeed.inference.quantization.quantization import _init_group_wise_weight_quantization +pipe.model = _init_group_wise_weight_quantization(pipe.model, ds_config) +pipe.device = torch.device(get_accelerator().device_name(local_rank)) + +query = "DeepSpeed is the greatest" +inf_kwargs = {"do_sample": False, "temperature": 1.0, "max_length": 20} +ds_output = pipe(query, **inf_kwargs) + +print(local_rank, "deepspeed", ds_output) \ No newline at end of file