Describe the bug
After the AutoEP feature was merged (#7938, #8060), DeepSpeed fails on Python 3.9 with:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
The AutoEP modules use Python 3.10+ union type syntax (str | None, int | None) in runtime type annotations. On Python 3.9, these are evaluated at import time and raise TypeError.
The imports in engine.py are guarded with try/except ImportError, but TypeError escapes:
# engine.py lines 1611, 1685, 3627
try:
from deepspeed.module_inject.auto_ep_layer import AutoEPMoELayer as _AutoEPMoELayer
except ImportError: # <-- doesn't catch TypeError from str | None syntax
_AutoEPMoELayer = None
To reproduce
# On Python 3.9
python3.9 -c "from deepspeed.module_inject.auto_ep import AutoEP"
# TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
Or run any DeepSpeed training script:
deepspeed --num_gpus=2 test_script.py --deepspeed_config ds_config_z3.json
# Crashes in deepspeed.initialize() -> _configure_distributed_model()
Affected files
deepspeed/module_inject/auto_ep.py — lines 62, 110, 115, 231, 232
deepspeed/module_inject/auto_ep_presets/base.py — lines 36, 52, 68, 79, 80, 85, 86, 102-115
Environment
- Python: 3.9.25
- DeepSpeed: 0.19.3 (current master, commit 5aef6d8)
- torch: 2.8.0+cu128
- OS: RHEL 9
Describe the bug
After the AutoEP feature was merged (#7938, #8060), DeepSpeed fails on Python 3.9 with:
The AutoEP modules use Python 3.10+ union type syntax (
str | None,int | None) in runtime type annotations. On Python 3.9, these are evaluated at import time and raiseTypeError.The imports in
engine.pyare guarded withtry/except ImportError, butTypeErrorescapes:To reproduce
Or run any DeepSpeed training script:
deepspeed --num_gpus=2 test_script.py --deepspeed_config ds_config_z3.json # Crashes in deepspeed.initialize() -> _configure_distributed_model()Affected files
deepspeed/module_inject/auto_ep.py— lines 62, 110, 115, 231, 232deepspeed/module_inject/auto_ep_presets/base.py— lines 36, 52, 68, 79, 80, 85, 86, 102-115Environment