Skip to content

Commit 210c54b

Browse files
committed
[distributed] Require torch>=2.10 for context parallelism
1 parent f1371dc commit 210c54b

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎src/transformers/distributed/configuration_utils.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ def _validate_mesh_config(self):
192192
raise ValueError("`ep_size` must divide `fsdp_size * cp_size * tp_size`.")
193193

194194
if self.cp_size > 1:
195+
if not is_torch_greater_or_equal("2.10"):
196+
raise OSError("Context parallelism requires `torch>=2.10` (`DeviceMesh._unflatten`).")
195197
unsupported = [name for name in ("pp_size", "ep_size") if getattr(self, name) > 1]
196198
if unsupported:
197199
raise ValueError(

‎tests/context_parallel/test_context_parallel.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from transformers.masking_utils import create_causal_mask
4444
from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS
4545
from transformers.testing_utils import require_flash_attn, require_torch_multi_accelerator
46+
from transformers.utils import is_torch_greater_or_equal
4647

4748
from ..distributed_testing_utils import run_distributed
4849
from ..test_fsdp_mixin import _deterministic_init_model_dir, _distributed_tmpdir
@@ -721,6 +722,10 @@ def _test_save_load_distributed_checkpoint(rank, cp_size):
721722

722723

723724
class TestContextParallelConfig(unittest.TestCase):
725+
def setUp(self):
726+
if not is_torch_greater_or_equal("2.10"):
727+
self.skipTest("Context parallelism requires torch>=2.10")
728+
724729
def test_refuses_other_parallelisms(self):
725730
for other in ({"pp_size": 2}, {"ep_size": 2}):
726731
with self.subTest(**other), self.assertRaisesRegex(ValueError, "not supported yet with"):
@@ -743,6 +748,8 @@ class TestContextParallelModel(unittest.TestCase):
743748
def setUp(self):
744749
if torch._C._get_accelerator().type == "mps":
745750
self.skipTest("Distributed meshes are built on the default accelerator, which MPS cannot back")
751+
if not is_torch_greater_or_equal("2.10"):
752+
self.skipTest("Context parallelism requires torch>=2.10")
746753

747754
def test_matches_unsharded(self):
748755
for packed in (False, True):

0 commit comments

Comments
 (0)