Skip to content

Commit a812429

Browse files
tom-armbdemirb
andauthored
Arm backend: Add Qwen3 VL language model MXFP8 test (pytorch#20533)
* Add an E2E TOSA test for the Qwen3 VL language model with linear layers converted to MXFP8. cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani Co-authored-by: Baris Demir <baris.demir@arm.com>
1 parent f11805c commit a812429

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

‎backends/arm/test/models/Qwen3_VL/test_qwen3_vl_model.py‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
import pytest
1212
import torch
1313
import torch.nn.functional as F
14+
from executorch.backends.arm.ao_ext import MXFPOpConfig
1415
from executorch.backends.arm.test import common
1516
from executorch.backends.arm.test.models.Qwen3_VL.qwen3_vl_test_config import (
1617
get_qwen3_vl_2b_instruct_checkpoint_config,
1718
)
19+
from executorch.backends.arm.test.ops.mxfp.common import MXFPTosaPipelineFP
1820
from executorch.backends.arm.test.tester.test_pipeline import (
1921
TosaPipelineFP,
2022
VgfPipeline,
@@ -25,6 +27,7 @@
2527
)
2628

2729
input_t = Tuple[torch.Tensor, ...]
30+
aten_op_mxfp_linear = "torch.ops.tosa_mxfp.linear.default"
2831

2932

3033
def _make_qwen3_vl_2b_instruct_layer_config():
@@ -104,6 +107,10 @@ def _to_bfloat16_model_and_floating_inputs(
104107
)
105108

106109

110+
def _is_linear(module: torch.nn.Module, _fqn: str) -> bool:
111+
return isinstance(module, torch.nn.Linear)
112+
113+
107114
class TextModelWrapper(Qwen3VLModelTestModule):
108115
def __init__(self, config) -> None:
109116
super().__init__()
@@ -300,3 +307,35 @@ def test_qwen3_vl_full_models_vgf_no_quant_bf16(test_case: Qwen3VLModelTestCase)
300307
tosa_spec="TOSA-1.0+FP+bf16",
301308
)
302309
pipeline.run()
310+
311+
312+
@pytest.mark.slow
313+
def test_qwen3_vl_text_model_tosa_mxfp8_bf16():
314+
# The Qwen 3 VL FP8 model only quantizes the TextModel
315+
model, inputs = TextModelWrapper.prepare_model_and_inputs()
316+
model, inputs = _to_bfloat16_model_and_floating_inputs(model, inputs)
317+
mxfp_config = MXFPOpConfig(weight_dtype=torch.float8_e4m3fn)
318+
with torch.no_grad():
319+
pipeline = MXFPTosaPipelineFP[input_t](
320+
model,
321+
inputs,
322+
aten_op=aten_op_mxfp_linear,
323+
exir_op=[],
324+
filter_fn=_is_linear,
325+
frobenius_threshold=0.1,
326+
cosine_threshold=0.98,
327+
mxfp_config=mxfp_config,
328+
tosa_version="1.1",
329+
tosa_extensions=["bf16", "mxfp"],
330+
)
331+
# Check all linear layers are converted to MXFP
332+
linear_count = sum(
333+
_is_linear(submodule, name) for name, submodule in model.named_modules()
334+
)
335+
pipeline.add_stage_after(
336+
"export",
337+
pipeline.tester.check_count,
338+
{aten_op_mxfp_linear: linear_count},
339+
suffix="mxfp_linear",
340+
)
341+
pipeline.run()

0 commit comments

Comments
 (0)