|
15 | 15 | from onnxscript._internal.builder import build_function |
16 | 16 |
|
17 | 17 | from mobius._constants import OPSET_VERSION |
| 18 | +from mobius._flags import override_flags |
18 | 19 | from mobius.functions import lower_qmoe, register_function_bodies |
19 | 20 |
|
20 | 21 | ort = pytest.importorskip("onnxruntime") |
|
32 | 33 | pytestmark = _requires_opset29 |
33 | 34 |
|
34 | 35 |
|
| 36 | +@pytest.fixture(autouse=True) |
| 37 | +def _enable_experimental_opset29(): |
| 38 | + with override_flags(experimental_opset29=True): |
| 39 | + yield |
| 40 | + |
| 41 | + |
35 | 42 | def _value(name, array): |
36 | 43 | tensor = ir.tensor(array) |
37 | 44 | return ir.Value( |
@@ -457,6 +464,22 @@ def test_reject_shapes_and_types(index, shape, dtype, message): |
457 | 464 | assert model.graph.opset_imports[""] == 24 |
458 | 465 |
|
459 | 466 |
|
| 467 | +def test_lowering_requires_experimental_opset29_before_mutation(tmp_path): |
| 468 | + model = _model() |
| 469 | + register_function_bodies(model) |
| 470 | + before, after = tmp_path / "before.onnx", tmp_path / "after.onnx" |
| 471 | + ir.save(model, before) |
| 472 | + |
| 473 | + with ( |
| 474 | + override_flags(experimental_opset29=False), |
| 475 | + pytest.raises(ValueError, match="MOBIUS_EXPERIMENTAL_OPSET29=1"), |
| 476 | + ): |
| 477 | + lower_qmoe(model) |
| 478 | + |
| 479 | + ir.save(model, after) |
| 480 | + assert before.read_bytes() == after.read_bytes() |
| 481 | + |
| 482 | + |
460 | 483 | def test_native_serialization_no_automatic_opset29(tmp_path): |
461 | 484 | model = _model() |
462 | 485 | path = tmp_path / "native.onnx" |
@@ -715,13 +738,15 @@ def test_compatible_caller_function_preserved_and_aligned(tmp_path): |
715 | 738 | np.testing.assert_array_equal(actual, feeds["caller_feed"]) |
716 | 739 |
|
717 | 740 |
|
718 | | -def test_no_qmoe_does_not_align_or_reject_caller_functions(tmp_path): |
| 741 | +@pytest.mark.parametrize("enabled", [False, True]) |
| 742 | +def test_no_qmoe_does_not_align_or_reject_caller_functions(tmp_path, enabled): |
719 | 743 | function = _caller_function("Softmax", opset=11) |
720 | 744 | graph = ir.Graph([], [], nodes=[], name="no_qmoe", opset_imports={"": 24}) |
721 | 745 | model = ir.Model(graph, ir_version=10, functions=[function]) |
722 | 746 | before, after = tmp_path / "before.onnx", tmp_path / "after.onnx" |
723 | 747 | ir.save(model, before) |
724 | | - lower_qmoe(model) |
| 748 | + with override_flags(experimental_opset29=enabled): |
| 749 | + lower_qmoe(model) |
725 | 750 | ir.save(model, after) |
726 | 751 | assert before.read_bytes() == after.read_bytes() |
727 | 752 | assert function.opset_imports[""] == 11 |
|
0 commit comments