Skip to content

Commit 5acd8bd

Browse files
committed
Merge branch 'cp-5-docs' into cp-6-tp-x-cp
2 parents 4b7f076 + fea7319 commit 5acd8bd

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎src/transformers/distributed/context_parallel.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ def _check_context_parallelism(model: nn.Module) -> None:
242242
"disable context parallelism."
243243
)
244244

245+
if model._is_stateful:
246+
raise ValueError(
247+
f"Context parallelism does not support {model.__class__.__name__}: its recurrent layers carry a state "
248+
"along the sequence, so they would run on this rank's slice only and be silently cut at the slice "
249+
"boundaries. Use another model, or disable context parallelism."
250+
)
251+
245252
text_config = model.config.get_text_config()
246253
layer_types = set(getattr(text_config, "layer_types", None) or ())
247254
if unsupported := layer_types - set(SOFTMAX_ATTENTION_LAYER_TYPES):

‎tests/context_parallel/test_context_parallel.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,13 @@ class LlamaWithOwnAttention(LlamaForCausalLM):
419419
with self.assertRaisesRegex(ValueError, "`_supports_attention_backend`"):
420420
self._check(LlamaWithOwnAttention(_tiny_config()))
421421

422+
def test_refuses_stateful_models(self):
423+
class StatefulLlama(LlamaForCausalLM):
424+
_is_stateful = True
425+
426+
with self.assertRaisesRegex(ValueError, "carry a state along the sequence"):
427+
self._check(StatefulLlama(_tiny_config()))
428+
422429
def test_refuses_layers_that_mix_tokens_outside_attention(self):
423430
config = _tiny_config()
424431
config.layer_types = ["full_attention", "linear_attention"]

0 commit comments

Comments
 (0)