Coverage for  / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / trainer / __init__.py: 55%

11 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-10-25 05:45 +0800

1# Copyright 2026 Huawei Technologies Co., Ltd 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14# ============================================================================ 

15"""Top-level training public API. 

16 

17Rebuilt in stage 7 (05 §10.1): the trainer classes moved here from 

18``auto_models/trainer/`` (S7d). Exports are lazy so that importing the 

19package (e.g. for ``trainer.config`` or ``trainer.callbacks``) stays cheap 

20and does not pull the model/data stack until a trainer class is touched. 

21""" 

22 

23__all__ = [ 

24 "BaseTrainer", 

25 "TextTrainer", 

26 "VLMTrainer", 

27 "TrainerState", 

28] 

29 

30_LAZY_EXPORTS = { 

31 "BaseTrainer": "hyper_parallel.trainer.base", 

32 "TextTrainer": "hyper_parallel.trainer.text_trainer", 

33 "VLMTrainer": "hyper_parallel.trainer.vlm_trainer", 

34 "TrainerState": "hyper_parallel.trainer.state", 

35} 

36 

37 

38def __getattr__(name): 

39 """Resolve trainer classes lazily on first attribute access.""" 

40 if name in _LAZY_EXPORTS: 

41 import importlib # pylint: disable=import-outside-toplevel 

42 

43 value = getattr(importlib.import_module(_LAZY_EXPORTS[name]), name) 

44 globals()[name] = value 

45 return value 

46 raise AttributeError(f"module {__name__!r} has no attribute {name!r}") 

47 

48 

49def __dir__(): 

50 """List lazy exports for interactive discovery.""" 

51 return sorted(__all__)