2from functools
import wraps
4from typeguard
import typechecked
8max_data_len : maximum data length, sum of maximum sequence lengths on all NPU cores. Defaults to 4096.
9max_seq_len : maximum sequence length. Defaults to 4096.
10max_cache_len : maximum cache length. Defaults to 4096.
11random_seq_len_calib : sequence length for random calibration. Defaults to 80.
12use_full_seq_len_calib : whether to use full sequence length for calibration for the last attention layer. Defaults to False.
13use_custom_mask_input : whether to use custom mask input. Defaults to False.
14start_dram_offset : start dram offset. Defaults to 0.
15use_global_core : whether to use global core. Defaults to False.
16llm_batch_size : batch size for LLM. Defaults to 1.
17npu_core_ids : NPU core IDs to use(batched LLM). Defaults to [0]. If the llm_batch_size is greater than 1, then defaults to [0, 1, 2, 3, 4, 5, 6, 7].
23 "max_data_len":
"maxDataLen",
24 "max_seq_len":
"maxSeqLen",
25 "max_cache_len":
"maxCacheLen",
26 "random_seq_len_calib":
"randomSeqLenCalib",
27 "use_full_seq_len_calib":
"useFullSeqLenCalib",
28 "use_custom_mask_input":
"useCustomMaskInput",
29 "start_dram_offset":
"startDramOffset",
30 "use_global_core":
"useGlobalCore",
31 "llm_batch_size":
"llmBatchSize",
32 "npu_core_ids":
"npuCoreIds",
36 "max_data_len": [0,
None],
37 "max_seq_len": [0,
None],
38 "max_cache_len": [0,
None],
39 "random_seq_len_calib": [0,
None],
40 "use_full_seq_len_calib": [0, 1],
41 "use_custom_mask_input": [0, 1],
42 "start_dram_offset": [0,
None],
43 "use_global_core": [0, 1],
44 "llm_batch_size": [0,
None],
53 random_seq_len_calib: int,
54 use_full_seq_len_calib: bool,
55 use_custom_mask_input: bool,
56 start_dram_offset: int,
57 use_global_core: bool,
59 npu_core_ids: list[int],
60 optional: bool =
True,
62 super().__init__(optional)
76 def default_config(cls):
80 random_seq_len_calib = 80
81 use_full_seq_len_calib =
False
82 use_custom_mask_input =
False
84 use_global_core =
False
90 max_data_len=max_data_len,
91 max_seq_len=max_seq_len,
92 max_cache_len=max_cache_len,
93 random_seq_len_calib=random_seq_len_calib,
94 use_full_seq_len_calib=use_full_seq_len_calib,
95 use_custom_mask_input=use_custom_mask_input,
96 start_dram_offset=start_dram_offset,
97 use_global_core=use_global_core,
98 llm_batch_size=llm_batch_size,
99 npu_core_ids=npu_core_ids,
103 llm_config_dict = dict()
105 for py_name, cpp_name
in LlmConfig.py_to_cpp_name.items():
106 value = getattr(self, py_name)
107 llm_params[cpp_name] = value
108 llm_config_dict[
"LLM"] = llm_params
109 return llm_config_dict
112def track_passed_args(fn):
114 def wrapper(*args, **kwargs):
115 sig = inspect.signature(fn)
116 bound_args = sig.bind_partial(*args, **kwargs)
120 if "llm_batch_size" in bound_args.arguments:
121 llm_batch_size = bound_args.arguments[
"llm_batch_size"]
122 if llm_batch_size > 1
and "npu_core_ids" not in bound_args.arguments:
123 npu_core_ids = [0, 1, 2, 3, 4, 5, 6, 7]
126 bound_args.apply_defaults()
128 bound_args.arguments[
"npu_core_ids"] = npu_core_ids
130 return fn(**bound_args.arguments)
137 max_data_len: int = 4096,
138 max_seq_len: int = 4096,
139 max_cache_len: int = 4096,
140 random_seq_len_calib: int = 80,
141 use_full_seq_len_calib: bool =
False,
142 use_custom_mask_input: bool =
False,
143 start_dram_offset: int = 0,
144 use_global_core: bool =
False,
145 llm_batch_size: int = 1,
146 npu_core_ids: list[int] = [0],
149 max_data_len=max_data_len,
150 max_seq_len=max_seq_len,
151 max_cache_len=max_cache_len,
152 random_seq_len_calib=random_seq_len_calib,
153 use_full_seq_len_calib=use_full_seq_len_calib,
154 use_custom_mask_input=use_custom_mask_input,
155 start_dram_offset=start_dram_offset,
156 use_global_core=use_global_core,
157 llm_batch_size=llm_batch_size,
158 npu_core_ids=npu_core_ids,