MCPcopy Create free account
hub / github.com/huggingface/evaluate / __init__

Method __init__

src/evaluate/module.py:180–251  ·  view source on GitHub ↗
(
        self,
        config_name: Optional[str] = None,
        keep_in_memory: bool = False,
        cache_dir: Optional[str] = None,
        num_process: int = 1,
        process_id: int = 0,
        seed: Optional[int] = None,
        experiment_id: Optional[str] = None,
        hash: str = None,
        max_concurrent_cache_files: int = 10000,
        timeout: Union[int, float] = 100,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

178 """
179
180 def __init__(
181 self,
182 config_name: Optional[str] = None,
183 keep_in_memory: bool = False,
184 cache_dir: Optional[str] = None,
185 num_process: int = 1,
186 process_id: int = 0,
187 seed: Optional[int] = None,
188 experiment_id: Optional[str] = None,
189 hash: str = None,
190 max_concurrent_cache_files: int = 10000,
191 timeout: Union[int, float] = 100,
192 **kwargs,
193 ):
194 # prepare info
195 self.config_name = config_name or "default"
196 info = self._info()
197 info.module_name = camelcase_to_snakecase(self.__class__.__name__)
198 info.config_name = self.config_name
199 info.experiment_id = experiment_id or "default_experiment"
200 EvaluationModuleInfoMixin.__init__(self, info) # For easy access on low level
201
202 # Safety checks on num_process and process_id
203 if not isinstance(process_id, int) or process_id < 0:
204 raise ValueError("'process_id' should be a number greater than 0")
205 if not isinstance(num_process, int) or num_process <= process_id:
206 raise ValueError("'num_process' should be a number greater than process_id")
207 if keep_in_memory and num_process != 1:
208 raise ValueError("Using 'keep_in_memory' is not possible in distributed setting (num_process > 1).")
209
210 self.num_process = num_process
211 self.process_id = process_id
212 self.max_concurrent_cache_files = max_concurrent_cache_files
213
214 self.keep_in_memory = keep_in_memory
215 self._data_dir_root = os.path.expanduser(cache_dir or config.HF_METRICS_CACHE)
216 self.data_dir = self._build_data_dir()
217 if seed is None:
218 _, seed, pos, *_ = np.random.get_state()
219 self.seed: int = seed[pos] if pos < 624 else seed[0]
220 else:
221 self.seed: int = seed
222 self.timeout: Union[int, float] = timeout
223
224 # Update 'compute' and 'add' docstring
225 # methods need to be copied otherwise it changes the docstrings of every instance
226 self.compute = types.MethodType(copyfunc(self.compute), self)
227 self.add_batch = types.MethodType(copyfunc(self.add_batch), self)
228 self.add = types.MethodType(copyfunc(self.add), self)
229 self.compute.__func__.__doc__ += self.info.inputs_description
230 self.add_batch.__func__.__doc__ += self.info.inputs_description
231 self.add.__func__.__doc__ += self.info.inputs_description
232
233 # self.arrow_schema = pa.schema(field for field in self.info.features.type)
234 self.selected_feature_format = None
235 self.buf_writer = None
236 self.writer = None
237 self.writer_batch_size = None

Callers

nothing calls this directly

Calls 4

_infoMethod · 0.95
_build_data_dirMethod · 0.95
camelcase_to_snakecaseFunction · 0.85
__init__Method · 0.45

Tested by

no test coverage detected