Skip to content

Commit 4f1b772

Browse files
committed
Arm backend: Use MXFP op config values directly
Use the weight dtype and block size on MXFP linear and Conv2d directly instead of accessing them through the config. Signed-off-by: Martin Lindström <Martin.Lindstroem@arm.com> Change-Id: Iffc96d00a887ffbcdf94f3af6d535b4d538451fb
1 parent 252f57c commit 4f1b772

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

‎backends/arm/ao_ext/ops/mxfp_conv2d_op.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,12 @@ def __init__(
206206
padding: tuple[int, int],
207207
dilation: tuple[int, int],
208208
groups: int,
209-
config: MXFPOpConfig,
209+
weight_dtype: MXFPDType,
210+
block_size: int,
210211
) -> None:
211212
super().__init__()
212-
self.config = config
213-
self.weight_dtype = mxfp_dtype_to_str(config.weight_dtype)
213+
self.weight_dtype = mxfp_dtype_to_str(weight_dtype)
214+
self.block_size = block_size
214215

215216
self.register_buffer("weight_qdata", weight_qdata, persistent=True)
216217
self.register_buffer("weight_scale", weight_scale, persistent=True)
@@ -241,7 +242,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
241242
list(self.padding),
242243
list(self.dilation),
243244
self.groups,
244-
self.config.block_size,
245+
self.block_size,
245246
self.weight_dtype,
246247
)
247248

@@ -283,5 +284,6 @@ def transform_conv2d_to_mxfp(
283284
padding,
284285
dilation,
285286
module.groups,
286-
config,
287+
config.weight_dtype,
288+
config.block_size,
287289
)

‎backends/arm/ao_ext/ops/mxfp_linear_op.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@ def __init__(
137137
weight_qdata: torch.Tensor,
138138
weight_scale: torch.Tensor,
139139
bias: torch.Tensor | None,
140-
config: MXFPOpConfig,
140+
weight_dtype: MXFPDType,
141+
block_size: int,
141142
) -> None:
142143
super().__init__()
143-
self.config = config
144-
self.weight_dtype = mxfp_dtype_to_str(config.weight_dtype)
144+
self.weight_dtype = mxfp_dtype_to_str(weight_dtype)
145+
self.block_size = block_size
145146

146147
self.register_buffer("weight_qdata", weight_qdata, persistent=True)
147148
self.register_buffer("weight_scale", weight_scale, persistent=True)
@@ -163,7 +164,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
163164
self.weight_qdata,
164165
self.weight_scale,
165166
self.bias,
166-
self.config.block_size,
167+
self.block_size,
167168
self.weight_dtype,
168169
)
169170

@@ -195,4 +196,10 @@ def transform_linear_to_mxfp(
195196
weight_scale = weight_scale.unsqueeze(0)
196197

197198
bias = module.bias.detach().to(torch.float32) if module.bias is not None else None
198-
return MXFPLinearOp(weight_qdata, weight_scale, bias, config)
199+
return MXFPLinearOp(
200+
weight_qdata,
201+
weight_scale,
202+
bias,
203+
config.weight_dtype,
204+
config.block_size,
205+
)

0 commit comments

Comments
 (0)