Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9bacc1c

Browse files
committedMar 19, 2025
support ascend w8a8 graph_mode
1 parent 7c33db5 commit 9bacc1c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎lmdeploy/pytorch/models/q_modules.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (c) OpenMMLab. All rights reserved.
22

3-
from dataclasses import dataclass
3+
from dataclasses import dataclass, fields
44

55
import torch
66
import torch.nn as nn
@@ -19,13 +19,15 @@ class QTensor:
1919
scale: torch.Tensor
2020
zero_point: torch.Tensor = None
2121

22+
def __post_init__(self):
23+
self.fields = [field.name for field in fields(self)]
24+
2225
def __getattr__(self, name: str):
2326
"""Allows attribute access to be forwarded to the wrapped tensor when
2427
the attribute doesn't exist in QTensor."""
25-
try:
28+
if name in self.fields:
2629
return super().__getattr__(name)
27-
except AttributeError:
28-
return getattr(self.tensor, name)
30+
return getattr(self.tensor, name)
2931

3032

3133
class QRMSNorm(nn.Module):

0 commit comments

Comments
 (0)
Please sign in to comment.