Skip to content
Merged
Changes from all 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
19 changes: 17 additions & 2 deletions vllm_omni/diffusion/layers/adalayernorm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from importlib.util import find_spec

import torch
import torch.nn as nn
from vllm.logger import init_logger
Expand All @@ -6,6 +8,8 @@

logger = init_logger(__name__)

_HAS_MINDIESD = find_spec("mindiesd") is not None


class AdaLayerNorm(CustomOp):
"""
Expand Down Expand Up @@ -83,10 +87,21 @@ def forward_npu(
) -> torch.Tensor:
shift_result, scale_result, gate_result = self.preprocess(mod_params, index)

if _HAS_MINDIESD:
try:
from mindiesd import layernorm_scale_shift

output = layernorm_scale_shift(self.layernorm, x, scale_result, shift_result, fused=True)

return output, gate_result
except ImportError as e:
logger.warning_once(f"mindiesd import failed, falling back to torch_npu: {e}")

import torch_npu

output = torch_npu.npu_layer_norm_eval(
x, normalized_shape=[self.hidden_size], weight=(1 + scale_result), bias=shift_result, eps=self.eps
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Duplicated line. Remove one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you mean the rebundant logger.warning_once? I have pull request to solve it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

output = (
torch_npu.npu_layer_norm_eval(x, normalized_shape=[self.hidden_size], eps=self.eps) * (1 + scale_result)
+ shift_result
)

return output, gate_result
Expand Down