-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 1-bit Adam v1 (squash) (#346) * testing_onebit * test_passed * test_passed * updated compressed_allreduce * 123 * cpu2gpu test added * Add non-cuda-aware code path. Segfaults for > 2 procs. * Works for 4 procs with numpy buffers now. TODO: cleanup, evalute perf. * Fix gather. Cleanup. * Add new tests. * Reduce memory footprint. BERT large with BS=16 works. * Revert "Reduce memory footprint. BERT large with BS=16 works." This reverts commit e7f38fc. * Update optim to support bert-large. * with initialization added on bert_onebit_adam * This works!! * Force igather for cupy. Better performance. Need cleanup and reorg to support TCP now. * X * testing the fintune task for FP32 training * Added the fintune taks for FP32 training * With the control flag of freeze_step added * added the freeze_step inside fp32_onebitadam * Seperate freeze_kernnel added * Added the sanity test for the Compressed_Allreduce * Test for Compressed_Allreduce passed, but AllGather need sync. * add checks for finetuning. * Running passed for finetune on EastUs * Add one bit adam clean file. * Refactor comms. code and move it to a new file. * fix compile/run errors. * Adding changes for onebit_adam from Hank * Save memory by modifying in-place. Co-authored-by: Your Name <[email protected]> Co-authored-by: Ammar Ahmad Awan <[email protected]> Co-authored-by: tanghl1994 <[email protected]> Co-authored-by: Hank <[email protected]> Co-authored-by: root <[email protected]> * Staging 1bit adam v1 (#348) * Refactor to correct locations. * Deleted unused files. * Fix imports for refactored codebase. * update the com reduce test. * Fix some errors. * Fix optimizer name * Delete unused tests. * Fix formatting for pre-commit. * Add cupy dependencies. * add cupy for cuda 10add cupy for cuda 10 * Add mpi4py requirement. Co-authored-by: Ammar Ahmad Awan <[email protected]> * Use correct initialization for exp_avg. * Cleanup onebit adam. * minor wording fix. * Cleanup custom collectives. * Fixes for TCP support. * fix formatting. fix formatting. * move 1bit adam reqs * delay importing 1bit adam unless it's used, this will ensure we delay importing mpi4py * Fix cuda version parsing. * Temporary tcp fix. * Update install.sh * Refactor code to properly support cuda-aware comm. * Fix imports. * add cuda_aware flag to tests. * Cleanup. Add copyrights. * Add 1-bit Adam tutorial v1. * Minor fixes to copyright and print statements. * Update utils.py * Update utils.py Co-authored-by: Jeff Rasley <[email protected]> Co-authored-by: Your Name <[email protected]> Co-authored-by: tanghl1994 <[email protected]> Co-authored-by: Hank <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: Ammar Ahmad Awan <[email protected]>
- Loading branch information
1 parent
1ebcd6c
commit fa66867
Showing
12 changed files
with
871 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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,154 @@ | ||
''' | ||
Copyright 2019 The Microsoft DeepSpeed Team | ||
''' | ||
|
||
from mpi4py import MPI | ||
import numpy as np | ||
import cupy | ||
|
||
|
||
def my_igather(rank, size, comm, sendbuf, recbuf, root): | ||
req = [] | ||
if rank == root: | ||
for idx in range(size): | ||
if idx != rank: | ||
req.append(comm.Irecv(recbuf[idx], source=idx)) | ||
else: | ||
recbuf[rank] = sendbuf | ||
else: | ||
req.append(comm.Isend(sendbuf, dest=root)) | ||
return req | ||
|
||
|
||
def gather_cuda(rank, | ||
world_size, | ||
comm, | ||
cupy_sign_list_packed, | ||
cupy_recvbuf_sign, | ||
cupy_worker_scale, | ||
cupy_recvbuf_scale): | ||
# We do in-place operations on cupy buffers so we do not return any buffers | ||
requests = [] | ||
for idx in range(world_size): | ||
req_sign = my_igather(rank, | ||
world_size, | ||
comm, | ||
cupy_sign_list_packed[idx], | ||
cupy_recvbuf_sign, | ||
root=idx) | ||
requests += req_sign | ||
|
||
for idx in range(world_size): | ||
req_scale = my_igather(rank, | ||
world_size, | ||
comm, | ||
cupy_worker_scale, | ||
cupy_recvbuf_scale, | ||
root=idx) | ||
requests += req_scale | ||
|
||
MPI.Request.Waitall(requests) | ||
|
||
|
||
def gather_host(rank, | ||
world_size, | ||
comm, | ||
cupy_sign_list_packed, | ||
cupy_recvbuf_sign, | ||
cupy_worker_scale, | ||
cupy_recvbuf_scale): | ||
# In-place operations are not possible for newly created cupy arrays | ||
# so we need to return the new buffers | ||
numpy_recvbuf_sign = np.zeros([world_size, | ||
cupy_sign_list_packed[rank].size], | ||
dtype=cupy_sign_list_packed[0].dtype) | ||
numpy_recvbuf_scale = np.zeros([world_size, 1], dtype=cupy_worker_scale.dtype) | ||
|
||
# 1. convert from cupy to numpy | ||
numpy_sign_list_packed = cupy_sign_list_packed | ||
|
||
for idx in range(world_size): | ||
numpy_sign_list_packed[idx] = cupy.asnumpy(cupy_sign_list_packed[idx]) | ||
|
||
numpy_worker_scale = cupy.asnumpy(cupy_worker_scale) | ||
numpy_recvbuf_scale = cupy.asnumpy(cupy_recvbuf_scale) | ||
|
||
cupy.cuda.get_current_stream().synchronize() | ||
|
||
# 2. use numpy buffers for communication | ||
requests = [] | ||
|
||
for idx in range(world_size): | ||
req_sign = my_igather(rank, | ||
world_size, | ||
comm, | ||
numpy_sign_list_packed[idx], | ||
numpy_recvbuf_sign, | ||
root=idx) | ||
requests += req_sign | ||
|
||
for idx in range(world_size): | ||
req_scale = my_igather(rank, | ||
world_size, | ||
comm, | ||
numpy_worker_scale, | ||
numpy_recvbuf_scale, | ||
root=idx) | ||
requests += req_scale | ||
|
||
MPI.Request.Waitall(requests) | ||
|
||
# 3. Convert back from numpy to cupy | ||
cupy_recvbuf_sign = cupy.asarray(numpy_recvbuf_sign) | ||
for idx in range(world_size): | ||
cupy_sign_list_packed[idx] = cupy.asarray(numpy_sign_list_packed[idx]) | ||
|
||
cupy_worker_scale = cupy.asarray(numpy_worker_scale) | ||
cupy_recvbuf_scale = cupy.asarray(numpy_recvbuf_scale) | ||
cupy.cuda.get_current_stream().synchronize() | ||
|
||
return cupy_sign_list_packed, cupy_recvbuf_sign, cupy_worker_scale, cupy_recvbuf_scale | ||
|
||
|
||
def allgather_cuda(comm, | ||
cupy_server_sign_packed, | ||
cupy_recvbuf_sign_server, | ||
cupy_server_scale, | ||
cupy_recvbuf_scale_server): | ||
comm.Allgather(cupy_server_sign_packed, cupy_recvbuf_sign_server) | ||
comm.Allgather(cupy_server_scale, cupy_recvbuf_scale_server) | ||
|
||
|
||
def allgather_host(comm, | ||
cupy_server_sign_packed, | ||
cupy_recvbuf_sign_server, | ||
cupy_server_scale, | ||
cupy_recvbuf_scale_server): | ||
|
||
# 1. Convert cupy to numpy | ||
numpy_recvbuf_sign_server = np.zeros([comm.Get_size(), | ||
cupy_server_sign_packed.size], | ||
dtype=cupy_server_sign_packed.dtype) | ||
numpy_recvbuf_scale_server = np.zeros([comm.Get_size(), | ||
1], | ||
dtype=cupy_server_scale.dtype) | ||
|
||
numpy_server_sign_packed = cupy.asnumpy(cupy_server_sign_packed) | ||
numpy_recvbuf_sign_server = cupy.asnumpy(cupy_recvbuf_sign_server) | ||
numpy_server_scale = cupy.asnumpy(cupy_server_scale) | ||
numpy_recvbuf_scale_server = cupy.asnumpy(cupy_recvbuf_scale_server) | ||
cupy.cuda.get_current_stream().synchronize() | ||
|
||
# 2. Communicate numpy buffers | ||
comm.Allgather(numpy_server_sign_packed, numpy_recvbuf_sign_server) | ||
comm.Allgather(numpy_server_scale, numpy_recvbuf_scale_server) | ||
comm.Barrier() | ||
|
||
# 3. Convert numpy back to cupy | ||
cupy_server_sign_packed = cupy.asarray(numpy_server_sign_packed) | ||
cupy_recvbuf_sign_server = cupy.asarray(numpy_recvbuf_sign_server) | ||
cupy_server_scale = cupy.asarray(numpy_server_scale) | ||
cupy_recvbuf_scale_server = cupy.asarray(numpy_recvbuf_scale_server) | ||
cupy.cuda.get_current_stream().synchronize() | ||
|
||
return cupy_server_sign_packed, cupy_recvbuf_sign_server, cupy_server_scale, cupy_recvbuf_scale_server |
This file contains 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 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
Oops, something went wrong.