Skip to content
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

[NeuralChat] Add Multi-Socket LLM Inference Example #1073

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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
```
Original file line number Diff line number Diff line change
@@ -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)
Loading