Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix circular import in ds_transformer.py #5804

Closed
wants to merge 9 commits into from
10 changes: 7 additions & 3 deletions deepspeed/model_implementations/transformers/ds_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
from deepspeed.accelerator import get_accelerator
from deepspeed.ops.op_builder import InferenceBuilder
import deepspeed
if deepspeed.HAS_TRITON:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eonsparks - could you please run the pre-commit formatter (pre-commit run --all-files) to resolve te formatting errors?

from deepspeed.ops.transformer.inference.triton.mlp import TritonMLP
from deepspeed.ops.transformer.inference.triton.attention import TritonSelfAttention

inference_module = None

Expand All @@ -38,6 +35,9 @@ class DeepSpeedTransformerInference(nn.Module):
"""
layer_id = 0

class DeepSpeedTransformerInference(nn.Module):
layer_id = 0

def __init__(self,
config,
mp_group=None,
Expand Down Expand Up @@ -67,12 +67,16 @@ def __init__(self,
assert not self.config.use_triton
else:
if deepspeed.HAS_TRITON and self.config.use_triton:
# Lazy import to avoid circular dependency
from deepspeed.ops.transformer.inference.triton.attention import TritonSelfAttention
self.attention = TritonSelfAttention(self.config)
else:
self.attention = DeepSpeedSelfAttention(self.config, mp_group, quantize_scales, quantize_groups,
merge_count)

if deepspeed.HAS_TRITON and self.config.use_triton:
# Lazy import to avoid circular dependency
from deepspeed.ops.transformer.inference.triton.mlp import TritonMLP
self.mlp = TritonMLP(self.config)
else:
self.mlp = DeepSpeedMLP(self.config, mp_group, quantize_scales, quantize_groups, merge_count,
Expand Down
Loading