deepspeedai / deepspeedai/DeepSpeed

[BUG] circular import on `DeepSpeedTransformerInference`

Open
#7,159 5 comments 0 reactions 1 assignee View on GitHub

@loadams is already working on this.

Since Mar 20, 2025.

bug inference
Dominant language
Python
Stars
43.1k
Forks
5k
Avg merge
4d 15h
Merged PRs (30d)
112

Description

Describe the bug

I am getting this circular import error in CI with deepspeed==0.15.4, triton==0.3.2, and torch==2.6.0:

    from deepspeed import DeepSpeedEngine
.venv/lib/python3.12/site-packages/deepspeed/__init__.py:25: in <module>
    from . import ops
.venv/lib/python3.12/site-packages/deepspeed/ops/__init__.py:11: in <module>
    from . import transformer
.venv/lib/python3.12/site-packages/deepspeed/ops/transformer/__init__.py:8: in <module>
    from ...model_implementations.transformers.ds_transformer import DeepSpeedTransformerInference
.venv/lib/python3.12/site-packages/deepspeed/model_implementations/transformers/ds_transformer.py:18: in <module>
    from deepspeed.ops.transformer.inference.triton.mlp import TritonMLP
.venv/lib/python3.12/site-packages/deepspeed/ops/transformer/inference/__init__.py:7: in <module>
    from ....model_implementations.transformers.ds_transformer import DeepSpeedTransformerInference
E   ImportError: cannot import name 'DeepSpeedTransformerInference' from partially initialized module 'deepspeed.model_implementations.transformers.ds_transformer' (most likely due to a circular import) (/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/deepspeed/model_implementations/transformers/ds_transformer.py)

To Reproduce

from deepspeed import DeepSpeedEngine

Expected behavior

Not to have a circular import.

ds_report output

uv run python -m deepspeed.env_report crashes:

Traceback (most recent call last):
  File "<frozen runpy>", line 18[9](https://github.com/org/repo/actions/runs/13976826925/job/39132580550?pr=322#step:5:10), in _run_module_as_main
  File "<frozen runpy>", line 112, in _get_module_details
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/deepspeed/__init__.py", line 25, in <module>
    from . import ops
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/deepspeed/ops/__init__.py", line 11, in <module>
    from . import transformer
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/deepspeed/ops/transformer/__init__.py", line 7, in <module>
    from .inference.config import DeepSpeedInferenceConfig
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/deepspeed/ops/transformer/inference/__init__.py", line 7, in <module>
    from ....model_implementations.transformers.ds_transformer import DeepSpeedTransformerInference
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/deepspeed/model_implementations/__init__.py", line 6, in <module>
    from .transformers.ds_transformer import DeepSpeedTransformerInference
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/deepspeed/model_implementations/transformers/ds_transformer.py", line 18, in <module>
    from deepspeed.ops.transformer.inference.triton.mlp import TritonMLP
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/deepspeed/ops/transformer/inference/triton/__init__.py", line [10](https://github.com/org/repo/actions/runs/13976826925/job/39132580550?pr=322#step:5:11), in <module>
    from .ops import *
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/deepspeed/ops/transformer/inference/triton/ops.py", line 6, in <module>
    import deepspeed.ops.transformer.inference.triton.matmul_ext as matmul_ext
  File "/home/runner/work/repo/repo/.venv/lib/python3.[12](https://github.com/org/repo/actions/runs/13976826925/job/39132580550?pr=322#step:5:13)/site-packages/deepspeed/ops/transformer/inference/triton/matmul_ext.py", line 10, in <module>
    import deepspeed.ops.transformer.inference.triton.triton_matmul_kernel as triton_matmul_kernel
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/deepspeed/ops/transformer/inference/triton/triton_matmul_kernel.py", line 51, in <module>
    @triton.autotune(
     ^^^^^^^^^^^^^^^^
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/triton/runtime/autotuner.py", line 368, in decorator
    return Autotuner(fn, fn.arg_names, configs, key, reset_to_zero, restore_value, pre_hook=pre_hook,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/triton/runtime/autotuner.py", line [13](https://github.com/org/repo/actions/runs/13976826925/job/39132580550?pr=322#step:5:14)0, in __init__
    self.do_bench = driver.active.get_benchmarker()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/triton/runtime/driver.py", line 23, in __getattr__
    self._initialize_obj()
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/triton/runtime/driver.py", line 20, in _initialize_obj
    self._obj = self._init_fn()
                ^^^^^^^^^^^^^^^
  File "/home/runner/work/repo/repo/.venv/lib/python3.12/site-packages/triton/runtime/driver.py", line 8, in _create_driver
    raise RuntimeError(f"{len(actives)} active drivers ({actives}). There should only be one.")
RuntimeError: 0 active drivers ([]). There should only be one.

Screenshots

N/a

System info (please complete the following information):

In GitHub Actions' ubuntu-latest runner as of 3/20/2025 with Python 3.12.3

deepspeed==0.15.4
torch==2.6.0
triton==0.3.2

Docker context

N/a

Additional context

N/a

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.