From b01fb0f8ce8f8ce2ab574e7de9ec12afe1789b61 Mon Sep 17 00:00:00 2001 From: Qubitium Date: Sat, 8 Aug 2026 00:27:34 +0000 Subject: [PATCH] fix test fakes drift and MoE subset hook-order flake Port of GPT-QModel-Ultra PR #224 to upstream, limited to what applies here: - test_calibration_data_device.py: StageInputsCapture.cache_inputs calls get_modules_with_direct_meta_tensors on the model, but the three FakeGPTQModel stubs predate that API, so the stage-capture tests failed with AttributeError on multi-GPU hosts. Add the classmethod stub returning an empty list. - test_subset.py: test_qwen3_5_moe_subset_early_stop_follows_module_tree_ execution_order asserts the last forward hook is mlp.experts.3.up_proj, but with num_experts_per_tok=2 the executed expert set comes from the random router weights, whose RNG state shifts with prior test files, so the test flakes. Route all experts (num_experts_per_tok=4) to make the executed set and hook order deterministic. The HRM module_path and get_input_embeddings/offload_to_disk fake updates from the ultra PR do not apply upstream (those APIs do not exist here). --- tests/module_tree/test_subset.py | 7 ++++++- tests/test_calibration_data_device.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/module_tree/test_subset.py b/tests/module_tree/test_subset.py index 4ac5958e9..ef41ea711 100644 --- a/tests/module_tree/test_subset.py +++ b/tests/module_tree/test_subset.py @@ -573,7 +573,12 @@ def test_qwen3_5_moe_subset_early_stop_follows_module_tree_execution_order(): num_attention_heads=4, num_key_value_heads=4, num_experts=4, - num_experts_per_tok=2, + # Route all experts: with top-k < num_experts the executed expert set + # (and therefore the forward-hook order asserted below) depends on the + # random router weights, which shift with prior RNG consumption in + # other test files. Routing every expert keeps the subset execution + # order fully deterministic. + num_experts_per_tok=4, vocab_size=128, pad_token_id=0, bos_token_id=1, diff --git a/tests/test_calibration_data_device.py b/tests/test_calibration_data_device.py index 372ddf40e..01cd97ef4 100644 --- a/tests/test_calibration_data_device.py +++ b/tests/test_calibration_data_device.py @@ -241,6 +241,10 @@ def shell_module_materialize(self, target_submodule, device, **kwargs): def get_base_modules(self, model): return [] + @classmethod + def get_modules_with_direct_meta_tensors(cls, model): + return [] + def pre_quantize_generate_hook_start(self): pass @@ -387,6 +391,10 @@ def shell_module_materialize(self, target_submodule, device, **kwargs): def get_base_modules(self, model): return [] + @classmethod + def get_modules_with_direct_meta_tensors(cls, model): + return [] + def pre_quantize_generate_hook_start(self): pass @@ -542,6 +550,10 @@ def shell_module_materialize(self, target_submodule, device, **kwargs): def get_base_modules(self, model): return [] + @classmethod + def get_modules_with_direct_meta_tensors(cls, model): + return [] + def pre_quantize_generate_hook_start(self): pass