euroeval.utils¶
source module euroeval.utils
Utility functions to be used in other scripts.
Functions
-
resolve_model_path — Resolve the path to the directory containing the model config files and weights.
-
clear_memory — Clears the memory of unused items.
-
enforce_reproducibility — Ensures reproducibility of experiments.
-
get_min_cuda_compute_capability — Gets the lowest cuda capability.
-
internet_connection_available — Checks if internet connection is available.
-
raise_if_model_output_contains_nan_values — Raise an exception if the model output contains NaN values.
-
get_hf_token — Get the Hugging Face token.
source resolve_model_path(download_dir: str) → str
Resolve the path to the directory containing the model config files and weights.
Parameters
-
download_dir : str — The download directory
Returns
-
str — The path to the model.
Raises
-
InvalidModel — If the model path is not valid, or if required files are missing.
source clear_memory() → None
Clears the memory of unused items.
source enforce_reproducibility(seed: int = 4242) → np.random.Generator
Ensures reproducibility of experiments.
Parameters
-
seed : int — Seed for the random number generator.
Returns
-
np.random.Generator — A numpy random generator
source get_min_cuda_compute_capability() → float | None
Gets the lowest cuda capability.
Returns
-
float | None — Device capability as float, or None if CUDA is not available.
source internet_connection_available() → bool
Checks if internet connection is available.
Returns
-
bool — Whether or not internet connection is available.
Raises
-
e
source raise_if_model_output_contains_nan_values(model_output: Predictions) → None
Raise an exception if the model output contains NaN values.
Parameters
-
model_output : Predictions — The model output to check.
Raises
-
NaNValueInModelOutput — If the model output contains NaN values.
source get_hf_token(api_key: str | None) → str | bool
Get the Hugging Face token.
Parameters
-
api_key : str | None — The API key to use as the Hugging Face token. If None, we will try to extract it in other ways.
Returns
-
str | bool — The Hugging Face token, or True if no token is set but the user is logged in, or False if no token is set and the user is not logged in.