MCPcopy Create free account
hub / github.com/InternScience/SciReason / __init__

Method __init__

opencompass/models/interntrain.py:135–206  ·  view source on GitHub ↗
(self,
                 path: str,
                 module_path: str,
                 max_seq_len: int = 2048,
                 tokenizer_only: bool = False,
                 tokenizer_path: Optional[str] = None,
                 tokenizer_type: str = 'INTERNLM',
                 model_config: Optional[Union[str, Dict]] = None,
                 parallel_config: Optional[str] = None,
                 model_type: str = 'INTERNLM2',
                 ckpt_type: Optional[str] = None,
                 meta_template: Optional[Dict] = None,
                 model_dtype: Optional[str] = None,
                 generation_kwargs={},
                 sync_rank: bool = False,
                 mode='none',
                 end_str: Optional[str] = None)

Source from the content-addressed store, hash-verified

133 """
134
135 def __init__(self,
136 path: str,
137 module_path: str,
138 max_seq_len: int = 2048,
139 tokenizer_only: bool = False,
140 tokenizer_path: Optional[str] = None,
141 tokenizer_type: str = 'INTERNLM',
142 model_config: Optional[Union[str, Dict]] = None,
143 parallel_config: Optional[str] = None,
144 model_type: str = 'INTERNLM2',
145 ckpt_type: Optional[str] = None,
146 meta_template: Optional[Dict] = None,
147 model_dtype: Optional[str] = None,
148 generation_kwargs={},
149 sync_rank: bool = False,
150 mode='none',
151 end_str: Optional[str] = None):
152
153 super().__init__(path=path,
154 max_seq_len=max_seq_len,
155 tokenizer_only=tokenizer_only,
156 meta_template=meta_template,
157 sync_rank=sync_rank)
158
159 self.logger = get_logger()
160 # insert interntrain module
161 self.manager = InternTrainManager.build(module_path)
162
163 # TODO: mode is not a good name, change it both here and huggingface.py
164 # mode = 'mid' is used only in longtext eval, which cut off tokens in
165 # the middle
166 # https://github.com/THUDM/LongBench
167 assert mode in ['none', 'mid']
168 self.mode = mode
169
170 self._load_tokenizer(tokenizer_path=tokenizer_path,
171 tokenizer_type=tokenizer_type)
172
173 if not tokenizer_only:
174 self._load_model(path=path,
175 model_config=model_config,
176 parallel_config=parallel_config,
177 model_type=model_type,
178 model_dtype=model_dtype,
179 ckpt_type=ckpt_type)
180
181 # default generation_kwargs
182 assert generation_kwargs.pop('num_return_sequences', 1) == 1 # TODO
183 self.generation_kwargs = {
184 'temperature': 1.0,
185 'top_p': 1.0,
186 'top_k': 50,
187 'do_sample': False,
188 'repetition_penalty': 1.0,
189 }
190 self.generation_kwargs.update(generation_kwargs)
191 self.logger.info(f'generation_kwargs: {self.generation_kwargs}')
192

Callers

nothing calls this directly

Calls 6

_load_tokenizerMethod · 0.95
_load_modelMethod · 0.95
get_loggerFunction · 0.90
buildMethod · 0.80
updateMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected