Skip to content

[BUG] AutoEP breaks Python 3.9 compatibility -- TypeError: unsupported operand type(s) for |: 'type' and 'NoneType' #8102

Description

@XAheli

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions