Skip to content

Commit e8c47d7

Browse files
authored
Arm backend: Add DeepSeek-R1-Distill-Qwen FP8 layer tests (#21012)
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani
1 parent 2da24ae commit e8c47d7

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

backends/arm/test/models/DeepSeek_R1_Distill_Qwen/test_deepseek_r1_distill_qwen_layers.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
import pytest
1212
import torch
13+
from executorch.backends.arm.ao_ext import MXFPOpConfig
1314
from executorch.backends.arm.test import common
1415
from executorch.backends.arm.test.models.DeepSeek_R1_Distill_Qwen.deepseek_r1_distill_qwen_test_config import (
1516
get_deepseek_r1_distill_qwen_1_5b_checkpoint_config,
1617
)
18+
from executorch.backends.arm.test.ops.mxfp.common import MXFPTosaPipelineFP
1719
from executorch.backends.arm.test.tester.test_pipeline import (
1820
TosaPipelineFP,
1921
VgfPipeline,
@@ -32,6 +34,7 @@
3234
)
3335

3436
input_t = Tuple[torch.Tensor, ...]
37+
aten_op_mxfp_linear = "torch.ops.tosa_mxfp.linear.default"
3538

3639

3740
def _make_deepseek_r1_distill_qwen_1_5b_layer_config():
@@ -84,6 +87,10 @@ def _to_bfloat16(
8487
)
8588

8689

90+
def _is_linear(module: torch.nn.Module, _fqn: str) -> bool:
91+
return isinstance(module, torch.nn.Linear)
92+
93+
8794
class RotaryEmbeddingModel(DeepSeekR1DistillQwenTestModule):
8895
def __init__(self, config) -> None:
8996
super().__init__()
@@ -326,6 +333,12 @@ class DeepSeekR1DistillQwenTestCase:
326333
TOSA_BF16_TEST_CASES
327334
)
328335

336+
TOSA_MXFP8_TEST_CASES: dict[str, DeepSeekR1DistillQwenTestCase] = {
337+
"attention": DeepSeekR1DistillQwenTestCase(model_cls=AttentionModel),
338+
"mlp": DeepSeekR1DistillQwenTestCase(model_cls=MLPModel),
339+
"decoder_layer": DeepSeekR1DistillQwenTestCase(model_cls=DecoderLayerModel),
340+
}
341+
329342

330343
@common.parametrize(
331344
"test_case",
@@ -369,6 +382,59 @@ def test_deepseek_r1_distill_qwen_tosa_FP_bf16(
369382
pipeline.run()
370383

371384

385+
@common.parametrize(
386+
"test_case",
387+
TOSA_MXFP8_TEST_CASES,
388+
)
389+
def test_deepseek_r1_distill_qwen_tosa_mxfp8_fp32(
390+
test_case: DeepSeekR1DistillQwenTestCase,
391+
):
392+
model, inputs = test_case.model_cls.prepare_model_and_inputs()
393+
mxfp_config = MXFPOpConfig(weight_dtype=torch.float8_e4m3fn)
394+
395+
with torch.no_grad():
396+
pipeline = MXFPTosaPipelineFP[input_t](
397+
model,
398+
inputs,
399+
aten_op=aten_op_mxfp_linear,
400+
exir_op=[],
401+
filter_fn=_is_linear,
402+
frobenius_threshold=0.05,
403+
cosine_threshold=0.995,
404+
mxfp_config=mxfp_config,
405+
tosa_version="1.1",
406+
tosa_extensions=["mxfp"],
407+
)
408+
pipeline.run()
409+
410+
411+
@common.parametrize(
412+
"test_case",
413+
TOSA_MXFP8_TEST_CASES,
414+
)
415+
def test_deepseek_r1_distill_qwen_tosa_mxfp8_bf16(
416+
test_case: DeepSeekR1DistillQwenTestCase,
417+
):
418+
model, inputs = test_case.model_cls.prepare_model_and_inputs()
419+
model, inputs = _to_bfloat16(model, inputs)
420+
mxfp_config = MXFPOpConfig(weight_dtype=torch.float8_e4m3fn)
421+
422+
with torch.no_grad():
423+
pipeline = MXFPTosaPipelineFP[input_t](
424+
model,
425+
inputs,
426+
aten_op=aten_op_mxfp_linear,
427+
exir_op=[],
428+
filter_fn=_is_linear,
429+
frobenius_threshold=0.05,
430+
cosine_threshold=0.995,
431+
mxfp_config=mxfp_config,
432+
tosa_version="1.1",
433+
tosa_extensions=["bf16", "mxfp"],
434+
)
435+
pipeline.run()
436+
437+
372438
@common.SkipIfNoModelConverter
373439
@common.parametrize(
374440
"test_case",

0 commit comments

Comments
 (0)