Skip to content

Commit 89e108c

Browse files
authored
Fix the Samsung MobileBert test setup so it can run (pytorch#22550)
### Summary The Samsung model test job runs every test under `backends/samsung/test/models`. One of those tests, the MobileBert fine-tuning test, always errors out before it does any work: ``` ERROR: setUpClass (test_mobilebert_finetuning.Test_Milestone_MobileBertFinetune) AttributeError: type object 'Test_Milestone_MobileBertFinetune' has no attribute 'model_cache_dir' ``` One error fails the whole job, so the other ten Samsung model tests passing does not help. The job only runs the tests when a Samsung device is available, which is why this looks like it comes and goes. There were three separate problems stacked in the test setup, and each one was hidden behind the one before it: 1. `setUpClass` read `cls.model_cache_dir`, which is not defined anywhere. 2. It passed that value to `patch_mobilebert_finetuning()`, which takes no arguments. Python only checks the number of arguments when the call happens, so this could not be seen until the first problem was gone. 3. The setup replaced `load_tokenizer` with a copy of itself that left out the model name, so `AutoTokenizer.from_pretrained()` had nothing to load. The replacement tokenizer loader was the same as the real one except for the missing model name, so it could only ever do less than the real one. Removing the setup that installed it fixes all three problems at once and lets the test use the real loader. The test now has the same shape as the other ten tests in the same directory, which build a model and check it with no extra setup. ### Test plan Ran the real test collection and setup for this file before and after the change, with the heavy third party dependencies stubbed out so only the setup path was under test. - Before: reproduces the same `AttributeError` seen in CI, and never reaches the test body. - After: setup succeeds and the test body is reached. Also checked that `model_cache_dir`, `setUpClass` and the now unused `AutoTokenizer` import are all gone, and that the file still compiles.
1 parent c65b23a commit 89e108c

1 file changed

Lines changed: 0 additions & 26 deletions

File tree

‎backends/samsung/test/models/test_mobilebert_finetuning.py‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,10 @@
1212
)
1313
from executorch.backends.samsung.test.tester import SamsungTester
1414
from executorch.backends.samsung.test.utils.utils import TestConfig
15-
1615
from executorch.examples.samsung.scripts.mobilebert_finetune import MobileBertFinetune
17-
from transformers import AutoTokenizer
18-
19-
20-
def patch_mobilebert_finetuning():
21-
def _monkeypatch_load_tokenizer(self):
22-
tokenizer = AutoTokenizer.from_pretrained(
23-
do_lower_case=True,
24-
)
25-
return tokenizer
26-
27-
old_func = MobileBertFinetune.load_tokenizer
28-
MobileBertFinetune.load_tokenizer = _monkeypatch_load_tokenizer
29-
return old_func
30-
31-
32-
def recover_mobilebert_finetuning(old_func):
33-
MobileBertFinetune.load_tokenizer = old_func
3416

3517

3618
class Test_Milestone_MobileBertFinetune(unittest.TestCase):
37-
@classmethod
38-
def setUpClass(cls):
39-
cls._old_func = patch_mobilebert_finetuning(cls.model_cache_dir)
40-
41-
@classmethod
42-
def tearDownClass(cls):
43-
recover_mobilebert_finetuning(cls._old_func)
44-
4519
def test_mobilebert_finetuning_fp16(self):
4620
mobilebert_finetune = MobileBertFinetune()
4721
model, _ = mobilebert_finetune.get_finetune_mobilebert(None)

0 commit comments

Comments
 (0)