Fix Switch Transformers When sparse_step = 1 (#28564)

Fix sparse_step = 1

I case sparse_step = 1, the current code will not work.
This commit is contained in:
Ahmed Elnaggar 2024-01-17 22:26:21 +01:00 committed by GitHub
parent fa6d12f74f
commit 98dda8ed03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -898,7 +898,7 @@ class SwitchTransformersStack(SwitchTransformersPreTrainedModel):
config.num_layers = config.num_decoder_layers if self.is_decoder else config.num_layers
self.block = nn.ModuleList()
for i in range(config.num_layers):
is_sparse = (i % sparse_step == 1) if sparse_step > 0 else False
is_sparse = (i % sparse_step == 1 or sparse_step == 1) if sparse_step > 0 else False
self.block.append(
SwitchTransformersBlock(config, has_relative_attention_bias=bool(i == 0), is_sparse=is_sparse)