-
Notifications
You must be signed in to change notification settings - Fork 5k
[CPU] Support Intel CPU inference #3041
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
Merged
+1,414
−329
Merged
Changes from all commits
Commits
Show all changes
179 commits
Select commit
Hold shift + click to select a range
edf1c12
add fallback path for kernels used in megatron
delock 9a89405
temporary numactl WA for SPR 56core
delock d1b8f13
adapt core allocation according to number of ranks
delock e31439e
add switch to turn on numactl
delock c5828f7
detect number of cores on the system
delock 6b9dcd2
allow select a subset of the cores on the system to bind
4031a6e
Merge branch 'up-master' into gma/numactl
delock 893c18d
remove unneeded changes
delock ad71233
Merge branch 'up-master' into gma/bf16_kernel
delock 3551850
Merge branch 'master' into gma/numactl
delock 04d17e8
Merge branch 'gma/numactl' into gma/cpu_support
delock 1369eda
add ccl backend
delock 3c927c7
change nccl to ccl
delock e1eecd2
remove unused code
delock c005399
add comm/ccl to ops
delock b7d455e
initial ccl comm support
delock 6f2a73e
first broadcast case passed
delock 2c012fd
add CCL_Backend to DeepSpeed
delock 3435185
support comm timer for CPU
delock 92cc50e
support barrier for comm backend
delock 62c53f7
support specify master address from deepspeed command line
delock 9ce6fce
support pytorch 2.0
delock f4e1d3c
remove 'block' from api
delock 1e583fa
Tweak for debug
CaoZhongZ a363f01
Remove unecessary directory
CaoZhongZ bb29b1a
Add bf16 kernel support for inference
5e07174
Add temporary torch implement for cpu inference
076d699
Add softmax ops cpu fallback for inference
baodii 0a35d9c
bind cores to numa domain as well
delock c1d78b9
Merge branch 'up-master' into gma/cpu_support
delock 620c81c
merge latest change in gma/numactl
delock 1b138ba
initial bf16 kernel support with fallback path
delock a3b663c
initial fallback path for bloom kernel injection
delock 6ca0f0d
Merge branch 'zhong_master' into gma/cpu_support
delock 4323a90
fix softmax attn mask
delock cc6df65
check KMP_AFFINITY to avoid conflict with numactl
delock 9e503a5
New CCLBackend which utilize TorchBackend for initialization
delock 9a38b28
rollback last change because there is result error
delock a2d9c9e
fix bloom injection policy TP could not work issue.
sywangyi 705de70
Merge pull request #3 from sywangyi/yi_bloom_dev
delock 1f21813
Use TorchBackend to initialize CCLBackend, make behavior consistent
delock df4b0d7
remove comm under deepspeed/ops
delock ad84219
Merge branch 'microsoft:master' into gma/cpu_support
delock 7702ba7
add license header
delock e5ff34c
code clean up
delock adb1adf
fix format issue
delock 8ad2dbc
remove magic number in main address
delock ce5830e
add caching support but not turn on by default
delock da9053f
change name of inference_cuda_module to inference_module
delock 626a9bf
Merge branch 'master' into gma/cpu_support
delock e79ae9f
Check for is_synchronized_device in accelerator before get Event
delock 9e41f21
fix typo
delock c675547
Fix fallback path of softmax kernel on CUDA device for BF16 data type…
delock d42df02
add cpu backend files
delock 9fca9be
change CPU_Accelerator op_builder_dir
delock e797502
remove cpu_kernel_path
delock 1fddaf9
using CPU_Accelerator on non-cuda device
delock 43a7aae
fix deepspeed.op_builder => deepspeed.ops.op_builder
delock ad4d39a
add alias for num_gpus: num_accelerators
delock 705c519
Merge branch 'gma/cpu_support_add_backend' into gma/cpu_support
delock e685e98
allow loading cpu_builder in build stage
delock a4e76e7
Assume cuda available if torch not installed
delock 71a6f47
add oneccl_binding_pt to requirements
delock 8faae83
move oneccl-binding-pt to seperate requiremetns-cpu.txt
delock 7997887
add missing file
delock a027af6
use dependency_links in setuptools.setup() call for additional depend…
delock 4742e23
Merge branch 'master' into gma/cpu_support
delock 62772ea
install oneccl_bind_pt in workflows
delock a4499d6
change oneccl_bind_pt's version from 1.13 to 2.0
delock fe63c7b
use intel_exention_for_pytorch as indicator that CPU_Accelerator shou…
delock 3905264
Add indicator for Accelerator used
delock f7ead2d
change foo.c to foo.cpp
delock d4e63b9
exclude 'cpu' directory in CUDA op builder reflection
delock a34b886
Merge branch 'master' into gma/cpu_support
delock d0e5b1c
add a cpu-inference workflow
delock 221896c
run cpu-inference workflow on self-hosted instance
delock a039688
change cpu runs-on node to v100 node
delock 5525ce0
print out python version in workflow
delock 3ddc8b2
add verbose in pip command to understand oneccl_bind_pt install issue
delock fa9d345
update cpu-inference workflow
delock 978314a
add a stage to detect instance instruction sets
delock c5b11ad
add back bf16 support for CPU inference
delock 312d85c
enable autoTP for bloom
sywangyi a66d8b5
update workflow to detect cpu instruction sets
delock 0447823
temporary WA for Intel Extension for PyTorch AVX2 instructioon set de…
delock a09c638
change cpu-inference workflow machine to ubuntu-20.04
delock 33803ee
add sharded checkpoint loading for AutoTP path to reduce the peak mem…
sywangyi 2deff63
Merge pull request #6 from sywangyi/autoTP_reduce_peak
delock 755a47b
enable policy for llama
jianan-gu bd021b5
Merge branch 'master' into gma/cpu_support
delock 21f9c28
use a special build ipex to test avx2 detection fix
delock c177c2e
Merge pull request #7 from jianan-gu/patch-1
delock 4e4a367
Merge branch 'up-master' into gma/cpu_support
delock db1f564
fix format
delock 20c79e1
Merge branch 'master' into gma/cpu_support
delock f66195e
fix test fail issue
sywangyi 8090867
Merge pull request #8 from sywangyi/yi_dev
delock f65030b
fix gptj sharded checkpoint loading problem
sywangyi 08284cc
Merge pull request #9 from sywangyi/yi_dev_gptj_shard
delock 2c4f209
Merge branch 'up-master' into gma/cpu_support
delock f83a130
return a not implemented build in get_op_builder in cpu_backend
delock e59bf32
Merge branch 'master' into gma/cpu_support
delock 302e5b0
support cpu device in tests
delock 27bcd04
use cpuinfo to extract number of CPUs
delock aafa40e
use ~/tmp as transfomer cache rather than /blob/
delock 8e90270
Add support for mpich launcher with prefer_deepspeed_comm
delock d70448c
add missing modification in accelerator
delock 16e4504
enable IMPI launcher
delock f5fd312
Merge branch 'up-master' into gma/cpu_support
delock c85cbe4
remove unused file and fix formatting
delock bc0b152
Merge branch 'up-master' into gma/cpu_support
delock 71ad82e
clean up ccl.cpp
delock 5e81692
Merge branch 'master' into gma/cpu_support
delock fc7a4fa
Merge branch 'master' into gma/cpu_support
delock f04d83d
Less confusing error message when certin op builder are not implemented
delock fa83d5a
Fix license header
delock 5b18bbc
Add license header
delock 900c007
add license headers
delock 57d790d
add license header
delock d001568
fix cuda specific code in test
delock 07ce43b
update CPU workflow
delock e21b073
Merge branch 'up-master' into gma/cpu_support
delock cb6d6f5
use numactl to bind to core
delock 7a8a8ef
allow bind_cores_to_rank in multi-node impi runner
delock c63bf45
fix format error
delock 8f5e51a
Remove InferenceBuilder
delock 7fd0738
fix format error in numa.py
delock e21a04e
check whether op is in installed ops in ds_report.py
delock cd45a4f
Merge branch 'master' into gma/cpu_support
delock a3c5da4
Merge branch 'master' into gma/cpu_support
tjruwase 9d0a47a
allow override accelerator with DS_ACCELERATOR='cuda','cpu' or 'xpu'
delock 72dcfc6
lazy init class_dict in CUDA_Accelerator to avoid cyclic initializati…
delock a71a462
Merge branch 'master' into gma/cpu_support
loadams 1e0aeaa
put short path in the beginning in real_accelerator.py
delock 880c466
device_count return number of NUMA nodes
delock 47da079
Merge branch 'up-master' into gma/cpu_support
delock 69ee9d2
fix typo
delock cd8d810
install numactl in cpu workflow
delock 9d1eec2
Merge branch 'up-master' into gma/cpu_support
delock 0b0eadb
Merge branch 'master' into gma/cpu_support
tjruwase a0ebaad
Follow comments
delock 3c0ece3
Merge branch 'master' into gma/cpu_support
delock 248c47b
Better implementation of device_count() and current_device()
delock 02ce81f
remove dependency_link for Intel Extension for DeepSpeed
delock 9babf03
use check is_synchronized_device in timer only once
delock 59dca3f
remove env mapping WA in cpu_accelerator
delock 0230c77
Merge branch 'master' into gma/cpu_support
delock 04d4a27
Merge branch 'up-master' into gma/cpu_support
delock 7aecab7
fix duplicate definition
delock 5cc61fb
fix format error
delock 1bd6458
Merge branch 'master' into gma/cpu_support
tjruwase 4027838
refine ccl backend selection
delock e4e92e0
move comments to the right place
delock 31e1785
Merge branch 'up-master' into gma/cpu_support
delock 50faa03
remove prefer_deepspeed_comm, use CCLBackend by default
delock 5d26c8e
refractor fallback path
delock 5957f56
Fix execution failure in kernel injection path
delock f7dd940
do not refractory kernel injection fallback path in residual_add bec…
delock 816e354
guard residual_add fallback path with environ DS_KI_FALLBACK=True
delock 803b17f
Merge branch 'master' into gma/cpu_support
delock 2b59496
Merge branch 'master' into gma/cpu_support
tjruwase 764d027
fix format error
delock 869724c
add test for allreduce on CPU workflow
delock f678b90
fix format error
delock 828dce0
Merge branch 'master' into gma/cpu_support
tjruwase 8c3444b
Merge branch 'up-master' into gma/cpu_support
delock 1b9cd90
Fallback to TorchBackend if CCLBackend kernel are not implemented
delock bf5657f
Merge branch 'master' into gma/cpu_support
delock c6c6eb2
Update Intel Extension for Pytorch installation link
delock e7fba93
Don't specify version number of Intel Extension for PyTorch
delock b2c7cb7
install oneCCL for CCLBackend
delock 8749366
fix link path for CPU comm kernels
delock 782a624
fix source oneCCL environment
delock 06f6815
source oneCCL env before run UT
delock 24a5a52
Merge branch 'master' into gma/cpu_support
tjruwase f63cbbd
Give more specific instruction when CCL_ROOT not defined
delock 06b55a0
Merge branch 'master' into gma/cpu_support
delock 1fc50be
Merge branch 'master' into gma/cpu_support
tjruwase 5f49686
Merge branch 'master' into gma/cpu_support
tjruwase File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| name: cpu-inference | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - 'staging**' | ||
| paths-ignore: | ||
| - 'docs/**' | ||
| pull_request: | ||
| paths-ignore: | ||
| - 'docs/**' | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| unit-tests: | ||
| runs-on: ubuntu-20.04 | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v2 | ||
|
|
||
| - id: setup-venv | ||
| uses: ./.github/workflows/setup-venv | ||
|
|
||
| - name: Detect instruction sets on instance | ||
| run: | | ||
| lscpu | ||
| pip install cmake | ||
| git clone https://github.com/intel/intel-extension-for-pytorch | ||
| cd intel-extension-for-pytorch/tests/cpu/isa | ||
| cmake . | ||
| make | ||
| ./cpu_features | ||
|
|
||
| - name: Install numactl | ||
| run: | | ||
| sudo apt-get install -y numactl | ||
|
|
||
| - name: Install oneCCL Bindings for PyTorch | ||
| run: | | ||
| python -m pip install intel_extension_for_pytorch | ||
| python -m pip install oneccl_bind_pt==2.0 -f https://developer.intel.com/ipex-whl-stable-cpu | ||
|
|
||
| - name: Install oneCCL | ||
| run: | | ||
| git clone https://github.com/oneapi-src/oneCCL | ||
| cd oneCCL | ||
| mkdir build | ||
| cd build | ||
| cmake .. | ||
| make | ||
| make install | ||
| #source ./_install/env/setvars.sh | ||
| # test whether oneCCL is correctly installed | ||
| #mpirun -n 2 ./examples/benchmark/benchmark | ||
|
|
||
| - name: Install transformers | ||
| run: | | ||
| git clone https://github.com/huggingface/transformers | ||
| cd transformers | ||
| git rev-parse --short HEAD | ||
| pip install . | ||
|
|
||
| - name: Install deepspeed | ||
| run: | | ||
| # check why the host does not have AVX2 support | ||
| pip install .[dev,1bit,autotuning,inf] | ||
| ds_report | ||
|
|
||
| - name: Python environment | ||
| run: | | ||
| pip list | ||
|
|
||
| - name: Unit tests | ||
| run: | | ||
| source oneCCL/build/_install/env/setvars.sh | ||
| unset TORCH_CUDA_ARCH_LIST # only jit compile for current arch | ||
| if [[ -d ./torch-extensions ]]; then rm -rf ./torch-extensions; fi | ||
| cd tests | ||
| TRANSFORMERS_CACHE=~/tmp/transformers_cache/ TORCH_EXTENSIONS_DIR=./torch-extensions pytest -m 'inference' unit/inference/test_inference_config.py | ||
| TRANSFORMERS_CACHE=~/tmp/transformers_cache/ TORCH_EXTENSIONS_DIR=./torch-extensions pytest -k TestDistAllReduce unit/comm/test_dist.py | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,260 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # DeepSpeed Team | ||
|
|
||
| import torch | ||
| from deepspeed.accelerator.abstract_accelerator import DeepSpeedAccelerator | ||
| import oneccl_bindings_for_pytorch # noqa: F401 | ||
| import psutil | ||
| import os | ||
|
|
||
|
|
||
| # accelerator for Intel CPU | ||
| class CPU_Accelerator(DeepSpeedAccelerator): | ||
|
|
||
| def __init__(self): | ||
| self._name = 'cpu' | ||
| self._communication_backend_name = 'ccl' | ||
| self.max_mem = psutil.Process().memory_info().rss | ||
|
|
||
| def is_synchronized_device(self): | ||
| return True | ||
|
|
||
| # Device APIs | ||
| def device_name(self, device_index=None): | ||
| return 'cpu' | ||
|
|
||
| def device(self, device_index=None): | ||
| return None | ||
|
|
||
| def set_device(self, device_index): | ||
| return | ||
|
|
||
| def current_device(self): | ||
| return os.environ.get('LOCAL_RANK', 0) | ||
|
|
||
| def current_device_name(self): | ||
| return 'cpu' | ||
|
|
||
| def device_count(self): | ||
|
delock marked this conversation as resolved.
|
||
| device_count = int(os.environ.get('LOCAL_SIZE', 0)) | ||
| if device_count > 0: | ||
| return os.environ.get('LOCAL_SIZE') | ||
| else: | ||
| from deepspeed.utils.numa import get_numa_cores | ||
| # Count NUMA node for number of cpu accelerators. On machine with HBM | ||
| # In flat mode, HBM is in separate NUMA node with no cores on this node. | ||
| # Ignore these NUMA nodes with no cores. | ||
| numa_core_lists = get_numa_cores() | ||
| numa_count = 0 | ||
| for core_list in numa_core_lists: | ||
| if len(core_list) > 0: | ||
| numa_count += 1 | ||
| return numa_count | ||
|
|
||
| def synchronize(self, device_index=None): | ||
| return | ||
|
|
||
| # RNG APIs | ||
| def random(self): | ||
| return torch.random | ||
|
|
||
| def set_rng_state(self, new_state, device_index=None): | ||
| if device_index == None: | ||
| return torch.set_rng_state(new_state) | ||
| return torch.set_rng_state(new_state, device_index) | ||
|
|
||
| def get_rng_state(self, device_index=None): | ||
| return torch.get_rng_state() | ||
|
|
||
| def manual_seed(self, seed): | ||
| return torch.manual_seed(seed) | ||
|
|
||
| def manual_seed_all(self, seed): | ||
| return torch.manual_seed(seed) | ||
|
|
||
| def initial_seed(self, seed): | ||
| return torch.initial_seed(seed) | ||
|
|
||
| def default_generator(self, device_index): | ||
| return torch.default_generator | ||
|
|
||
| # Streams/Events | ||
| @property | ||
| def Stream(self): | ||
| return None | ||
|
|
||
| def stream(self, stream): | ||
| from deepspeed.runtime.utils import noop_decorator | ||
| return noop_decorator | ||
|
|
||
| def current_stream(self, device_index=None): | ||
| return None | ||
|
|
||
| def default_stream(self, device_index=None): | ||
| return None | ||
|
|
||
| @property | ||
| def Event(self): | ||
| return None | ||
|
|
||
| # Memory management | ||
| def empty_cache(self): | ||
| return | ||
|
|
||
| def get_rss(self): | ||
| mem = psutil.Process().memory_info().rss | ||
| if mem > self.max_mem: | ||
| self.max_mem = mem | ||
| return mem | ||
|
|
||
| def reset_rss(self): | ||
| mem = psutil.Process().memory_info().rss | ||
| self.max_mem = mem | ||
| return mem | ||
|
|
||
| def memory_allocated(self, device_index=None): | ||
| return self.get_rss() | ||
|
|
||
| def max_memory_allocated(self, device_index=None): | ||
| self.get_rss() | ||
| return self.max_mem | ||
|
|
||
| def reset_max_memory_allocated(self, device_index=None): | ||
| self.reset_rss() | ||
| return | ||
|
|
||
| def memory_cached(self, device_index=None): | ||
| return self.get_rss() | ||
|
|
||
| def max_memory_cached(self, device_index=None): | ||
| self.get_rss() | ||
| return self.max_mem | ||
|
|
||
| def reset_max_memory_cached(self, device_index=None): | ||
| self.reset_rss() | ||
| return | ||
|
|
||
| def memory_stats(self, device_index=None): | ||
| return self.get_rss() | ||
|
|
||
| def reset_peak_memory_stats(self, device_index=None): | ||
| self.reset_rss() | ||
| return | ||
|
|
||
| def memory_reserved(self, device_index=None): | ||
| return self.get_rss() | ||
|
|
||
| def max_memory_reserved(self, device_index=None): | ||
| self.get_rss() | ||
| return self.max_mem | ||
|
|
||
| def total_memory(self, device_index=None): | ||
| return psutil.virtual_memory().total | ||
|
|
||
| # Misc | ||
| def amp(self): | ||
| return torch.cpu.amp | ||
|
|
||
| def is_available(self): | ||
| return True | ||
|
|
||
| def range_push(self, msg): | ||
| # TODO itt is currently not supported yet | ||
| # return torch.profiler.itt.range_push(msg) | ||
| return | ||
|
|
||
| def range_pop(self): | ||
| # TODO itt is currently not supported yet | ||
| # return torch.profiler.itt.range_pop() | ||
| return | ||
|
|
||
| def lazy_call(self, callback): | ||
| return callback() | ||
|
|
||
| def communication_backend_name(self): | ||
| return self._communication_backend_name | ||
|
|
||
| # Data types | ||
| def is_bf16_supported(self): | ||
| return True | ||
|
|
||
| def is_fp16_supported(self): | ||
| return True | ||
|
|
||
| # Tensor operations | ||
|
|
||
| @property | ||
| def BFloat16Tensor(self): | ||
| return torch.BFloat16Tensor | ||
|
|
||
| @property | ||
| def ByteTensor(self): | ||
| return torch.ByteTensor | ||
|
|
||
| @property | ||
| def DoubleTensor(self): | ||
| return torch.DoubleTensor | ||
|
|
||
| @property | ||
| def FloatTensor(self): | ||
| return torch.FloatTensor | ||
|
|
||
| @property | ||
| def HalfTensor(self): | ||
| return torch.HalfTensor | ||
|
|
||
| @property | ||
| def IntTensor(self): | ||
| return torch.IntTensor | ||
|
|
||
| @property | ||
| def LongTensor(self): | ||
| return torch.LongTensor | ||
|
|
||
| def pin_memory(self, tensor): | ||
| return tensor | ||
|
|
||
| def op_builder_dir(self): | ||
| try: | ||
| # is op_builder from deepspeed or a 3p version? this should only succeed if it's deepspeed | ||
| # if successful this also means we're doing a local install and not JIT compile path | ||
| from op_builder import __deepspeed__ # noqa: F401 | ||
| return "op_builder.cpu" | ||
| except ImportError: | ||
| return "deepspeed.ops.op_builder.cpu" | ||
|
|
||
| def on_accelerator(self, tensor): | ||
| device_str = str(tensor.device) | ||
| if device_str.startswith('cpu'): | ||
| return True | ||
| else: | ||
| return False | ||
|
|
||
| # create an instance of op builder and return, name specified by class_name | ||
| def create_op_builder(self, op_name): | ||
| builder_class = self.get_op_builder(op_name) | ||
| if builder_class != None: | ||
| return builder_class() | ||
| return None | ||
|
|
||
| # return an op builder class, name specified by class_name | ||
| def get_op_builder(self, class_name): | ||
| try: | ||
| # is op_builder from deepspeed or a 3p version? this should only succeed if it's deepspeed | ||
| # if successful this also means we're doing a local install and not JIT compile path | ||
| from op_builder import __deepspeed__ # noqa: F401 | ||
| from op_builder.cpu import CCLCommBuilder, NotImplementedBuilder | ||
| except ImportError: | ||
| from deepspeed.ops.op_builder.cpu import CCLCommBuilder, NotImplementedBuilder | ||
|
|
||
| if class_name == "CCLCommBuilder": | ||
| return CCLCommBuilder | ||
| else: | ||
| # return a NotImplementedBuilder to avoid get NoneType[Name] in unit tests | ||
| return NotImplementedBuilder | ||
|
|
||
| def build_extension(self): | ||
| from torch.utils.cpp_extension import BuildExtension | ||
| return BuildExtension | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.