-
Notifications
You must be signed in to change notification settings - Fork 943
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
TP sharding v2 #216
Merged
Merged
TP sharding v2 #216
Conversation
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
Narsil
force-pushed
the
llama_multiprocess2
branch
from
July 25, 2023 19:29
7ac49b5
to
d384f9f
Compare
Narsil
commented
Jul 26, 2023
Comment on lines
+30
to
+74
struct AllReduce { | ||
comm: Rc<Comm>, | ||
} | ||
|
||
/// This is actually not safe: https://docs.nvidia.com/deeplearning/nccl/user-guide/docs/usage/threadsafety.html | ||
/// But for this example purposes, this will work | ||
unsafe impl Sync for AllReduce {} | ||
/// This is actually not safe: https://docs.nvidia.com/deeplearning/nccl/user-guide/docs/usage/threadsafety.html | ||
/// But for this example purposes, this will work | ||
unsafe impl Send for AllReduce {} | ||
|
||
impl CustomOp1 for AllReduce { | ||
fn name(&self) -> &'static str { | ||
"allreduce" | ||
} | ||
|
||
fn cpu_fwd(&self, _s: &CpuStorage, _l: &Layout) -> Result<(CpuStorage, Shape)> { | ||
todo!("implement allreduce for cpu is not necessary for single node"); | ||
} | ||
|
||
#[cfg(feature = "cuda")] | ||
fn cuda_fwd( | ||
&self, | ||
s: &candle::CudaStorage, | ||
l: &Layout, | ||
) -> Result<(candle::CudaStorage, Shape)> { | ||
use candle::cuda_backend::WrapErr; | ||
let elem_count = l.shape().elem_count(); | ||
let dev = s.device().clone(); | ||
let s = s.as_cuda_slice::<f16>()?; | ||
// let s = match l.contiguous_offsets() { | ||
// None => Err(Error::Wrapped("input has to be contiguous".into()))?, | ||
// Some((o1, o2)) => s.slice(o1..o2), | ||
// }; | ||
let mut dst = unsafe { dev.alloc::<f16>(elem_count) }.w()?; | ||
self.comm.all_reduce(s, &mut dst, &ReduceOp::Sum).unwrap(); | ||
let dst = candle::CudaStorage::wrap_cuda_slice(dst, dev); | ||
Ok((dst, l.shape().clone())) | ||
} | ||
} | ||
|
||
fn all_reduce_sum(x: &Tensor, comm: &Rc<Comm>) -> Result<Tensor> { | ||
x.custom_op1(AllReduce { comm: comm.clone() }) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the core of the new thing.
- TP Row/Col
Narsil
force-pushed
the
llama_multiprocess2
branch
from
July 27, 2023 09:26
ee41ce7
to
25a2086
Compare
LaurentMazare
approved these changes
Jul 28, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Second update version of TP sharding.
all_reduce
directly and recreate a tensor from that. (That way I don't justpub
everything)I tried to keep the modifications minimal in
var_builder
for now as this is not the purpose of this PR.