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

5 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""" 

16HyperParallel Graph Mode - Graph-mode architecture for HyperParallel 

17 

18Graph-mode architecture for automatic parallelization. 

19 

20Core Features: 

21- Users write model code + parallel configuration 

22- Framework automatically handles all parallel logic 

23- Graph capture → Parallel partitioning → Communication-compute overlap → Execution 

24 

25Usage Example: 

26 from hyper_parallel.compile import ( 

27 GraphCompiler, 

28 GraphParallelPlan, 

29 GraphTrainer, 

30 PassConfig, 

31 ) 

32 

33 # Create model 

34 model = Llama3ForCausalLM(config) 

35 

36 # Configure parallelism 

37 pass_config = PassConfig(enable_overlap=True) 

38 

39 # Build parallel plan 

40 parallel_plan = GraphParallelPlan() 

41 parallel_plan.fsdp_mark_pattern("layers.*") 

42 

43 # Compile + forward_backward only (no optimizer / training loop); model 

44 # inputs travel as kwargs, forwarded to train_fn(model, **inputs): 

45 compiler = GraphCompiler(model, train_fn, pass_config, parallel_plan) 

46 compiler.compile(input_ids=input_ids, labels=labels) 

47 loss = compiler.forward_backward(input_ids=input_ids, labels=labels) # grads -> param.grad 

48 

49 # Or drive the whole train/optimize loop -- the trainer composes a 

50 # GraphCompiler, compiles on the first batch, moves each input dict onto 

51 # its device, and owns the optimizer. data_iterable yields input dicts: 

52 trainer = GraphTrainer(model, train_fn, pass_config, parallel_plan) 

53 trainer.train(dataloader, max_steps=100, log_interval=10) 

54""" 

55 

56from .compiler import GraphCompiler 

57 

58from .graph_parallel_plan import ( 

59 GraphParallelPlan, 

60 create_all_fsdp_plan, 

61 create_plan_from_yaml, 

62) 

63 

64from .pass_config import PassConfig 

65 

66from .trainer import GraphTrainer 

67 

68__all__ = [ 

69 # Parallel plan 

70 "GraphParallelPlan", 

71 "create_plan_from_yaml", 

72 "create_all_fsdp_plan", 

73 # Config 

74 "PassConfig", 

75 # Compiler (compile + forward_backward only) 

76 "GraphCompiler", 

77 # Trainer 

78 "GraphTrainer", 

79]