Skip to content
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
2 changes: 1 addition & 1 deletion colossalai/shardformer/modeling/gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _get_attention_mask(
# Received input is already split for non-first pipeline stages,
# but attn mask isn't
batch_size = hidden_states.size(0)
seq_len = attention_mask.size(-1)
seq_len = attention_mask.size(-1) if attention_mask is not None else hidden_states.size(1)

sp_mode = shard_config.sequence_parallelism_mode
# If a 2D or 3D attention mask is provided for the cross-attention
Expand Down
4 changes: 3 additions & 1 deletion colossalai/shardformer/policies/gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ def module_policy(self):
target_key=GPT2Attention,
)

if not self.shard_config.pipeline_stage_manager and self.shard_config.enable_sequence_parallelism:
if not self.shard_config.pipeline_stage_manager and (
self.shard_config.enable_sequence_parallelism or use_flash_attention
):
policy[GPT2Model].method_replacement = {
"forward": partial(GPT2PipelineForwards.gpt2_model_forward, shard_config=self.shard_config)
}
Expand Down
8 changes: 8 additions & 0 deletions tests/test_shardformer/test_model/test_shard_gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ def check_forward_backward(model_fn, data_gen_fn, output_transform_fn, loss_fn,
@parameterize(
"test_config",
[
{
"tp_size": 1,
"pp_size": 1,
"enable_all_optimization": True,
"use_lazy_init": False,
"precision": "fp32",
"initial_scale": 1,
},
{
"sp_size": 2,
"tp_size": 1,
Expand Down