File tree Expand file tree Collapse file tree
src/transformers/distributed Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ):
Original file line number Diff line number Diff 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" ]
You can’t perform that action at this time.
0 commit comments