Coverage for  / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / codegen / inline / templates.py: 0%

4 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"""Inline strategy templates rendered into generated modeling files.""" 

16 

17from __future__ import annotations 

18 

19 

20#: Bare parallel operators for the generated forwards. The generated file no 

21#: longer embeds its own operator class or a module-level state accessor: 

22#: ``runtime.TPOperators`` (wrapping the native 

23#: ``create_tp_collective_lowerer``) is bound to the instance as ``_hp_tp`` 

24#: at install time by the boundary install path, next to the 

25#: ``{tp,cp,ep}_enable`` guards — so a boundary-lowered forward and a switch 

26#: (toggle) forward dispatch through one production collective path. An inline 

27#: *strategy* body (the shell below) reads only the EP channel 

28#: (``self.ep_enable`` / ``self._hp_ep_group``), which 

29#: ``hp_bind_inline_state`` binds. 

30MOE_EP_FORWARD_SHELL = '''"""Inline EP routed MoE forward (framework generic).""" 

31if not self.ep_enable: 

32 return self._forward_impl(hidden_states) 

33 

34return moe_ep_forward( 

35 self, 

36 hidden_states, 

37 router_kind={router_kind!r}, 

38 shared={shared!r}, 

39 ep_group=self._hp_ep_group, 

40) 

41''' 

42 

43 

44def moe_ep_forward_body(router_kind: str, shared: str) -> str: 

45 """Return the thin inline EP forward body for the given structural keys. 

46 

47 A single shared body referenced by every MoE render spec. The only 

48 inputs are the structure-selected router kind and shared merge mode, so 

49 no model-family EP dispatch literal remains in any adapter. 

50 

51 Args: 

52 router_kind: Structural key selecting the router implementation. 

53 shared: Structural key selecting the shared-expert merge mode. 

54 

55 Returns: 

56 The rendered forward body source. 

57 """ 

58 return MOE_EP_FORWARD_SHELL.format(router_kind=router_kind, shared=shared)