Skip to content

Commit

Permalink
add env to support different mm layout on maca.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinerzhou committed Nov 29, 2024
1 parent 3913ead commit 8364005
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lmdeploy/pytorch/backends/dlinfer/linear.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) OpenMMLab. All rights reserved.
import os
from typing import Optional

import torch
Expand All @@ -11,6 +12,14 @@
class DlinferLinearImpl(LinearImpl):
"""Dlinfer linear implementation api."""

def update_weights(self,
weight: torch.Tensor,
bias: Optional[torch.Tensor] = None):
"""update weights."""
if os.getenv('TORCH_MACA_NN_LAYOUT', 'False').lower() == 'false':
weight = weight.data.t().contiguous()
return weight, bias

def forward(self,
x,
weight: torch.Tensor,
Expand Down

0 comments on commit 8364005

Please sign in to comment.