Skip to content

Commit 7a74f96

Browse files
Arm backend: Add Qwen3 VL FP32 MXFP8 layer tests (pytorch#20485)
Add TOSA MXFP8 coverage for Qwen3 VL text attention, MLP, and decoder layer wrappers. Keep the tests in FP32 while converting linear layers to MXFP through the MXFP pipeline. Change-Id: Ib94bfdc114031a7558d42ea9e347142d721f7403 cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani Signed-off-by: Yufeng Shi <yufeng.shi@arm.com>
1 parent 84daf79 commit 7a74f96

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

backends/arm/test/models/Qwen3_VL/test_qwen3_vl_layers.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
from typing import Tuple
1010

1111
import torch
12+
from executorch.backends.arm.ao_ext import MXFPOpConfig
1213
from executorch.backends.arm.test import common
1314
from executorch.backends.arm.test.models.Qwen3_VL.qwen3_vl_test_config import (
1415
get_qwen3_vl_2b_instruct_checkpoint_config,
1516
)
17+
from executorch.backends.arm.test.ops.mxfp.common import MXFPTosaPipelineFP
1618
from executorch.backends.arm.test.tester.test_pipeline import (
1719
TosaPipelineFP,
1820
VgfPipeline,
@@ -34,6 +36,7 @@
3436
)
3537

3638
input_t = Tuple[torch.Tensor | int, ...]
39+
aten_op_mxfp_linear = "torch.ops.tosa_mxfp.linear.default"
3740

3841

3942
def _make_qwen3_vl_2b_instruct_layer_config():
@@ -112,6 +115,10 @@ def _to_bfloat16(
112115
)
113116

114117

118+
def _is_linear(module: torch.nn.Module, _fqn: str) -> bool:
119+
return isinstance(module, torch.nn.Linear)
120+
121+
115122
class Qwen3VLVisionMLPModel(Qwen3VLTestModule):
116123
def __init__(self, config) -> None:
117124
super().__init__()
@@ -468,6 +475,19 @@ class Qwen3VLTestCase:
468475
}
469476

470477

478+
TOSA_MXFP8_TEST_CASES: dict[str, Qwen3VLTestCase] = {
479+
"text_attention": Qwen3VLTestCase(
480+
model_cls=TextAttentionModel,
481+
),
482+
"text_mlp": Qwen3VLTestCase(
483+
model_cls=TextMLPModel,
484+
),
485+
"text_decoder_layer": Qwen3VLTestCase(
486+
model_cls=TextDecoderLayerModel,
487+
),
488+
}
489+
490+
471491
@common.parametrize(
472492
"test_case",
473493
TOSA_FP_TEST_CASES,
@@ -516,6 +536,30 @@ def test_qwen3_vl_tosa_FP_bf16(test_case: Qwen3VLTestCase):
516536
pipeline.run()
517537

518538

539+
@common.parametrize(
540+
"test_case",
541+
TOSA_MXFP8_TEST_CASES,
542+
)
543+
def test_qwen3_vl_tosa_mxfp8_fp32(test_case: Qwen3VLTestCase):
544+
model, inputs = test_case.model_cls.prepare_model_and_inputs()
545+
mxfp_config = MXFPOpConfig(weight_dtype=torch.float8_e4m3fn)
546+
547+
with torch.no_grad():
548+
pipeline = MXFPTosaPipelineFP[input_t](
549+
model,
550+
inputs,
551+
aten_op=aten_op_mxfp_linear,
552+
exir_op=[],
553+
filter_fn=_is_linear,
554+
frobenius_threshold=0.05,
555+
cosine_threshold=0.995,
556+
mxfp_config=mxfp_config,
557+
tosa_version="1.1",
558+
tosa_extensions=["mxfp"],
559+
)
560+
pipeline.run()
561+
562+
519563
@common.SkipIfNoModelConverter
520564
@common.parametrize(
521565
"test_case",

0 commit comments

Comments
 (0)