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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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