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

[Bug] fix sp bug when global_bs = 1 #435

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

foreverpiano
Copy link

@foreverpiano foreverpiano commented Sep 8, 2024

The original code has a bug when use reshape(-1) for automatic data layout inferring. Move it to fixed data layout.

Failed case: train_batch_size = 1, sp_size = 4, train_sp_batch_size=1.

hidden_states = rearrange(hidden_states, 'b h s d -> s b h d')
hidden_states = hidden_states.reshape(-1, attn.heads // sp_size, head_dim)
# [s * b, h // sp, d] -> [s // sp * b, h, d] -> [s // sp, b, h * d]
hidden_states = all_to_all_SBH(hidden_states, scatter_dim=0, gather_dim=1).reshape(-1, batch_size, h_size)

change to

hidden_states = rearrange(hidden_states, 'b h s d -> s h b d').contiguous()
hidden_states = all_to_all_SBH(hidden_states, scatter_dim=0, gather_dim=1)
# [s * b, h // sp, d] -> [s // sp * b, h, d] -> [s // sp, b, h * d]
hidden_states = rearrange(hidden_states, 's h b d -> s b (h d)').contiguous()

@LinB203 @apprivoiser

@foreverpiano foreverpiano changed the title fix sp bug when global_bs = 1 [Bug] fix sp bug when global_bs = 1 Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant